circuit-json-to-step 0.0.30 → 0.0.31

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 CHANGED
@@ -916,6 +916,11 @@ function rotatePoint(x, y, centerX, centerY, angle) {
916
916
  y: centerY + dx * sin + dy * cos
917
917
  };
918
918
  }
919
+ function createVertexAt(repo, x, y, z) {
920
+ return repo.add(
921
+ new VertexPoint2("", repo.add(new CartesianPoint3("", x, y, z)))
922
+ );
923
+ }
919
924
  function createLineEdge(repo, v1, v2) {
920
925
  const p1 = v1.resolve(repo).pnt.resolve(repo);
921
926
  const p2 = v2.resolve(repo).pnt.resolve(repo);
@@ -934,228 +939,54 @@ function createLineEdge(repo, v1, v2) {
934
939
  const line = repo.add(new Line2("", v1.resolve(repo).pnt, vec));
935
940
  return repo.add(new EdgeCurve2("", v1, v2, line, true));
936
941
  }
937
- function createArcEdge(repo, centerX, centerY, z, radius, startAngle, endAngle, rotation, centerX0, centerY0) {
938
- const startX = centerX + radius * Math.cos(startAngle);
939
- const startY = centerY + radius * Math.sin(startAngle);
940
- const endX = centerX + radius * Math.cos(endAngle);
941
- const endY = centerY + radius * Math.sin(endAngle);
942
- const startRotated = rotatePoint(startX, startY, centerX0, centerY0, rotation);
943
- const endRotated = rotatePoint(endX, endY, centerX0, centerY0, rotation);
944
- const startVertex = repo.add(
945
- new VertexPoint2(
946
- "",
947
- repo.add(new CartesianPoint3("", startRotated.x, startRotated.y, z))
948
- )
949
- );
950
- const endVertex = repo.add(
951
- new VertexPoint2(
952
- "",
953
- repo.add(new CartesianPoint3("", endRotated.x, endRotated.y, z))
954
- )
955
- );
956
- const centerRotated = rotatePoint(
957
- centerX,
958
- centerY,
942
+ function createLineSegment(repo, start, end, z) {
943
+ const startVertex = createVertexAt(repo, start.x, start.y, z);
944
+ const endVertex = createVertexAt(repo, end.x, end.y, z);
945
+ return {
946
+ kind: "line",
947
+ edge: createLineEdge(repo, startVertex, endVertex),
948
+ start: startVertex,
949
+ end: endVertex
950
+ };
951
+ }
952
+ function createArcSegment(repo, centerX, centerY, z, radius, startAngle, endAngle, rotation, centerX0, centerY0) {
953
+ const start = rotatePoint(
954
+ centerX + radius * Math.cos(startAngle),
955
+ centerY + radius * Math.sin(startAngle),
959
956
  centerX0,
960
957
  centerY0,
961
958
  rotation
962
959
  );
963
- const centerPoint = repo.add(
964
- new CartesianPoint3("", centerRotated.x, centerRotated.y, z)
960
+ const end = rotatePoint(
961
+ centerX + radius * Math.cos(endAngle),
962
+ centerY + radius * Math.sin(endAngle),
963
+ centerX0,
964
+ centerY0,
965
+ rotation
965
966
  );
967
+ const center = rotatePoint(centerX, centerY, centerX0, centerY0, rotation);
968
+ const startVertex = createVertexAt(repo, start.x, start.y, z);
969
+ const endVertex = createVertexAt(repo, end.x, end.y, z);
970
+ const centerPoint = repo.add(new CartesianPoint3("", center.x, center.y, z));
966
971
  const normalDir = repo.add(new Direction3("", 0, 0, -1));
967
- const refAngle = rotation;
968
972
  const refDir = repo.add(
969
- new Direction3("", Math.cos(refAngle), Math.sin(refAngle), 0)
973
+ new Direction3("", Math.cos(rotation), Math.sin(rotation), 0)
970
974
  );
971
975
  const placement = repo.add(
972
976
  new Axis2Placement3D3("", centerPoint, normalDir, refDir)
973
977
  );
974
978
  const circle = repo.add(new Circle("", placement, radius));
975
- return repo.add(new EdgeCurve2("", startVertex, endVertex, circle, false));
976
- }
977
- function createPillHoleLoop(repo, hole, z, xDir) {
978
- const geom = getPillGeometry(hole);
979
- const {
979
+ return {
980
+ kind: "arc",
981
+ edge: repo.add(new EdgeCurve2("", startVertex, endVertex, circle, false)),
982
+ start: startVertex,
983
+ end: endVertex,
980
984
  centerX,
981
985
  centerY,
982
- radius,
983
- straightHalfLength,
984
- rotation,
985
- isHorizontal
986
- } = geom;
987
- const edges = [];
988
- if (isHorizontal) {
989
- const capOffset = straightHalfLength;
990
- const rightArc = createArcEdge(
991
- repo,
992
- centerX + capOffset,
993
- centerY,
994
- z,
995
- radius,
996
- -Math.PI / 2,
997
- Math.PI / 2,
998
- rotation,
999
- centerX,
1000
- centerY
1001
- );
1002
- edges.push(rightArc);
1003
- const bottomStart = rotatePoint(
1004
- centerX + capOffset,
1005
- centerY - radius,
1006
- centerX,
1007
- centerY,
1008
- rotation
1009
- );
1010
- const bottomEnd = rotatePoint(
1011
- centerX - capOffset,
1012
- centerY - radius,
1013
- centerX,
1014
- centerY,
1015
- rotation
1016
- );
1017
- const bottomV1 = repo.add(
1018
- new VertexPoint2(
1019
- "",
1020
- repo.add(new CartesianPoint3("", bottomStart.x, bottomStart.y, z))
1021
- )
1022
- );
1023
- const bottomV2 = repo.add(
1024
- new VertexPoint2(
1025
- "",
1026
- repo.add(new CartesianPoint3("", bottomEnd.x, bottomEnd.y, z))
1027
- )
1028
- );
1029
- edges.push(createLineEdge(repo, bottomV1, bottomV2));
1030
- const leftArc = createArcEdge(
1031
- repo,
1032
- centerX - capOffset,
1033
- centerY,
1034
- z,
1035
- radius,
1036
- Math.PI / 2,
1037
- 3 * Math.PI / 2,
1038
- rotation,
1039
- centerX,
1040
- centerY
1041
- );
1042
- edges.push(leftArc);
1043
- const topStart = rotatePoint(
1044
- centerX - capOffset,
1045
- centerY + radius,
1046
- centerX,
1047
- centerY,
1048
- rotation
1049
- );
1050
- const topEnd = rotatePoint(
1051
- centerX + capOffset,
1052
- centerY + radius,
1053
- centerX,
1054
- centerY,
1055
- rotation
1056
- );
1057
- const topV1 = repo.add(
1058
- new VertexPoint2(
1059
- "",
1060
- repo.add(new CartesianPoint3("", topStart.x, topStart.y, z))
1061
- )
1062
- );
1063
- const topV2 = repo.add(
1064
- new VertexPoint2(
1065
- "",
1066
- repo.add(new CartesianPoint3("", topEnd.x, topEnd.y, z))
1067
- )
1068
- );
1069
- edges.push(createLineEdge(repo, topV1, topV2));
1070
- } else {
1071
- const capOffset = straightHalfLength;
1072
- const topArc = createArcEdge(
1073
- repo,
1074
- centerX,
1075
- centerY - capOffset,
1076
- z,
1077
- radius,
1078
- Math.PI,
1079
- 0,
1080
- rotation,
1081
- centerX,
1082
- centerY
1083
- );
1084
- edges.push(topArc);
1085
- const rightStart = rotatePoint(
1086
- centerX + radius,
1087
- centerY - capOffset,
1088
- centerX,
1089
- centerY,
1090
- rotation
1091
- );
1092
- const rightEnd = rotatePoint(
1093
- centerX + radius,
1094
- centerY + capOffset,
1095
- centerX,
1096
- centerY,
1097
- rotation
1098
- );
1099
- const rightV1 = repo.add(
1100
- new VertexPoint2(
1101
- "",
1102
- repo.add(new CartesianPoint3("", rightStart.x, rightStart.y, z))
1103
- )
1104
- );
1105
- const rightV2 = repo.add(
1106
- new VertexPoint2(
1107
- "",
1108
- repo.add(new CartesianPoint3("", rightEnd.x, rightEnd.y, z))
1109
- )
1110
- );
1111
- edges.push(createLineEdge(repo, rightV1, rightV2));
1112
- const bottomArc = createArcEdge(
1113
- repo,
1114
- centerX,
1115
- centerY + capOffset,
1116
- z,
1117
- radius,
1118
- 0,
1119
- Math.PI,
1120
- rotation,
1121
- centerX,
1122
- centerY
1123
- );
1124
- edges.push(bottomArc);
1125
- const leftStart = rotatePoint(
1126
- centerX - radius,
1127
- centerY + capOffset,
1128
- centerX,
1129
- centerY,
1130
- rotation
1131
- );
1132
- const leftEnd = rotatePoint(
1133
- centerX - radius,
1134
- centerY - capOffset,
1135
- centerX,
1136
- centerY,
1137
- rotation
1138
- );
1139
- const leftV1 = repo.add(
1140
- new VertexPoint2(
1141
- "",
1142
- repo.add(new CartesianPoint3("", leftStart.x, leftStart.y, z))
1143
- )
1144
- );
1145
- const leftV2 = repo.add(
1146
- new VertexPoint2(
1147
- "",
1148
- repo.add(new CartesianPoint3("", leftEnd.x, leftEnd.y, z))
1149
- )
1150
- );
1151
- edges.push(createLineEdge(repo, leftV1, leftV2));
1152
- }
1153
- const orientedEdges = edges.map(
1154
- (edge) => repo.add(new OrientedEdge2("", edge, true))
1155
- );
1156
- return repo.add(new EdgeLoop2("", orientedEdges));
986
+ radius
987
+ };
1157
988
  }
1158
- function createPillCylindricalFaces(repo, hole, zMin, zMax, xDir, zDir) {
989
+ function createPillBoundarySegments(repo, hole, z) {
1159
990
  const geom = getPillGeometry(hole);
1160
991
  const {
1161
992
  centerX,
@@ -1165,341 +996,233 @@ function createPillCylindricalFaces(repo, hole, zMin, zMax, xDir, zDir) {
1165
996
  rotation,
1166
997
  isHorizontal
1167
998
  } = geom;
1168
- const faces = [];
999
+ const capOffset = straightHalfLength;
1169
1000
  if (isHorizontal) {
1170
- const capOffset = straightHalfLength;
1171
- faces.push(
1172
- createCylindricalWall(
1001
+ return [
1002
+ createArcSegment(
1173
1003
  repo,
1174
1004
  centerX + capOffset,
1175
1005
  centerY,
1006
+ z,
1176
1007
  radius,
1177
1008
  -Math.PI / 2,
1178
1009
  Math.PI / 2,
1179
1010
  rotation,
1180
1011
  centerX,
1181
- centerY,
1182
- zMin,
1183
- zMax,
1184
- zDir,
1185
- xDir
1186
- )
1187
- );
1188
- faces.push(
1189
- createPlanarWall(
1012
+ centerY
1013
+ ),
1014
+ createLineSegment(
1190
1015
  repo,
1191
- centerX - capOffset,
1192
- centerY - radius,
1193
- centerX + capOffset,
1194
- centerY - radius,
1195
- rotation,
1196
- centerX,
1197
- centerY,
1198
- zMin,
1199
- zMax,
1200
- zDir
1201
- )
1202
- );
1203
- faces.push(
1204
- createCylindricalWall(
1016
+ rotatePoint(
1017
+ centerX + capOffset,
1018
+ centerY - radius,
1019
+ centerX,
1020
+ centerY,
1021
+ rotation
1022
+ ),
1023
+ rotatePoint(
1024
+ centerX - capOffset,
1025
+ centerY - radius,
1026
+ centerX,
1027
+ centerY,
1028
+ rotation
1029
+ ),
1030
+ z
1031
+ ),
1032
+ createArcSegment(
1205
1033
  repo,
1206
1034
  centerX - capOffset,
1207
1035
  centerY,
1036
+ z,
1208
1037
  radius,
1209
1038
  Math.PI / 2,
1210
1039
  3 * Math.PI / 2,
1211
1040
  rotation,
1212
1041
  centerX,
1213
- centerY,
1214
- zMin,
1215
- zMax,
1216
- zDir,
1217
- xDir
1218
- )
1219
- );
1220
- faces.push(
1221
- createPlanarWall(
1042
+ centerY
1043
+ ),
1044
+ createLineSegment(
1222
1045
  repo,
1223
- centerX + capOffset,
1224
- centerY + radius,
1225
- centerX - capOffset,
1226
- centerY + radius,
1227
- rotation,
1228
- centerX,
1229
- centerY,
1230
- zMin,
1231
- zMax,
1232
- zDir
1046
+ rotatePoint(
1047
+ centerX - capOffset,
1048
+ centerY + radius,
1049
+ centerX,
1050
+ centerY,
1051
+ rotation
1052
+ ),
1053
+ rotatePoint(
1054
+ centerX + capOffset,
1055
+ centerY + radius,
1056
+ centerX,
1057
+ centerY,
1058
+ rotation
1059
+ ),
1060
+ z
1233
1061
  )
1234
- );
1235
- } else {
1236
- const capOffset = straightHalfLength;
1237
- faces.push(
1238
- createCylindricalWall(
1239
- repo,
1240
- centerX,
1062
+ ];
1063
+ }
1064
+ return [
1065
+ createArcSegment(
1066
+ repo,
1067
+ centerX,
1068
+ centerY - capOffset,
1069
+ z,
1070
+ radius,
1071
+ Math.PI,
1072
+ 0,
1073
+ rotation,
1074
+ centerX,
1075
+ centerY
1076
+ ),
1077
+ createLineSegment(
1078
+ repo,
1079
+ rotatePoint(
1080
+ centerX + radius,
1241
1081
  centerY - capOffset,
1242
- radius,
1243
- Math.PI,
1244
- 0,
1245
- rotation,
1246
1082
  centerX,
1247
1083
  centerY,
1248
- zMin,
1249
- zMax,
1250
- zDir,
1251
- xDir
1252
- )
1253
- );
1254
- faces.push(
1255
- createPlanarWall(
1256
- repo,
1257
- centerX + radius,
1258
- centerY - capOffset,
1084
+ rotation
1085
+ ),
1086
+ rotatePoint(
1259
1087
  centerX + radius,
1260
1088
  centerY + capOffset,
1261
- rotation,
1262
1089
  centerX,
1263
1090
  centerY,
1264
- zMin,
1265
- zMax,
1266
- zDir
1267
- )
1268
- );
1269
- faces.push(
1270
- createCylindricalWall(
1271
- repo,
1272
- centerX,
1091
+ rotation
1092
+ ),
1093
+ z
1094
+ ),
1095
+ createArcSegment(
1096
+ repo,
1097
+ centerX,
1098
+ centerY + capOffset,
1099
+ z,
1100
+ radius,
1101
+ 0,
1102
+ Math.PI,
1103
+ rotation,
1104
+ centerX,
1105
+ centerY
1106
+ ),
1107
+ createLineSegment(
1108
+ repo,
1109
+ rotatePoint(
1110
+ centerX - radius,
1273
1111
  centerY + capOffset,
1274
- radius,
1275
- 0,
1276
- Math.PI,
1277
- rotation,
1278
1112
  centerX,
1279
1113
  centerY,
1280
- zMin,
1281
- zMax,
1282
- zDir,
1283
- xDir
1284
- )
1285
- );
1286
- faces.push(
1287
- createPlanarWall(
1288
- repo,
1289
- centerX - radius,
1290
- centerY + capOffset,
1114
+ rotation
1115
+ ),
1116
+ rotatePoint(
1291
1117
  centerX - radius,
1292
1118
  centerY - capOffset,
1293
- rotation,
1294
1119
  centerX,
1295
1120
  centerY,
1296
- zMin,
1297
- zMax,
1298
- zDir
1299
- )
1300
- );
1301
- }
1302
- return faces;
1303
- }
1304
- function createCylindricalWall(repo, centerX, centerY, radius, startAngle, endAngle, rotation, centerX0, centerY0, zMin, zMax, zDir, xDir) {
1305
- const bottomStartX = centerX + radius * Math.cos(startAngle);
1306
- const bottomStartY = centerY + radius * Math.sin(startAngle);
1307
- const bottomEndX = centerX + radius * Math.cos(endAngle);
1308
- const bottomEndY = centerY + radius * Math.sin(endAngle);
1309
- const bottomStart = rotatePoint(
1310
- bottomStartX,
1311
- bottomStartY,
1312
- centerX0,
1313
- centerY0,
1314
- rotation
1315
- );
1316
- const bottomEnd = rotatePoint(
1317
- bottomEndX,
1318
- bottomEndY,
1319
- centerX0,
1320
- centerY0,
1321
- rotation
1322
- );
1323
- const bottomStartVertex = repo.add(
1324
- new VertexPoint2(
1325
- "",
1326
- repo.add(new CartesianPoint3("", bottomStart.x, bottomStart.y, zMin))
1327
- )
1328
- );
1329
- const bottomEndVertex = repo.add(
1330
- new VertexPoint2(
1331
- "",
1332
- repo.add(new CartesianPoint3("", bottomEnd.x, bottomEnd.y, zMin))
1333
- )
1334
- );
1335
- const topStart = repo.add(
1336
- new VertexPoint2(
1337
- "",
1338
- repo.add(new CartesianPoint3("", bottomStart.x, bottomStart.y, zMax))
1339
- )
1340
- );
1341
- const topEnd = repo.add(
1342
- new VertexPoint2(
1343
- "",
1344
- repo.add(new CartesianPoint3("", bottomEnd.x, bottomEnd.y, zMax))
1121
+ rotation
1122
+ ),
1123
+ z
1345
1124
  )
1346
- );
1347
- const centerRotated = rotatePoint(
1348
- centerX,
1349
- centerY,
1350
- centerX0,
1351
- centerY0,
1352
- rotation
1353
- );
1354
- const bottomCenter = repo.add(
1355
- new CartesianPoint3("", centerRotated.x, centerRotated.y, zMin)
1356
- );
1357
- const bottomPlacement = repo.add(
1358
- new Axis2Placement3D3(
1359
- "",
1360
- bottomCenter,
1361
- repo.add(new Direction3("", 0, 0, -1)),
1362
- xDir
1363
- )
1364
- );
1365
- const bottomCircle = repo.add(new Circle("", bottomPlacement, radius));
1366
- const bottomArc = repo.add(
1367
- new EdgeCurve2("", bottomStartVertex, bottomEndVertex, bottomCircle, false)
1368
- );
1369
- const topCenter = repo.add(
1370
- new CartesianPoint3("", centerRotated.x, centerRotated.y, zMax)
1371
- );
1372
- const topPlacement = repo.add(new Axis2Placement3D3("", topCenter, zDir, xDir));
1373
- const topCircle = repo.add(new Circle("", topPlacement, radius));
1374
- const topArc = repo.add(new EdgeCurve2("", topEnd, topStart, topCircle, false));
1375
- const v1 = repo.add(
1376
- new VertexPoint2(
1377
- "",
1378
- repo.add(new CartesianPoint3("", bottomStart.x, bottomStart.y, zMin))
1379
- )
1380
- );
1381
- const v2 = repo.add(
1382
- new VertexPoint2(
1383
- "",
1384
- repo.add(new CartesianPoint3("", bottomStart.x, bottomStart.y, zMax))
1385
- )
1386
- );
1387
- const v3 = repo.add(
1388
- new VertexPoint2(
1389
- "",
1390
- repo.add(new CartesianPoint3("", bottomEnd.x, bottomEnd.y, zMin))
1391
- )
1392
- );
1393
- const v4 = repo.add(
1394
- new VertexPoint2(
1395
- "",
1396
- repo.add(new CartesianPoint3("", bottomEnd.x, bottomEnd.y, zMax))
1397
- )
1398
- );
1399
- const dir1 = repo.add(new Direction3("", 0, 0, 1));
1400
- const height = zMax - zMin;
1401
- const vec1 = repo.add(new Vector2("", dir1, height));
1402
- const line1 = repo.add(new Line2("", v1.resolve(repo).pnt, vec1));
1403
- const edge1 = repo.add(new EdgeCurve2("", v1, v2, line1, true));
1404
- const dir2 = repo.add(new Direction3("", 0, 0, 1));
1405
- const vec2 = repo.add(new Vector2("", dir2, height));
1406
- const line2 = repo.add(new Line2("", v3.resolve(repo).pnt, vec2));
1407
- const edge2 = repo.add(new EdgeCurve2("", v3, v4, line2, true));
1408
- const loop = repo.add(
1409
- new EdgeLoop2("", [
1410
- repo.add(new OrientedEdge2("", bottomArc, true)),
1411
- repo.add(new OrientedEdge2("", edge2, true)),
1412
- repo.add(new OrientedEdge2("", topArc, false)),
1413
- repo.add(new OrientedEdge2("", edge1, false))
1414
- ])
1415
- );
1416
- const cylinderPlacement = repo.add(
1417
- new Axis2Placement3D3("", bottomCenter, zDir, xDir)
1418
- );
1419
- const cylinderSurface = repo.add(
1420
- new CylindricalSurface("", cylinderPlacement, radius)
1421
- );
1422
- return repo.add(
1423
- new AdvancedFace2(
1424
- "",
1425
- [repo.add(new FaceOuterBound2("", loop, true))],
1426
- cylinderSurface,
1427
- false
1428
- )
1429
- );
1125
+ ];
1430
1126
  }
1431
- function createPlanarWall(repo, startX, startY, endX, endY, rotation, centerX0, centerY0, zMin, zMax, zDir) {
1432
- const start = rotatePoint(startX, startY, centerX0, centerY0, rotation);
1433
- const end = rotatePoint(endX, endY, centerX0, centerY0, rotation);
1434
- const v1 = repo.add(
1435
- new VertexPoint2(
1436
- "",
1437
- repo.add(new CartesianPoint3("", start.x, start.y, zMin))
1438
- )
1439
- );
1440
- const v2 = repo.add(
1441
- new VertexPoint2("", repo.add(new CartesianPoint3("", end.x, end.y, zMin)))
1442
- );
1443
- const v3 = repo.add(
1444
- new VertexPoint2("", repo.add(new CartesianPoint3("", end.x, end.y, zMax)))
1445
- );
1446
- const v4 = repo.add(
1447
- new VertexPoint2(
1448
- "",
1449
- repo.add(new CartesianPoint3("", start.x, start.y, zMax))
1450
- )
1451
- );
1452
- const dx = end.x - start.x;
1453
- const dy = end.y - start.y;
1454
- const edgeLength = Math.sqrt(dx * dx + dy * dy);
1455
- const bottomDir = repo.add(
1456
- new Direction3("", dx / edgeLength, dy / edgeLength, 0)
1457
- );
1458
- const bottomVec = repo.add(new Vector2("", bottomDir, edgeLength));
1459
- const bottomLine = repo.add(new Line2("", v1.resolve(repo).pnt, bottomVec));
1460
- const bottomEdge = repo.add(new EdgeCurve2("", v1, v2, bottomLine, true));
1461
- const topDir = repo.add(
1462
- new Direction3("", dx / edgeLength, dy / edgeLength, 0)
1463
- );
1464
- const topVec = repo.add(new Vector2("", topDir, edgeLength));
1465
- const topLine = repo.add(new Line2("", v4.resolve(repo).pnt, topVec));
1466
- const topEdge = repo.add(new EdgeCurve2("", v4, v3, topLine, true));
1467
- const vertDir = repo.add(new Direction3("", 0, 0, 1));
1468
- const height = zMax - zMin;
1469
- const vertVec1 = repo.add(new Vector2("", vertDir, height));
1470
- const vertLine1 = repo.add(new Line2("", v2.resolve(repo).pnt, vertVec1));
1471
- const vertEdge1 = repo.add(new EdgeCurve2("", v2, v3, vertLine1, true));
1472
- const vertVec2 = repo.add(new Vector2("", vertDir, height));
1473
- const vertLine2 = repo.add(new Line2("", v1.resolve(repo).pnt, vertVec2));
1474
- const vertEdge2 = repo.add(new EdgeCurve2("", v1, v4, vertLine2, true));
1475
- const loop = repo.add(
1476
- new EdgeLoop2("", [
1477
- repo.add(new OrientedEdge2("", bottomEdge, true)),
1478
- repo.add(new OrientedEdge2("", vertEdge1, true)),
1479
- repo.add(new OrientedEdge2("", topEdge, false)),
1480
- repo.add(new OrientedEdge2("", vertEdge2, false))
1481
- ])
1482
- );
1483
- const normalDir = repo.add(
1484
- new Direction3("", dy / edgeLength, -dx / edgeLength, 0)
1485
- );
1486
- const refDir = repo.add(
1487
- new Direction3("", dx / edgeLength, dy / edgeLength, 0)
1488
- );
1489
- const planeOrigin = repo.add(new CartesianPoint3("", start.x, start.y, zMin));
1490
- const placement = repo.add(
1491
- new Axis2Placement3D3("", planeOrigin, normalDir, refDir)
1492
- );
1493
- const plane = repo.add(new Plane2("", placement));
1127
+ function createLoopFromSegments(repo, segments, orientation) {
1494
1128
  return repo.add(
1495
- new AdvancedFace2(
1129
+ new EdgeLoop2(
1496
1130
  "",
1497
- [repo.add(new FaceOuterBound2("", loop, true))],
1498
- plane,
1499
- true
1131
+ segments.map(
1132
+ (segment) => repo.add(new OrientedEdge2("", segment.edge, orientation))
1133
+ )
1500
1134
  )
1501
1135
  );
1502
1136
  }
1137
+ function createPillHoleGeometry(repo, hole, zMin, zMax, zDir) {
1138
+ const geom = getPillGeometry(hole);
1139
+ const bottomSegments = createPillBoundarySegments(repo, hole, zMin);
1140
+ const topSegments = createPillBoundarySegments(repo, hole, zMax);
1141
+ const bottomLoop = createLoopFromSegments(repo, bottomSegments, true);
1142
+ const topLoop = createLoopFromSegments(repo, topSegments, true);
1143
+ const wallFaces = [];
1144
+ for (let i = 0; i < bottomSegments.length; i++) {
1145
+ const bottomSegment = bottomSegments[i];
1146
+ const topSegment = topSegments[i];
1147
+ const startVertical = createLineEdge(
1148
+ repo,
1149
+ bottomSegment.start,
1150
+ topSegment.start
1151
+ );
1152
+ const endVertical = createLineEdge(repo, bottomSegment.end, topSegment.end);
1153
+ const loop = repo.add(
1154
+ new EdgeLoop2("", [
1155
+ repo.add(new OrientedEdge2("", bottomSegment.edge, true)),
1156
+ repo.add(new OrientedEdge2("", endVertical, true)),
1157
+ repo.add(new OrientedEdge2("", topSegment.edge, false)),
1158
+ repo.add(new OrientedEdge2("", startVertical, false))
1159
+ ])
1160
+ );
1161
+ if (bottomSegment.kind === "arc") {
1162
+ const center = rotatePoint(
1163
+ bottomSegment.centerX,
1164
+ bottomSegment.centerY,
1165
+ geom.centerX,
1166
+ geom.centerY,
1167
+ geom.rotation
1168
+ );
1169
+ const bottomCenter = repo.add(
1170
+ new CartesianPoint3("", center.x, center.y, zMin)
1171
+ );
1172
+ const refDir2 = repo.add(
1173
+ new Direction3("", Math.cos(geom.rotation), Math.sin(geom.rotation), 0)
1174
+ );
1175
+ const cylinderPlacement = repo.add(
1176
+ new Axis2Placement3D3("", bottomCenter, zDir, refDir2)
1177
+ );
1178
+ const cylinderSurface = repo.add(
1179
+ new CylindricalSurface("", cylinderPlacement, bottomSegment.radius)
1180
+ );
1181
+ wallFaces.push(
1182
+ repo.add(
1183
+ new AdvancedFace2(
1184
+ "",
1185
+ [repo.add(new FaceOuterBound2("", loop, true))],
1186
+ cylinderSurface,
1187
+ false
1188
+ )
1189
+ )
1190
+ );
1191
+ continue;
1192
+ }
1193
+ const startPoint = bottomSegment.start.resolve(repo).pnt.resolve(repo);
1194
+ const endPoint = bottomSegment.end.resolve(repo).pnt.resolve(repo);
1195
+ const dx = endPoint.x - startPoint.x;
1196
+ const dy = endPoint.y - startPoint.y;
1197
+ const edgeLength = Math.sqrt(dx * dx + dy * dy);
1198
+ const normalDir = repo.add(
1199
+ new Direction3("", dy / edgeLength, -dx / edgeLength, 0)
1200
+ );
1201
+ const refDir = repo.add(
1202
+ new Direction3("", dx / edgeLength, dy / edgeLength, 0)
1203
+ );
1204
+ const placement = repo.add(
1205
+ new Axis2Placement3D3(
1206
+ "",
1207
+ bottomSegment.start.resolve(repo).pnt,
1208
+ normalDir,
1209
+ refDir
1210
+ )
1211
+ );
1212
+ const plane = repo.add(new Plane2("", placement));
1213
+ wallFaces.push(
1214
+ repo.add(
1215
+ new AdvancedFace2(
1216
+ "",
1217
+ [repo.add(new FaceOuterBound2("", loop, true))],
1218
+ plane,
1219
+ true
1220
+ )
1221
+ )
1222
+ );
1223
+ }
1224
+ return { bottomLoop, topLoop, wallFaces };
1225
+ }
1503
1226
 
1504
1227
  // lib/index.ts
1505
1228
  async function circuitJsonToStep(circuitJson, options = {}) {
@@ -1711,53 +1434,6 @@ async function circuitJsonToStep(circuitJson, options = {}) {
1711
1434
  bottomEdges.map((edge) => repo.add(new OrientedEdge3("", edge, true)))
1712
1435
  )
1713
1436
  );
1714
- const bottomHoleLoops = [];
1715
- for (const hole of holes) {
1716
- const holeShape = hole.hole_shape ?? hole.shape;
1717
- if (holeShape === "circle") {
1718
- const holeX = typeof hole.x === "number" ? hole.x : hole.x ?? 0;
1719
- const holeY = typeof hole.y === "number" ? hole.y : hole.y ?? 0;
1720
- const radius = (hole.hole_diameter ?? 0) / 2;
1721
- const holeCenter = repo.add(
1722
- new CartesianPoint4("", holeX, holeY, -halfBoardThickness)
1723
- );
1724
- const holeVertex = repo.add(
1725
- new VertexPoint3(
1726
- "",
1727
- repo.add(
1728
- new CartesianPoint4("", holeX + radius, holeY, -halfBoardThickness)
1729
- )
1730
- )
1731
- );
1732
- const holePlacement = repo.add(
1733
- new Axis2Placement3D4(
1734
- "",
1735
- holeCenter,
1736
- repo.add(new Direction4("", 0, 0, -1)),
1737
- xDir
1738
- )
1739
- );
1740
- const holeCircle = repo.add(new Circle2("", holePlacement, radius));
1741
- const holeEdge = repo.add(
1742
- new EdgeCurve3("", holeVertex, holeVertex, holeCircle, true)
1743
- );
1744
- const holeLoop = repo.add(
1745
- new EdgeLoop3("", [repo.add(new OrientedEdge3("", holeEdge, false))])
1746
- );
1747
- bottomHoleLoops.push(repo.add(new FaceBound("", holeLoop, true)));
1748
- } else if (holeShape === "rotated_pill" || holeShape === "pill") {
1749
- const pillLoop = createPillHoleLoop(repo, hole, -halfBoardThickness, xDir);
1750
- bottomHoleLoops.push(repo.add(new FaceBound("", pillLoop, true)));
1751
- }
1752
- }
1753
- const bottomFace = repo.add(
1754
- new AdvancedFace3(
1755
- "",
1756
- [repo.add(new FaceOuterBound3("", bottomLoop, true)), ...bottomHoleLoops],
1757
- bottomPlane,
1758
- true
1759
- )
1760
- );
1761
1437
  const topOrigin = repo.add(new CartesianPoint4("", 0, 0, halfBoardThickness));
1762
1438
  const topFrame = repo.add(new Axis2Placement3D4("", topOrigin, zDir, xDir));
1763
1439
  const topPlane = repo.add(new Plane3("", topFrame));
@@ -1767,40 +1443,124 @@ async function circuitJsonToStep(circuitJson, options = {}) {
1767
1443
  topEdges.map((edge) => repo.add(new OrientedEdge3("", edge, false)))
1768
1444
  )
1769
1445
  );
1770
- const topHoleLoops = [];
1446
+ function getHoleCoordinate(coordinate) {
1447
+ if (typeof coordinate === "number") return coordinate;
1448
+ return coordinate?.value ?? 0;
1449
+ }
1450
+ function createCircularHoleGeometry(hole) {
1451
+ const holeX = getHoleCoordinate(hole.x);
1452
+ const holeY = getHoleCoordinate(hole.y);
1453
+ const radius = (hole.hole_diameter ?? 0) / 2;
1454
+ const bottomHoleCenter = repo.add(
1455
+ new CartesianPoint4("", holeX, holeY, -halfBoardThickness)
1456
+ );
1457
+ const bottomHoleVertex = repo.add(
1458
+ new VertexPoint3(
1459
+ "",
1460
+ repo.add(
1461
+ new CartesianPoint4("", holeX + radius, holeY, -halfBoardThickness)
1462
+ )
1463
+ )
1464
+ );
1465
+ const bottomHolePlacement = repo.add(
1466
+ new Axis2Placement3D4(
1467
+ "",
1468
+ bottomHoleCenter,
1469
+ repo.add(new Direction4("", 0, 0, -1)),
1470
+ xDir
1471
+ )
1472
+ );
1473
+ const bottomHoleCircle = repo.add(
1474
+ new Circle2("", bottomHolePlacement, radius)
1475
+ );
1476
+ const bottomHoleEdge = repo.add(
1477
+ new EdgeCurve3(
1478
+ "",
1479
+ bottomHoleVertex,
1480
+ bottomHoleVertex,
1481
+ bottomHoleCircle,
1482
+ true
1483
+ )
1484
+ );
1485
+ const topHoleCenter = repo.add(
1486
+ new CartesianPoint4("", holeX, holeY, halfBoardThickness)
1487
+ );
1488
+ const topHoleVertex = repo.add(
1489
+ new VertexPoint3(
1490
+ "",
1491
+ repo.add(
1492
+ new CartesianPoint4("", holeX + radius, holeY, halfBoardThickness)
1493
+ )
1494
+ )
1495
+ );
1496
+ const topHolePlacement = repo.add(
1497
+ new Axis2Placement3D4("", topHoleCenter, zDir, xDir)
1498
+ );
1499
+ const topHoleCircle = repo.add(new Circle2("", topHolePlacement, radius));
1500
+ const topHoleEdge = repo.add(
1501
+ new EdgeCurve3("", topHoleVertex, topHoleVertex, topHoleCircle, true)
1502
+ );
1503
+ const bottomLoop2 = repo.add(
1504
+ new EdgeLoop3("", [repo.add(new OrientedEdge3("", bottomHoleEdge, false))])
1505
+ );
1506
+ const topLoop2 = repo.add(
1507
+ new EdgeLoop3("", [repo.add(new OrientedEdge3("", topHoleEdge, true))])
1508
+ );
1509
+ const wallLoop = repo.add(
1510
+ new EdgeLoop3("", [
1511
+ repo.add(new OrientedEdge3("", bottomHoleEdge, true)),
1512
+ repo.add(new OrientedEdge3("", topHoleEdge, false))
1513
+ ])
1514
+ );
1515
+ const holeCylinderPlacement = repo.add(
1516
+ new Axis2Placement3D4("", bottomHoleCenter, zDir, xDir)
1517
+ );
1518
+ const holeCylinderSurface = repo.add(
1519
+ new CylindricalSurface2("", holeCylinderPlacement, radius)
1520
+ );
1521
+ const wallFace = repo.add(
1522
+ new AdvancedFace3(
1523
+ "",
1524
+ [repo.add(new FaceOuterBound3("", wallLoop, true))],
1525
+ holeCylinderSurface,
1526
+ false
1527
+ )
1528
+ );
1529
+ return { bottomLoop: bottomLoop2, topLoop: topLoop2, wallFaces: [wallFace] };
1530
+ }
1531
+ const sharedHoleGeometries = [];
1771
1532
  for (const hole of holes) {
1772
1533
  const holeShape = hole.hole_shape ?? hole.shape;
1773
1534
  if (holeShape === "circle") {
1774
- const holeX = typeof hole.x === "number" ? hole.x : hole.x ?? 0;
1775
- const holeY = typeof hole.y === "number" ? hole.y : hole.y ?? 0;
1776
- const radius = (hole.hole_diameter ?? 0) / 2;
1777
- const holeCenter = repo.add(
1778
- new CartesianPoint4("", holeX, holeY, halfBoardThickness)
1779
- );
1780
- const holeVertex = repo.add(
1781
- new VertexPoint3(
1782
- "",
1783
- repo.add(
1784
- new CartesianPoint4("", holeX + radius, holeY, halfBoardThickness)
1785
- )
1535
+ sharedHoleGeometries.push(createCircularHoleGeometry(hole));
1536
+ } else if (holeShape === "rotated_pill" || holeShape === "pill") {
1537
+ sharedHoleGeometries.push(
1538
+ createPillHoleGeometry(
1539
+ repo,
1540
+ hole,
1541
+ -halfBoardThickness,
1542
+ halfBoardThickness,
1543
+ zDir
1786
1544
  )
1787
1545
  );
1788
- const holePlacement = repo.add(
1789
- new Axis2Placement3D4("", holeCenter, zDir, xDir)
1790
- );
1791
- const holeCircle = repo.add(new Circle2("", holePlacement, radius));
1792
- const holeEdge = repo.add(
1793
- new EdgeCurve3("", holeVertex, holeVertex, holeCircle, true)
1794
- );
1795
- const holeLoop = repo.add(
1796
- new EdgeLoop3("", [repo.add(new OrientedEdge3("", holeEdge, true))])
1797
- );
1798
- topHoleLoops.push(repo.add(new FaceBound("", holeLoop, true)));
1799
- } else if (holeShape === "rotated_pill" || holeShape === "pill") {
1800
- const pillLoop = createPillHoleLoop(repo, hole, halfBoardThickness, xDir);
1801
- topHoleLoops.push(repo.add(new FaceBound("", pillLoop, true)));
1802
1546
  }
1803
1547
  }
1548
+ const bottomHoleLoops = [];
1549
+ const topHoleLoops = [];
1550
+ for (const holeGeometry of sharedHoleGeometries) {
1551
+ bottomHoleLoops.push(
1552
+ repo.add(new FaceBound("", holeGeometry.bottomLoop, true))
1553
+ );
1554
+ topHoleLoops.push(repo.add(new FaceBound("", holeGeometry.topLoop, true)));
1555
+ }
1556
+ const bottomFace = repo.add(
1557
+ new AdvancedFace3(
1558
+ "",
1559
+ [repo.add(new FaceOuterBound3("", bottomLoop, true)), ...bottomHoleLoops],
1560
+ bottomPlane,
1561
+ true
1562
+ )
1563
+ );
1804
1564
  const topFace = repo.add(
1805
1565
  new AdvancedFace3(
1806
1566
  "",
@@ -1809,6 +1569,10 @@ async function circuitJsonToStep(circuitJson, options = {}) {
1809
1569
  true
1810
1570
  )
1811
1571
  );
1572
+ const holeCylindricalFaces = [];
1573
+ for (const holeGeometry of sharedHoleGeometries) {
1574
+ holeCylindricalFaces.push(...holeGeometry.wallFaces);
1575
+ }
1812
1576
  const sideFaces = [];
1813
1577
  for (let i = 0; i < bottomEdges.length; i++) {
1814
1578
  const nextI = (i + 1) % bottomEdges.length;
@@ -1845,95 +1609,6 @@ async function circuitJsonToStep(circuitJson, options = {}) {
1845
1609
  );
1846
1610
  sideFaces.push(sideFace);
1847
1611
  }
1848
- const holeCylindricalFaces = [];
1849
- for (const hole of holes) {
1850
- const holeShape = hole.hole_shape ?? hole.shape;
1851
- if (holeShape === "circle") {
1852
- const holeX = typeof hole.x === "number" ? hole.x : hole.x ?? 0;
1853
- const holeY = typeof hole.y === "number" ? hole.y : hole.y ?? 0;
1854
- const radius = (hole.hole_diameter ?? 0) / 2;
1855
- const bottomHoleCenter = repo.add(
1856
- new CartesianPoint4("", holeX, holeY, -halfBoardThickness)
1857
- );
1858
- const bottomHoleVertex = repo.add(
1859
- new VertexPoint3(
1860
- "",
1861
- repo.add(
1862
- new CartesianPoint4("", holeX + radius, holeY, -halfBoardThickness)
1863
- )
1864
- )
1865
- );
1866
- const bottomHolePlacement = repo.add(
1867
- new Axis2Placement3D4(
1868
- "",
1869
- bottomHoleCenter,
1870
- repo.add(new Direction4("", 0, 0, -1)),
1871
- xDir
1872
- )
1873
- );
1874
- const bottomHoleCircle = repo.add(
1875
- new Circle2("", bottomHolePlacement, radius)
1876
- );
1877
- const bottomHoleEdge = repo.add(
1878
- new EdgeCurve3(
1879
- "",
1880
- bottomHoleVertex,
1881
- bottomHoleVertex,
1882
- bottomHoleCircle,
1883
- true
1884
- )
1885
- );
1886
- const topHoleCenter = repo.add(
1887
- new CartesianPoint4("", holeX, holeY, halfBoardThickness)
1888
- );
1889
- const topHoleVertex = repo.add(
1890
- new VertexPoint3(
1891
- "",
1892
- repo.add(
1893
- new CartesianPoint4("", holeX + radius, holeY, halfBoardThickness)
1894
- )
1895
- )
1896
- );
1897
- const topHolePlacement = repo.add(
1898
- new Axis2Placement3D4("", topHoleCenter, zDir, xDir)
1899
- );
1900
- const topHoleCircle = repo.add(new Circle2("", topHolePlacement, radius));
1901
- const topHoleEdge = repo.add(
1902
- new EdgeCurve3("", topHoleVertex, topHoleVertex, topHoleCircle, true)
1903
- );
1904
- const holeCylinderLoop = repo.add(
1905
- new EdgeLoop3("", [
1906
- repo.add(new OrientedEdge3("", bottomHoleEdge, true)),
1907
- repo.add(new OrientedEdge3("", topHoleEdge, false))
1908
- ])
1909
- );
1910
- const holeCylinderPlacement = repo.add(
1911
- new Axis2Placement3D4("", bottomHoleCenter, zDir, xDir)
1912
- );
1913
- const holeCylinderSurface = repo.add(
1914
- new CylindricalSurface2("", holeCylinderPlacement, radius)
1915
- );
1916
- const holeCylinderFace = repo.add(
1917
- new AdvancedFace3(
1918
- "",
1919
- [repo.add(new FaceOuterBound3("", holeCylinderLoop, true))],
1920
- holeCylinderSurface,
1921
- false
1922
- )
1923
- );
1924
- holeCylindricalFaces.push(holeCylinderFace);
1925
- } else if (holeShape === "rotated_pill" || holeShape === "pill") {
1926
- const pillFaces = createPillCylindricalFaces(
1927
- repo,
1928
- hole,
1929
- -halfBoardThickness,
1930
- halfBoardThickness,
1931
- xDir,
1932
- zDir
1933
- );
1934
- holeCylindricalFaces.push(...pillFaces);
1935
- }
1936
- }
1937
1612
  const allFaces = [bottomFace, topFace, ...sideFaces, ...holeCylindricalFaces];
1938
1613
  const styleCache = createStyleCache();
1939
1614
  const boardStyledItems = createStyledItems(repo, {