circuit-json-to-step 0.0.31 → 0.0.32
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 +46 -21
- package/lib/pill-geometry.ts +48 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -828,7 +828,7 @@ function normalizeStepNumericExponents(stepText) {
|
|
|
828
828
|
var package_default = {
|
|
829
829
|
name: "circuit-json-to-step",
|
|
830
830
|
main: "dist/index.js",
|
|
831
|
-
version: "0.0.
|
|
831
|
+
version: "0.0.31",
|
|
832
832
|
type: "module",
|
|
833
833
|
scripts: {
|
|
834
834
|
"pull-reference": `git clone https://github.com/tscircuit/circuit-json.git && find circuit-json/tests -name '*.test.ts' -exec bash -c 'mv "$0" "\${0%.test.ts}.ts"' {} \\; && git clone https://github.com/tscircuit/stepts.git && find stepts/tests -name '*.test.ts' -exec bash -c 'mv "$0" "\${0%.test.ts}.ts"' {} \\;`,
|
|
@@ -921,6 +921,21 @@ function createVertexAt(repo, x, y, z) {
|
|
|
921
921
|
new VertexPoint2("", repo.add(new CartesianPoint3("", x, y, z)))
|
|
922
922
|
);
|
|
923
923
|
}
|
|
924
|
+
function createVertexCache(repo, z) {
|
|
925
|
+
const vertices = /* @__PURE__ */ new Map();
|
|
926
|
+
const normalize = (value) => {
|
|
927
|
+
const rounded = Number(value.toFixed(9));
|
|
928
|
+
return Object.is(rounded, -0) ? 0 : rounded;
|
|
929
|
+
};
|
|
930
|
+
return (x, y) => {
|
|
931
|
+
const key = `${normalize(x)},${normalize(y)},${normalize(z)}`;
|
|
932
|
+
const existing = vertices.get(key);
|
|
933
|
+
if (existing) return existing;
|
|
934
|
+
const vertex = createVertexAt(repo, x, y, z);
|
|
935
|
+
vertices.set(key, vertex);
|
|
936
|
+
return vertex;
|
|
937
|
+
};
|
|
938
|
+
}
|
|
924
939
|
function createLineEdge(repo, v1, v2) {
|
|
925
940
|
const p1 = v1.resolve(repo).pnt.resolve(repo);
|
|
926
941
|
const p2 = v2.resolve(repo).pnt.resolve(repo);
|
|
@@ -939,9 +954,9 @@ function createLineEdge(repo, v1, v2) {
|
|
|
939
954
|
const line = repo.add(new Line2("", v1.resolve(repo).pnt, vec));
|
|
940
955
|
return repo.add(new EdgeCurve2("", v1, v2, line, true));
|
|
941
956
|
}
|
|
942
|
-
function createLineSegment(repo, start, end,
|
|
943
|
-
const startVertex =
|
|
944
|
-
const endVertex =
|
|
957
|
+
function createLineSegment(repo, start, end, getVertex) {
|
|
958
|
+
const startVertex = getVertex(start.x, start.y);
|
|
959
|
+
const endVertex = getVertex(end.x, end.y);
|
|
945
960
|
return {
|
|
946
961
|
kind: "line",
|
|
947
962
|
edge: createLineEdge(repo, startVertex, endVertex),
|
|
@@ -949,7 +964,7 @@ function createLineSegment(repo, start, end, z) {
|
|
|
949
964
|
end: endVertex
|
|
950
965
|
};
|
|
951
966
|
}
|
|
952
|
-
function createArcSegment(repo, centerX, centerY, z, radius, startAngle, endAngle, rotation, centerX0, centerY0) {
|
|
967
|
+
function createArcSegment(repo, centerX, centerY, z, radius, startAngle, endAngle, rotation, centerX0, centerY0, getVertex) {
|
|
953
968
|
const start = rotatePoint(
|
|
954
969
|
centerX + radius * Math.cos(startAngle),
|
|
955
970
|
centerY + radius * Math.sin(startAngle),
|
|
@@ -965,8 +980,8 @@ function createArcSegment(repo, centerX, centerY, z, radius, startAngle, endAngl
|
|
|
965
980
|
rotation
|
|
966
981
|
);
|
|
967
982
|
const center = rotatePoint(centerX, centerY, centerX0, centerY0, rotation);
|
|
968
|
-
const startVertex =
|
|
969
|
-
const endVertex =
|
|
983
|
+
const startVertex = getVertex(start.x, start.y);
|
|
984
|
+
const endVertex = getVertex(end.x, end.y);
|
|
970
985
|
const centerPoint = repo.add(new CartesianPoint3("", center.x, center.y, z));
|
|
971
986
|
const normalDir = repo.add(new Direction3("", 0, 0, -1));
|
|
972
987
|
const refDir = repo.add(
|
|
@@ -997,6 +1012,7 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
997
1012
|
isHorizontal
|
|
998
1013
|
} = geom;
|
|
999
1014
|
const capOffset = straightHalfLength;
|
|
1015
|
+
const getVertex = createVertexCache(repo, z);
|
|
1000
1016
|
if (isHorizontal) {
|
|
1001
1017
|
return [
|
|
1002
1018
|
createArcSegment(
|
|
@@ -1009,7 +1025,8 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1009
1025
|
Math.PI / 2,
|
|
1010
1026
|
rotation,
|
|
1011
1027
|
centerX,
|
|
1012
|
-
centerY
|
|
1028
|
+
centerY,
|
|
1029
|
+
getVertex
|
|
1013
1030
|
),
|
|
1014
1031
|
createLineSegment(
|
|
1015
1032
|
repo,
|
|
@@ -1027,7 +1044,7 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1027
1044
|
centerY,
|
|
1028
1045
|
rotation
|
|
1029
1046
|
),
|
|
1030
|
-
|
|
1047
|
+
getVertex
|
|
1031
1048
|
),
|
|
1032
1049
|
createArcSegment(
|
|
1033
1050
|
repo,
|
|
@@ -1039,7 +1056,8 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1039
1056
|
3 * Math.PI / 2,
|
|
1040
1057
|
rotation,
|
|
1041
1058
|
centerX,
|
|
1042
|
-
centerY
|
|
1059
|
+
centerY,
|
|
1060
|
+
getVertex
|
|
1043
1061
|
),
|
|
1044
1062
|
createLineSegment(
|
|
1045
1063
|
repo,
|
|
@@ -1057,7 +1075,7 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1057
1075
|
centerY,
|
|
1058
1076
|
rotation
|
|
1059
1077
|
),
|
|
1060
|
-
|
|
1078
|
+
getVertex
|
|
1061
1079
|
)
|
|
1062
1080
|
];
|
|
1063
1081
|
}
|
|
@@ -1072,7 +1090,8 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1072
1090
|
0,
|
|
1073
1091
|
rotation,
|
|
1074
1092
|
centerX,
|
|
1075
|
-
centerY
|
|
1093
|
+
centerY,
|
|
1094
|
+
getVertex
|
|
1076
1095
|
),
|
|
1077
1096
|
createLineSegment(
|
|
1078
1097
|
repo,
|
|
@@ -1090,7 +1109,7 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1090
1109
|
centerY,
|
|
1091
1110
|
rotation
|
|
1092
1111
|
),
|
|
1093
|
-
|
|
1112
|
+
getVertex
|
|
1094
1113
|
),
|
|
1095
1114
|
createArcSegment(
|
|
1096
1115
|
repo,
|
|
@@ -1102,7 +1121,8 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1102
1121
|
Math.PI,
|
|
1103
1122
|
rotation,
|
|
1104
1123
|
centerX,
|
|
1105
|
-
centerY
|
|
1124
|
+
centerY,
|
|
1125
|
+
getVertex
|
|
1106
1126
|
),
|
|
1107
1127
|
createLineSegment(
|
|
1108
1128
|
repo,
|
|
@@ -1120,7 +1140,7 @@ function createPillBoundarySegments(repo, hole, z) {
|
|
|
1120
1140
|
centerY,
|
|
1121
1141
|
rotation
|
|
1122
1142
|
),
|
|
1123
|
-
|
|
1143
|
+
getVertex
|
|
1124
1144
|
)
|
|
1125
1145
|
];
|
|
1126
1146
|
}
|
|
@@ -1141,15 +1161,20 @@ function createPillHoleGeometry(repo, hole, zMin, zMax, zDir) {
|
|
|
1141
1161
|
const bottomLoop = createLoopFromSegments(repo, bottomSegments, true);
|
|
1142
1162
|
const topLoop = createLoopFromSegments(repo, topSegments, true);
|
|
1143
1163
|
const wallFaces = [];
|
|
1164
|
+
const verticalEdges = /* @__PURE__ */ new Map();
|
|
1165
|
+
const getVerticalEdge = (bottomVertex, topVertex) => {
|
|
1166
|
+
const key = `${bottomVertex.id}:${topVertex.id}`;
|
|
1167
|
+
const existing = verticalEdges.get(key);
|
|
1168
|
+
if (existing) return existing;
|
|
1169
|
+
const edge = createLineEdge(repo, bottomVertex, topVertex);
|
|
1170
|
+
verticalEdges.set(key, edge);
|
|
1171
|
+
return edge;
|
|
1172
|
+
};
|
|
1144
1173
|
for (let i = 0; i < bottomSegments.length; i++) {
|
|
1145
1174
|
const bottomSegment = bottomSegments[i];
|
|
1146
1175
|
const topSegment = topSegments[i];
|
|
1147
|
-
const startVertical =
|
|
1148
|
-
|
|
1149
|
-
bottomSegment.start,
|
|
1150
|
-
topSegment.start
|
|
1151
|
-
);
|
|
1152
|
-
const endVertical = createLineEdge(repo, bottomSegment.end, topSegment.end);
|
|
1176
|
+
const startVertical = getVerticalEdge(bottomSegment.start, topSegment.start);
|
|
1177
|
+
const endVertical = getVerticalEdge(bottomSegment.end, topSegment.end);
|
|
1153
1178
|
const loop = repo.add(
|
|
1154
1179
|
new EdgeLoop2("", [
|
|
1155
1180
|
repo.add(new OrientedEdge2("", bottomSegment.edge, true)),
|
package/lib/pill-geometry.ts
CHANGED
|
@@ -101,6 +101,24 @@ function createVertexAt(
|
|
|
101
101
|
)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
function createVertexCache(repo: Repository, z: number) {
|
|
105
|
+
const vertices = new Map<string, Ref<VertexPoint>>()
|
|
106
|
+
const normalize = (value: number) => {
|
|
107
|
+
const rounded = Number(value.toFixed(9))
|
|
108
|
+
return Object.is(rounded, -0) ? 0 : rounded
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return (x: number, y: number) => {
|
|
112
|
+
const key = `${normalize(x)},${normalize(y)},${normalize(z)}`
|
|
113
|
+
const existing = vertices.get(key)
|
|
114
|
+
if (existing) return existing
|
|
115
|
+
|
|
116
|
+
const vertex = createVertexAt(repo, x, y, z)
|
|
117
|
+
vertices.set(key, vertex)
|
|
118
|
+
return vertex
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
104
122
|
function createLineEdge(
|
|
105
123
|
repo: Repository,
|
|
106
124
|
v1: Ref<VertexPoint>,
|
|
@@ -130,10 +148,10 @@ function createLineSegment(
|
|
|
130
148
|
repo: Repository,
|
|
131
149
|
start: { x: number; y: number },
|
|
132
150
|
end: { x: number; y: number },
|
|
133
|
-
|
|
151
|
+
getVertex: (x: number, y: number) => Ref<VertexPoint>,
|
|
134
152
|
): PillBoundarySegment {
|
|
135
|
-
const startVertex =
|
|
136
|
-
const endVertex =
|
|
153
|
+
const startVertex = getVertex(start.x, start.y)
|
|
154
|
+
const endVertex = getVertex(end.x, end.y)
|
|
137
155
|
return {
|
|
138
156
|
kind: "line",
|
|
139
157
|
edge: createLineEdge(repo, startVertex, endVertex),
|
|
@@ -153,6 +171,7 @@ function createArcSegment(
|
|
|
153
171
|
rotation: number,
|
|
154
172
|
centerX0: number,
|
|
155
173
|
centerY0: number,
|
|
174
|
+
getVertex: (x: number, y: number) => Ref<VertexPoint>,
|
|
156
175
|
): PillBoundarySegment {
|
|
157
176
|
const start = rotatePoint(
|
|
158
177
|
centerX + radius * Math.cos(startAngle),
|
|
@@ -169,8 +188,8 @@ function createArcSegment(
|
|
|
169
188
|
rotation,
|
|
170
189
|
)
|
|
171
190
|
const center = rotatePoint(centerX, centerY, centerX0, centerY0, rotation)
|
|
172
|
-
const startVertex =
|
|
173
|
-
const endVertex =
|
|
191
|
+
const startVertex = getVertex(start.x, start.y)
|
|
192
|
+
const endVertex = getVertex(end.x, end.y)
|
|
174
193
|
const centerPoint = repo.add(new CartesianPoint("", center.x, center.y, z))
|
|
175
194
|
const normalDir = repo.add(new Direction("", 0, 0, -1))
|
|
176
195
|
const refDir = repo.add(
|
|
@@ -207,6 +226,7 @@ function createPillBoundarySegments(
|
|
|
207
226
|
isHorizontal,
|
|
208
227
|
} = geom
|
|
209
228
|
const capOffset = straightHalfLength
|
|
229
|
+
const getVertex = createVertexCache(repo, z)
|
|
210
230
|
|
|
211
231
|
if (isHorizontal) {
|
|
212
232
|
return [
|
|
@@ -221,6 +241,7 @@ function createPillBoundarySegments(
|
|
|
221
241
|
rotation,
|
|
222
242
|
centerX,
|
|
223
243
|
centerY,
|
|
244
|
+
getVertex,
|
|
224
245
|
),
|
|
225
246
|
createLineSegment(
|
|
226
247
|
repo,
|
|
@@ -238,7 +259,7 @@ function createPillBoundarySegments(
|
|
|
238
259
|
centerY,
|
|
239
260
|
rotation,
|
|
240
261
|
),
|
|
241
|
-
|
|
262
|
+
getVertex,
|
|
242
263
|
),
|
|
243
264
|
createArcSegment(
|
|
244
265
|
repo,
|
|
@@ -251,6 +272,7 @@ function createPillBoundarySegments(
|
|
|
251
272
|
rotation,
|
|
252
273
|
centerX,
|
|
253
274
|
centerY,
|
|
275
|
+
getVertex,
|
|
254
276
|
),
|
|
255
277
|
createLineSegment(
|
|
256
278
|
repo,
|
|
@@ -268,7 +290,7 @@ function createPillBoundarySegments(
|
|
|
268
290
|
centerY,
|
|
269
291
|
rotation,
|
|
270
292
|
),
|
|
271
|
-
|
|
293
|
+
getVertex,
|
|
272
294
|
),
|
|
273
295
|
]
|
|
274
296
|
}
|
|
@@ -285,6 +307,7 @@ function createPillBoundarySegments(
|
|
|
285
307
|
rotation,
|
|
286
308
|
centerX,
|
|
287
309
|
centerY,
|
|
310
|
+
getVertex,
|
|
288
311
|
),
|
|
289
312
|
createLineSegment(
|
|
290
313
|
repo,
|
|
@@ -302,7 +325,7 @@ function createPillBoundarySegments(
|
|
|
302
325
|
centerY,
|
|
303
326
|
rotation,
|
|
304
327
|
),
|
|
305
|
-
|
|
328
|
+
getVertex,
|
|
306
329
|
),
|
|
307
330
|
createArcSegment(
|
|
308
331
|
repo,
|
|
@@ -315,6 +338,7 @@ function createPillBoundarySegments(
|
|
|
315
338
|
rotation,
|
|
316
339
|
centerX,
|
|
317
340
|
centerY,
|
|
341
|
+
getVertex,
|
|
318
342
|
),
|
|
319
343
|
createLineSegment(
|
|
320
344
|
repo,
|
|
@@ -332,7 +356,7 @@ function createPillBoundarySegments(
|
|
|
332
356
|
centerY,
|
|
333
357
|
rotation,
|
|
334
358
|
),
|
|
335
|
-
|
|
359
|
+
getVertex,
|
|
336
360
|
),
|
|
337
361
|
]
|
|
338
362
|
}
|
|
@@ -365,16 +389,25 @@ export function createPillHoleGeometry(
|
|
|
365
389
|
const bottomLoop = createLoopFromSegments(repo, bottomSegments, true)
|
|
366
390
|
const topLoop = createLoopFromSegments(repo, topSegments, true)
|
|
367
391
|
const wallFaces: Ref<AdvancedFace>[] = []
|
|
392
|
+
const verticalEdges = new Map<string, Ref<EdgeCurve>>()
|
|
393
|
+
const getVerticalEdge = (
|
|
394
|
+
bottomVertex: Ref<VertexPoint>,
|
|
395
|
+
topVertex: Ref<VertexPoint>,
|
|
396
|
+
) => {
|
|
397
|
+
const key = `${bottomVertex.id}:${topVertex.id}`
|
|
398
|
+
const existing = verticalEdges.get(key)
|
|
399
|
+
if (existing) return existing
|
|
400
|
+
|
|
401
|
+
const edge = createLineEdge(repo, bottomVertex, topVertex)
|
|
402
|
+
verticalEdges.set(key, edge)
|
|
403
|
+
return edge
|
|
404
|
+
}
|
|
368
405
|
|
|
369
406
|
for (let i = 0; i < bottomSegments.length; i++) {
|
|
370
407
|
const bottomSegment = bottomSegments[i]!
|
|
371
408
|
const topSegment = topSegments[i]!
|
|
372
|
-
const startVertical =
|
|
373
|
-
|
|
374
|
-
bottomSegment.start,
|
|
375
|
-
topSegment.start,
|
|
376
|
-
)
|
|
377
|
-
const endVertical = createLineEdge(repo, bottomSegment.end, topSegment.end)
|
|
409
|
+
const startVertical = getVerticalEdge(bottomSegment.start, topSegment.start)
|
|
410
|
+
const endVertical = getVerticalEdge(bottomSegment.end, topSegment.end)
|
|
378
411
|
const loop = repo.add(
|
|
379
412
|
new EdgeLoop("", [
|
|
380
413
|
repo.add(new OrientedEdge("", bottomSegment.edge, true)),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "circuit-json-to-step",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.32",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"pull-reference": "git clone https://github.com/tscircuit/circuit-json.git && find circuit-json/tests -name '*.test.ts' -exec bash -c 'mv \"$0\" \"${0%.test.ts}.ts\"' {} \\; && git clone https://github.com/tscircuit/stepts.git && find stepts/tests -name '*.test.ts' -exec bash -c 'mv \"$0\" \"${0%.test.ts}.ts\"' {} \\;",
|