brepjs 12.7.3 → 12.8.1
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/2d/blueprints/boolean2D.d.ts.map +1 -1
- package/dist/2d/blueprints/lib.d.ts.map +1 -1
- package/dist/2d/blueprints/offset.d.ts.map +1 -1
- package/dist/2d.cjs +2 -2
- package/dist/2d.js +3 -3
- package/dist/{Blueprint-CnDVffSX.cjs → Blueprint-CQ28WJhz.cjs} +29 -30
- package/dist/{Blueprint-C3lWY1Jf.js → Blueprint-DbVaf6k7.js} +7 -8
- package/dist/{boolean2D-DyQJt8Na.cjs → boolean2D-0blbVtJ8.cjs} +70 -61
- package/dist/{boolean2D-CwZAIJDS.js → boolean2D-y3E92F0u.js} +37 -28
- package/dist/{booleanFns-CcNUsgI8.js → booleanFns-BCTjYZAg.js} +4 -4
- package/dist/{booleanFns-D7HmkpYt.cjs → booleanFns-gmsX3Cv2.cjs} +59 -59
- package/dist/brepjs.cjs +319 -372
- package/dist/brepjs.js +358 -411
- package/dist/core/errors.d.ts +14 -5
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core.cjs +30 -31
- package/dist/core.js +19 -20
- package/dist/{cornerFinder-BV-l1BCw.js → cornerFinder-Ckz-mPHE.js} +1 -1
- package/dist/{cornerFinder-3zfbQvXg.cjs → cornerFinder-ZmOyOOsh.cjs} +1 -1
- package/dist/{curveFns-Ch87sD5O.cjs → curveFns-BZngcnQ1.cjs} +17 -17
- package/dist/{curveFns-CloOqAQ_.js → curveFns-mROFhiuG.js} +1 -1
- package/dist/{drawFns-5myJTgtX.js → drawFns-Bwakrq7w.js} +24 -25
- package/dist/{drawFns-CDNafQhv.cjs → drawFns-CjRc1NfQ.cjs} +51 -52
- package/dist/{faceFns-B6ebRh5I.js → faceFns-B8GnxjdY.js} +1 -1
- package/dist/{faceFns-BLTEPBKq.cjs → faceFns-DB1Fc5gy.cjs} +20 -20
- package/dist/{helpers-6kn30cSD.cjs → helpers-C8NoT0Wu.cjs} +14 -14
- package/dist/{helpers-C9KvE1RW.js → helpers-X0juxnwj.js} +4 -4
- package/dist/io.cjs +26 -26
- package/dist/io.js +3 -3
- package/dist/kernel/brepkitAdapter.d.ts +8 -8
- package/dist/kernel/brepkitAdapter.d.ts.map +1 -1
- package/dist/kernel/brepkitWasmTypes.d.ts +6 -0
- package/dist/kernel/brepkitWasmTypes.d.ts.map +1 -1
- package/dist/kernel/historyOps.d.ts +3 -3
- package/dist/kernel/historyOps.d.ts.map +1 -1
- package/dist/kernel/types.d.ts +8 -8
- package/dist/kernel/types.d.ts.map +1 -1
- package/dist/{loft-BcZUCGKi.js → loft-Bhw-FMoL.js} +4 -4
- package/dist/{loft-DR1UN5uN.cjs → loft-hp3pc1M7.cjs} +43 -43
- package/dist/{measurement-DoYXRaKI.cjs → measurement-BoNTUBAp.cjs} +1 -1
- package/dist/{measurement-oWvhSVZG.js → measurement-D8EJ694A.js} +1 -1
- package/dist/measurement.cjs +1 -1
- package/dist/measurement.js +1 -1
- package/dist/{meshFns-3gy0empP.cjs → meshFns-BnV0ZR8w.cjs} +17 -17
- package/dist/{meshFns-DsLRd3tA.js → meshFns-nQjK38EC.js} +2 -2
- package/dist/{operations-Dcz6YlOt.js → operations-BfbkK6DU.js} +5 -5
- package/dist/{operations-DLFzmdFX.cjs → operations-CYpmLSC4.cjs} +75 -75
- package/dist/operations.cjs +2 -2
- package/dist/operations.js +2 -2
- package/dist/query.cjs +3 -3
- package/dist/query.js +4 -4
- package/dist/{errors-B7kgv0cd.js → result-BaSD1fqR.js} +43 -23
- package/dist/{errors-9fDehDNc.cjs → result-fAX0OZzI.cjs} +20 -0
- package/dist/result.cjs +30 -41
- package/dist/result.js +18 -29
- package/dist/{shapeFns-D-MOoqJd.cjs → shapeFns-C2SnNvdH.cjs} +39 -39
- package/dist/{shapeFns-D2PlLFE6.js → shapeFns-FDuKkrDR.js} +4 -4
- package/dist/sketching.cjs +2 -2
- package/dist/sketching.js +2 -2
- package/dist/{solidBuilders-BzfRBizW.cjs → solidBuilders-994_MQwB.cjs} +12 -12
- package/dist/{solidBuilders-BXhh5hP2.js → solidBuilders-DmwhTCCd.js} +2 -2
- package/dist/{surfaceBuilders-Be_ENWSA.cjs → surfaceBuilders-5VA34a3_.cjs} +27 -27
- package/dist/{surfaceBuilders-D6iDVPIM.js → surfaceBuilders-nQdJ56fe.js} +2 -2
- package/dist/{topology-CKtCGLmb.cjs → topology-ANwCzGL8.cjs} +54 -54
- package/dist/{topology-DxD58iQ6.js → topology-C7x98OVn.js} +8 -8
- package/dist/topology.cjs +6 -6
- package/dist/topology.js +6 -6
- package/dist/{vectors-CESkzEm6.js → vectors-Bx8wkNui.js} +1 -1
- package/dist/{vectors-BafmMf96.cjs → vectors-D_IiZx0q.cjs} +6 -6
- package/dist/vectors.cjs +1 -1
- package/dist/vectors.js +1 -1
- package/package.json +5 -8
|
@@ -44,23 +44,22 @@ var __callDispose = (stack, error, hasError) => {
|
|
|
44
44
|
};
|
|
45
45
|
return next();
|
|
46
46
|
};
|
|
47
|
-
const
|
|
48
|
-
const vectors = require("./vectors-
|
|
47
|
+
const result = require("./result-fAX0OZzI.cjs");
|
|
48
|
+
const vectors = require("./vectors-D_IiZx0q.cjs");
|
|
49
49
|
const types = require("./types-CA_xrgDq.cjs");
|
|
50
50
|
const vecOps = require("./vecOps-CjRL1jau.cjs");
|
|
51
|
-
const boolean2D = require("./boolean2D-
|
|
52
|
-
const faceFns = require("./faceFns-
|
|
53
|
-
const curveFns = require("./curveFns-
|
|
54
|
-
const surfaceBuilders = require("./surfaceBuilders-
|
|
51
|
+
const boolean2D = require("./boolean2D-0blbVtJ8.cjs");
|
|
52
|
+
const faceFns = require("./faceFns-DB1Fc5gy.cjs");
|
|
53
|
+
const curveFns = require("./curveFns-BZngcnQ1.cjs");
|
|
54
|
+
const surfaceBuilders = require("./surfaceBuilders-5VA34a3_.cjs");
|
|
55
55
|
const shapeTypes = require("./shapeTypes-7xEam9Ri.cjs");
|
|
56
|
-
const Blueprint = require("./Blueprint-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const loft = require("./loft-DR1UN5uN.cjs");
|
|
56
|
+
const Blueprint = require("./Blueprint-CQ28WJhz.cjs");
|
|
57
|
+
const helpers = require("./helpers-C8NoT0Wu.cjs");
|
|
58
|
+
const shapeFns = require("./shapeFns-C2SnNvdH.cjs");
|
|
59
|
+
const solidBuilders = require("./solidBuilders-994_MQwB.cjs");
|
|
60
|
+
const loft = require("./loft-hp3pc1M7.cjs");
|
|
62
61
|
const opentype = require("opentype.js");
|
|
63
|
-
const cornerFinder = require("./cornerFinder-
|
|
62
|
+
const cornerFinder = require("./cornerFinder-ZmOyOOsh.cjs");
|
|
64
63
|
const stitchCurves = (curves, precision = 1e-7) => {
|
|
65
64
|
const startPoints = new boolean2D.Flatbush(curves.length);
|
|
66
65
|
curves.forEach((c) => {
|
|
@@ -138,7 +137,7 @@ class Sketcher extends boolean2D.BaseSketcher2d {
|
|
|
138
137
|
const edges = Blueprint.curvesAsEdgesOnPlane(this.pendingCurves, this.plane).map(
|
|
139
138
|
(e) => scope.register(e)
|
|
140
139
|
);
|
|
141
|
-
return
|
|
140
|
+
return result.unwrap(surfaceBuilders.assembleWire(edges));
|
|
142
141
|
} catch (_) {
|
|
143
142
|
var _error = _, _hasError = true;
|
|
144
143
|
} finally {
|
|
@@ -175,11 +174,11 @@ class Sketcher extends boolean2D.BaseSketcher2d {
|
|
|
175
174
|
const diff = vecOps.vecSub(pointer3d, firstPoint3d);
|
|
176
175
|
const startToEndVector = vecOps.vecNormalize(diff);
|
|
177
176
|
const normal = vecOps.vecCross(startToEndVector, this.plane.zDir);
|
|
178
|
-
const clonedWrapped =
|
|
177
|
+
const clonedWrapped = result.unwrap(faceFns.downcast(wire.wrapped));
|
|
179
178
|
const mirroredRaw = Blueprint.mirror(clonedWrapped, normal, pointer3d);
|
|
180
|
-
const mirroredWrapped =
|
|
179
|
+
const mirroredWrapped = result.unwrap(faceFns.downcast(mirroredRaw));
|
|
181
180
|
const mirroredWire = shapeTypes.createWire(mirroredWrapped);
|
|
182
|
-
const combinedWire =
|
|
181
|
+
const combinedWire = result.unwrap(surfaceBuilders.assembleWire([wire, mirroredWire]));
|
|
183
182
|
return new boolean2D.Sketch(combinedWire, {
|
|
184
183
|
defaultOrigin: this.plane.origin,
|
|
185
184
|
defaultDirection: this.plane.zDir
|
|
@@ -200,7 +199,7 @@ class Sketcher extends boolean2D.BaseSketcher2d {
|
|
|
200
199
|
}
|
|
201
200
|
const guessFaceFromWires = (wires) => {
|
|
202
201
|
const wireShapes = wires.map((w) => w.wrapped);
|
|
203
|
-
const newFace =
|
|
202
|
+
const newFace = result.unwrap(faceFns.cast(shapeTypes.getKernel().fillSurface(wireShapes)));
|
|
204
203
|
if (!shapeTypes.isFace(newFace)) {
|
|
205
204
|
result.bug("guessFaceFromWires", "Failed to create a face");
|
|
206
205
|
}
|
|
@@ -214,7 +213,7 @@ const faceFromWires = (wires) => {
|
|
|
214
213
|
let baseFace;
|
|
215
214
|
let holeWires;
|
|
216
215
|
const faceResult = surfaceBuilders.makeFace(wires[0]);
|
|
217
|
-
if (
|
|
216
|
+
if (result.isOk(faceResult)) {
|
|
218
217
|
baseFace = faceResult.value;
|
|
219
218
|
holeWires = wires.slice(1);
|
|
220
219
|
} else {
|
|
@@ -228,14 +227,14 @@ const solidFromShellGenerator = (sketches, shellGenerator) => {
|
|
|
228
227
|
const startWires = [];
|
|
229
228
|
const endWires = [];
|
|
230
229
|
sketches.forEach((sketch) => {
|
|
231
|
-
const [shell, startWire, endWire] =
|
|
230
|
+
const [shell, startWire, endWire] = result.unwrap(shellGenerator(sketch));
|
|
232
231
|
shells.push(shell);
|
|
233
232
|
startWires.push(startWire);
|
|
234
233
|
endWires.push(endWire);
|
|
235
234
|
});
|
|
236
235
|
const startFace = faceFromWires(startWires);
|
|
237
236
|
const endFace = faceFromWires(endWires);
|
|
238
|
-
const solid =
|
|
237
|
+
const solid = result.unwrap(solidBuilders.makeSolid([startFace, ...shells, endFace]));
|
|
239
238
|
return solid;
|
|
240
239
|
};
|
|
241
240
|
class CompoundSketch {
|
|
@@ -323,7 +322,7 @@ class CompoundSketch {
|
|
|
323
322
|
* (defaults to the sketch origin)
|
|
324
323
|
*/
|
|
325
324
|
revolve(revolutionAxis, { origin } = {}) {
|
|
326
|
-
return
|
|
325
|
+
return result.unwrap(
|
|
327
326
|
loft.revolution(
|
|
328
327
|
this.face(),
|
|
329
328
|
origin ? types.toVec3(origin) : this.outerSketch.defaultOrigin,
|
|
@@ -343,9 +342,9 @@ class CompoundSketch {
|
|
|
343
342
|
return base.clone().loftWith(outer.clone(), { ruled: loftConfig.ruled }, true);
|
|
344
343
|
});
|
|
345
344
|
const baseFaceRaw = this.face();
|
|
346
|
-
const baseFace = shapeTypes.createFace(
|
|
345
|
+
const baseFace = shapeTypes.createFace(result.unwrap(faceFns.downcast(baseFaceRaw.wrapped)));
|
|
347
346
|
shells.push(baseFace, otherCompound.face());
|
|
348
|
-
return
|
|
347
|
+
return result.unwrap(solidBuilders.makeSolid(shells));
|
|
349
348
|
}
|
|
350
349
|
}
|
|
351
350
|
class Sketches {
|
|
@@ -387,7 +386,7 @@ class Sketches {
|
|
|
387
386
|
}
|
|
388
387
|
const sketchCircle = (radius, planeConfig = {}) => {
|
|
389
388
|
const plane = planeConfig.plane && typeof planeConfig.plane !== "string" ? { ...planeConfig.plane } : vectors.resolvePlane(planeConfig.plane ?? "XY", planeConfig.origin);
|
|
390
|
-
const wire =
|
|
389
|
+
const wire = result.unwrap(surfaceBuilders.assembleWire([surfaceBuilders.makeCircle(radius, plane.origin, plane.zDir)]));
|
|
391
390
|
const sketch = new boolean2D.Sketch(wire, {
|
|
392
391
|
defaultOrigin: [...plane.origin],
|
|
393
392
|
defaultDirection: [...plane.zDir]
|
|
@@ -404,8 +403,8 @@ const sketchEllipse = (xRadius = 1, yRadius = 2, planeConfig = {}) => {
|
|
|
404
403
|
majR = yRadius;
|
|
405
404
|
minR = xRadius;
|
|
406
405
|
}
|
|
407
|
-
const wire =
|
|
408
|
-
surfaceBuilders.assembleWire([
|
|
406
|
+
const wire = result.unwrap(
|
|
407
|
+
surfaceBuilders.assembleWire([result.unwrap(surfaceBuilders.makeEllipse(majR, minR, plane.origin, plane.zDir, xDir))])
|
|
409
408
|
);
|
|
410
409
|
const sketch = new boolean2D.Sketch(wire, {
|
|
411
410
|
defaultOrigin: [...plane.origin],
|
|
@@ -454,7 +453,7 @@ const polysideInnerRadius = (outerRadius, sidesCount, sagitta = 0) => {
|
|
|
454
453
|
const sketchFaceOffset = (face, offset2) => {
|
|
455
454
|
const defaultOrigin = [...faceFns.faceCenter(face)];
|
|
456
455
|
const defaultDirection = [...faceFns.normalAt(face)];
|
|
457
|
-
const wire =
|
|
456
|
+
const wire = result.unwrap(curveFns.offsetWire2D(faceFns.outerWire(face), offset2));
|
|
458
457
|
const sketch = new boolean2D.Sketch(wire, { defaultOrigin, defaultDirection });
|
|
459
458
|
return sketch;
|
|
460
459
|
};
|
|
@@ -468,8 +467,8 @@ const sketchParametricFunction = (func, planeConfig = {}, { pointsCount = 400, s
|
|
|
468
467
|
const point = func(start + t * stepSize);
|
|
469
468
|
return vectors.planeToWorld(plane, point);
|
|
470
469
|
});
|
|
471
|
-
const wire =
|
|
472
|
-
surfaceBuilders.assembleWire([scope.register(
|
|
470
|
+
const wire = result.unwrap(
|
|
471
|
+
surfaceBuilders.assembleWire([scope.register(result.unwrap(surfaceBuilders.makeBSplineApproximation(points, approximationConfig)))])
|
|
473
472
|
);
|
|
474
473
|
const sketch = new boolean2D.Sketch(wire, {
|
|
475
474
|
defaultOrigin: [...plane.origin],
|
|
@@ -486,7 +485,7 @@ const sketchHelix = (pitch, height, radius, center = [0, 0, 0], dir = [0, 0, 1],
|
|
|
486
485
|
const centerVec3 = types.toVec3(center);
|
|
487
486
|
const dirVec3 = types.toVec3(dir);
|
|
488
487
|
return new boolean2D.Sketch(
|
|
489
|
-
|
|
488
|
+
result.unwrap(surfaceBuilders.assembleWire([surfaceBuilders.makeHelix(pitch, height, radius, centerVec3, dirVec3, lefthand)]))
|
|
490
489
|
);
|
|
491
490
|
};
|
|
492
491
|
const makeBaseBox = (xLength, yLength, zLength) => {
|
|
@@ -586,18 +585,18 @@ function rawOffsets(blueprint, offset2, offsetConfig = {}) {
|
|
|
586
585
|
}
|
|
587
586
|
let intersections = [];
|
|
588
587
|
if (previousCurve.offset instanceof Blueprint.Curve2D && curve.offset instanceof Blueprint.Curve2D) {
|
|
589
|
-
const { intersections: pointIntersections, commonSegmentsPoints } =
|
|
588
|
+
const { intersections: pointIntersections, commonSegmentsPoints } = result.unwrap(
|
|
590
589
|
boolean2D.intersectCurves(previousCurve.offset, curve.offset, helpers.PRECISION_OFFSET / 100)
|
|
591
590
|
);
|
|
592
591
|
intersections = [...pointIntersections, ...commonSegmentsPoints];
|
|
593
592
|
}
|
|
594
593
|
if (intersections.length > 0) {
|
|
595
|
-
let intersection = intersections
|
|
594
|
+
let intersection = result.safeIndex(intersections, 0, "rawOffsets");
|
|
596
595
|
if (intersections.length > 1) {
|
|
597
596
|
const originalEndpoint = previousCurve.original.lastPoint;
|
|
598
597
|
let minDist = helpers.squareDistance2d(intersection, originalEndpoint);
|
|
599
598
|
for (let i = 1; i < intersections.length; i++) {
|
|
600
|
-
const point = intersections
|
|
599
|
+
const point = result.safeIndex(intersections, i, "rawOffsets");
|
|
601
600
|
const d = helpers.squareDistance2d(point, originalEndpoint);
|
|
602
601
|
if (d < minDist) {
|
|
603
602
|
minDist = d;
|
|
@@ -605,10 +604,11 @@ function rawOffsets(blueprint, offset2, offsetConfig = {}) {
|
|
|
605
604
|
}
|
|
606
605
|
}
|
|
607
606
|
}
|
|
608
|
-
const splitPreviousCurve =
|
|
609
|
-
[intersection],
|
|
610
|
-
|
|
611
|
-
|
|
607
|
+
const splitPreviousCurve = result.safeIndex(
|
|
608
|
+
previousCurve.offset.splitAt([intersection], helpers.PRECISION_OFFSET),
|
|
609
|
+
0,
|
|
610
|
+
"rawOffsets"
|
|
611
|
+
);
|
|
612
612
|
const splitCurve = curve.offset.splitAt([intersection], helpers.PRECISION_OFFSET).at(-1);
|
|
613
613
|
if (!splitCurve) result.bug("offset.rawOffsets", "Split produced no trailing curve segment");
|
|
614
614
|
appendCurve({
|
|
@@ -648,8 +648,8 @@ function offsetBlueprint(blueprint, offset2, offsetConfig = {}) {
|
|
|
648
648
|
const pairKey = `${firstIndex}-${secondIndex}`;
|
|
649
649
|
if (testedPairs.has(pairKey)) continue;
|
|
650
650
|
testedPairs.add(pairKey);
|
|
651
|
-
const secondCurve = offsettedArray
|
|
652
|
-
const { intersections: rawIntersections, commonSegmentsPoints } =
|
|
651
|
+
const secondCurve = result.safeIndex(offsettedArray, secondIndex, "offsetBlueprint");
|
|
652
|
+
const { intersections: rawIntersections, commonSegmentsPoints } = result.unwrap(
|
|
653
653
|
boolean2D.intersectCurves(firstCurve, secondCurve, helpers.PRECISION_OFFSET)
|
|
654
654
|
);
|
|
655
655
|
const intersections = [...rawIntersections, ...commonSegmentsPoints].filter(
|
|
@@ -686,14 +686,14 @@ function offsetBlueprint(blueprint, offset2, offsetConfig = {}) {
|
|
|
686
686
|
const blueprints = curvesGrouped.filter((c) => c.length > 1).map((c) => new Blueprint.Blueprint(c)).filter((b) => b.isClosed());
|
|
687
687
|
if (!blueprints.length) return null;
|
|
688
688
|
if (blueprints.length === 1) {
|
|
689
|
-
return blueprints
|
|
689
|
+
return result.safeIndex(blueprints, 0, "offsetBlueprint");
|
|
690
690
|
}
|
|
691
691
|
return new boolean2D.Blueprints(blueprints);
|
|
692
692
|
}
|
|
693
693
|
const fuseAll = (blueprints) => {
|
|
694
|
-
let fused = blueprints
|
|
694
|
+
let fused = result.safeIndex(blueprints, 0, "fuseAll");
|
|
695
695
|
for (let i = 1; i < blueprints.length; i++) {
|
|
696
|
-
fused = boolean2D.fuse2D(fused, blueprints
|
|
696
|
+
fused = boolean2D.fuse2D(fused, result.safeIndex(blueprints, i, "fuseAll"));
|
|
697
697
|
}
|
|
698
698
|
return fused;
|
|
699
699
|
};
|
|
@@ -707,8 +707,7 @@ function offset(bp, offsetDistance, offsetConfig = {}) {
|
|
|
707
707
|
bp.blueprints.slice(1).map((b) => offset(b, offsetDistance, offsetConfig))
|
|
708
708
|
);
|
|
709
709
|
return boolean2D.cut2D(
|
|
710
|
-
|
|
711
|
-
offset(bp.blueprints[0], offsetDistance, offsetConfig),
|
|
710
|
+
offset(result.safeIndex(bp.blueprints, 0, "offset"), offsetDistance, offsetConfig),
|
|
712
711
|
innerShape
|
|
713
712
|
);
|
|
714
713
|
}
|
|
@@ -950,8 +949,8 @@ function makeProjectedEdges(shape, camera, withHiddenLines = true) {
|
|
|
950
949
|
function createCamera(position = [0, 0, 0], direction = [0, 0, 1], xAxis) {
|
|
951
950
|
const dirLength = vecOps.vecLength(direction);
|
|
952
951
|
if (dirLength < 1e-12) {
|
|
953
|
-
return
|
|
954
|
-
|
|
952
|
+
return result.err(
|
|
953
|
+
result.validationError("CAMERA_ZERO_DIRECTION", "Camera direction cannot be a zero-length vector")
|
|
955
954
|
);
|
|
956
955
|
}
|
|
957
956
|
let resolvedXAxis;
|
|
@@ -968,7 +967,7 @@ function createCamera(position = [0, 0, 0], direction = [0, 0, 1], xAxis) {
|
|
|
968
967
|
resolvedXAxis = vecOps.vecNormalize(cross);
|
|
969
968
|
}
|
|
970
969
|
const yAxis = vecOps.vecNormalize(vecOps.vecCross(direction, resolvedXAxis));
|
|
971
|
-
return
|
|
970
|
+
return result.ok({
|
|
972
971
|
position,
|
|
973
972
|
direction: vecOps.vecNormalize(direction),
|
|
974
973
|
xAxis: resolvedXAxis,
|
|
@@ -1253,7 +1252,7 @@ const drawPointsInterpolation = (points, approximationConfig = {}, options = {})
|
|
|
1253
1252
|
`Need at least 2 points for interpolation, got ${points.length}`
|
|
1254
1253
|
);
|
|
1255
1254
|
}
|
|
1256
|
-
const curves = [
|
|
1255
|
+
const curves = [result.unwrap(Blueprint.make2dInerpolatedBSplineCurve(points, approximationConfig))];
|
|
1257
1256
|
const firstPoint = points[0];
|
|
1258
1257
|
const lastPoint = points[points.length - 1];
|
|
1259
1258
|
if (options.closeShape && firstPoint && lastPoint && !helpers.samePoint(firstPoint, lastPoint)) {
|
|
@@ -1273,7 +1272,7 @@ const edgesToDrawing = (edges) => {
|
|
|
1273
1272
|
try {
|
|
1274
1273
|
const scope = __using(_stack, new shapeTypes.DisposalScope());
|
|
1275
1274
|
const planeSketch = drawRectangle(1e3, 1e3).sketchOnPlane();
|
|
1276
|
-
const planeFace = scope.register(
|
|
1275
|
+
const planeFace = scope.register(result.unwrap(surfaceBuilders.makeFace(planeSketch.wire)));
|
|
1277
1276
|
const curves = edges.map((e) => Blueprint.edgeToCurve(e, planeFace));
|
|
1278
1277
|
const stitchedCurves = stitchCurves(curves).map((s) => new Blueprint.Blueprint(s));
|
|
1279
1278
|
if (stitchedCurves.length === 0) return new Drawing();
|
|
@@ -1288,7 +1287,7 @@ const edgesToDrawing = (edges) => {
|
|
|
1288
1287
|
function drawProjection(shape, projectionCamera = "front") {
|
|
1289
1288
|
let camera;
|
|
1290
1289
|
if (typeof projectionCamera === "string") {
|
|
1291
|
-
camera =
|
|
1290
|
+
camera = result.unwrap(cameraFromPlane(projectionCamera));
|
|
1292
1291
|
} else {
|
|
1293
1292
|
camera = projectionCamera;
|
|
1294
1293
|
}
|
|
@@ -1302,7 +1301,7 @@ function drawFaceOutline(face) {
|
|
|
1302
1301
|
var _stack = [];
|
|
1303
1302
|
try {
|
|
1304
1303
|
const scope = __using(_stack, new shapeTypes.DisposalScope());
|
|
1305
|
-
const clonedFace = scope.register(shapeTypes.createFace(
|
|
1304
|
+
const clonedFace = scope.register(shapeTypes.createFace(result.unwrap(faceFns.downcast(face.wrapped))));
|
|
1306
1305
|
const faceOuterWire = scope.register(faceFns.outerWire(clonedFace));
|
|
1307
1306
|
const curves = shapeFns.getEdges(faceOuterWire).map((e) => Blueprint.edgeToCurve(e, face));
|
|
1308
1307
|
const stitchedCurves = stitchCurves(curves).map((s) => new Blueprint.Blueprint(s));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { B as getKernel, c as castShape, p as isShape3D$1, u as isWire$1 } from "./shapeTypes-CpSaBLDv.js";
|
|
2
2
|
import { a as toVec3 } from "./types-CWDdqcrq.js";
|
|
3
|
-
import { e as err,
|
|
3
|
+
import { e as err, r as typeCastError, o as ok, v as unwrap } from "./result-BaSD1fqR.js";
|
|
4
4
|
const TOPO_ENUM = {
|
|
5
5
|
compound: 0,
|
|
6
6
|
solidCompound: 1,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const shapeTypes = require("./shapeTypes-7xEam9Ri.cjs");
|
|
3
3
|
const types = require("./types-CA_xrgDq.cjs");
|
|
4
|
-
const
|
|
4
|
+
const result = require("./result-fAX0OZzI.cjs");
|
|
5
5
|
const TOPO_ENUM = {
|
|
6
6
|
compound: 0,
|
|
7
7
|
solidCompound: 1,
|
|
@@ -37,24 +37,24 @@ const iterTopo = function* iterTopo2(shape, topo) {
|
|
|
37
37
|
};
|
|
38
38
|
const shapeType = (shape) => {
|
|
39
39
|
if (shapeTypes.getKernel().isNull(shape))
|
|
40
|
-
return
|
|
41
|
-
return
|
|
40
|
+
return result.err(result.typeCastError("NULL_SHAPE", "This shape has no type, it is null"));
|
|
41
|
+
return result.ok(shape.ShapeType());
|
|
42
42
|
};
|
|
43
43
|
function downcast(shape) {
|
|
44
44
|
if (shapeTypes.getKernel().isNull(shape)) {
|
|
45
|
-
return
|
|
45
|
+
return result.err(result.typeCastError("NULL_SHAPE", "This shape has no type, it is null"));
|
|
46
46
|
}
|
|
47
47
|
try {
|
|
48
|
-
return
|
|
48
|
+
return result.ok(shapeTypes.getKernel().downcast(shape));
|
|
49
49
|
} catch {
|
|
50
|
-
return
|
|
50
|
+
return result.err(result.typeCastError("NO_WRAPPER", "Could not find a wrapper for this shape type"));
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
function cast(shape) {
|
|
54
54
|
if (shapeTypes.getKernel().isNull(shape)) {
|
|
55
|
-
return
|
|
55
|
+
return result.err(result.typeCastError("NULL_SHAPE", "Cannot cast a null shape"));
|
|
56
56
|
}
|
|
57
|
-
return
|
|
57
|
+
return result.ok(shapeTypes.castShape(shape));
|
|
58
58
|
}
|
|
59
59
|
function isShape3D(shape) {
|
|
60
60
|
return shapeTypes.isShape3D(shape);
|
|
@@ -83,10 +83,10 @@ const KERNEL_TO_PUBLIC_SURFACE_TYPE = {
|
|
|
83
83
|
};
|
|
84
84
|
function getSurfaceType(face) {
|
|
85
85
|
const kernelType = shapeTypes.getKernel().surfaceType(face.wrapped);
|
|
86
|
-
return
|
|
86
|
+
return result.ok(KERNEL_TO_PUBLIC_SURFACE_TYPE[kernelType]);
|
|
87
87
|
}
|
|
88
88
|
function faceGeomType(face) {
|
|
89
|
-
return
|
|
89
|
+
return result.unwrap(getSurfaceType(face));
|
|
90
90
|
}
|
|
91
91
|
function faceOrientation(face) {
|
|
92
92
|
const orient = shapeTypes.getKernel().shapeOrientation(face.wrapped);
|
|
@@ -106,11 +106,11 @@ function pointOnSurface(face, u, v) {
|
|
|
106
106
|
}
|
|
107
107
|
function uvCoordinates(face, point) {
|
|
108
108
|
const v = types.toVec3(point);
|
|
109
|
-
const
|
|
110
|
-
if (!
|
|
109
|
+
const result2 = shapeTypes.getKernel().uvFromPoint(face.wrapped, v);
|
|
110
|
+
if (!result2) {
|
|
111
111
|
return [0, 0];
|
|
112
112
|
}
|
|
113
|
-
return
|
|
113
|
+
return result2;
|
|
114
114
|
}
|
|
115
115
|
function projectPointOnFace(face, point) {
|
|
116
116
|
const v = types.toVec3(point);
|
|
@@ -118,21 +118,21 @@ function projectPointOnFace(face, point) {
|
|
|
118
118
|
const vMut = v;
|
|
119
119
|
const uvResult = shapeTypes.getKernel().uvFromPoint(face.wrapped, vMut);
|
|
120
120
|
if (!uvResult) {
|
|
121
|
-
return
|
|
121
|
+
return result.err(result.typeCastError("PROJECTION_FAILED", "No projection found on the face"));
|
|
122
122
|
}
|
|
123
123
|
const projectedPoint = shapeTypes.getKernel().projectPointOnFace(face.wrapped, vMut);
|
|
124
124
|
const dx = v[0] - projectedPoint[0];
|
|
125
125
|
const dy = v[1] - projectedPoint[1];
|
|
126
126
|
const dz = v[2] - projectedPoint[2];
|
|
127
127
|
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
128
|
-
return
|
|
128
|
+
return result.ok({
|
|
129
129
|
uv: uvResult,
|
|
130
130
|
point: projectedPoint,
|
|
131
131
|
distance
|
|
132
132
|
});
|
|
133
133
|
} catch (e) {
|
|
134
|
-
return
|
|
135
|
-
|
|
134
|
+
return result.err(
|
|
135
|
+
result.typeCastError(
|
|
136
136
|
"PROJECTION_FAILED",
|
|
137
137
|
`Point projection failed: ${e instanceof Error ? e.message : String(e)}`
|
|
138
138
|
)
|
|
@@ -167,10 +167,10 @@ function removeHolesFromFace(face) {
|
|
|
167
167
|
function innerWires(face) {
|
|
168
168
|
const outer = outerWire(face);
|
|
169
169
|
const allWires = Array.from(iterTopo(face.wrapped, "wire")).map(
|
|
170
|
-
(w) => shapeTypes.castShape(
|
|
170
|
+
(w) => shapeTypes.castShape(result.unwrap(downcast(w)))
|
|
171
171
|
);
|
|
172
|
-
const result = allWires.filter((w) => !shapeTypes.getKernel().isSame(w.wrapped, outer.wrapped));
|
|
173
|
-
return result;
|
|
172
|
+
const result$1 = allWires.filter((w) => !shapeTypes.getKernel().isSame(w.wrapped, outer.wrapped));
|
|
173
|
+
return result$1;
|
|
174
174
|
}
|
|
175
175
|
exports.asTopo = asTopo;
|
|
176
176
|
exports.cast = cast;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const shapeTypes = require("./shapeTypes-7xEam9Ri.cjs");
|
|
3
|
-
const
|
|
3
|
+
const result = require("./result-fAX0OZzI.cjs");
|
|
4
4
|
const vecOps = require("./vecOps-CjRL1jau.cjs");
|
|
5
|
-
const faceFns = require("./faceFns-
|
|
6
|
-
const measurement = require("./measurement-
|
|
7
|
-
const shapeFns = require("./shapeFns-
|
|
5
|
+
const faceFns = require("./faceFns-DB1Fc5gy.cjs");
|
|
6
|
+
const measurement = require("./measurement-BoNTUBAp.cjs");
|
|
7
|
+
const shapeFns = require("./shapeFns-C2SnNvdH.cjs");
|
|
8
8
|
const PRECISION_INTERSECTION = 1e-9;
|
|
9
9
|
const PRECISION_OFFSET = 1e-8;
|
|
10
10
|
const PRECISION_POINT = 1e-6;
|
|
@@ -60,14 +60,14 @@ function createTypedFinder(topoKind, filters, rebuild, extend) {
|
|
|
60
60
|
const withFilter = (pred) => rebuild([...filters, pred]);
|
|
61
61
|
const shouldKeep = (element) => filters.every((f) => f(element));
|
|
62
62
|
const extractElements = (shape) => {
|
|
63
|
-
const result = [];
|
|
63
|
+
const result$1 = [];
|
|
64
64
|
for (const raw of faceFns.iterTopo(shape.wrapped, topoKind)) {
|
|
65
|
-
const element = shapeTypes.castShape(
|
|
65
|
+
const element = shapeTypes.castShape(result.unwrap(faceFns.downcast(raw)));
|
|
66
66
|
if (shouldKeep(element)) {
|
|
67
|
-
result.push(element);
|
|
67
|
+
result$1.push(element);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
return result;
|
|
70
|
+
return result$1;
|
|
71
71
|
};
|
|
72
72
|
const emptyFinder = () => createTypedFinder(topoKind, [], rebuild, extend);
|
|
73
73
|
const base = {
|
|
@@ -100,7 +100,7 @@ function createTypedFinder(topoKind, filters, rebuild, extend) {
|
|
|
100
100
|
let match;
|
|
101
101
|
let count = 0;
|
|
102
102
|
for (const raw of faceFns.iterTopo(shape.wrapped, topoKind)) {
|
|
103
|
-
const element = shapeTypes.castShape(
|
|
103
|
+
const element = shapeTypes.castShape(result.unwrap(faceFns.downcast(raw)));
|
|
104
104
|
if (shouldKeep(element)) {
|
|
105
105
|
count++;
|
|
106
106
|
if (count === 1) match = element;
|
|
@@ -108,14 +108,14 @@ function createTypedFinder(topoKind, filters, rebuild, extend) {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
if (count !== 1) {
|
|
111
|
-
return
|
|
112
|
-
|
|
111
|
+
return result.err(
|
|
112
|
+
result.queryError(
|
|
113
113
|
"FINDER_NOT_UNIQUE",
|
|
114
114
|
`Finder expected a unique match but found ${count === 0 ? 0 : "2+"} element(s)`
|
|
115
115
|
)
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
|
-
return
|
|
118
|
+
return result.ok(match);
|
|
119
119
|
},
|
|
120
120
|
shouldKeep
|
|
121
121
|
};
|
|
@@ -155,7 +155,7 @@ function buildFaceFinder(filters) {
|
|
|
155
155
|
(_base, withFilter) => ({
|
|
156
156
|
inDirection: (dir = "Z", angle = 0) => withFilter(faceDirectionFilter(dir, angle)),
|
|
157
157
|
parallelTo: (dir = "Z") => buildFaceFinder(filters).inDirection(dir, 0),
|
|
158
|
-
ofSurfaceType: (surfaceType) => withFilter((face) =>
|
|
158
|
+
ofSurfaceType: (surfaceType) => withFilter((face) => result.unwrap(faceFns.getSurfaceType(face)) === surfaceType),
|
|
159
159
|
ofArea: (area, tolerance = 1e-3) => withFilter((face) => Math.abs(measurement.measureArea(face) - area) < tolerance),
|
|
160
160
|
atDistance: (distance, point = [0, 0, 0]) => withFilter(distanceFromPointFilter(distance, point, 1e-6))
|
|
161
161
|
})
|
|
@@ -168,7 +168,7 @@ function getSingleFace(f, shape) {
|
|
|
168
168
|
if (typeof f === "object" && "_topoKind" in f) {
|
|
169
169
|
return f.findUnique(shape);
|
|
170
170
|
}
|
|
171
|
-
if (typeof f !== "function" && shapeTypes.isFace(f)) return
|
|
171
|
+
if (typeof f !== "function" && shapeTypes.isFace(f)) return result.ok(f);
|
|
172
172
|
const fnResult = f(faceFinder());
|
|
173
173
|
return fnResult.findUnique(shape);
|
|
174
174
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { c as castShape, B as getKernel, k as isFace } from "./shapeTypes-CpSaBLDv.js";
|
|
2
|
-
import {
|
|
2
|
+
import { v as unwrap, e as err, q as queryError, o as ok } from "./result-BaSD1fqR.js";
|
|
3
3
|
import { j as vecNormalize, d as vecDot, D as DEG2RAD } from "./vecOps-ZDdZWbwT.js";
|
|
4
|
-
import { i as iterTopo, d as downcast, g as getSurfaceType, n as normalAt } from "./faceFns-
|
|
5
|
-
import { m as measureArea } from "./measurement-
|
|
6
|
-
import { f as getHashCode, i as isSameShape } from "./shapeFns-
|
|
4
|
+
import { i as iterTopo, d as downcast, g as getSurfaceType, n as normalAt } from "./faceFns-B8GnxjdY.js";
|
|
5
|
+
import { m as measureArea } from "./measurement-D8EJ694A.js";
|
|
6
|
+
import { f as getHashCode, i as isSameShape } from "./shapeFns-FDuKkrDR.js";
|
|
7
7
|
const PRECISION_INTERSECTION = 1e-9;
|
|
8
8
|
const PRECISION_OFFSET = 1e-8;
|
|
9
9
|
const PRECISION_POINT = 1e-6;
|
package/dist/io.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const shapeTypes = require("./shapeTypes-7xEam9Ri.cjs");
|
|
4
|
-
const
|
|
5
|
-
const meshFns = require("./meshFns-
|
|
6
|
-
const Blueprint = require("./Blueprint-
|
|
4
|
+
const result = require("./result-fAX0OZzI.cjs");
|
|
5
|
+
const meshFns = require("./meshFns-BnV0ZR8w.cjs");
|
|
6
|
+
const Blueprint = require("./Blueprint-CQ28WJhz.cjs");
|
|
7
7
|
function vec3At(arr, i) {
|
|
8
8
|
const off = i * 3;
|
|
9
9
|
return [arr[off], arr[off + 1], arr[off + 2]];
|
|
@@ -465,11 +465,11 @@ function flattenBlueprints(drawing) {
|
|
|
465
465
|
return [drawing];
|
|
466
466
|
}
|
|
467
467
|
if ("blueprints" in drawing && Array.isArray(drawing.blueprints)) {
|
|
468
|
-
const
|
|
468
|
+
const result2 = [];
|
|
469
469
|
for (const item of drawing.blueprints) {
|
|
470
|
-
|
|
470
|
+
result2.push(...flattenBlueprints(item));
|
|
471
471
|
}
|
|
472
|
-
return
|
|
472
|
+
return result2;
|
|
473
473
|
}
|
|
474
474
|
return [];
|
|
475
475
|
}
|
|
@@ -923,12 +923,12 @@ function importSVGPathD(pathD) {
|
|
|
923
923
|
try {
|
|
924
924
|
const curves = parseSVGPathToCurves(pathD);
|
|
925
925
|
if (curves.length === 0) {
|
|
926
|
-
return
|
|
926
|
+
return result.err(result.ioError("SVG_EMPTY_PATH", "SVG path produced no curves"));
|
|
927
927
|
}
|
|
928
|
-
return
|
|
928
|
+
return result.ok(new Blueprint.Blueprint(curves));
|
|
929
929
|
} catch (e) {
|
|
930
|
-
return
|
|
931
|
-
|
|
930
|
+
return result.err(
|
|
931
|
+
result.ioError(
|
|
932
932
|
"SVG_PARSE_FAILED",
|
|
933
933
|
`Failed to parse SVG path: ${e instanceof Error ? e.message : String(e)}`
|
|
934
934
|
)
|
|
@@ -951,18 +951,18 @@ function importSVG(svgString) {
|
|
|
951
951
|
const attrMatch = dAttrRe.exec(tag);
|
|
952
952
|
const d = attrMatch?.[1] ?? attrMatch?.[2];
|
|
953
953
|
if (!d) continue;
|
|
954
|
-
const
|
|
955
|
-
if (
|
|
956
|
-
blueprints.push(
|
|
954
|
+
const result2 = importSVGPathD(d);
|
|
955
|
+
if (result2.ok) {
|
|
956
|
+
blueprints.push(result2.value);
|
|
957
957
|
}
|
|
958
958
|
}
|
|
959
959
|
if (blueprints.length === 0) {
|
|
960
|
-
return
|
|
960
|
+
return result.err(result.ioError("SVG_NO_PATHS", "No <path> elements found in SVG"));
|
|
961
961
|
}
|
|
962
|
-
return
|
|
962
|
+
return result.ok(blueprints);
|
|
963
963
|
} catch (e) {
|
|
964
|
-
return
|
|
965
|
-
|
|
964
|
+
return result.err(
|
|
965
|
+
result.ioError(
|
|
966
966
|
"SVG_IMPORT_FAILED",
|
|
967
967
|
`Failed to import SVG: ${e instanceof Error ? e.message : String(e)}`
|
|
968
968
|
)
|
|
@@ -974,11 +974,11 @@ async function importSTEP(blob) {
|
|
|
974
974
|
const data = await blob.arrayBuffer();
|
|
975
975
|
const shapes = shapeTypes.getKernel().importSTEP(data);
|
|
976
976
|
if (shapes.length === 0) {
|
|
977
|
-
return
|
|
977
|
+
return result.err(result.ioError("STEP_IMPORT_FAILED", "STEP file contains no valid geometry"));
|
|
978
978
|
}
|
|
979
|
-
return
|
|
979
|
+
return result.ok(shapeTypes.castShape(shapes[0]));
|
|
980
980
|
} catch {
|
|
981
|
-
return
|
|
981
|
+
return result.err(result.ioError("STEP_IMPORT_FAILED", "Failed to load STEP file"));
|
|
982
982
|
}
|
|
983
983
|
}
|
|
984
984
|
async function importSTL(blob) {
|
|
@@ -986,11 +986,11 @@ async function importSTL(blob) {
|
|
|
986
986
|
const data = await blob.arrayBuffer();
|
|
987
987
|
const shape = shapeTypes.getKernel().importSTL(data);
|
|
988
988
|
if (shape.IsNull()) {
|
|
989
|
-
return
|
|
989
|
+
return result.err(result.ioError("STL_IMPORT_FAILED", "Failed to create solid from STL mesh"));
|
|
990
990
|
}
|
|
991
|
-
return
|
|
991
|
+
return result.ok(shapeTypes.castShape(shape));
|
|
992
992
|
} catch {
|
|
993
|
-
return
|
|
993
|
+
return result.err(result.ioError("STL_IMPORT_FAILED", "Failed to load STL file"));
|
|
994
994
|
}
|
|
995
995
|
}
|
|
996
996
|
async function importIGES(blob) {
|
|
@@ -998,11 +998,11 @@ async function importIGES(blob) {
|
|
|
998
998
|
const data = await blob.arrayBuffer();
|
|
999
999
|
const shapes = shapeTypes.getKernel().importIGES(data);
|
|
1000
1000
|
if (shapes.length === 0) {
|
|
1001
|
-
return
|
|
1001
|
+
return result.err(result.ioError("IGES_IMPORT_FAILED", "IGES file contains no valid geometry"));
|
|
1002
1002
|
}
|
|
1003
|
-
return
|
|
1003
|
+
return result.ok(shapeTypes.castShape(shapes[0]));
|
|
1004
1004
|
} catch {
|
|
1005
|
-
return
|
|
1005
|
+
return result.err(result.ioError("IGES_IMPORT_FAILED", "Failed to load IGES file"));
|
|
1006
1006
|
}
|
|
1007
1007
|
}
|
|
1008
1008
|
exports.exportIGES = meshFns.exportIGES;
|
package/dist/io.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { B as getKernel, c as castShape } from "./shapeTypes-CpSaBLDv.js";
|
|
2
|
-
import { e as err, i as ioError, o as ok } from "./
|
|
3
|
-
import { e, d, f } from "./meshFns-
|
|
4
|
-
import { B as Blueprint, a as make2dSegmentCurve, o as make2dThreePointArc, s as make2dBezierCurve } from "./Blueprint-
|
|
2
|
+
import { e as err, i as ioError, o as ok } from "./result-BaSD1fqR.js";
|
|
3
|
+
import { e, d, f } from "./meshFns-nQjK38EC.js";
|
|
4
|
+
import { B as Blueprint, a as make2dSegmentCurve, o as make2dThreePointArc, s as make2dBezierCurve } from "./Blueprint-DbVaf6k7.js";
|
|
5
5
|
function vec3At(arr, i) {
|
|
6
6
|
const off = i * 3;
|
|
7
7
|
return [arr[off], arr[off + 1], arr[off + 2]];
|