kicad-to-circuit-json 0.0.136 → 0.0.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +299 -194
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1025,6 +1025,257 @@ function createCustomPlatedHole(params) {
|
|
|
1025
1025
|
ctx.db.pcb_plated_hole.insert(platedHole);
|
|
1026
1026
|
}
|
|
1027
1027
|
|
|
1028
|
+
// lib/stages/pcb/arc-utils.ts
|
|
1029
|
+
var FULL_TURN = Math.PI * 2;
|
|
1030
|
+
function normalizeToArray(value) {
|
|
1031
|
+
if (!value) return [];
|
|
1032
|
+
return Array.isArray(value) ? value : [value];
|
|
1033
|
+
}
|
|
1034
|
+
function getLayerNames(layer) {
|
|
1035
|
+
if (!layer) return [];
|
|
1036
|
+
if (typeof layer === "string") return [layer];
|
|
1037
|
+
return layer.names || [];
|
|
1038
|
+
}
|
|
1039
|
+
function getGraphicLayerNames(graphic) {
|
|
1040
|
+
return getLayerNames(graphic?.layer);
|
|
1041
|
+
}
|
|
1042
|
+
function getPcbPoint(point) {
|
|
1043
|
+
return {
|
|
1044
|
+
x: point?.x ?? 0,
|
|
1045
|
+
y: point?.y ?? 0
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
function getLineStartEnd(line) {
|
|
1049
|
+
return {
|
|
1050
|
+
start: getPcbPoint(line.start),
|
|
1051
|
+
end: getPcbPoint(line.end)
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function getArcStartMidEnd(arc) {
|
|
1055
|
+
return {
|
|
1056
|
+
start: getPcbPoint(arc.start),
|
|
1057
|
+
mid: getPcbPoint(arc.mid),
|
|
1058
|
+
end: getPcbPoint(arc.end)
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
function getCircleCenterEnd(circle) {
|
|
1062
|
+
return {
|
|
1063
|
+
center: getPcbPoint(circle.center),
|
|
1064
|
+
end: getPcbPoint(circle.end)
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
function getGraphicArcs(kicadPcb) {
|
|
1068
|
+
return normalizeToArray(kicadPcb.graphicArcs);
|
|
1069
|
+
}
|
|
1070
|
+
function getGraphicCircles(kicadPcb) {
|
|
1071
|
+
return normalizeToArray(kicadPcb.graphicCircles);
|
|
1072
|
+
}
|
|
1073
|
+
function getGraphicCurves(kicadPcb) {
|
|
1074
|
+
return normalizeToArray(kicadPcb.graphicCurves);
|
|
1075
|
+
}
|
|
1076
|
+
function getTopLevelCopperArcs(kicadPcb) {
|
|
1077
|
+
return normalizeToArray(kicadPcb.arcs);
|
|
1078
|
+
}
|
|
1079
|
+
function approximateArcPoints(params) {
|
|
1080
|
+
const { start, mid, end, segmentLength = 0.25, minSegments = 8 } = params;
|
|
1081
|
+
const geometry = getArcGeometry({ start, mid, end });
|
|
1082
|
+
if (!geometry) {
|
|
1083
|
+
return [start, end];
|
|
1084
|
+
}
|
|
1085
|
+
const arcLength = Math.abs(geometry.radius * geometry.sweepAngle);
|
|
1086
|
+
const numSegments = Math.max(
|
|
1087
|
+
2,
|
|
1088
|
+
minSegments,
|
|
1089
|
+
Math.ceil(arcLength / segmentLength)
|
|
1090
|
+
);
|
|
1091
|
+
const points = [];
|
|
1092
|
+
for (let i = 0; i <= numSegments; i++) {
|
|
1093
|
+
const t = i / numSegments;
|
|
1094
|
+
const angle = geometry.startAngle + geometry.sweepAngle * t;
|
|
1095
|
+
points.push({
|
|
1096
|
+
x: geometry.center.x + geometry.radius * Math.cos(angle),
|
|
1097
|
+
y: geometry.center.y + geometry.radius * Math.sin(angle)
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
return points;
|
|
1101
|
+
}
|
|
1102
|
+
function getCurvePoints(curve) {
|
|
1103
|
+
const ptsData = curve.points?.points ?? [];
|
|
1104
|
+
const xyPoints = ptsData.filter((point) => point.token === "xy").map((point) => getPcbPoint(point));
|
|
1105
|
+
if (xyPoints.length < 4) {
|
|
1106
|
+
return null;
|
|
1107
|
+
}
|
|
1108
|
+
return {
|
|
1109
|
+
start: xyPoints[0],
|
|
1110
|
+
control1: xyPoints[1],
|
|
1111
|
+
control2: xyPoints[2],
|
|
1112
|
+
end: xyPoints[3]
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
function approximateCubicBezierPoints(params) {
|
|
1116
|
+
const {
|
|
1117
|
+
start,
|
|
1118
|
+
control1,
|
|
1119
|
+
control2,
|
|
1120
|
+
end,
|
|
1121
|
+
segmentLength = 0.25,
|
|
1122
|
+
minSegments = 8
|
|
1123
|
+
} = params;
|
|
1124
|
+
const controlPolygonLength = getDistance(start, control1) + getDistance(control1, control2) + getDistance(control2, end);
|
|
1125
|
+
const numSegments = Math.max(
|
|
1126
|
+
2,
|
|
1127
|
+
minSegments,
|
|
1128
|
+
Math.ceil(controlPolygonLength / segmentLength)
|
|
1129
|
+
);
|
|
1130
|
+
const points = [];
|
|
1131
|
+
for (let i = 0; i <= numSegments; i++) {
|
|
1132
|
+
const t = i / numSegments;
|
|
1133
|
+
const omt = 1 - t;
|
|
1134
|
+
points.push({
|
|
1135
|
+
x: omt ** 3 * start.x + 3 * omt ** 2 * t * control1.x + 3 * omt * t ** 2 * control2.x + t ** 3 * end.x,
|
|
1136
|
+
y: omt ** 3 * start.y + 3 * omt ** 2 * t * control1.y + 3 * omt * t ** 2 * control2.y + t ** 3 * end.y
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
return points;
|
|
1140
|
+
}
|
|
1141
|
+
function approximateCirclePoints(params) {
|
|
1142
|
+
const { center, end, segmentLength = 0.25, minSegments = 16 } = params;
|
|
1143
|
+
const radius = getDistance(center, end);
|
|
1144
|
+
if (radius <= 0) {
|
|
1145
|
+
return [center];
|
|
1146
|
+
}
|
|
1147
|
+
const circumference = FULL_TURN * radius;
|
|
1148
|
+
const numSegments = Math.max(
|
|
1149
|
+
8,
|
|
1150
|
+
minSegments,
|
|
1151
|
+
Math.ceil(circumference / segmentLength)
|
|
1152
|
+
);
|
|
1153
|
+
const startAngle = Math.atan2(end.y - center.y, end.x - center.x);
|
|
1154
|
+
const points = [];
|
|
1155
|
+
for (let i = 0; i <= numSegments; i++) {
|
|
1156
|
+
const t = i / numSegments;
|
|
1157
|
+
const angle = startAngle + FULL_TURN * t;
|
|
1158
|
+
points.push({
|
|
1159
|
+
x: center.x + radius * Math.cos(angle),
|
|
1160
|
+
y: center.y + radius * Math.sin(angle)
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
return points;
|
|
1164
|
+
}
|
|
1165
|
+
function getArcGeometry(params) {
|
|
1166
|
+
const { start, mid, end } = params;
|
|
1167
|
+
const circle = calculateArcCenter2({ start, mid, end });
|
|
1168
|
+
if (!circle) {
|
|
1169
|
+
return null;
|
|
1170
|
+
}
|
|
1171
|
+
const startAngle = Math.atan2(
|
|
1172
|
+
start.y - circle.center.y,
|
|
1173
|
+
start.x - circle.center.x
|
|
1174
|
+
);
|
|
1175
|
+
const midAngle = Math.atan2(mid.y - circle.center.y, mid.x - circle.center.x);
|
|
1176
|
+
const endAngle = Math.atan2(end.y - circle.center.y, end.x - circle.center.x);
|
|
1177
|
+
let sweepAngle = normalizeSignedAngle(endAngle - startAngle);
|
|
1178
|
+
const midSweep = normalizeSignedAngle(midAngle - startAngle);
|
|
1179
|
+
const isCounterClockwise = sweepAngle > 0;
|
|
1180
|
+
const midIsBetween = isCounterClockwise && midSweep > 0 && midSweep < sweepAngle || !isCounterClockwise && midSweep < 0 && midSweep > sweepAngle;
|
|
1181
|
+
if (!midIsBetween) {
|
|
1182
|
+
sweepAngle = sweepAngle > 0 ? sweepAngle - FULL_TURN : sweepAngle + FULL_TURN;
|
|
1183
|
+
}
|
|
1184
|
+
return {
|
|
1185
|
+
center: circle.center,
|
|
1186
|
+
radius: circle.radius,
|
|
1187
|
+
startAngle,
|
|
1188
|
+
sweepAngle
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
function normalizeSignedAngle(angle) {
|
|
1192
|
+
while (angle <= -Math.PI) angle += FULL_TURN;
|
|
1193
|
+
while (angle > Math.PI) angle -= FULL_TURN;
|
|
1194
|
+
return angle;
|
|
1195
|
+
}
|
|
1196
|
+
function calculateArcCenter2(params) {
|
|
1197
|
+
const { start, mid, end } = params;
|
|
1198
|
+
const ax = start.x;
|
|
1199
|
+
const ay = start.y;
|
|
1200
|
+
const bx = mid.x;
|
|
1201
|
+
const by = mid.y;
|
|
1202
|
+
const cx = end.x;
|
|
1203
|
+
const cy = end.y;
|
|
1204
|
+
const determinant = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
|
|
1205
|
+
if (Math.abs(determinant) < 1e-10) {
|
|
1206
|
+
return null;
|
|
1207
|
+
}
|
|
1208
|
+
const ux = ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by) * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / determinant;
|
|
1209
|
+
const uy = ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by) * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / determinant;
|
|
1210
|
+
return {
|
|
1211
|
+
center: { x: ux, y: uy },
|
|
1212
|
+
radius: Math.sqrt((ax - ux) ** 2 + (ay - uy) ** 2)
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
function getDistance(a, b) {
|
|
1216
|
+
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// lib/stages/pcb/CollectFootprintsStage/get-chamfered-pad-points.ts
|
|
1220
|
+
function getChamferedPadPoints({
|
|
1221
|
+
width,
|
|
1222
|
+
height,
|
|
1223
|
+
chamferRatio,
|
|
1224
|
+
chamferCorners,
|
|
1225
|
+
roundrectRatio
|
|
1226
|
+
}) {
|
|
1227
|
+
const corners = [
|
|
1228
|
+
{ name: "top_left", x: -width / 2, y: -height / 2 },
|
|
1229
|
+
{ name: "top_right", x: width / 2, y: -height / 2 },
|
|
1230
|
+
{ name: "bottom_right", x: width / 2, y: height / 2 },
|
|
1231
|
+
{ name: "bottom_left", x: -width / 2, y: height / 2 }
|
|
1232
|
+
];
|
|
1233
|
+
const points = [];
|
|
1234
|
+
for (let i = 0; i < corners.length; i++) {
|
|
1235
|
+
const corner = corners[i];
|
|
1236
|
+
const previous = corners[(i + 3) % 4];
|
|
1237
|
+
const next = corners[(i + 1) % 4];
|
|
1238
|
+
const chamfered = chamferCorners.includes(corner.name);
|
|
1239
|
+
const distance = Math.min(width, height) * (chamfered ? chamferRatio : roundrectRatio);
|
|
1240
|
+
if (distance === 0) {
|
|
1241
|
+
points.push({ x: corner.x, y: corner.y });
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
const incoming = {
|
|
1245
|
+
x: Math.sign(previous.x - corner.x),
|
|
1246
|
+
y: Math.sign(previous.y - corner.y)
|
|
1247
|
+
};
|
|
1248
|
+
const outgoing = {
|
|
1249
|
+
x: Math.sign(next.x - corner.x),
|
|
1250
|
+
y: Math.sign(next.y - corner.y)
|
|
1251
|
+
};
|
|
1252
|
+
const start = {
|
|
1253
|
+
x: corner.x + incoming.x * distance,
|
|
1254
|
+
y: corner.y + incoming.y * distance
|
|
1255
|
+
};
|
|
1256
|
+
const end = {
|
|
1257
|
+
x: corner.x + outgoing.x * distance,
|
|
1258
|
+
y: corner.y + outgoing.y * distance
|
|
1259
|
+
};
|
|
1260
|
+
if (chamfered) {
|
|
1261
|
+
points.push(start, end);
|
|
1262
|
+
} else {
|
|
1263
|
+
const inset = distance * (1 - 1 / Math.SQRT2);
|
|
1264
|
+
points.push(
|
|
1265
|
+
...approximateArcPoints({
|
|
1266
|
+
start,
|
|
1267
|
+
end,
|
|
1268
|
+
mid: {
|
|
1269
|
+
x: corner.x + (incoming.x + outgoing.x) * inset,
|
|
1270
|
+
y: corner.y + (incoming.y + outgoing.y) * inset
|
|
1271
|
+
}
|
|
1272
|
+
})
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return points;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1028
1279
|
// lib/stages/pcb/CollectFootprintsStage/get-supported-pad-type.ts
|
|
1029
1280
|
function getSupportedPadType(pad) {
|
|
1030
1281
|
switch (pad.padType) {
|
|
@@ -1259,6 +1510,38 @@ function createSmdPad({
|
|
|
1259
1510
|
}) {
|
|
1260
1511
|
const layers = pad.layers || [];
|
|
1261
1512
|
const layer = determineLayerFromLayers(layers);
|
|
1513
|
+
const chamferRatio = pad.chamferRatio;
|
|
1514
|
+
const chamferCorners = pad.chamferCorners;
|
|
1515
|
+
if (shape === "roundrect" && chamferRatio && chamferCorners?.length) {
|
|
1516
|
+
const points = getChamferedPadPoints({
|
|
1517
|
+
width: size.x,
|
|
1518
|
+
height: size.y,
|
|
1519
|
+
chamferRatio,
|
|
1520
|
+
chamferCorners,
|
|
1521
|
+
roundrectRatio: pad.roundrectRatio ?? 0
|
|
1522
|
+
}).map((point) => {
|
|
1523
|
+
const rotated = rotatePoint({
|
|
1524
|
+
point,
|
|
1525
|
+
ccwRotationDegrees: customPrimitiveKicadRotationDegrees
|
|
1526
|
+
});
|
|
1527
|
+
return applyToPoint3(ctx.k2cMatPcb, {
|
|
1528
|
+
x: padKicadPos.x + rotated.x,
|
|
1529
|
+
y: padKicadPos.y + rotated.y
|
|
1530
|
+
});
|
|
1531
|
+
});
|
|
1532
|
+
const smtpad = {
|
|
1533
|
+
type: "pcb_smtpad",
|
|
1534
|
+
shape: "polygon",
|
|
1535
|
+
pcb_component_id: componentId,
|
|
1536
|
+
pcb_port_id: pcbPortId,
|
|
1537
|
+
layer,
|
|
1538
|
+
port_hints: [pad.number.toString()],
|
|
1539
|
+
points
|
|
1540
|
+
};
|
|
1541
|
+
ctx.db.pcb_smtpad.insert(smtpad);
|
|
1542
|
+
if (ctx.stats) ctx.stats.pads = (ctx.stats.pads || 0) + 1;
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1262
1545
|
if (shape === "custom") {
|
|
1263
1546
|
const primitives = pad.primitives?.graphics ?? [];
|
|
1264
1547
|
let primitivesProcessed = 0;
|
|
@@ -2004,10 +2287,25 @@ function processFootprint(ctx, footprint) {
|
|
|
2004
2287
|
const hasReference = Boolean(refdes?.trim());
|
|
2005
2288
|
const value = getFootprintValue(footprint);
|
|
2006
2289
|
const jlcpcbPartNumbers = getJlcpcbPartNumbers(footprint);
|
|
2290
|
+
const manufacturerPartNumber = findFootprintPropertyValue(
|
|
2291
|
+
footprint,
|
|
2292
|
+
"MPN"
|
|
2293
|
+
)?.trim();
|
|
2294
|
+
const manufacturer = findFootprintPropertyValue(
|
|
2295
|
+
footprint,
|
|
2296
|
+
"Manufacturer"
|
|
2297
|
+
)?.trim();
|
|
2298
|
+
if (manufacturer) {
|
|
2299
|
+
;
|
|
2300
|
+
(ctx.warnings ??= []).push(
|
|
2301
|
+
`Footprint ${refdes || uuid}: Manufacturer ${JSON.stringify(manufacturer)} is not supported by Circuit JSON and was not imported.`
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2007
2304
|
const ftype = inferComponentType(refdes, footprint);
|
|
2008
2305
|
const sourceComponentData = {
|
|
2009
2306
|
name: refdes ?? "",
|
|
2010
|
-
ftype
|
|
2307
|
+
ftype,
|
|
2308
|
+
...manufacturerPartNumber ? { manufacturer_part_number: manufacturerPartNumber } : {}
|
|
2011
2309
|
};
|
|
2012
2310
|
if (ftype === "simple_transistor") {
|
|
2013
2311
|
sourceComponentData.transistor_type = inferTransistorTypeFromFootprint(
|
|
@@ -3077,199 +3375,6 @@ var CollectFootprintsStage = class extends ConverterStage {
|
|
|
3077
3375
|
|
|
3078
3376
|
// lib/stages/pcb/CollectGraphicsStage.ts
|
|
3079
3377
|
import { applyToPoint as applyToPoint7 } from "transformation-matrix";
|
|
3080
|
-
|
|
3081
|
-
// lib/stages/pcb/arc-utils.ts
|
|
3082
|
-
var FULL_TURN = Math.PI * 2;
|
|
3083
|
-
function normalizeToArray(value) {
|
|
3084
|
-
if (!value) return [];
|
|
3085
|
-
return Array.isArray(value) ? value : [value];
|
|
3086
|
-
}
|
|
3087
|
-
function getLayerNames(layer) {
|
|
3088
|
-
if (!layer) return [];
|
|
3089
|
-
if (typeof layer === "string") return [layer];
|
|
3090
|
-
return layer.names || [];
|
|
3091
|
-
}
|
|
3092
|
-
function getGraphicLayerNames(graphic) {
|
|
3093
|
-
return getLayerNames(graphic?.layer);
|
|
3094
|
-
}
|
|
3095
|
-
function getPcbPoint(point) {
|
|
3096
|
-
return {
|
|
3097
|
-
x: point?.x ?? 0,
|
|
3098
|
-
y: point?.y ?? 0
|
|
3099
|
-
};
|
|
3100
|
-
}
|
|
3101
|
-
function getLineStartEnd(line) {
|
|
3102
|
-
return {
|
|
3103
|
-
start: getPcbPoint(line.start),
|
|
3104
|
-
end: getPcbPoint(line.end)
|
|
3105
|
-
};
|
|
3106
|
-
}
|
|
3107
|
-
function getArcStartMidEnd(arc) {
|
|
3108
|
-
return {
|
|
3109
|
-
start: getPcbPoint(arc.start),
|
|
3110
|
-
mid: getPcbPoint(arc.mid),
|
|
3111
|
-
end: getPcbPoint(arc.end)
|
|
3112
|
-
};
|
|
3113
|
-
}
|
|
3114
|
-
function getCircleCenterEnd(circle) {
|
|
3115
|
-
return {
|
|
3116
|
-
center: getPcbPoint(circle.center),
|
|
3117
|
-
end: getPcbPoint(circle.end)
|
|
3118
|
-
};
|
|
3119
|
-
}
|
|
3120
|
-
function getGraphicArcs(kicadPcb) {
|
|
3121
|
-
return normalizeToArray(kicadPcb.graphicArcs);
|
|
3122
|
-
}
|
|
3123
|
-
function getGraphicCircles(kicadPcb) {
|
|
3124
|
-
return normalizeToArray(kicadPcb.graphicCircles);
|
|
3125
|
-
}
|
|
3126
|
-
function getGraphicCurves(kicadPcb) {
|
|
3127
|
-
return normalizeToArray(kicadPcb.graphicCurves);
|
|
3128
|
-
}
|
|
3129
|
-
function getTopLevelCopperArcs(kicadPcb) {
|
|
3130
|
-
return normalizeToArray(kicadPcb.arcs);
|
|
3131
|
-
}
|
|
3132
|
-
function approximateArcPoints(params) {
|
|
3133
|
-
const { start, mid, end, segmentLength = 0.25, minSegments = 8 } = params;
|
|
3134
|
-
const geometry = getArcGeometry({ start, mid, end });
|
|
3135
|
-
if (!geometry) {
|
|
3136
|
-
return [start, end];
|
|
3137
|
-
}
|
|
3138
|
-
const arcLength = Math.abs(geometry.radius * geometry.sweepAngle);
|
|
3139
|
-
const numSegments = Math.max(
|
|
3140
|
-
2,
|
|
3141
|
-
minSegments,
|
|
3142
|
-
Math.ceil(arcLength / segmentLength)
|
|
3143
|
-
);
|
|
3144
|
-
const points = [];
|
|
3145
|
-
for (let i = 0; i <= numSegments; i++) {
|
|
3146
|
-
const t = i / numSegments;
|
|
3147
|
-
const angle = geometry.startAngle + geometry.sweepAngle * t;
|
|
3148
|
-
points.push({
|
|
3149
|
-
x: geometry.center.x + geometry.radius * Math.cos(angle),
|
|
3150
|
-
y: geometry.center.y + geometry.radius * Math.sin(angle)
|
|
3151
|
-
});
|
|
3152
|
-
}
|
|
3153
|
-
return points;
|
|
3154
|
-
}
|
|
3155
|
-
function getCurvePoints(curve) {
|
|
3156
|
-
const ptsData = curve.points?.points ?? [];
|
|
3157
|
-
const xyPoints = ptsData.filter((point) => point.token === "xy").map((point) => getPcbPoint(point));
|
|
3158
|
-
if (xyPoints.length < 4) {
|
|
3159
|
-
return null;
|
|
3160
|
-
}
|
|
3161
|
-
return {
|
|
3162
|
-
start: xyPoints[0],
|
|
3163
|
-
control1: xyPoints[1],
|
|
3164
|
-
control2: xyPoints[2],
|
|
3165
|
-
end: xyPoints[3]
|
|
3166
|
-
};
|
|
3167
|
-
}
|
|
3168
|
-
function approximateCubicBezierPoints(params) {
|
|
3169
|
-
const {
|
|
3170
|
-
start,
|
|
3171
|
-
control1,
|
|
3172
|
-
control2,
|
|
3173
|
-
end,
|
|
3174
|
-
segmentLength = 0.25,
|
|
3175
|
-
minSegments = 8
|
|
3176
|
-
} = params;
|
|
3177
|
-
const controlPolygonLength = getDistance(start, control1) + getDistance(control1, control2) + getDistance(control2, end);
|
|
3178
|
-
const numSegments = Math.max(
|
|
3179
|
-
2,
|
|
3180
|
-
minSegments,
|
|
3181
|
-
Math.ceil(controlPolygonLength / segmentLength)
|
|
3182
|
-
);
|
|
3183
|
-
const points = [];
|
|
3184
|
-
for (let i = 0; i <= numSegments; i++) {
|
|
3185
|
-
const t = i / numSegments;
|
|
3186
|
-
const omt = 1 - t;
|
|
3187
|
-
points.push({
|
|
3188
|
-
x: omt ** 3 * start.x + 3 * omt ** 2 * t * control1.x + 3 * omt * t ** 2 * control2.x + t ** 3 * end.x,
|
|
3189
|
-
y: omt ** 3 * start.y + 3 * omt ** 2 * t * control1.y + 3 * omt * t ** 2 * control2.y + t ** 3 * end.y
|
|
3190
|
-
});
|
|
3191
|
-
}
|
|
3192
|
-
return points;
|
|
3193
|
-
}
|
|
3194
|
-
function approximateCirclePoints(params) {
|
|
3195
|
-
const { center, end, segmentLength = 0.25, minSegments = 16 } = params;
|
|
3196
|
-
const radius = getDistance(center, end);
|
|
3197
|
-
if (radius <= 0) {
|
|
3198
|
-
return [center];
|
|
3199
|
-
}
|
|
3200
|
-
const circumference = FULL_TURN * radius;
|
|
3201
|
-
const numSegments = Math.max(
|
|
3202
|
-
8,
|
|
3203
|
-
minSegments,
|
|
3204
|
-
Math.ceil(circumference / segmentLength)
|
|
3205
|
-
);
|
|
3206
|
-
const startAngle = Math.atan2(end.y - center.y, end.x - center.x);
|
|
3207
|
-
const points = [];
|
|
3208
|
-
for (let i = 0; i <= numSegments; i++) {
|
|
3209
|
-
const t = i / numSegments;
|
|
3210
|
-
const angle = startAngle + FULL_TURN * t;
|
|
3211
|
-
points.push({
|
|
3212
|
-
x: center.x + radius * Math.cos(angle),
|
|
3213
|
-
y: center.y + radius * Math.sin(angle)
|
|
3214
|
-
});
|
|
3215
|
-
}
|
|
3216
|
-
return points;
|
|
3217
|
-
}
|
|
3218
|
-
function getArcGeometry(params) {
|
|
3219
|
-
const { start, mid, end } = params;
|
|
3220
|
-
const circle = calculateArcCenter2({ start, mid, end });
|
|
3221
|
-
if (!circle) {
|
|
3222
|
-
return null;
|
|
3223
|
-
}
|
|
3224
|
-
const startAngle = Math.atan2(
|
|
3225
|
-
start.y - circle.center.y,
|
|
3226
|
-
start.x - circle.center.x
|
|
3227
|
-
);
|
|
3228
|
-
const midAngle = Math.atan2(mid.y - circle.center.y, mid.x - circle.center.x);
|
|
3229
|
-
const endAngle = Math.atan2(end.y - circle.center.y, end.x - circle.center.x);
|
|
3230
|
-
let sweepAngle = normalizeSignedAngle(endAngle - startAngle);
|
|
3231
|
-
const midSweep = normalizeSignedAngle(midAngle - startAngle);
|
|
3232
|
-
const isCounterClockwise = sweepAngle > 0;
|
|
3233
|
-
const midIsBetween = isCounterClockwise && midSweep > 0 && midSweep < sweepAngle || !isCounterClockwise && midSweep < 0 && midSweep > sweepAngle;
|
|
3234
|
-
if (!midIsBetween) {
|
|
3235
|
-
sweepAngle = sweepAngle > 0 ? sweepAngle - FULL_TURN : sweepAngle + FULL_TURN;
|
|
3236
|
-
}
|
|
3237
|
-
return {
|
|
3238
|
-
center: circle.center,
|
|
3239
|
-
radius: circle.radius,
|
|
3240
|
-
startAngle,
|
|
3241
|
-
sweepAngle
|
|
3242
|
-
};
|
|
3243
|
-
}
|
|
3244
|
-
function normalizeSignedAngle(angle) {
|
|
3245
|
-
while (angle <= -Math.PI) angle += FULL_TURN;
|
|
3246
|
-
while (angle > Math.PI) angle -= FULL_TURN;
|
|
3247
|
-
return angle;
|
|
3248
|
-
}
|
|
3249
|
-
function calculateArcCenter2(params) {
|
|
3250
|
-
const { start, mid, end } = params;
|
|
3251
|
-
const ax = start.x;
|
|
3252
|
-
const ay = start.y;
|
|
3253
|
-
const bx = mid.x;
|
|
3254
|
-
const by = mid.y;
|
|
3255
|
-
const cx = end.x;
|
|
3256
|
-
const cy = end.y;
|
|
3257
|
-
const determinant = 2 * (ax * (by - cy) + bx * (cy - ay) + cx * (ay - by));
|
|
3258
|
-
if (Math.abs(determinant) < 1e-10) {
|
|
3259
|
-
return null;
|
|
3260
|
-
}
|
|
3261
|
-
const ux = ((ax * ax + ay * ay) * (by - cy) + (bx * bx + by * by) * (cy - ay) + (cx * cx + cy * cy) * (ay - by)) / determinant;
|
|
3262
|
-
const uy = ((ax * ax + ay * ay) * (cx - bx) + (bx * bx + by * by) * (ax - cx) + (cx * cx + cy * cy) * (bx - ax)) / determinant;
|
|
3263
|
-
return {
|
|
3264
|
-
center: { x: ux, y: uy },
|
|
3265
|
-
radius: Math.sqrt((ax - ux) ** 2 + (ay - uy) ** 2)
|
|
3266
|
-
};
|
|
3267
|
-
}
|
|
3268
|
-
function getDistance(a, b) {
|
|
3269
|
-
return Math.hypot(b.x - a.x, b.y - a.y);
|
|
3270
|
-
}
|
|
3271
|
-
|
|
3272
|
-
// lib/stages/pcb/CollectGraphicsStage.ts
|
|
3273
3378
|
var EDGE_CUT_POINT_EPSILON = 0.01;
|
|
3274
3379
|
function convertKiCadAngleToCircuitJsonCcwRotation2(rotationDegrees) {
|
|
3275
3380
|
if (!rotationDegrees) return 0;
|