Skip to content

Commit 5c61446

Browse files
authored
Honor ccw_rotation for plated pill hole cutouts (#156)
1 parent e8c0945 commit 5c61446

3 files changed

Lines changed: 38 additions & 41 deletions

File tree

lib/utils/pcb-board-geometry.ts

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
roundedRectangle,
1414
} from "@jscad/modeling/src/primitives"
1515
import type {
16-
PCBPlatedHole,
16+
PcbPlatedHole,
1717
PcbBoard,
1818
PcbHole,
1919
PcbPanel,
@@ -43,7 +43,7 @@ export { arePointsClockwise } from "./pcb-board-cutouts"
4343
export interface BoardGeometryOptions {
4444
thickness: number
4545
holes?: PcbHole[]
46-
platedHoles?: PCBPlatedHole[]
46+
platedHoles?: PcbPlatedHole[]
4747
cutouts?: BoardCutout[]
4848
drillQuality?: "high" | "fast"
4949
}
@@ -104,7 +104,7 @@ const createPillHoleWithSegments = (
104104
width: number,
105105
height: number,
106106
thickness: number,
107-
rotate: boolean,
107+
rotationRad: number = 0,
108108
segments: number = DEFAULT_QUALITY_MODE_SEGMENTS,
109109
): Geom3 => {
110110
const minDimension = Math.min(width, height)
@@ -119,8 +119,8 @@ const createPillHoleWithSegments = (
119119
let hole3d = extrudeLinear({ height: thickness + 1 }, hole2d)
120120
hole3d = translate([0, 0, -(thickness + 1) / 2], hole3d)
121121

122-
if (rotate) {
123-
hole3d = rotateZ(Math.PI / 2, hole3d)
122+
if (rotationRad !== 0) {
123+
hole3d = rotateZ(rotationRad, hole3d)
124124
}
125125

126126
return translate([x, y, 0], hole3d)
@@ -130,7 +130,7 @@ export const createHoleGeoms = (
130130
boardCenter: { x: number; y: number },
131131
thickness: number,
132132
holes: PcbHole[] = [],
133-
platedHoles: PCBPlatedHole[] = [],
133+
platedHoles: PcbPlatedHole[] = [],
134134
segments: number = DEFAULT_QUALITY_MODE_SEGMENTS,
135135
): Geom3[] => {
136136
const holeGeoms: Geom3[] = []
@@ -156,7 +156,7 @@ export const createHoleGeoms = (
156156
width,
157157
height,
158158
thickness,
159-
rotate,
159+
rotate ? Math.PI / 2 : 0,
160160
segments,
161161
),
162162
)
@@ -170,24 +170,17 @@ export const createHoleGeoms = (
170170

171171
const rotation = getNumberProperty(holeRecord, "ccw_rotation") ?? 0
172172
const rotationRad = -(rotation * Math.PI) / 180
173-
174-
const minDimension = Math.min(holeWidth, holeHeight)
175-
const maxAllowedRadius = Math.max(0, minDimension / 2 - RADIUS_EPSILON)
176-
const roundRadius =
177-
maxAllowedRadius <= 0 ? 0 : Math.min(holeHeight / 2, maxAllowedRadius)
178-
179-
const hole2d = roundedRectangle({
180-
size: [holeWidth, holeHeight],
181-
roundRadius,
182-
segments,
183-
})
184-
185-
let hole3d = extrudeLinear({ height: thickness + 1 }, hole2d)
186-
hole3d = translate([0, 0, -(thickness + 1) / 2], hole3d)
187-
if (rotationRad !== 0) {
188-
hole3d = rotateZ(rotationRad, hole3d)
189-
}
190-
holeGeoms.push(translate([relX, relY, 0], hole3d))
173+
holeGeoms.push(
174+
createPillHoleWithSegments(
175+
relX,
176+
relY,
177+
holeWidth,
178+
holeHeight,
179+
thickness,
180+
rotationRad,
181+
segments,
182+
),
183+
)
191184
continue
192185
}
193186

@@ -219,17 +212,16 @@ export const createHoleGeoms = (
219212
0
220213
if (!holeWidth || !holeHeight) continue
221214

222-
const rotate = holeHeight > holeWidth
223-
const width = rotate ? holeHeight : holeWidth
224-
const height = rotate ? holeWidth : holeHeight
215+
const rotation = getNumberProperty(platedRecord, "ccw_rotation") ?? 0
216+
const rotationRad = -(rotation * Math.PI) / 180
225217
holeGeoms.push(
226218
createPillHoleWithSegments(
227219
relX,
228220
relY,
229-
width,
230-
height,
221+
holeWidth,
222+
holeHeight,
231223
thickness,
232-
rotate,
224+
rotationRad,
233225
segments,
234226
),
235227
)

lib/utils/pcb-hole-loops.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export const createHoleLoops = ({
4646
const height = rotate ? holeWidth : holeHeight
4747

4848
let loop = createRoundedRectLoop({ width, height, segments })
49-
if (rotate) loop = rotateLoop({ loop, angle: Math.PI / 2 })
49+
if (rotate) {
50+
loop = rotateLoop({ loop, angle: Math.PI / 2 })
51+
}
5052
loops.push(translateLoop({ loop, offset: { x: relX, y: relY } }))
5153
continue
5254
}
@@ -56,17 +58,16 @@ export const createHoleLoops = ({
5658
const holeHeight = getNumberProperty(holeRecord, "hole_height")
5759
if (!holeWidth || !holeHeight) continue
5860

61+
const rotation = getNumberProperty(holeRecord, "ccw_rotation") ?? 0
62+
const rotationRad = -(rotation * Math.PI) / 180
5963
let loop = createRoundedRectLoop({
6064
width: holeWidth,
6165
height: holeHeight,
6266
segments,
6367
})
64-
const rotation = getNumberProperty(holeRecord, "ccw_rotation") ?? 0
65-
const rotationRad = -(rotation * Math.PI) / 180
6668
if (rotationRad !== 0) {
6769
loop = rotateLoop({ loop, angle: rotationRad })
6870
}
69-
7071
loops.push(translateLoop({ loop, offset: { x: relX, y: relY } }))
7172
continue
7273
}
@@ -104,12 +105,16 @@ export const createHoleLoops = ({
104105
0
105106
if (!holeWidth || !holeHeight) continue
106107

107-
const rotate = holeHeight > holeWidth
108-
const width = rotate ? holeHeight : holeWidth
109-
const height = rotate ? holeWidth : holeHeight
110-
111-
let loop = createRoundedRectLoop({ width, height, segments })
112-
if (rotate) loop = rotateLoop({ loop, angle: Math.PI / 2 })
108+
const rotation = getNumberProperty(platedRecord, "ccw_rotation") ?? 0
109+
const rotationRad = -(rotation * Math.PI) / 180
110+
let loop = createRoundedRectLoop({
111+
width: holeWidth,
112+
height: holeHeight,
113+
segments,
114+
})
115+
if (rotationRad !== 0) {
116+
loop = rotateLoop({ loop, angle: rotationRad })
117+
}
113118
loops.push(translateLoop({ loop, offset: { x: relX, y: relY } }))
114119
continue
115120
}
-365 Bytes
Loading

0 commit comments

Comments
 (0)