circuit-json-to-gltf 0.0.136 → 0.0.137
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 +240 -80
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -204,11 +204,11 @@ var require_constants = __commonJS({
|
|
|
204
204
|
"node_modules/@jscad/modeling/src/maths/constants.js"(exports, module) {
|
|
205
205
|
"use strict";
|
|
206
206
|
var spatialResolution = 1e5;
|
|
207
|
-
var
|
|
207
|
+
var EPS4 = 1e-5;
|
|
208
208
|
var NEPS = 1e-13;
|
|
209
209
|
var TAU = Math.PI * 2;
|
|
210
210
|
module.exports = {
|
|
211
|
-
EPS:
|
|
211
|
+
EPS: EPS4,
|
|
212
212
|
NEPS,
|
|
213
213
|
TAU,
|
|
214
214
|
spatialResolution
|
|
@@ -259,13 +259,13 @@ var require_identity = __commonJS({
|
|
|
259
259
|
var require_fromRotation = __commonJS({
|
|
260
260
|
"node_modules/@jscad/modeling/src/maths/mat4/fromRotation.js"(exports, module) {
|
|
261
261
|
"use strict";
|
|
262
|
-
var { EPS:
|
|
262
|
+
var { EPS: EPS4 } = require_constants();
|
|
263
263
|
var { sin, cos } = require_trigonometry();
|
|
264
264
|
var identity = require_identity();
|
|
265
265
|
var fromRotation = (out, rad, axis) => {
|
|
266
266
|
let [x, y, z] = axis;
|
|
267
267
|
const lengthSquared = x * x + y * y + z * z;
|
|
268
|
-
if (Math.abs(lengthSquared) <
|
|
268
|
+
if (Math.abs(lengthSquared) < EPS4) {
|
|
269
269
|
return identity(out);
|
|
270
270
|
}
|
|
271
271
|
const len = 1 / Math.sqrt(lengthSquared);
|
|
@@ -1192,13 +1192,13 @@ var require_multiply2 = __commonJS({
|
|
|
1192
1192
|
var require_rotate = __commonJS({
|
|
1193
1193
|
"node_modules/@jscad/modeling/src/maths/mat4/rotate.js"(exports, module) {
|
|
1194
1194
|
"use strict";
|
|
1195
|
-
var { EPS:
|
|
1195
|
+
var { EPS: EPS4 } = require_constants();
|
|
1196
1196
|
var { sin, cos } = require_trigonometry();
|
|
1197
1197
|
var copy = require_copy();
|
|
1198
1198
|
var rotate = (out, matrix, radians, axis) => {
|
|
1199
1199
|
let [x, y, z] = axis;
|
|
1200
1200
|
const lengthSquared = x * x + y * y + z * z;
|
|
1201
|
-
if (Math.abs(lengthSquared) <
|
|
1201
|
+
if (Math.abs(lengthSquared) < EPS4) {
|
|
1202
1202
|
return copy(out, matrix);
|
|
1203
1203
|
}
|
|
1204
1204
|
const len = 1 / Math.sqrt(lengthSquared);
|
|
@@ -3687,19 +3687,19 @@ var require_fromPoints3 = __commonJS({
|
|
|
3687
3687
|
var require_fromPointsRandom = __commonJS({
|
|
3688
3688
|
"node_modules/@jscad/modeling/src/maths/plane/fromPointsRandom.js"(exports, module) {
|
|
3689
3689
|
"use strict";
|
|
3690
|
-
var { EPS:
|
|
3690
|
+
var { EPS: EPS4 } = require_constants();
|
|
3691
3691
|
var vec3 = require_vec3();
|
|
3692
3692
|
var fromPointsRandom = (out, a, b, c) => {
|
|
3693
3693
|
let ba = vec3.subtract(vec3.create(), b, a);
|
|
3694
3694
|
let ca = vec3.subtract(vec3.create(), c, a);
|
|
3695
|
-
if (vec3.length(ba) <
|
|
3695
|
+
if (vec3.length(ba) < EPS4) {
|
|
3696
3696
|
ba = vec3.orthogonal(ba, ca);
|
|
3697
3697
|
}
|
|
3698
|
-
if (vec3.length(ca) <
|
|
3698
|
+
if (vec3.length(ca) < EPS4) {
|
|
3699
3699
|
ca = vec3.orthogonal(ca, ba);
|
|
3700
3700
|
}
|
|
3701
3701
|
let normal = vec3.cross(vec3.create(), ba, ca);
|
|
3702
|
-
if (vec3.length(normal) <
|
|
3702
|
+
if (vec3.length(normal) < EPS4) {
|
|
3703
3703
|
ca = vec3.orthogonal(ca, ba);
|
|
3704
3704
|
normal = vec3.cross(normal, ba, ca);
|
|
3705
3705
|
}
|
|
@@ -4382,7 +4382,7 @@ var require_isA3 = __commonJS({
|
|
|
4382
4382
|
var require_isConvex2 = __commonJS({
|
|
4383
4383
|
"node_modules/@jscad/modeling/src/geometries/geom3/isConvex.js"(exports, module) {
|
|
4384
4384
|
"use strict";
|
|
4385
|
-
var { EPS:
|
|
4385
|
+
var { EPS: EPS4 } = require_constants();
|
|
4386
4386
|
var vec3 = require_vec3();
|
|
4387
4387
|
var geom35 = require_isA3();
|
|
4388
4388
|
var toPolygons5 = require_toPolygons();
|
|
@@ -4413,7 +4413,7 @@ var require_isConvex2 = __commonJS({
|
|
|
4413
4413
|
for (let j = 0; j < vertices.length; j++) {
|
|
4414
4414
|
const v = vertices[j];
|
|
4415
4415
|
const distance = vec3.dot(plane, v) - plane[3];
|
|
4416
|
-
if (distance >
|
|
4416
|
+
if (distance > EPS4) {
|
|
4417
4417
|
return false;
|
|
4418
4418
|
}
|
|
4419
4419
|
}
|
|
@@ -4605,7 +4605,7 @@ var require_clone8 = __commonJS({
|
|
|
4605
4605
|
var require_close = __commonJS({
|
|
4606
4606
|
"node_modules/@jscad/modeling/src/geometries/path2/close.js"(exports, module) {
|
|
4607
4607
|
"use strict";
|
|
4608
|
-
var { EPS:
|
|
4608
|
+
var { EPS: EPS4 } = require_constants();
|
|
4609
4609
|
var vec2 = require_vec2();
|
|
4610
4610
|
var clone = require_clone8();
|
|
4611
4611
|
var close = (geometry) => {
|
|
@@ -4616,7 +4616,7 @@ var require_close = __commonJS({
|
|
|
4616
4616
|
const points = cloned.points;
|
|
4617
4617
|
const p0 = points[0];
|
|
4618
4618
|
let pn = points[points.length - 1];
|
|
4619
|
-
while (vec2.distance(p0, pn) <
|
|
4619
|
+
while (vec2.distance(p0, pn) < EPS4 * EPS4) {
|
|
4620
4620
|
points.pop();
|
|
4621
4621
|
if (points.length === 1) break;
|
|
4622
4622
|
pn = points[points.length - 1];
|
|
@@ -4651,7 +4651,7 @@ var require_create8 = __commonJS({
|
|
|
4651
4651
|
var require_fromPoints5 = __commonJS({
|
|
4652
4652
|
"node_modules/@jscad/modeling/src/geometries/path2/fromPoints.js"(exports, module) {
|
|
4653
4653
|
"use strict";
|
|
4654
|
-
var { EPS:
|
|
4654
|
+
var { EPS: EPS4 } = require_constants();
|
|
4655
4655
|
var vec2 = require_vec2();
|
|
4656
4656
|
var close = require_close();
|
|
4657
4657
|
var create = require_create8();
|
|
@@ -4663,7 +4663,7 @@ var require_fromPoints5 = __commonJS({
|
|
|
4663
4663
|
if (created.points.length > 1) {
|
|
4664
4664
|
const p0 = created.points[0];
|
|
4665
4665
|
const pn = created.points[created.points.length - 1];
|
|
4666
|
-
if (vec2.distance(p0, pn) <
|
|
4666
|
+
if (vec2.distance(p0, pn) < EPS4 * EPS4) {
|
|
4667
4667
|
closed = true;
|
|
4668
4668
|
}
|
|
4669
4669
|
}
|
|
@@ -6490,12 +6490,12 @@ var require_fromPlanes = __commonJS({
|
|
|
6490
6490
|
"use strict";
|
|
6491
6491
|
var vec3 = require_vec3();
|
|
6492
6492
|
var { solve2Linear } = require_utils();
|
|
6493
|
-
var { EPS:
|
|
6493
|
+
var { EPS: EPS4 } = require_constants();
|
|
6494
6494
|
var fromPointAndDirection = require_fromPointAndDirection();
|
|
6495
6495
|
var fromPlanes = (out, plane1, plane2) => {
|
|
6496
6496
|
let direction = vec3.cross(vec3.create(), plane1, plane2);
|
|
6497
6497
|
let length = vec3.length(direction);
|
|
6498
|
-
if (length <
|
|
6498
|
+
if (length < EPS4) {
|
|
6499
6499
|
throw new Error("parallel planes do not intersect");
|
|
6500
6500
|
}
|
|
6501
6501
|
length = 1 / length;
|
|
@@ -6834,13 +6834,13 @@ var require_measureAggregateBoundingBox = __commonJS({
|
|
|
6834
6834
|
var require_calculateEpsilonFromBounds = __commonJS({
|
|
6835
6835
|
"node_modules/@jscad/modeling/src/measurements/calculateEpsilonFromBounds.js"(exports, module) {
|
|
6836
6836
|
"use strict";
|
|
6837
|
-
var { EPS:
|
|
6837
|
+
var { EPS: EPS4 } = require_constants();
|
|
6838
6838
|
var calculateEpsilonFromBounds = (bounds, dimensions) => {
|
|
6839
6839
|
let total = 0;
|
|
6840
6840
|
for (let i = 0; i < dimensions; i++) {
|
|
6841
6841
|
total += bounds[1][i] - bounds[0][i];
|
|
6842
6842
|
}
|
|
6843
|
-
return
|
|
6843
|
+
return EPS4 * total / dimensions;
|
|
6844
6844
|
};
|
|
6845
6845
|
module.exports = calculateEpsilonFromBounds;
|
|
6846
6846
|
}
|
|
@@ -7209,7 +7209,7 @@ var require_commonChecks = __commonJS({
|
|
|
7209
7209
|
var require_arc = __commonJS({
|
|
7210
7210
|
"node_modules/@jscad/modeling/src/primitives/arc.js"(exports, module) {
|
|
7211
7211
|
"use strict";
|
|
7212
|
-
var { EPS:
|
|
7212
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7213
7213
|
var vec2 = require_vec2();
|
|
7214
7214
|
var path2 = require_path2();
|
|
7215
7215
|
var { isGT, isGTE, isNumberArray } = require_commonChecks();
|
|
@@ -7237,7 +7237,7 @@ var require_arc = __commonJS({
|
|
|
7237
7237
|
if (startAngle > endAngle) {
|
|
7238
7238
|
rotation = endAngle + (TAU - startAngle);
|
|
7239
7239
|
}
|
|
7240
|
-
const minangle = Math.acos((radius * radius + radius * radius -
|
|
7240
|
+
const minangle = Math.acos((radius * radius + radius * radius - EPS4 * EPS4) / (2 * radius * radius));
|
|
7241
7241
|
const centerv = vec2.clone(center);
|
|
7242
7242
|
let point;
|
|
7243
7243
|
const pointArray = [];
|
|
@@ -7275,7 +7275,7 @@ var require_arc = __commonJS({
|
|
|
7275
7275
|
var require_ellipse = __commonJS({
|
|
7276
7276
|
"node_modules/@jscad/modeling/src/primitives/ellipse.js"(exports, module) {
|
|
7277
7277
|
"use strict";
|
|
7278
|
-
var { EPS:
|
|
7278
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7279
7279
|
var vec2 = require_vec2();
|
|
7280
7280
|
var geom2 = require_geom2();
|
|
7281
7281
|
var { sin, cos } = require_trigonometry();
|
|
@@ -7306,7 +7306,7 @@ var require_ellipse = __commonJS({
|
|
|
7306
7306
|
rotation = endAngle + (TAU - startAngle);
|
|
7307
7307
|
}
|
|
7308
7308
|
const minradius = Math.min(radius[0], radius[1]);
|
|
7309
|
-
const minangle = Math.acos((minradius * minradius + minradius * minradius -
|
|
7309
|
+
const minangle = Math.acos((minradius * minradius + minradius * minradius - EPS4 * EPS4) / (2 * minradius * minradius));
|
|
7310
7310
|
if (rotation < minangle) throw new Error("startAngle and endAngle do not define a significant rotation");
|
|
7311
7311
|
segments = Math.floor(segments * (rotation / TAU));
|
|
7312
7312
|
const centerv = vec2.clone(center);
|
|
@@ -7418,7 +7418,7 @@ var require_cube = __commonJS({
|
|
|
7418
7418
|
var require_cylinderElliptic = __commonJS({
|
|
7419
7419
|
"node_modules/@jscad/modeling/src/primitives/cylinderElliptic.js"(exports, module) {
|
|
7420
7420
|
"use strict";
|
|
7421
|
-
var { EPS:
|
|
7421
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7422
7422
|
var vec3 = require_vec3();
|
|
7423
7423
|
var geom35 = require_geom3();
|
|
7424
7424
|
var poly3 = require_poly3();
|
|
@@ -7455,7 +7455,7 @@ var require_cylinderElliptic = __commonJS({
|
|
|
7455
7455
|
rotation = endAngle + (TAU - startAngle);
|
|
7456
7456
|
}
|
|
7457
7457
|
const minradius = Math.min(startRadius[0], startRadius[1], endRadius[0], endRadius[1]);
|
|
7458
|
-
const minangle = Math.acos((minradius * minradius + minradius * minradius -
|
|
7458
|
+
const minangle = Math.acos((minradius * minradius + minradius * minradius - EPS4 * EPS4) / (2 * minradius * minradius));
|
|
7459
7459
|
if (rotation < minangle) throw new Error("startAngle and endAngle do not define a significant rotation");
|
|
7460
7460
|
const slices = Math.floor(segments * (rotation / TAU));
|
|
7461
7461
|
const start = vec3.fromValues(0, 0, -(height / 2));
|
|
@@ -7904,7 +7904,7 @@ var require_rectangle = __commonJS({
|
|
|
7904
7904
|
var require_roundedCuboid = __commonJS({
|
|
7905
7905
|
"node_modules/@jscad/modeling/src/primitives/roundedCuboid.js"(exports, module) {
|
|
7906
7906
|
"use strict";
|
|
7907
|
-
var { EPS:
|
|
7907
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
7908
7908
|
var vec2 = require_vec2();
|
|
7909
7909
|
var vec3 = require_vec3();
|
|
7910
7910
|
var geom35 = require_geom3();
|
|
@@ -7920,7 +7920,7 @@ var require_roundedCuboid = __commonJS({
|
|
|
7920
7920
|
let layerradius = radius * cospitch;
|
|
7921
7921
|
let layeroffset = size[2] - (radius - radius * sinpitch);
|
|
7922
7922
|
if (!positive) layeroffset = radius - radius * sinpitch - size[2];
|
|
7923
|
-
layerradius = layerradius >
|
|
7923
|
+
layerradius = layerradius > EPS4 ? layerradius : 0;
|
|
7924
7924
|
const corner0 = vec3.add(vec3.create(), center, [size[0] - radius, size[1] - radius, layeroffset]);
|
|
7925
7925
|
const corner1 = vec3.add(vec3.create(), center, [radius - size[0], size[1] - radius, layeroffset]);
|
|
7926
7926
|
const corner2 = vec3.add(vec3.create(), center, [radius - size[0], radius - size[1], layeroffset]);
|
|
@@ -8015,7 +8015,7 @@ var require_roundedCuboid = __commonJS({
|
|
|
8015
8015
|
if (size[0] === 0 || size[1] === 0 || size[2] === 0) return geom35.create();
|
|
8016
8016
|
if (roundRadius === 0) return cuboid({ center, size });
|
|
8017
8017
|
size = size.map((v) => v / 2);
|
|
8018
|
-
if (roundRadius > size[0] -
|
|
8018
|
+
if (roundRadius > size[0] - EPS4 || roundRadius > size[1] - EPS4 || roundRadius > size[2] - EPS4) throw new Error("roundRadius must be smaller than the radius of all dimensions");
|
|
8019
8019
|
segments = Math.floor(segments / 4);
|
|
8020
8020
|
let prevCornersPos = null;
|
|
8021
8021
|
let prevCornersNeg = null;
|
|
@@ -8057,7 +8057,7 @@ var require_roundedCuboid = __commonJS({
|
|
|
8057
8057
|
var require_roundedCylinder = __commonJS({
|
|
8058
8058
|
"node_modules/@jscad/modeling/src/primitives/roundedCylinder.js"(exports, module) {
|
|
8059
8059
|
"use strict";
|
|
8060
|
-
var { EPS:
|
|
8060
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
8061
8061
|
var vec3 = require_vec3();
|
|
8062
8062
|
var geom35 = require_geom3();
|
|
8063
8063
|
var poly3 = require_poly3();
|
|
@@ -8085,7 +8085,7 @@ var require_roundedCylinder = __commonJS({
|
|
|
8085
8085
|
const end = [0, 0, height / 2];
|
|
8086
8086
|
const direction = vec3.subtract(vec3.create(), end, start);
|
|
8087
8087
|
const length = vec3.length(direction);
|
|
8088
|
-
if (2 * roundRadius > length -
|
|
8088
|
+
if (2 * roundRadius > length - EPS4) throw new Error("height must be larger than twice roundRadius");
|
|
8089
8089
|
let defaultnormal;
|
|
8090
8090
|
if (Math.abs(direction[0]) > Math.abs(direction[1])) {
|
|
8091
8091
|
defaultnormal = vec3.fromValues(0, 1, 0);
|
|
@@ -8170,7 +8170,7 @@ var require_roundedCylinder = __commonJS({
|
|
|
8170
8170
|
var require_roundedRectangle = __commonJS({
|
|
8171
8171
|
"node_modules/@jscad/modeling/src/primitives/roundedRectangle.js"(exports, module) {
|
|
8172
8172
|
"use strict";
|
|
8173
|
-
var { EPS:
|
|
8173
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
8174
8174
|
var vec2 = require_vec2();
|
|
8175
8175
|
var geom2 = require_geom2();
|
|
8176
8176
|
var { isGTE, isNumberArray } = require_commonChecks();
|
|
@@ -8191,7 +8191,7 @@ var require_roundedRectangle = __commonJS({
|
|
|
8191
8191
|
if (size[0] === 0 || size[1] === 0) return geom2.create();
|
|
8192
8192
|
if (roundRadius === 0) return rectangle3({ center, size });
|
|
8193
8193
|
size = size.map((v) => v / 2);
|
|
8194
|
-
if (roundRadius > size[0] -
|
|
8194
|
+
if (roundRadius > size[0] - EPS4 || roundRadius > size[1] - EPS4) throw new Error("roundRadius must be smaller than the radius of all dimensions");
|
|
8195
8195
|
const cornersegments = Math.floor(segments / 4);
|
|
8196
8196
|
const corner0 = vec2.add(vec2.create(), center, [size[0] - roundRadius, size[1] - roundRadius]);
|
|
8197
8197
|
const corner1 = vec2.add(vec2.create(), center, [roundRadius - size[0], size[1] - roundRadius]);
|
|
@@ -9255,7 +9255,7 @@ var require_repair = __commonJS({
|
|
|
9255
9255
|
var require_extrudeWalls = __commonJS({
|
|
9256
9256
|
"node_modules/@jscad/modeling/src/operations/extrusions/extrudeWalls.js"(exports, module) {
|
|
9257
9257
|
"use strict";
|
|
9258
|
-
var { EPS:
|
|
9258
|
+
var { EPS: EPS4 } = require_constants();
|
|
9259
9259
|
var vec3 = require_vec3();
|
|
9260
9260
|
var poly3 = require_poly3();
|
|
9261
9261
|
var slice = require_slice();
|
|
@@ -9295,7 +9295,7 @@ var require_extrudeWalls = __commonJS({
|
|
|
9295
9295
|
});
|
|
9296
9296
|
return newEdges;
|
|
9297
9297
|
};
|
|
9298
|
-
var EPSAREA =
|
|
9298
|
+
var EPSAREA = EPS4 * EPS4 / 2 * Math.sin(Math.PI / 3);
|
|
9299
9299
|
var extrudeWalls = (slice0, slice1) => {
|
|
9300
9300
|
let edges0 = slice.toEdges(slice0);
|
|
9301
9301
|
let edges1 = slice.toEdges(slice1);
|
|
@@ -10278,7 +10278,7 @@ var require_OrthoNormalBasis = __commonJS({
|
|
|
10278
10278
|
var require_reTesselateCoplanarPolygons = __commonJS({
|
|
10279
10279
|
"node_modules/@jscad/modeling/src/operations/modifiers/reTesselateCoplanarPolygons.js"(exports, module) {
|
|
10280
10280
|
"use strict";
|
|
10281
|
-
var { EPS:
|
|
10281
|
+
var { EPS: EPS4 } = require_constants();
|
|
10282
10282
|
var line2 = require_line2();
|
|
10283
10283
|
var vec2 = require_vec2();
|
|
10284
10284
|
var OrthoNormalBasis = require_OrthoNormalBasis();
|
|
@@ -10296,7 +10296,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10296
10296
|
const topy2polygonindexes = /* @__PURE__ */ new Map();
|
|
10297
10297
|
const ycoordinatetopolygonindexes = /* @__PURE__ */ new Map();
|
|
10298
10298
|
const ycoordinatebins = /* @__PURE__ */ new Map();
|
|
10299
|
-
const ycoordinateBinningFactor = 10 /
|
|
10299
|
+
const ycoordinateBinningFactor = 10 / EPS4;
|
|
10300
10300
|
for (let polygonindex = 0; polygonindex < numpolygons; polygonindex++) {
|
|
10301
10301
|
const poly3d = sourcepolygons[polygonindex];
|
|
10302
10302
|
let vertices2d = [];
|
|
@@ -10476,7 +10476,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10476
10476
|
const prevoutpolygon = newoutpolygonrow[newoutpolygonrow.length - 1];
|
|
10477
10477
|
const d1 = vec2.distance(outpolygon.topleft, prevoutpolygon.topright);
|
|
10478
10478
|
const d2 = vec2.distance(outpolygon.bottomleft, prevoutpolygon.bottomright);
|
|
10479
|
-
if (d1 <
|
|
10479
|
+
if (d1 < EPS4 && d2 < EPS4) {
|
|
10480
10480
|
outpolygon.topleft = prevoutpolygon.topleft;
|
|
10481
10481
|
outpolygon.leftline = prevoutpolygon.leftline;
|
|
10482
10482
|
outpolygon.bottomleft = prevoutpolygon.bottomleft;
|
|
@@ -10493,8 +10493,8 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10493
10493
|
for (let ii = 0; ii < prevoutpolygonrow.length; ii++) {
|
|
10494
10494
|
if (!matchedindexes.has(ii)) {
|
|
10495
10495
|
const prevpolygon = prevoutpolygonrow[ii];
|
|
10496
|
-
if (vec2.distance(prevpolygon.bottomleft, thispolygon.topleft) <
|
|
10497
|
-
if (vec2.distance(prevpolygon.bottomright, thispolygon.topright) <
|
|
10496
|
+
if (vec2.distance(prevpolygon.bottomleft, thispolygon.topleft) < EPS4) {
|
|
10497
|
+
if (vec2.distance(prevpolygon.bottomright, thispolygon.topright) < EPS4) {
|
|
10498
10498
|
matchedindexes.add(ii);
|
|
10499
10499
|
const v1 = line2.direction(thispolygon.leftline);
|
|
10500
10500
|
const v2 = line2.direction(prevpolygon.leftline);
|
|
@@ -10502,8 +10502,8 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10502
10502
|
const v3 = line2.direction(thispolygon.rightline);
|
|
10503
10503
|
const v4 = line2.direction(prevpolygon.rightline);
|
|
10504
10504
|
const d2 = v3[0] - v4[0];
|
|
10505
|
-
const leftlinecontinues = Math.abs(d1) <
|
|
10506
|
-
const rightlinecontinues = Math.abs(d2) <
|
|
10505
|
+
const leftlinecontinues = Math.abs(d1) < EPS4;
|
|
10506
|
+
const rightlinecontinues = Math.abs(d2) < EPS4;
|
|
10507
10507
|
const leftlineisconvex = leftlinecontinues || d1 >= 0;
|
|
10508
10508
|
const rightlineisconvex = rightlinecontinues || d2 >= 0;
|
|
10509
10509
|
if (leftlineisconvex && rightlineisconvex) {
|
|
@@ -10522,7 +10522,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10522
10522
|
if (!prevcontinuedindexes.has(ii)) {
|
|
10523
10523
|
const prevpolygon = prevoutpolygonrow[ii];
|
|
10524
10524
|
prevpolygon.outpolygon.rightpoints.push(prevpolygon.bottomright);
|
|
10525
|
-
if (vec2.distance(prevpolygon.bottomright, prevpolygon.bottomleft) >
|
|
10525
|
+
if (vec2.distance(prevpolygon.bottomright, prevpolygon.bottomleft) > EPS4) {
|
|
10526
10526
|
prevpolygon.outpolygon.leftpoints.push(prevpolygon.bottomleft);
|
|
10527
10527
|
}
|
|
10528
10528
|
prevpolygon.outpolygon.leftpoints.reverse();
|
|
@@ -10541,7 +10541,7 @@ var require_reTesselateCoplanarPolygons = __commonJS({
|
|
|
10541
10541
|
rightpoints: []
|
|
10542
10542
|
};
|
|
10543
10543
|
thispolygon.outpolygon.leftpoints.push(thispolygon.topleft);
|
|
10544
|
-
if (vec2.distance(thispolygon.topleft, thispolygon.topright) >
|
|
10544
|
+
if (vec2.distance(thispolygon.topleft, thispolygon.topright) > EPS4) {
|
|
10545
10545
|
thispolygon.outpolygon.rightpoints.push(thispolygon.topright);
|
|
10546
10546
|
}
|
|
10547
10547
|
} else {
|
|
@@ -10642,7 +10642,7 @@ var require_retessellate = __commonJS({
|
|
|
10642
10642
|
var require_mayOverlap = __commonJS({
|
|
10643
10643
|
"node_modules/@jscad/modeling/src/operations/booleans/mayOverlap.js"(exports, module) {
|
|
10644
10644
|
"use strict";
|
|
10645
|
-
var { EPS:
|
|
10645
|
+
var { EPS: EPS4 } = require_constants();
|
|
10646
10646
|
var measureBoundingBox3 = require_measureBoundingBox2();
|
|
10647
10647
|
var mayOverlap = (geometry1, geometry2) => {
|
|
10648
10648
|
if (geometry1.polygons.length === 0 || geometry2.polygons.length === 0) {
|
|
@@ -10654,12 +10654,12 @@ var require_mayOverlap = __commonJS({
|
|
|
10654
10654
|
const bounds2 = measureBoundingBox3(geometry2);
|
|
10655
10655
|
const min2 = bounds2[0];
|
|
10656
10656
|
const max2 = bounds2[1];
|
|
10657
|
-
if (min2[0] - max1[0] >
|
|
10658
|
-
if (min1[0] - max2[0] >
|
|
10659
|
-
if (min2[1] - max1[1] >
|
|
10660
|
-
if (min1[1] - max2[1] >
|
|
10661
|
-
if (min2[2] - max1[2] >
|
|
10662
|
-
if (min1[2] - max2[2] >
|
|
10657
|
+
if (min2[0] - max1[0] > EPS4) return false;
|
|
10658
|
+
if (min1[0] - max2[0] > EPS4) return false;
|
|
10659
|
+
if (min2[1] - max1[1] > EPS4) return false;
|
|
10660
|
+
if (min1[1] - max2[1] > EPS4) return false;
|
|
10661
|
+
if (min2[2] - max1[2] > EPS4) return false;
|
|
10662
|
+
if (min1[2] - max2[2] > EPS4) return false;
|
|
10663
10663
|
return true;
|
|
10664
10664
|
};
|
|
10665
10665
|
module.exports = mayOverlap;
|
|
@@ -10809,12 +10809,12 @@ var require_splitLineSegmentByPlane = __commonJS({
|
|
|
10809
10809
|
var require_splitPolygonByPlane = __commonJS({
|
|
10810
10810
|
"node_modules/@jscad/modeling/src/operations/booleans/trees/splitPolygonByPlane.js"(exports, module) {
|
|
10811
10811
|
"use strict";
|
|
10812
|
-
var { EPS:
|
|
10812
|
+
var { EPS: EPS4 } = require_constants();
|
|
10813
10813
|
var plane = require_plane();
|
|
10814
10814
|
var vec3 = require_vec3();
|
|
10815
10815
|
var poly3 = require_poly3();
|
|
10816
10816
|
var splitLineSegmentByPlane = require_splitLineSegmentByPlane();
|
|
10817
|
-
var EPS_SQUARED =
|
|
10817
|
+
var EPS_SQUARED = EPS4 * EPS4;
|
|
10818
10818
|
var removeConsecutiveDuplicates = (vertices) => {
|
|
10819
10819
|
const result = [];
|
|
10820
10820
|
let prevvertex = vertices[vertices.length - 1];
|
|
@@ -10842,12 +10842,12 @@ var require_splitPolygonByPlane = __commonJS({
|
|
|
10842
10842
|
let hasfront = false;
|
|
10843
10843
|
let hasback = false;
|
|
10844
10844
|
const vertexIsBack = [];
|
|
10845
|
-
const MINEPS = -
|
|
10845
|
+
const MINEPS = -EPS4;
|
|
10846
10846
|
for (let i = 0; i < numvertices; i++) {
|
|
10847
10847
|
const t = vec3.dot(splane, vertices[i]) - splane[3];
|
|
10848
10848
|
const isback = t < MINEPS;
|
|
10849
10849
|
vertexIsBack.push(isback);
|
|
10850
|
-
if (t >
|
|
10850
|
+
if (t > EPS4) hasfront = true;
|
|
10851
10851
|
if (t < MINEPS) hasback = true;
|
|
10852
10852
|
}
|
|
10853
10853
|
if (!hasfront && !hasback) {
|
|
@@ -10912,7 +10912,7 @@ var require_splitPolygonByPlane = __commonJS({
|
|
|
10912
10912
|
var require_PolygonTreeNode = __commonJS({
|
|
10913
10913
|
"node_modules/@jscad/modeling/src/operations/booleans/trees/PolygonTreeNode.js"(exports, module) {
|
|
10914
10914
|
"use strict";
|
|
10915
|
-
var { EPS:
|
|
10915
|
+
var { EPS: EPS4 } = require_constants();
|
|
10916
10916
|
var vec3 = require_vec3();
|
|
10917
10917
|
var poly3 = require_poly3();
|
|
10918
10918
|
var splitPolygonByPlane = require_splitPolygonByPlane();
|
|
@@ -11015,7 +11015,7 @@ var require_PolygonTreeNode = __commonJS({
|
|
|
11015
11015
|
const polygon3 = this.polygon;
|
|
11016
11016
|
if (polygon3) {
|
|
11017
11017
|
const bound = poly3.measureBoundingSphere(polygon3);
|
|
11018
|
-
const sphereradius = bound[3] +
|
|
11018
|
+
const sphereradius = bound[3] + EPS4;
|
|
11019
11019
|
const spherecenter = bound;
|
|
11020
11020
|
const d = vec3.dot(splane, spherecenter) - splane[3];
|
|
11021
11021
|
if (d > sphereradius) {
|
|
@@ -11731,7 +11731,7 @@ var require_booleans = __commonJS({
|
|
|
11731
11731
|
var require_offsetFromPoints = __commonJS({
|
|
11732
11732
|
"node_modules/@jscad/modeling/src/operations/expansions/offsetFromPoints.js"(exports, module) {
|
|
11733
11733
|
"use strict";
|
|
11734
|
-
var { EPS:
|
|
11734
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
11735
11735
|
var intersect = require_intersect();
|
|
11736
11736
|
var line2 = require_line2();
|
|
11737
11737
|
var vec2 = require_vec2();
|
|
@@ -11744,7 +11744,7 @@ var require_offsetFromPoints = __commonJS({
|
|
|
11744
11744
|
segments: 16
|
|
11745
11745
|
};
|
|
11746
11746
|
let { delta, corners, closed, segments } = Object.assign({}, defaults, options);
|
|
11747
|
-
if (Math.abs(delta) <
|
|
11747
|
+
if (Math.abs(delta) < EPS4) return points;
|
|
11748
11748
|
let rotation = options.closed ? area(points) : 1;
|
|
11749
11749
|
if (rotation === 0) rotation = 1;
|
|
11750
11750
|
const orientation = rotation > 0 && delta >= 0 || rotation < 0 && delta < 0;
|
|
@@ -11931,7 +11931,7 @@ var require_extrudePolygon = __commonJS({
|
|
|
11931
11931
|
var require_expandShell = __commonJS({
|
|
11932
11932
|
"node_modules/@jscad/modeling/src/operations/expansions/expandShell.js"(exports, module) {
|
|
11933
11933
|
"use strict";
|
|
11934
|
-
var { EPS:
|
|
11934
|
+
var { EPS: EPS4, TAU } = require_constants();
|
|
11935
11935
|
var mat4 = require_mat4();
|
|
11936
11936
|
var vec3 = require_vec3();
|
|
11937
11937
|
var fnNumberSort = require_fnNumberSort();
|
|
@@ -12036,7 +12036,7 @@ var require_expandShell = __commonJS({
|
|
|
12036
12036
|
const p2 = vec3.add(vec3.create(), endpoint, v1);
|
|
12037
12037
|
let skip = false;
|
|
12038
12038
|
if (i >= 0) {
|
|
12039
|
-
if (vec3.distance(p1, prevp1) <
|
|
12039
|
+
if (vec3.distance(p1, prevp1) < EPS4) {
|
|
12040
12040
|
skip = true;
|
|
12041
12041
|
}
|
|
12042
12042
|
}
|
|
@@ -13699,9 +13699,137 @@ var require_src = __commonJS({
|
|
|
13699
13699
|
// node_modules/@tscircuit/flex-utils/dist/index.js
|
|
13700
13700
|
import earcut from "earcut";
|
|
13701
13701
|
var EPS = 1e-7;
|
|
13702
|
-
|
|
13702
|
+
var samePoint = (a, b) => Math.hypot(a.x - b.x, a.y - b.y) < EPS;
|
|
13703
|
+
function pointInPolygon(point, polygon3, includeBoundary = true) {
|
|
13704
|
+
let inside = false;
|
|
13705
|
+
for (let i = 0; i < polygon3.length; i++) {
|
|
13706
|
+
const a = polygon3[i], b = polygon3[(i + 1) % polygon3.length];
|
|
13707
|
+
const cross2 = (point.x - a.x) * (b.y - a.y) - (point.y - a.y) * (b.x - a.x);
|
|
13708
|
+
if (Math.abs(cross2) < EPS * Math.max(1, Math.hypot(b.x - a.x, b.y - a.y)) && point.x >= Math.min(a.x, b.x) - EPS && point.x <= Math.max(a.x, b.x) + EPS && point.y >= Math.min(a.y, b.y) - EPS && point.y <= Math.max(a.y, b.y) + EPS)
|
|
13709
|
+
return includeBoundary;
|
|
13710
|
+
if (a.y > point.y !== b.y > point.y && point.x < a.x + (b.x - a.x) * (point.y - a.y) / (b.y - a.y))
|
|
13711
|
+
inside = !inside;
|
|
13712
|
+
}
|
|
13713
|
+
return inside;
|
|
13714
|
+
}
|
|
13715
|
+
function lineCrossings(outline, nx, ny, d) {
|
|
13716
|
+
const crossings = [];
|
|
13717
|
+
for (let edge = 0; edge < outline.length; edge++) {
|
|
13718
|
+
const a = outline[edge], b = outline[(edge + 1) % outline.length];
|
|
13719
|
+
const da = a.x * nx + a.y * ny - d, db = b.x * nx + b.y * ny - d;
|
|
13720
|
+
if (Math.abs(da) < EPS && Math.abs(db) < EPS) continue;
|
|
13721
|
+
if (da > EPS && db > EPS || da < -EPS && db < -EPS) continue;
|
|
13722
|
+
if (Math.abs(da - db) < EPS) continue;
|
|
13723
|
+
const fraction = Math.max(0, Math.min(1, da / (da - db)));
|
|
13724
|
+
const point = {
|
|
13725
|
+
x: a.x + (b.x - a.x) * fraction,
|
|
13726
|
+
y: a.y + (b.y - a.y) * fraction
|
|
13727
|
+
};
|
|
13728
|
+
if (crossings.some((crossing) => samePoint(crossing.point, point))) continue;
|
|
13729
|
+
crossings.push(
|
|
13730
|
+
fraction > 1 - EPS ? { point: b, edge: (edge + 1) % outline.length, fraction: 0 } : { point, edge, fraction }
|
|
13731
|
+
);
|
|
13732
|
+
}
|
|
13733
|
+
return crossings.sort(
|
|
13734
|
+
(a, b) => -ny * a.point.x + nx * a.point.y - (-ny * b.point.x + nx * b.point.y)
|
|
13735
|
+
);
|
|
13736
|
+
}
|
|
13737
|
+
function movingPolygon(outline, a, b, nx, ny) {
|
|
13738
|
+
const polygon3 = [];
|
|
13739
|
+
for (let edge = 0; edge < outline.length; edge++) {
|
|
13740
|
+
polygon3.push(outline[edge]);
|
|
13741
|
+
for (const crossing of [a, b].filter((c) => c.edge === edge).sort((a2, b2) => a2.fraction - b2.fraction))
|
|
13742
|
+
if (crossing.fraction > EPS) polygon3.push(crossing.point);
|
|
13743
|
+
}
|
|
13744
|
+
const start = polygon3.findIndex((p) => samePoint(p, a.point));
|
|
13745
|
+
const end = polygon3.findIndex((p) => samePoint(p, b.point));
|
|
13746
|
+
if (start < 0 || end < 0)
|
|
13747
|
+
throw new Error("Cannot resolve PCB bend boundary crossings");
|
|
13748
|
+
const path = (from, to) => {
|
|
13749
|
+
const points = [polygon3[from]];
|
|
13750
|
+
while (from !== to) {
|
|
13751
|
+
from = (from + 1) % polygon3.length;
|
|
13752
|
+
points.push(polygon3[from]);
|
|
13753
|
+
}
|
|
13754
|
+
return points;
|
|
13755
|
+
};
|
|
13756
|
+
const area = outline.reduce((sum, p, i) => {
|
|
13757
|
+
const next = outline[(i + 1) % outline.length];
|
|
13758
|
+
return sum + p.x * next.y - next.x * p.y;
|
|
13759
|
+
}, 0);
|
|
13760
|
+
const side = Math.sign(area) * ((b.point.y - a.point.y) * nx - (b.point.x - a.point.x) * ny);
|
|
13761
|
+
return side > 0 ? path(start, end) : path(end, start);
|
|
13762
|
+
}
|
|
13763
|
+
function getFiniteBendRegion({
|
|
13764
|
+
outline,
|
|
13765
|
+
nx,
|
|
13766
|
+
ny,
|
|
13767
|
+
center,
|
|
13768
|
+
proximal,
|
|
13769
|
+
axisMin,
|
|
13770
|
+
axisMax
|
|
13771
|
+
}) {
|
|
13772
|
+
const finiteCrossings = lineCrossings(outline, nx, ny, center).filter(
|
|
13773
|
+
({ point }) => {
|
|
13774
|
+
const along = -ny * point.x + nx * point.y;
|
|
13775
|
+
return along >= axisMin - EPS && along <= axisMax + EPS;
|
|
13776
|
+
}
|
|
13777
|
+
);
|
|
13778
|
+
if (finiteCrossings.length !== 2)
|
|
13779
|
+
throw new Error(
|
|
13780
|
+
"A finite PCB bend must cut one board cross-section from boundary to boundary"
|
|
13781
|
+
);
|
|
13782
|
+
const [a, b] = finiteCrossings;
|
|
13783
|
+
const middle = {
|
|
13784
|
+
x: (a.point.x + b.point.x) / 2,
|
|
13785
|
+
y: (a.point.y + b.point.y) / 2
|
|
13786
|
+
};
|
|
13787
|
+
if (!pointInPolygon(middle, outline, false))
|
|
13788
|
+
throw new Error("A finite PCB bend must pass through the board interior");
|
|
13789
|
+
const centerRegion = movingPolygon(outline, a, b, nx, ny);
|
|
13790
|
+
const alongMiddle = -ny * middle.x + nx * middle.y;
|
|
13791
|
+
const proximalCrossings = lineCrossings(outline, nx, ny, proximal);
|
|
13792
|
+
for (let i = 0; i + 1 < proximalCrossings.length; i++) {
|
|
13793
|
+
const left = proximalCrossings[i], right = proximalCrossings[i + 1];
|
|
13794
|
+
const lo = -ny * left.point.x + nx * left.point.y;
|
|
13795
|
+
const hi = -ny * right.point.x + nx * right.point.y;
|
|
13796
|
+
if (alongMiddle <= lo + EPS || alongMiddle >= hi - EPS) continue;
|
|
13797
|
+
const midpoint = {
|
|
13798
|
+
x: (left.point.x + right.point.x) / 2,
|
|
13799
|
+
y: (left.point.y + right.point.y) / 2
|
|
13800
|
+
};
|
|
13801
|
+
if (!pointInPolygon(midpoint, outline, false)) continue;
|
|
13802
|
+
const region = movingPolygon(outline, left, right, nx, ny);
|
|
13803
|
+
if (region.some((p) => p.x * nx + p.y * ny < proximal - EPS) || centerRegion.some((p) => !pointInPolygon(p, region)) || region.some(
|
|
13804
|
+
(p) => p.x * nx + p.y * ny >= center - EPS && !pointInPolygon(p, centerRegion)
|
|
13805
|
+
))
|
|
13806
|
+
break;
|
|
13807
|
+
return region;
|
|
13808
|
+
}
|
|
13809
|
+
throw new Error(
|
|
13810
|
+
"The finite PCB bend zone must remain in one connected board cross-section"
|
|
13811
|
+
);
|
|
13812
|
+
}
|
|
13813
|
+
function polygonsTouch(a, b) {
|
|
13814
|
+
if (a.some((p) => pointInPolygon(p, b)) || b.some((p) => pointInPolygon(p, a)))
|
|
13815
|
+
return true;
|
|
13816
|
+
const cross2 = (p, q, r) => (q.x - p.x) * (r.y - p.y) - (q.y - p.y) * (r.x - p.x);
|
|
13817
|
+
for (let i = 0; i < a.length; i++)
|
|
13818
|
+
for (let j = 0; j < b.length; j++) {
|
|
13819
|
+
const p = a[i], q = a[(i + 1) % a.length], r = b[j], s = b[(j + 1) % b.length];
|
|
13820
|
+
if (cross2(p, q, r) * cross2(p, q, s) < -EPS && cross2(r, s, p) * cross2(r, s, q) < -EPS)
|
|
13821
|
+
return true;
|
|
13822
|
+
}
|
|
13823
|
+
return false;
|
|
13824
|
+
}
|
|
13825
|
+
var EPS2 = 1e-7;
|
|
13826
|
+
function createPcbFold(records, thickness, { outline } = {}) {
|
|
13703
13827
|
if (!Number.isFinite(thickness) || thickness < 0)
|
|
13704
13828
|
throw new Error("Board thickness must be finite and nonnegative");
|
|
13829
|
+
if (outline && (outline.length < 3 || outline.some((p) => !Number.isFinite(p.x) || !Number.isFinite(p.y))))
|
|
13830
|
+
throw new Error(
|
|
13831
|
+
"A finite board outline with at least three points is required"
|
|
13832
|
+
);
|
|
13705
13833
|
const bends = records.map((b) => {
|
|
13706
13834
|
const { start, end, bend_angle: degrees, bend_radius: radius } = b;
|
|
13707
13835
|
const values = [start?.x, start?.y, end?.x, end?.y, degrees, radius];
|
|
@@ -13711,7 +13839,7 @@ function createPcbFold(records, thickness) {
|
|
|
13711
13839
|
);
|
|
13712
13840
|
}
|
|
13713
13841
|
const length = Math.hypot(end.x - start.x, end.y - start.y);
|
|
13714
|
-
if (length <
|
|
13842
|
+
if (length < EPS2 || Math.abs(degrees) > 180)
|
|
13715
13843
|
throw new Error(
|
|
13716
13844
|
`Unsupported PCB bend ${b.pcb_bend_id}: distinct endpoints and angles within \xB1180 degrees are required`
|
|
13717
13845
|
);
|
|
@@ -13721,7 +13849,7 @@ function createPcbFold(records, thickness) {
|
|
|
13721
13849
|
const angle = degrees * Math.PI / 180;
|
|
13722
13850
|
const width = radius * Math.abs(angle);
|
|
13723
13851
|
const center = start.x * nx + start.y * ny;
|
|
13724
|
-
|
|
13852
|
+
const geometry = {
|
|
13725
13853
|
id: b.pcb_bend_id,
|
|
13726
13854
|
nx,
|
|
13727
13855
|
ny,
|
|
@@ -13738,20 +13866,33 @@ function createPcbFold(records, thickness) {
|
|
|
13738
13866
|
-ny * end.x + nx * end.y
|
|
13739
13867
|
)
|
|
13740
13868
|
};
|
|
13741
|
-
|
|
13869
|
+
if (outline && Math.abs(angle) > EPS2)
|
|
13870
|
+
geometry.movingOutline = getFiniteBendRegion({
|
|
13871
|
+
outline,
|
|
13872
|
+
nx,
|
|
13873
|
+
ny,
|
|
13874
|
+
center,
|
|
13875
|
+
proximal: geometry.start,
|
|
13876
|
+
axisMin: geometry.axisMin,
|
|
13877
|
+
axisMax: geometry.axisMax
|
|
13878
|
+
});
|
|
13879
|
+
return geometry;
|
|
13880
|
+
}).filter((b) => Math.abs(b.angle) > EPS2);
|
|
13742
13881
|
const first = bends[0];
|
|
13743
13882
|
if (first && bends.some(
|
|
13744
|
-
(b) => Math.abs(b.nx - first.nx) >
|
|
13883
|
+
(b) => Math.abs(b.nx - first.nx) > EPS2 || Math.abs(b.ny - first.ny) > EPS2
|
|
13745
13884
|
)) {
|
|
13746
13885
|
throw new Error(
|
|
13747
13886
|
"Folded PCB rendering currently requires parallel bends with the same moving direction"
|
|
13748
13887
|
);
|
|
13749
13888
|
}
|
|
13750
13889
|
bends.sort((a, b) => a.start - b.start);
|
|
13751
|
-
for (let i =
|
|
13752
|
-
|
|
13753
|
-
|
|
13754
|
-
|
|
13890
|
+
for (let i = 0; i < bends.length; i++)
|
|
13891
|
+
for (let j = i + 1; j < bends.length; j++) {
|
|
13892
|
+
const a = bends[i], b = bends[j];
|
|
13893
|
+
if (b.start < a.end - EPS2 && (!a.movingOutline || !b.movingOutline || polygonsTouch(a.movingOutline, b.movingOutline)))
|
|
13894
|
+
throw new Error("Overlapping PCB bend zones are not supported");
|
|
13895
|
+
}
|
|
13755
13896
|
const distalFirst = [...bends].reverse();
|
|
13756
13897
|
const transform = ({
|
|
13757
13898
|
p,
|
|
@@ -13760,6 +13901,7 @@ function createPcbFold(records, thickness) {
|
|
|
13760
13901
|
}) => {
|
|
13761
13902
|
let result = { ...p };
|
|
13762
13903
|
for (const b of distalFirst) {
|
|
13904
|
+
if (b.movingOutline && !pointInPolygon(anchor, b.movingOutline)) continue;
|
|
13763
13905
|
const width = b.end - b.start;
|
|
13764
13906
|
const s = anchor.x * b.nx + anchor.y * b.ny - b.start;
|
|
13765
13907
|
const q = Math.max(0, Math.min(width, s));
|
|
@@ -13807,14 +13949,17 @@ function createPcbFold(records, thickness) {
|
|
|
13807
13949
|
direction: (p, anchor) => transform({ p, anchor, direction: true }),
|
|
13808
13950
|
assertRigid(points, label) {
|
|
13809
13951
|
for (const b of bends) {
|
|
13810
|
-
const
|
|
13811
|
-
|
|
13952
|
+
const width = b.end - b.start;
|
|
13953
|
+
const progress = points.map(
|
|
13954
|
+
(p) => b.movingOutline && !pointInPolygon(p, b.movingOutline) ? 0 : Math.max(0, Math.min(width, p.x * b.nx + p.y * b.ny - b.start))
|
|
13955
|
+
);
|
|
13956
|
+
if (Math.max(...progress) > EPS2 && Math.min(...progress) < width - EPS2)
|
|
13812
13957
|
throw new Error(`${label} intersects PCB bend zone ${b.id}`);
|
|
13813
13958
|
}
|
|
13814
13959
|
}
|
|
13815
13960
|
};
|
|
13816
13961
|
}
|
|
13817
|
-
var
|
|
13962
|
+
var EPS3 = 1e-7;
|
|
13818
13963
|
function boundsOfTriangles(triangles) {
|
|
13819
13964
|
const points = triangles.flatMap((t) => t.vertices);
|
|
13820
13965
|
if (!points.length)
|
|
@@ -13844,7 +13989,7 @@ function foldSurfaceMesh(mesh, fold) {
|
|
|
13844
13989
|
d
|
|
13845
13990
|
}) => {
|
|
13846
13991
|
const distances = polygon3.map(({ p }) => nx * p.x + ny * p.y - d);
|
|
13847
|
-
if (Math.min(...distances) >= -
|
|
13992
|
+
if (Math.min(...distances) >= -EPS3 || Math.max(...distances) <= EPS3)
|
|
13848
13993
|
return [polygon3];
|
|
13849
13994
|
const halves = [[], []];
|
|
13850
13995
|
for (let side = 0; side < 2; side++) {
|
|
@@ -13852,8 +13997,8 @@ function foldSurfaceMesh(mesh, fold) {
|
|
|
13852
13997
|
for (let i = 0; i < polygon3.length; i++) {
|
|
13853
13998
|
const a = polygon3[i], next = (i + 1) % polygon3.length, b = polygon3[next];
|
|
13854
13999
|
const da = distances[i] * sign, db = distances[next] * sign;
|
|
13855
|
-
if (da >= -
|
|
13856
|
-
if (da >
|
|
14000
|
+
if (da >= -EPS3) halves[side].push(a);
|
|
14001
|
+
if (da > EPS3 && db < -EPS3 || da < -EPS3 && db > EPS3) {
|
|
13857
14002
|
const t = da / (da - db);
|
|
13858
14003
|
halves[side].push({
|
|
13859
14004
|
p: {
|
|
@@ -13889,10 +14034,11 @@ function foldSurfaceMesh(mesh, fold) {
|
|
|
13889
14034
|
);
|
|
13890
14035
|
for (const polygon3 of polygons) {
|
|
13891
14036
|
for (const b of fold.bends) {
|
|
14037
|
+
if (b.movingOutline) continue;
|
|
13892
14038
|
const mid = polygon3.reduce((sum, { p }) => sum + p.x * b.nx + p.y * b.ny, 0) / polygon3.length;
|
|
13893
|
-
if (mid > b.start +
|
|
14039
|
+
if (mid > b.start + EPS3 && mid < b.end - EPS3 && polygon3.some(({ p }) => {
|
|
13894
14040
|
const along = -b.ny * p.x + b.nx * p.y;
|
|
13895
|
-
return along < b.axisMin -
|
|
14041
|
+
return along < b.axisMin - EPS3 || along > b.axisMax + EPS3;
|
|
13896
14042
|
}))
|
|
13897
14043
|
throw new Error(
|
|
13898
14044
|
`PCB bend ${b.id} must span the full board cross-section through its bend zone`
|
|
@@ -14022,7 +14168,12 @@ function getCadFoldContext(cadComponent, json) {
|
|
|
14022
14168
|
(e) => e.type === "pcb_bend" && e.pcb_board_id === board.pcb_board_id
|
|
14023
14169
|
);
|
|
14024
14170
|
return {
|
|
14025
|
-
fold: createPcbFold(bends, board.thickness ?? 1.6
|
|
14171
|
+
fold: createPcbFold(bends, board.thickness ?? 1.6, {
|
|
14172
|
+
outline: board.outline?.map((p) => ({
|
|
14173
|
+
x: p.x - board.center.x,
|
|
14174
|
+
y: p.y - board.center.y
|
|
14175
|
+
}))
|
|
14176
|
+
}),
|
|
14026
14177
|
boardCenter: board.center,
|
|
14027
14178
|
flatMount: pcb.center,
|
|
14028
14179
|
defaultRotation: {
|
|
@@ -17824,7 +17975,16 @@ async function convertCircuitJsonTo3D(inputCircuitJson, options = {}) {
|
|
|
17824
17975
|
"PCB flex rendering requires exactly one board, matching board references, and no panel"
|
|
17825
17976
|
);
|
|
17826
17977
|
}
|
|
17827
|
-
const fold = foldPcbs && bends.length ? createPcbFold(bends, pcbBoard?.thickness ?? boardThickness
|
|
17978
|
+
const fold = foldPcbs && bends.length ? createPcbFold(bends, pcbBoard?.thickness ?? boardThickness, {
|
|
17979
|
+
// Outline points are circuit-world mm (+X right, +Y top, +Z above).
|
|
17980
|
+
// Translate them into the right-handed board-local frame used by
|
|
17981
|
+
// bend endpoints before folding the mesh into the +Y-up scene.
|
|
17982
|
+
// Matches flex-utils' getCadFoldContext outline translation.
|
|
17983
|
+
outline: pcbBoard?.outline?.map((point) => ({
|
|
17984
|
+
x: point.x - pcbBoard.center.x,
|
|
17985
|
+
y: point.y - pcbBoard.center.y
|
|
17986
|
+
}))
|
|
17987
|
+
}) : void 0;
|
|
17828
17988
|
const effectiveBoardThickness = pcbBoard?.thickness ?? boardThickness;
|
|
17829
17989
|
if (pcbPanel) {
|
|
17830
17990
|
const pcbHoles = db.pcb_hole?.list?.() ?? [];
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "circuit-json-to-gltf",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.137",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/tscircuit/circuit-json-to-gltf.git"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"occt-import-js": "^0.0.23"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tscircuit/flex-utils": "https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.
|
|
32
|
+
"@tscircuit/flex-utils": "https://jscdn.tscircuit.com/@tscircuit/flex-utils/0.0.6.tgz",
|
|
33
33
|
"@biomejs/biome": "^2.1.4",
|
|
34
34
|
"@google/model-viewer": "^4.1.0",
|
|
35
35
|
"@napi-rs/canvas": "^1.0.9",
|