brepjs 18.77.0 → 18.78.0

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.
Files changed (29) hide show
  1. package/dist/brepjs.cjs +135 -134
  2. package/dist/brepjs.js +8 -8
  3. package/dist/{drawFns-BBoTkSta.js → drawFns-C6h_w03r.js} +1 -1
  4. package/dist/{drawFns-DNokXs9U.cjs → drawFns-DxjMxRpE.cjs} +1 -1
  5. package/dist/{primitiveFns-ItlGYe3M.cjs → healingFns-B7dElsC4.cjs} +5 -462
  6. package/dist/{primitiveFns-DWIzRvTY.js → healingFns-DS_nK9KF.js} +6 -301
  7. package/dist/index.d.ts +1 -0
  8. package/dist/{extrudeFns-CSWqlW-n.js → loftFns-DuxEscJB.js} +92 -1
  9. package/dist/{extrudeFns-BJSW3EaV.cjs → loftFns-DycLH1Pq.cjs} +103 -0
  10. package/dist/operations/threadFns.d.ts +39 -0
  11. package/dist/operations.cjs +33 -32
  12. package/dist/operations.d.ts +1 -0
  13. package/dist/operations.js +3 -3
  14. package/dist/{booleanFns-D7Xgt-Og.js → primitiveFns-BxH5omw3.js} +300 -6
  15. package/dist/{booleanFns-CFa3bgbG.cjs → primitiveFns-JRmXxbRr.cjs} +456 -0
  16. package/dist/sketching.cjs +2 -2
  17. package/dist/sketching.js +2 -2
  18. package/dist/text.cjs +2 -2
  19. package/dist/text.js +2 -2
  20. package/dist/{textBlueprints-CYc0xi6l.js → textBlueprints-C3IbySW_.js} +4 -94
  21. package/dist/{textBlueprints-D31dKTZS.cjs → textBlueprints-SKuamOmI.cjs} +11 -113
  22. package/dist/{textMetrics-DfxB-y9A.js → textMetrics--BwiJH2B.js} +1 -1
  23. package/dist/{textMetrics-CjbXCzpg.cjs → textMetrics-Bzbkal_A.cjs} +1 -1
  24. package/dist/{historyFns-Ck2tXVAL.js → threadFns-D8-zfJ0b.js} +71 -4
  25. package/dist/{historyFns-4ggYGJB2.cjs → threadFns-aWgxzqmT.cjs} +76 -3
  26. package/dist/topology/booleanFns.d.ts +9 -1
  27. package/dist/topology.cjs +34 -34
  28. package/dist/topology.js +2 -2
  29. package/package.json +1 -1
@@ -40,99 +40,9 @@ const require_arrayAccess = require("./arrayAccess-e4H9cBfh.cjs");
40
40
  const require_surfaceBuilders = require("./surfaceBuilders-CPHOXRLE.cjs");
41
41
  const require_blueprintSketcher = require("./blueprintSketcher-D75tuXkF.cjs");
42
42
  const require_solidBuilders = require("./solidBuilders-diw2zyyN.cjs");
43
- const require_extrudeFns = require("./extrudeFns-BJSW3EaV.cjs");
43
+ const require_loftFns = require("./loftFns-DycLH1Pq.cjs");
44
44
  let opentype_js = require("opentype.js");
45
45
  opentype_js = __toESM(opentype_js, 1);
46
- //#region src/operations/loftFns.ts
47
- /**
48
- * Functional loft operation using branded shape types.
49
- */
50
- /**
51
- * Loft through a set of wire profiles to create a 3D shape.
52
- *
53
- * Builds a `BRepOffsetAPI_ThruSections` surface through the given wires,
54
- * optionally starting and/or ending at point vertices. Produces a solid
55
- * by default, or a shell when `returnShell` is `true`.
56
- *
57
- * @param wires - Ordered wire profiles to loft through.
58
- * @param config - Loft configuration (ruled interpolation, start/end points).
59
- * @param returnShell - When `true`, return a shell instead of a solid.
60
- * @returns `Result` containing the lofted 3D shape, or an error on failure.
61
- *
62
- * @example
63
- * ```ts
64
- * const result = loft([bottomWire, topWire], { ruled: false });
65
- * ```
66
- *
67
- * @see {@link loft!loft | loft} for the OOP API equivalent.
68
- */
69
- function loft(wires, { ruled = true, startPoint, endPoint, tolerance = 1e-6 } = {}, returnShell = false) {
70
- if (wires.length === 0 && !startPoint && !endPoint) return require_errors.err(require_errors.validationError("LOFT_EMPTY", "Loft requires at least one wire or start/end point"));
71
- const kernel = require_shapeTypes.getKernel();
72
- const startVertex = startPoint ? kernel.makeVertex(...require_types.toVec3(startPoint)) : void 0;
73
- const endVertex = endPoint ? kernel.makeVertex(...require_types.toVec3(endPoint)) : void 0;
74
- try {
75
- const result = require_shapeTypes.castShape(kernel.loftAdvanced(wires.map((w) => w.wrapped), {
76
- solid: !returnShell,
77
- ruled,
78
- tolerance,
79
- ...startVertex ? { startVertex } : {},
80
- ...endVertex ? { endVertex } : {}
81
- }));
82
- if (!require_shapeTypes.isShape3D(result)) return require_errors.err(require_errors.typeCastError("LOFT_NOT_3D", "Loft did not produce a 3D shape"));
83
- return require_errors.ok(result);
84
- } catch (e) {
85
- return require_errors.err(require_errors.kernelError("LOFT_FAILED", "Loft operation failed", e, void 0, "Common causes: wire profiles with different edge counts, self-intersecting result, or profiles too far apart. Ensure profiles are compatible and ordered."));
86
- }
87
- }
88
- /**
89
- * Batch loft: build N independent lofts in a single kernel call.
90
- *
91
- * Uses the C++ LoftBatch extractor when available (single WASM call),
92
- * falling back to N individual loft operations otherwise.
93
- *
94
- * @returns Array of 3D shapes, one per entry.
95
- */
96
- function loftAll(entries) {
97
- if (entries.length === 0) return require_errors.ok([]);
98
- const kernel = require_shapeTypes.getKernel();
99
- const verticesToDelete = [];
100
- const kernelEntries = entries.map((e) => {
101
- const startVertex = e.startPoint ? kernel.makeVertex(...require_types.toVec3(e.startPoint)) : void 0;
102
- const endVertex = e.endPoint ? kernel.makeVertex(...require_types.toVec3(e.endPoint)) : void 0;
103
- if (startVertex) verticesToDelete.push(startVertex);
104
- if (endVertex) verticesToDelete.push(endVertex);
105
- return {
106
- wires: e.wires.map((w) => w.wrapped),
107
- solid: true,
108
- ruled: e.ruled ?? true,
109
- tolerance: e.tolerance ?? 1e-6,
110
- startVertex,
111
- endVertex
112
- };
113
- });
114
- try {
115
- const shapes = kernel.loftBatch?.(kernelEntries) ?? kernelEntries.map((e) => kernel.loftAdvanced(e.wires, {
116
- solid: e.solid,
117
- ruled: e.ruled,
118
- tolerance: e.tolerance,
119
- startVertex: e.startVertex,
120
- endVertex: e.endVertex
121
- }));
122
- const results = [];
123
- for (const shape of shapes) {
124
- const cast = require_shapeTypes.castShape(shape);
125
- if (!require_shapeTypes.isShape3D(cast)) return require_errors.err(require_errors.typeCastError("LOFT_ALL_NOT_3D", "Batch loft entry did not produce a 3D shape"));
126
- results.push(cast);
127
- }
128
- return require_errors.ok(results);
129
- } catch (e) {
130
- return require_errors.err(require_errors.kernelError("LOFT_ALL_FAILED", "Batch loft operation failed", e));
131
- } finally {
132
- for (const v of verticesToDelete) kernel.dispose(v);
133
- }
134
- }
135
- //#endregion
136
46
  //#region src/sketching/compoundSketch.ts
137
47
  /**
138
48
  * Represent a face with holes as a group of sketches (one outer + zero or more inner).
@@ -230,7 +140,7 @@ function sketchWires(sketch) {
230
140
  */
231
141
  function sketchRevolve(sketch, revolutionAxis, { origin } = {}) {
232
142
  const face = require_errors.unwrap(require_surfaceBuilders.makeFace(sketch.wire));
233
- const solid = require_errors.unwrap(require_extrudeFns.revolve(face, origin ? require_types.toVec3(origin) : sketch.defaultOrigin, revolutionAxis ? require_types.toVec3(revolutionAxis) : [
143
+ const solid = require_errors.unwrap(require_loftFns.revolve(face, origin ? require_types.toVec3(origin) : sketch.defaultOrigin, revolutionAxis ? require_types.toVec3(revolutionAxis) : [
234
144
  0,
235
145
  0,
236
146
  1
@@ -251,16 +161,16 @@ function sketchExtrude(sketch, extrusionDistance, { extrusionDirection, extrusio
251
161
  const extrusionVec = require_vecOps.vecScale(require_vecOps.vecNormalize(extrusionDirection ? require_types.toVec3(extrusionDirection) : sketch.defaultDirection), extrusionDistance);
252
162
  const originVec = origin ? require_types.toVec3(origin) : sketch.defaultOrigin;
253
163
  if (extrusionProfile && !twistAngle) {
254
- const solid = require_errors.unwrap(require_extrudeFns.complexExtrude(sketch.wire, [...originVec], [...extrusionVec], extrusionProfile));
164
+ const solid = require_errors.unwrap(require_loftFns.complexExtrude(sketch.wire, [...originVec], [...extrusionVec], extrusionProfile));
255
165
  sketch.delete();
256
166
  return solid;
257
167
  }
258
168
  if (twistAngle) {
259
- const solid = require_errors.unwrap(require_extrudeFns.twistExtrude(sketch.wire, twistAngle, [...originVec], [...extrusionVec], extrusionProfile));
169
+ const solid = require_errors.unwrap(require_loftFns.twistExtrude(sketch.wire, twistAngle, [...originVec], [...extrusionVec], extrusionProfile));
260
170
  sketch.delete();
261
171
  return solid;
262
172
  }
263
- const solid = require_errors.unwrap(require_extrudeFns.extrude(require_errors.unwrap(require_surfaceBuilders.makeFace(sketch.wire)), [...extrusionVec]));
173
+ const solid = require_errors.unwrap(require_loftFns.extrude(require_errors.unwrap(require_surfaceBuilders.makeFace(sketch.wire)), [...extrusionVec]));
264
174
  sketch.delete();
265
175
  return solid;
266
176
  }
@@ -287,7 +197,7 @@ function sketchSweep(sketch, sketchOnPlane, sweepConfig = {}) {
287
197
  ...sweepConfig
288
198
  };
289
199
  if (sketch.baseFace) config.support = sketch.baseFace.wrapped;
290
- const shape = require_errors.unwrap(require_extrudeFns.sweep(profile.wire, sketch.wire, config));
200
+ const shape = require_errors.unwrap(require_loftFns.sweep(profile.wire, sketch.wire, config));
291
201
  sketch.delete();
292
202
  return shape;
293
203
  }
@@ -298,7 +208,7 @@ function sketchSweep(sketch, sketchOnPlane, sweepConfig = {}) {
298
208
  */
299
209
  function sketchLoft(sketch, otherSketches, loftConfig = {}, returnShell = false) {
300
210
  const sketchArray = Array.isArray(otherSketches) ? [sketch, ...otherSketches] : [sketch, otherSketches];
301
- const shape = require_errors.unwrap(loft(sketchArray.map((s) => s.wire), loftConfig, returnShell));
211
+ const shape = require_errors.unwrap(require_loftFns.loft(sketchArray.map((s) => s.wire), loftConfig, returnShell));
302
212
  sketchArray.forEach((s) => {
303
213
  s.delete();
304
214
  });
@@ -360,9 +270,9 @@ function compoundSketchWires(sketch) {
360
270
  */
361
271
  function compoundSketchExtrude(sketch, extrusionDistance, { extrusionDirection, extrusionProfile, twistAngle, origin } = {}) {
362
272
  const extrusionVec = require_vecOps.vecScale(require_vecOps.vecNormalize(extrusionDirection ? require_types.toVec3(extrusionDirection) : sketch.outerSketch.defaultDirection), extrusionDistance);
363
- if (extrusionProfile && !twistAngle) return solidFromShellGenerator(sketch.sketches, (s) => require_extrudeFns.complexExtrude(s.wire, origin ? require_types.toVec3(origin) : sketch.outerSketch.defaultOrigin, extrusionVec, extrusionProfile, true));
364
- if (twistAngle) return solidFromShellGenerator(sketch.sketches, (s) => require_extrudeFns.twistExtrude(s.wire, twistAngle, origin ? require_types.toVec3(origin) : sketch.outerSketch.defaultOrigin, extrusionVec, extrusionProfile, true));
365
- return require_errors.unwrap(require_extrudeFns.extrude(compoundSketchFace(sketch), extrusionVec));
273
+ if (extrusionProfile && !twistAngle) return solidFromShellGenerator(sketch.sketches, (s) => require_loftFns.complexExtrude(s.wire, origin ? require_types.toVec3(origin) : sketch.outerSketch.defaultOrigin, extrusionVec, extrusionProfile, true));
274
+ if (twistAngle) return solidFromShellGenerator(sketch.sketches, (s) => require_loftFns.twistExtrude(s.wire, twistAngle, origin ? require_types.toVec3(origin) : sketch.outerSketch.defaultOrigin, extrusionVec, extrusionProfile, true));
275
+ return require_errors.unwrap(require_loftFns.extrude(compoundSketchFace(sketch), extrusionVec));
366
276
  }
367
277
  /** Revolve a compound sketch (outer + holes) around an axis. */
368
278
  function compoundSketchRevolve(sketch, revolutionAxis, { origin } = {}) {
@@ -372,7 +282,7 @@ function compoundSketchRevolve(sketch, revolutionAxis, { origin } = {}) {
372
282
  0,
373
283
  1
374
284
  ];
375
- return require_errors.unwrap(require_extrudeFns.revolve(compoundSketchFace(sketch), center, dir));
285
+ return require_errors.unwrap(require_loftFns.revolve(compoundSketchFace(sketch), center, dir));
376
286
  }
377
287
  /** Loft between two compound sketches with matching sub-sketch counts. */
378
288
  function compoundSketchLoft(sketch, other, loftConfig) {
@@ -732,18 +642,6 @@ Object.defineProperty(exports, "loadFont", {
732
642
  return loadFont;
733
643
  }
734
644
  });
735
- Object.defineProperty(exports, "loft", {
736
- enumerable: true,
737
- get: function() {
738
- return loft;
739
- }
740
- });
741
- Object.defineProperty(exports, "loftAll", {
742
- enumerable: true,
743
- get: function() {
744
- return loftAll;
745
- }
746
- });
747
645
  Object.defineProperty(exports, "sketchExtrude", {
748
646
  enumerable: true,
749
647
  get: function() {
@@ -1,5 +1,5 @@
1
1
  import { A as ok, b as err, d as validationError, t as BrepErrorCode } from "./errors-DNWJsfVU.js";
2
- import { g as wrapSketchData, i as Sketches, n as getFont, t as textBlueprints, v as CompoundSketch } from "./textBlueprints-CYc0xi6l.js";
2
+ import { g as wrapSketchData, i as Sketches, n as getFont, t as textBlueprints, v as CompoundSketch } from "./textBlueprints-C3IbySW_.js";
3
3
  //#region src/text/sketchText.ts
4
4
  /**
5
5
  * Render text as 3D sketch outlines on a plane.
@@ -1,4 +1,4 @@
1
- const require_textBlueprints = require("./textBlueprints-D31dKTZS.cjs");
1
+ const require_textBlueprints = require("./textBlueprints-SKuamOmI.cjs");
2
2
  const require_errors = require("./errors-CXJtc4I7.cjs");
3
3
  //#region src/text/sketchText.ts
4
4
  /**
@@ -1,9 +1,10 @@
1
- import { B as createKernelHandle, Z as getKernel, t as castShape } from "./shapeTypes-CyTY0prh.js";
2
- import { A as ok, b as err, d as validationError, n as computationError, r as ioError } from "./errors-DNWJsfVU.js";
1
+ import { B as createKernelHandle, R as DisposalScope, Y as _usingCtx, Z as getKernel, t as castShape } from "./shapeTypes-CyTY0prh.js";
2
+ import { A as ok, T as isOk, b as err, d as validationError, n as computationError, r as ioError } from "./errors-DNWJsfVU.js";
3
3
  import { d as vecNormalize, s as vecIsZero } from "./vecOps-SKPRvPH-.js";
4
4
  import { y as fromBREP } from "./faceFns-BJ2hzXJp.js";
5
5
  import { s as toBREP } from "./shapeFns-DZ6poxP7.js";
6
- import { a as fuseAll } from "./booleanFns-D7Xgt-Og.js";
6
+ import { E as wire, M as fuseAll, h as line } from "./primitiveFns-BxH5omw3.js";
7
+ import { t as loft } from "./loftFns-DuxEscJB.js";
7
8
  //#region src/utils/uuid.ts
8
9
  /** Generate a v4-style UUID string using `crypto.getRandomValues`. */
9
10
  function uuidv() {
@@ -455,4 +456,70 @@ function deserializeHistory(data) {
455
456
  });
456
457
  }
457
458
  //#endregion
458
- export { walkAssembly as C, exportAssemblySTEP as D, linearPattern as E, createAssembly as O, updateNode as S, gridPattern as T, collectShapes as _, findStep as a, findNode as b, registerOperation as c, replayHistory as d, serializeHistory as f, addChild as g, undoLast as h, deserializeHistory as i, registerShape as l, stepsFrom as m, createHistory as n, getShape as o, stepCount as p, createRegistry as r, modifyStep as s, addStep as t, replayFrom as u, countNodes as v, circularPattern as w, removeChild as x, createAssemblyNode as y };
459
+ //#region src/operations/threadFns.ts
460
+ /**
461
+ * Build a helical screw-thread ridge by lofting rotated tooth sections.
462
+ *
463
+ * @param options - {@link ThreadOptions}.
464
+ * @returns `Result` with the thread-ridge solid, or an error.
465
+ *
466
+ * @example External thread (Ø12 rod, 2.5 mm pitch):
467
+ * ```ts
468
+ * const ridge = thread({ radius: 6, pitch: 2.5, height: 7.5 });
469
+ * const rod = fuse(cylinder(6.15, 7.5), unwrap(ridge));
470
+ * ```
471
+ * @example Internal thread (tapped Ø6 hole):
472
+ * ```ts
473
+ * const ridge = thread({ radius: 3, pitch: 1, height: 6, inward: true });
474
+ * const nut = cut(boredBlock, unwrap(ridge));
475
+ * ```
476
+ */
477
+ function thread(options) {
478
+ try {
479
+ var _usingCtx$1 = _usingCtx();
480
+ const { radius, pitch, height, depth = .6 * pitch, toothHalfWidth = .42 * pitch, sectionsPerTurn = 20, lefthand = false, inward = false } = options;
481
+ if (!(radius > 0)) return err(validationError("THREAD_INVALID_RADIUS", "radius must be > 0"));
482
+ if (!(pitch > 0)) return err(validationError("THREAD_INVALID_PITCH", "pitch must be > 0"));
483
+ if (!(height > 0)) return err(validationError("THREAD_INVALID_HEIGHT", "height must be > 0"));
484
+ if (!(depth > 0)) return err(validationError("THREAD_INVALID_DEPTH", "depth must be > 0"));
485
+ if (sectionsPerTurn < 3) return err(validationError("THREAD_TOO_FEW_SECTIONS", "sectionsPerTurn must be >= 3"));
486
+ const turns = height / pitch;
487
+ const nSec = Math.max(2, Math.round(turns * sectionsPerTurn));
488
+ const sign = lefthand ? -1 : 1;
489
+ const apexU = inward ? -depth : depth;
490
+ const baseU = inward ? .3 : -.3;
491
+ const a = toothHalfWidth;
492
+ const scope = _usingCtx$1.u(new DisposalScope());
493
+ const sections = [];
494
+ for (let i = 0; i <= nSec; i++) {
495
+ const th = sign * i * 2 * Math.PI / sectionsPerTurn;
496
+ const z = pitch * Math.abs(th) / (2 * Math.PI);
497
+ const cx = radius * Math.cos(th);
498
+ const cy = radius * Math.sin(th);
499
+ const rx = Math.cos(th);
500
+ const ry = Math.sin(th);
501
+ const pt = (u, v) => [
502
+ cx + u * rx,
503
+ cy + u * ry,
504
+ z + v
505
+ ];
506
+ const p1 = pt(baseU, -a);
507
+ const apex = pt(apexU, 0);
508
+ const p3 = pt(baseU, a);
509
+ const w = wire([
510
+ scope.register(line(p1, apex)),
511
+ scope.register(line(apex, p3)),
512
+ scope.register(line(p3, p1))
513
+ ]);
514
+ if (!isOk(w)) return w;
515
+ sections.push(scope.register(w.value));
516
+ }
517
+ return loft(sections, { ruled: true });
518
+ } catch (_) {
519
+ _usingCtx$1.e = _;
520
+ } finally {
521
+ _usingCtx$1.d();
522
+ }
523
+ }
524
+ //#endregion
525
+ export { updateNode as C, linearPattern as D, gridPattern as E, exportAssemblySTEP as O, removeChild as S, circularPattern as T, addChild as _, deserializeHistory as a, createAssemblyNode as b, modifyStep as c, replayFrom as d, replayHistory as f, undoLast as g, stepsFrom as h, createRegistry as i, createAssembly as k, registerOperation as l, stepCount as m, addStep as n, findStep as o, serializeHistory as p, createHistory as r, getShape as s, thread as t, registerShape as u, collectShapes as v, walkAssembly as w, findNode as x, countNodes as y };
@@ -3,7 +3,8 @@ const require_errors = require("./errors-CXJtc4I7.cjs");
3
3
  const require_vecOps = require("./vecOps-CCnJt-yH.cjs");
4
4
  const require_faceFns = require("./faceFns-p0lyVuyw.cjs");
5
5
  const require_shapeFns = require("./shapeFns-D5WNrq3s.cjs");
6
- const require_booleanFns = require("./booleanFns-CFa3bgbG.cjs");
6
+ const require_primitiveFns = require("./primitiveFns-JRmXxbRr.cjs");
7
+ const require_loftFns = require("./loftFns-DycLH1Pq.cjs");
7
8
  //#region src/utils/uuid.ts
8
9
  /** Generate a v4-style UUID string using `crypto.getRandomValues`. */
9
10
  function uuidv() {
@@ -127,7 +128,7 @@ function linearPattern(shape, direction, count, spacing, options) {
127
128
  if (count === 1) return require_errors.ok(shape);
128
129
  if (require_vecOps.vecIsZero(direction)) return require_errors.err(require_errors.validationError("PATTERN_ZERO_DIRECTION", "Pattern direction cannot be zero"));
129
130
  const dir = require_vecOps.vecNormalize(direction);
130
- return require_booleanFns.fuseAll(require_shapeTypes.getKernel().linearPattern(shape.wrapped, [...dir], spacing, count).map((s) => require_shapeTypes.castShape(s)), {
131
+ return require_primitiveFns.fuseAll(require_shapeTypes.getKernel().linearPattern(shape.wrapped, [...dir], spacing, count).map((s) => require_shapeTypes.castShape(s)), {
131
132
  optimisation: "sameFace",
132
133
  ...options,
133
134
  unsafe: true
@@ -153,7 +154,7 @@ function circularPattern(shape, axis, count, fullAngle = 360, center = [
153
154
  if (count === 1) return require_errors.ok(shape);
154
155
  if (require_vecOps.vecIsZero(axis)) return require_errors.err(require_errors.validationError("PATTERN_ZERO_AXIS", "Pattern axis cannot be zero"));
155
156
  const angleStep = fullAngle / count;
156
- return require_booleanFns.fuseAll(require_shapeTypes.getKernel().circularPattern(shape.wrapped, [...center], [...axis], angleStep, count).map((s) => require_shapeTypes.castShape(s)), {
157
+ return require_primitiveFns.fuseAll(require_shapeTypes.getKernel().circularPattern(shape.wrapped, [...center], [...axis], angleStep, count).map((s) => require_shapeTypes.castShape(s)), {
157
158
  optimisation: "sameFace",
158
159
  ...options,
159
160
  unsafe: true
@@ -455,6 +456,72 @@ function deserializeHistory(data) {
455
456
  });
456
457
  }
457
458
  //#endregion
459
+ //#region src/operations/threadFns.ts
460
+ /**
461
+ * Build a helical screw-thread ridge by lofting rotated tooth sections.
462
+ *
463
+ * @param options - {@link ThreadOptions}.
464
+ * @returns `Result` with the thread-ridge solid, or an error.
465
+ *
466
+ * @example External thread (Ø12 rod, 2.5 mm pitch):
467
+ * ```ts
468
+ * const ridge = thread({ radius: 6, pitch: 2.5, height: 7.5 });
469
+ * const rod = fuse(cylinder(6.15, 7.5), unwrap(ridge));
470
+ * ```
471
+ * @example Internal thread (tapped Ø6 hole):
472
+ * ```ts
473
+ * const ridge = thread({ radius: 3, pitch: 1, height: 6, inward: true });
474
+ * const nut = cut(boredBlock, unwrap(ridge));
475
+ * ```
476
+ */
477
+ function thread(options) {
478
+ try {
479
+ var _usingCtx$1 = require_shapeTypes._usingCtx();
480
+ const { radius, pitch, height, depth = .6 * pitch, toothHalfWidth = .42 * pitch, sectionsPerTurn = 20, lefthand = false, inward = false } = options;
481
+ if (!(radius > 0)) return require_errors.err(require_errors.validationError("THREAD_INVALID_RADIUS", "radius must be > 0"));
482
+ if (!(pitch > 0)) return require_errors.err(require_errors.validationError("THREAD_INVALID_PITCH", "pitch must be > 0"));
483
+ if (!(height > 0)) return require_errors.err(require_errors.validationError("THREAD_INVALID_HEIGHT", "height must be > 0"));
484
+ if (!(depth > 0)) return require_errors.err(require_errors.validationError("THREAD_INVALID_DEPTH", "depth must be > 0"));
485
+ if (sectionsPerTurn < 3) return require_errors.err(require_errors.validationError("THREAD_TOO_FEW_SECTIONS", "sectionsPerTurn must be >= 3"));
486
+ const turns = height / pitch;
487
+ const nSec = Math.max(2, Math.round(turns * sectionsPerTurn));
488
+ const sign = lefthand ? -1 : 1;
489
+ const apexU = inward ? -depth : depth;
490
+ const baseU = inward ? .3 : -.3;
491
+ const a = toothHalfWidth;
492
+ const scope = _usingCtx$1.u(new require_shapeTypes.DisposalScope());
493
+ const sections = [];
494
+ for (let i = 0; i <= nSec; i++) {
495
+ const th = sign * i * 2 * Math.PI / sectionsPerTurn;
496
+ const z = pitch * Math.abs(th) / (2 * Math.PI);
497
+ const cx = radius * Math.cos(th);
498
+ const cy = radius * Math.sin(th);
499
+ const rx = Math.cos(th);
500
+ const ry = Math.sin(th);
501
+ const pt = (u, v) => [
502
+ cx + u * rx,
503
+ cy + u * ry,
504
+ z + v
505
+ ];
506
+ const p1 = pt(baseU, -a);
507
+ const apex = pt(apexU, 0);
508
+ const p3 = pt(baseU, a);
509
+ const w = require_primitiveFns.wire([
510
+ scope.register(require_primitiveFns.line(p1, apex)),
511
+ scope.register(require_primitiveFns.line(apex, p3)),
512
+ scope.register(require_primitiveFns.line(p3, p1))
513
+ ]);
514
+ if (!require_errors.isOk(w)) return w;
515
+ sections.push(scope.register(w.value));
516
+ }
517
+ return require_loftFns.loft(sections, { ruled: true });
518
+ } catch (_) {
519
+ _usingCtx$1.e = _;
520
+ } finally {
521
+ _usingCtx$1.d();
522
+ }
523
+ }
524
+ //#endregion
458
525
  Object.defineProperty(exports, "addChild", {
459
526
  enumerable: true,
460
527
  get: function() {
@@ -605,6 +672,12 @@ Object.defineProperty(exports, "stepsFrom", {
605
672
  return stepsFrom;
606
673
  }
607
674
  });
675
+ Object.defineProperty(exports, "thread", {
676
+ enumerable: true,
677
+ get: function() {
678
+ return thread;
679
+ }
680
+ });
608
681
  Object.defineProperty(exports, "undoLast", {
609
682
  enumerable: true,
610
683
  get: function() {
@@ -55,7 +55,15 @@ export declare function intersect(a: Shape3D, b: Shape3D, options: BooleanOption
55
55
  * Fuse all shapes in a single boolean operation.
56
56
  *
57
57
  * With `strategy: 'native'` (default), uses N-way BRepAlgoAPI_BuilderAlgo.
58
- * With `strategy: 'pairwise'`, uses recursive divide-and-conquer.
58
+ * With `strategy: 'pairwise'`, uses recursive divide-and-conquer over
59
+ * BRepAlgoAPI_Fuse.
60
+ *
61
+ * `strategy: 'pairwise'` is the workaround for #1126: the native N-way builder
62
+ * can silently corrupt the topology of certain disjoint inputs (e.g. an
63
+ * annular-sector tread fused with a frenet-swept rail) so the result passes all
64
+ * in-memory checks but traps the STEP writer. The pairwise path uses a different
65
+ * OCCT algorithm that is not affected. Tracked upstream at
66
+ * andymai/opencascade.js#3.
59
67
  *
60
68
  * @param shapes - Array of 3D shapes to fuse (at least one required).
61
69
  * @param options - Boolean operation options.
package/dist/topology.cjs CHANGED
@@ -4,20 +4,20 @@ const require_faceFns = require("./faceFns-p0lyVuyw.cjs");
4
4
  const require_shapeFns = require("./shapeFns-D5WNrq3s.cjs");
5
5
  const require_curveFns = require("./curveFns-C0oCmjV2.cjs");
6
6
  const require_meshFns = require("./meshFns-BawS1xNA.cjs");
7
- const require_booleanFns = require("./booleanFns-CFa3bgbG.cjs");
8
- const require_primitiveFns = require("./primitiveFns-ItlGYe3M.cjs");
7
+ const require_primitiveFns = require("./primitiveFns-JRmXxbRr.cjs");
8
+ const require_healingFns = require("./healingFns-B7dElsC4.cjs");
9
9
  exports.addHoles = require_primitiveFns.addHoles;
10
- exports.adjacentFaces = require_primitiveFns.adjacentFaces;
10
+ exports.adjacentFaces = require_healingFns.adjacentFaces;
11
11
  exports.approximateCurve = require_curveFns.approximateCurve;
12
12
  exports.asTopo = require_faceFns.asTopo;
13
- exports.autoHeal = require_primitiveFns.autoHeal;
13
+ exports.autoHeal = require_healingFns.autoHeal;
14
14
  exports.bezier = require_primitiveFns.bezier;
15
15
  exports.box = require_primitiveFns.box;
16
16
  exports.bsplineApprox = require_primitiveFns.bsplineApprox;
17
17
  exports.cast = require_faceFns.cast;
18
- exports.chamferDistAngleShape = require_primitiveFns.chamferDistAngle;
19
- exports.chamferWithEvolution = require_primitiveFns.chamferWithEvolution;
20
- exports.checkBoolean = require_primitiveFns.checkBoolean;
18
+ exports.chamferDistAngleShape = require_healingFns.chamferDistAngle;
19
+ exports.chamferWithEvolution = require_healingFns.chamferWithEvolution;
20
+ exports.checkBoolean = require_healingFns.checkBoolean;
21
21
  exports.circle = require_primitiveFns.circle;
22
22
  exports.classifyPointOnFace = require_faceFns.classifyPointOnFace;
23
23
  exports.clearMeshCache = require_meshFns.clearMeshCache;
@@ -33,13 +33,13 @@ exports.curvePeriod = require_curveFns.curvePeriod;
33
33
  exports.curvePointAt = require_curveFns.curvePointAt;
34
34
  exports.curveStartPoint = require_curveFns.curveStartPoint;
35
35
  exports.curveTangentAt = require_curveFns.curveTangentAt;
36
- exports.cutAll = require_booleanFns.cutAll;
37
- exports.cutAllBisect = require_primitiveFns.cutAllBisect;
38
- exports.cutWithEvolution = require_primitiveFns.cutWithEvolution;
36
+ exports.cutAll = require_primitiveFns.cutAll;
37
+ exports.cutAllBisect = require_healingFns.cutAllBisect;
38
+ exports.cutWithEvolution = require_healingFns.cutWithEvolution;
39
39
  exports.cylinder = require_primitiveFns.cylinder;
40
40
  exports.deserializeShape = require_faceFns.fromBREP;
41
41
  exports.downcast = require_faceFns.downcast;
42
- exports.edgesOfFace = require_primitiveFns.edgesOfFace;
42
+ exports.edgesOfFace = require_healingFns.edgesOfFace;
43
43
  exports.ellipse = require_primitiveFns.ellipse;
44
44
  exports.ellipseArc = require_primitiveFns.ellipseArc;
45
45
  exports.ellipsoid = require_primitiveFns.ellipsoid;
@@ -51,34 +51,34 @@ exports.faceAxis = require_faceFns.faceAxis;
51
51
  exports.faceCenter = require_faceFns.faceCenter;
52
52
  exports.faceGeomType = require_faceFns.faceGeomType;
53
53
  exports.faceOrientation = require_faceFns.faceOrientation;
54
- exports.facesOfEdge = require_primitiveFns.facesOfEdge;
54
+ exports.facesOfEdge = require_healingFns.facesOfEdge;
55
55
  exports.filledFace = require_primitiveFns.filledFace;
56
- exports.filletWithEvolution = require_primitiveFns.filletWithEvolution;
57
- exports.fixSelfIntersection = require_primitiveFns.fixSelfIntersection;
58
- exports.fixShape = require_primitiveFns.fixShape;
56
+ exports.filletWithEvolution = require_healingFns.filletWithEvolution;
57
+ exports.fixSelfIntersection = require_healingFns.fixSelfIntersection;
58
+ exports.fixShape = require_healingFns.fixShape;
59
59
  exports.flipFaceOrientation = require_faceFns.flipFaceOrientation;
60
60
  exports.flipOrientation = require_curveFns.flipOrientation;
61
- exports.fuseAll = require_booleanFns.fuseAll;
62
- exports.fuseAllBisect = require_primitiveFns.fuseAllBisect;
63
- exports.fuseWithEvolution = require_primitiveFns.fuseWithEvolution;
61
+ exports.fuseAll = require_primitiveFns.fuseAll;
62
+ exports.fuseAllBisect = require_healingFns.fuseAllBisect;
63
+ exports.fuseWithEvolution = require_healingFns.fuseWithEvolution;
64
64
  exports.getBounds = require_topologyQueryFns.getBounds;
65
65
  exports.getCurveType = require_curveFns.getCurveType;
66
66
  exports.getEdges = require_topologyQueryFns.getEdges;
67
67
  exports.getFaces = require_topologyQueryFns.getFaces;
68
68
  exports.getHashCode = require_shapeFns.getHashCode;
69
- exports.getNurbsCurveData = require_primitiveFns.getNurbsCurveData;
70
- exports.getNurbsSurfaceData = require_primitiveFns.getNurbsSurfaceData;
69
+ exports.getNurbsCurveData = require_healingFns.getNurbsCurveData;
70
+ exports.getNurbsSurfaceData = require_healingFns.getNurbsSurfaceData;
71
71
  exports.getOrientation = require_curveFns.getOrientation;
72
72
  exports.getSurfaceType = require_faceFns.getSurfaceType;
73
73
  exports.getVertices = require_topologyQueryFns.getVertices;
74
74
  exports.getWires = require_topologyQueryFns.getWires;
75
- exports.healFace = require_primitiveFns.healFace;
76
- exports.healSolid = require_primitiveFns.healSolid;
77
- exports.healWire = require_primitiveFns.healWire;
75
+ exports.healFace = require_healingFns.healFace;
76
+ exports.healSolid = require_healingFns.healSolid;
77
+ exports.healWire = require_healingFns.healWire;
78
78
  exports.helix = require_primitiveFns.helix;
79
79
  exports.innerWires = require_faceFns.innerWires;
80
80
  exports.interpolateCurve = require_curveFns.interpolateCurve;
81
- exports.intersectWithEvolution = require_primitiveFns.intersectWithEvolution;
81
+ exports.intersectWithEvolution = require_healingFns.intersectWithEvolution;
82
82
  exports.invalidateShapeCache = require_topologyQueryFns.invalidateShapeCache;
83
83
  exports.isCompSolid = require_faceFns.isCompSolid;
84
84
  exports.isEqualShape = require_shapeFns.isEqualShape;
@@ -95,28 +95,28 @@ exports.offsetWire2D = require_curveFns.offsetWire2D;
95
95
  exports.outerWire = require_faceFns.outerWire;
96
96
  exports.pointOnSurface = require_faceFns.pointOnSurface;
97
97
  exports.polygon = require_primitiveFns.polygon;
98
- exports.positionOnCurve = require_primitiveFns.positionOnCurve;
98
+ exports.positionOnCurve = require_healingFns.positionOnCurve;
99
99
  exports.projectPointOnFace = require_faceFns.projectPointOnFace;
100
100
  exports.sewShells = require_primitiveFns.sewShells;
101
101
  exports.shapeType = require_faceFns.shapeType;
102
- exports.sharedEdges = require_primitiveFns.sharedEdges;
103
- exports.shellWithEvolution = require_primitiveFns.shellWithEvolution;
102
+ exports.sharedEdges = require_healingFns.sharedEdges;
103
+ exports.shellWithEvolution = require_healingFns.shellWithEvolution;
104
104
  exports.solid = require_primitiveFns.solid;
105
- exports.solidFromShell = require_primitiveFns.solidFromShell;
105
+ exports.solidFromShell = require_healingFns.solidFromShell;
106
106
  exports.sphere = require_primitiveFns.sphere;
107
107
  exports.subFace = require_primitiveFns.subFace;
108
108
  exports.tangentArc = require_primitiveFns.tangentArc;
109
109
  exports.threePointArc = require_primitiveFns.threePointArc;
110
- exports.toBufferGeometryData = require_primitiveFns.toBufferGeometryData;
111
- exports.toGroupedBufferGeometryData = require_primitiveFns.toGroupedBufferGeometryData;
112
- exports.toLineGeometryData = require_primitiveFns.toLineGeometryData;
110
+ exports.toBufferGeometryData = require_healingFns.toBufferGeometryData;
111
+ exports.toGroupedBufferGeometryData = require_healingFns.toGroupedBufferGeometryData;
112
+ exports.toLineGeometryData = require_healingFns.toLineGeometryData;
113
113
  exports.torus = require_primitiveFns.torus;
114
114
  exports.uvBounds = require_faceFns.uvBounds;
115
115
  exports.uvCoordinates = require_faceFns.uvCoordinates;
116
- exports.variableFillet = require_primitiveFns.variableFillet;
116
+ exports.variableFillet = require_healingFns.variableFillet;
117
117
  exports.vertex = require_primitiveFns.vertex;
118
118
  exports.vertexPosition = require_topologyQueryFns.vertexPosition;
119
- exports.verticesOfEdge = require_primitiveFns.verticesOfEdge;
119
+ exports.verticesOfEdge = require_healingFns.verticesOfEdge;
120
120
  exports.wire = require_primitiveFns.wire;
121
121
  exports.wireLoop = require_primitiveFns.wireLoop;
122
- exports.wiresOfFace = require_primitiveFns.wiresOfFace;
122
+ exports.wiresOfFace = require_healingFns.wiresOfFace;
package/dist/topology.js CHANGED
@@ -3,6 +3,6 @@ import { S as shapeType, _ as cast, a as faceOrientation, b as isCompSolid, c as
3
3
  import { a as isSameShape, i as isEqualShape, n as getHashCode } from "./shapeFns-DZ6poxP7.js";
4
4
  import { a as curveIsPeriodic, c as curvePointAt, d as flipOrientation, f as getCurveType, h as offsetWire2D, i as curveIsClosed, l as curveStartPoint, m as interpolateCurve, n as curveAxis, o as curveLength, p as getOrientation, r as curveEndPoint, s as curvePeriod, t as approximateCurve, u as curveTangentAt } from "./curveFns-B4KEYU1M.js";
5
5
  import { c as createMeshCache, n as exportSTEP, r as exportSTL, s as clearMeshCache, t as exportIGES } from "./meshFns-CuYzpojl.js";
6
- import { a as fuseAll, r as cutAll } from "./booleanFns-D7Xgt-Og.js";
7
- import { $ as fuseAllBisect, A as fixShape, C as threePointArc, D as wireLoop, E as wire, G as chamferWithEvolution, I as solidFromShell, J as fuseWithEvolution, K as cutWithEvolution, M as healFace, N as healSolid, O as autoHeal, P as healWire, Q as cutAllBisect, S as tangentArc, T as vertex, U as variableFillet, W as positionOnCurve, X as shellWithEvolution, Y as intersectWithEvolution, Z as checkBoolean, _ as polygon, a as circle, at as sharedEdges, b as sphere, c as cylinder, ct as chamferDistAngle, d as ellipsoid, et as getNurbsCurveData, f as face, ft as toLineGeometryData, g as offsetFace, h as line, i as bsplineApprox, it as facesOfEdge, k as fixSelfIntersection, l as ellipse, lt as toBufferGeometryData, m as helix, n as bezier, nt as adjacentFaces, o as compound, ot as verticesOfEdge, p as filledFace, q as filletWithEvolution, r as box, rt as edgesOfFace, s as cone, st as wiresOfFace, t as addHoles, tt as getNurbsSurfaceData, u as ellipseArc, ut as toGroupedBufferGeometryData, v as sewShells, w as torus, x as subFace, y as solid } from "./primitiveFns-DWIzRvTY.js";
6
+ import { A as cutAll, C as threePointArc, D as wireLoop, E as wire, M as fuseAll, S as tangentArc, T as vertex, _ as polygon, a as circle, b as sphere, c as cylinder, d as ellipsoid, f as face, g as offsetFace, h as line, i as bsplineApprox, l as ellipse, m as helix, n as bezier, o as compound, p as filledFace, r as box, s as cone, t as addHoles, u as ellipseArc, v as sewShells, w as torus, x as subFace, y as solid } from "./primitiveFns-BxH5omw3.js";
7
+ import { A as edgesOfFace, C as shellWithEvolution, D as getNurbsCurveData, E as fuseAllBisect, F as chamferDistAngle, I as toBufferGeometryData, L as toGroupedBufferGeometryData, M as sharedEdges, N as verticesOfEdge, O as getNurbsSurfaceData, P as wiresOfFace, S as intersectWithEvolution, T as cutAllBisect, _ as positionOnCurve, a as healFace, b as filletWithEvolution, g as variableFillet, j as facesOfEdge, k as adjacentFaces, l as solidFromShell, n as fixSelfIntersection, o as healSolid, r as fixShape, s as healWire, t as autoHeal, v as chamferWithEvolution, w as checkBoolean, x as fuseWithEvolution, y as cutWithEvolution, z as toLineGeometryData } from "./healingFns-DS_nK9KF.js";
8
8
  export { addHoles, adjacentFaces, approximateCurve, asTopo, autoHeal, bezier, box, bsplineApprox, cast, chamferDistAngle as chamferDistAngleShape, chamferWithEvolution, checkBoolean, circle, classifyPointOnFace, clearMeshCache, compound, cone, createMeshCache, curveAxis, curveEndPoint, curveIsClosed, curveIsPeriodic, curveLength, curvePeriod, curvePointAt, curveStartPoint, curveTangentAt, cutAll, cutAllBisect, cutWithEvolution, cylinder, fromBREP as deserializeShape, downcast, edgesOfFace, ellipse, ellipseArc, ellipsoid, exportIGES, exportSTEP, exportSTL, face, faceAxis, faceCenter, faceGeomType, faceOrientation, facesOfEdge, filledFace, filletWithEvolution, fixSelfIntersection, fixShape, flipFaceOrientation, flipOrientation, fuseAll, fuseAllBisect, fuseWithEvolution, getBounds, getCurveType, getEdges, getFaces, getHashCode, getNurbsCurveData, getNurbsSurfaceData, getOrientation, getSurfaceType, getVertices, getWires, healFace, healSolid, healWire, helix, innerWires, interpolateCurve, intersectWithEvolution, invalidateShapeCache, isCompSolid, isEqualShape, isSameShape, iterEdges, iterFaces, iterTopo, iterVertices, iterWires, line, normalAt, offsetFace, offsetWire2D, outerWire, pointOnSurface, polygon, positionOnCurve, projectPointOnFace, sewShells, shapeType, sharedEdges, shellWithEvolution, solid, solidFromShell, sphere, subFace, tangentArc, threePointArc, toBufferGeometryData, toGroupedBufferGeometryData, toLineGeometryData, torus, uvBounds, uvCoordinates, variableFillet, vertex, vertexPosition, verticesOfEdge, wire, wireLoop, wiresOfFace };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brepjs",
3
- "version": "18.77.0",
3
+ "version": "18.78.0",
4
4
  "description": "Web CAD library with pluggable geometry kernel",
5
5
  "keywords": [
6
6
  "cad",