brepjs 8.3.0 → 8.7.4

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 (119) hide show
  1. package/dist/2d/lib/Curve2D.d.ts.map +1 -1
  2. package/dist/2d.cjs +2 -2
  3. package/dist/2d.js +13 -13
  4. package/dist/{Blueprint-a3ukJMG4.cjs → Blueprint-BcbOBF-9.cjs} +17 -102
  5. package/dist/{Blueprint-CdVaHDSx.js → Blueprint-Cmh8lKc4.js} +35 -120
  6. package/dist/{boolean2D-pvPIs21j.cjs → boolean2D-CqacqjME.cjs} +24 -25
  7. package/dist/{boolean2D-DzA0STqC.js → boolean2D-D94Axs3i.js} +23 -24
  8. package/dist/{booleanFns-BcQUqjUu.js → booleanFns-DdjtpcM6.js} +306 -12
  9. package/dist/{booleanFns-Cd414V3l.cjs → booleanFns-NtKxkiXn.cjs} +299 -5
  10. package/dist/brepjs.cjs +1782 -68
  11. package/dist/brepjs.js +2030 -317
  12. package/dist/core/errors.d.ts +25 -0
  13. package/dist/core/errors.d.ts.map +1 -1
  14. package/dist/core.cjs +4 -4
  15. package/dist/core.js +4 -4
  16. package/dist/{cornerFinder-DvPiz-VR.js → cornerFinder-BBOYfsXl.js} +1 -1
  17. package/dist/{cornerFinder-BdKtobgb.cjs → cornerFinder-Bqy8Lw2p.cjs} +1 -1
  18. package/dist/{curveFns-CyHyk29c.js → curveFns-B85Glnfo.js} +19 -17
  19. package/dist/{curveFns-B5EQsSwv.cjs → curveFns-BXCbASW-.cjs} +6 -4
  20. package/dist/{drawFns-CAAE4Z88.js → drawFns-B-gJ2WUc.js} +52 -23
  21. package/dist/{drawFns-Mr2pghU8.cjs → drawFns-CAmFEqd1.cjs} +68 -39
  22. package/dist/{errors-wGhcJMpB.js → errors-Coh_5_19.js} +35 -1
  23. package/dist/{errors-DK1VAdP4.cjs → errors-eRQu29oc.cjs} +35 -1
  24. package/dist/{faceFns-ub3CugDN.js → faceFns-CltrEfOo.js} +109 -12
  25. package/dist/{faceFns-D1Sqnlu6.cjs → faceFns-DcndPHWm.cjs} +103 -6
  26. package/dist/{helpers-CP2KrBZl.cjs → helpers-CC21GeAr.cjs} +8 -9
  27. package/dist/{helpers-r_e-u1JM.js → helpers-SksQIreB.js} +16 -17
  28. package/dist/index.d.ts +20 -3
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/io/dxfImportFns.d.ts +17 -0
  31. package/dist/io/dxfImportFns.d.ts.map +1 -0
  32. package/dist/io/objImportFns.d.ts +19 -0
  33. package/dist/io/objImportFns.d.ts.map +1 -0
  34. package/dist/io/threemfImportFns.d.ts +19 -0
  35. package/dist/io/threemfImportFns.d.ts.map +1 -0
  36. package/dist/io.cjs +5 -5
  37. package/dist/io.js +5 -5
  38. package/dist/kernel/hullOps.d.ts +23 -0
  39. package/dist/kernel/hullOps.d.ts.map +1 -0
  40. package/dist/kernel/occtAdapter.d.ts +11 -0
  41. package/dist/kernel/occtAdapter.d.ts.map +1 -1
  42. package/dist/kernel/solverAdapter.d.ts +39 -0
  43. package/dist/kernel/solverAdapter.d.ts.map +1 -0
  44. package/dist/kernel/types.d.ts +11 -0
  45. package/dist/kernel/types.d.ts.map +1 -1
  46. package/dist/{loft-PMRx9iMG.cjs → loft-BcyyvWCj.cjs} +28 -28
  47. package/dist/{loft-BHn7GKm8.js → loft-CJMPx1NQ.js} +16 -16
  48. package/dist/{measurement-BfhEneUl.js → measurement-ByOztLxb.js} +3 -3
  49. package/dist/{measurement-B06hNs89.cjs → measurement-DU3ry-0Q.cjs} +3 -3
  50. package/dist/measurement.cjs +1 -1
  51. package/dist/measurement.js +1 -1
  52. package/dist/{meshFns-BEvGVcym.js → meshFns-D2gLyLFt.js} +3 -3
  53. package/dist/{meshFns-CJV_k_EQ.cjs → meshFns-DawUwI3W.cjs} +3 -3
  54. package/dist/{occtBoundary-CoXB2xvx.js → occtBoundary-CWzWqBCm.js} +436 -7
  55. package/dist/{occtBoundary-BFAaUtA7.cjs → occtBoundary-DH2VO-rq.cjs} +431 -2
  56. package/dist/operations/assemblyFns.d.ts +1 -0
  57. package/dist/operations/assemblyFns.d.ts.map +1 -1
  58. package/dist/operations/guidedSweepFns.d.ts +25 -0
  59. package/dist/operations/guidedSweepFns.d.ts.map +1 -0
  60. package/dist/operations/mateFns.d.ts +50 -0
  61. package/dist/operations/mateFns.d.ts.map +1 -0
  62. package/dist/operations/multiSweepFns.d.ts +32 -0
  63. package/dist/operations/multiSweepFns.d.ts.map +1 -0
  64. package/dist/operations/roofFns.d.ts +16 -0
  65. package/dist/operations/roofFns.d.ts.map +1 -0
  66. package/dist/operations/straightSkeleton.d.ts +28 -0
  67. package/dist/operations/straightSkeleton.d.ts.map +1 -0
  68. package/dist/{operations-CYGNxn5D.cjs → operations-CdELWxgv.cjs} +7 -7
  69. package/dist/{operations-B314mytX.js → operations-DiXo_4t9.js} +15 -15
  70. package/dist/operations.cjs +2 -2
  71. package/dist/operations.js +13 -13
  72. package/dist/query.cjs +5 -5
  73. package/dist/query.js +7 -7
  74. package/dist/result.cjs +1 -1
  75. package/dist/result.js +1 -1
  76. package/dist/{shapeFns-Z_ScEjmn.cjs → shapeFns-3RYtsUVY.cjs} +54 -21
  77. package/dist/{shapeFns-CWd_ASDV.js → shapeFns-4ioRrhih.js} +52 -19
  78. package/dist/{shapeTypes-UqVCIO_T.cjs → shapeTypes-CMjrTv36.cjs} +1 -1
  79. package/dist/{shapeTypes-BU2LKv2S.js → shapeTypes-D0vfRxWb.js} +13 -13
  80. package/dist/sketching.cjs +2 -2
  81. package/dist/sketching.js +2 -2
  82. package/dist/{curveBuilders-CN72XaIQ.js → surfaceBuilders-B7Jxob8g.js} +106 -13
  83. package/dist/{curveBuilders-Du03_Yyf.cjs → surfaceBuilders-Xx9DRRxs.cjs} +96 -3
  84. package/dist/text/textBlueprints.d.ts +38 -0
  85. package/dist/text/textBlueprints.d.ts.map +1 -1
  86. package/dist/topology/api.d.ts +5 -0
  87. package/dist/topology/api.d.ts.map +1 -1
  88. package/dist/topology/booleanFns.d.ts +10 -1
  89. package/dist/topology/booleanFns.d.ts.map +1 -1
  90. package/dist/topology/colorFns.d.ts +38 -0
  91. package/dist/topology/colorFns.d.ts.map +1 -0
  92. package/dist/topology/curveFns.d.ts +1 -1
  93. package/dist/topology/curveFns.d.ts.map +1 -1
  94. package/dist/topology/faceTagFns.d.ts +44 -0
  95. package/dist/topology/faceTagFns.d.ts.map +1 -0
  96. package/dist/topology/hullFns.d.ts +16 -0
  97. package/dist/topology/hullFns.d.ts.map +1 -0
  98. package/dist/topology/minkowskiFns.d.ts +20 -0
  99. package/dist/topology/minkowskiFns.d.ts.map +1 -0
  100. package/dist/topology/modifierFns.d.ts.map +1 -1
  101. package/dist/topology/polyhedronFns.d.ts +8 -0
  102. package/dist/topology/polyhedronFns.d.ts.map +1 -0
  103. package/dist/topology/shapeFns.d.ts +4 -0
  104. package/dist/topology/shapeFns.d.ts.map +1 -1
  105. package/dist/topology/surfaceBuilders.d.ts +7 -0
  106. package/dist/topology/surfaceBuilders.d.ts.map +1 -1
  107. package/dist/topology/surfaceFns.d.ts +38 -0
  108. package/dist/topology/surfaceFns.d.ts.map +1 -0
  109. package/dist/{topology-A7-jUtHB.cjs → topology-D-nGjCzV.cjs} +19 -20
  110. package/dist/{topology-BupialMm.js → topology-DRP9zreU.js} +8 -9
  111. package/dist/topology.cjs +13 -14
  112. package/dist/topology.js +51 -52
  113. package/dist/{vectors-BhfKwL9J.js → vectors-CZV4ZrTz.js} +2 -2
  114. package/dist/{vectors-t1XG4LpL.cjs → vectors-DwFeX0Ja.cjs} +2 -2
  115. package/dist/vectors.cjs +2 -2
  116. package/dist/vectors.js +2 -2
  117. package/package.json +8 -7
  118. package/dist/cast-C107o5ow.cjs +0 -102
  119. package/dist/cast-D0OhP1nV.js +0 -103
@@ -1041,7 +1041,7 @@ function makeWire(oc, edges) {
1041
1041
  progress.delete();
1042
1042
  return wire;
1043
1043
  }
1044
- function makeFace(oc, wire, planar = true) {
1044
+ function makeFace$1(oc, wire, planar = true) {
1045
1045
  if (planar) {
1046
1046
  const builder2 = new oc.BRepBuilderAPI_MakeFace_15(wire, false);
1047
1047
  const face = builder2.Face();
@@ -1440,6 +1440,416 @@ function approximatePoints(oc, points, options = {}) {
1440
1440
  splineBuilder.delete();
1441
1441
  return edge;
1442
1442
  }
1443
+ function sub(a, b) {
1444
+ return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
1445
+ }
1446
+ function cross(a, b) {
1447
+ return {
1448
+ x: a.y * b.z - a.z * b.y,
1449
+ y: a.z * b.x - a.x * b.z,
1450
+ z: a.x * b.y - a.y * b.x
1451
+ };
1452
+ }
1453
+ function dot(a, b) {
1454
+ return a.x * b.x + a.y * b.y + a.z * b.z;
1455
+ }
1456
+ function lengthVec(v) {
1457
+ return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
1458
+ }
1459
+ function distSq(a, b) {
1460
+ const dx = a.x - b.x;
1461
+ const dy = a.y - b.y;
1462
+ const dz = a.z - b.z;
1463
+ return dx * dx + dy * dy + dz * dz;
1464
+ }
1465
+ function at(arr, i) {
1466
+ const v = arr[i];
1467
+ if (v === void 0) throw new Error(`Index ${i} out of bounds`);
1468
+ return v;
1469
+ }
1470
+ function atN(arr, i) {
1471
+ const v = arr[i];
1472
+ if (v === void 0) throw new Error(`Index ${i} out of bounds`);
1473
+ return v;
1474
+ }
1475
+ function makeFace(points, a, b, c) {
1476
+ const normal = cross(sub(at(points, b), at(points, a)), sub(at(points, c), at(points, a)));
1477
+ const len = lengthVec(normal);
1478
+ const n = len > 1e-14 ? { x: normal.x / len, y: normal.y / len, z: normal.z / len } : normal;
1479
+ return {
1480
+ a,
1481
+ b,
1482
+ c,
1483
+ normal: n,
1484
+ offset: dot(n, at(points, a)),
1485
+ alive: true,
1486
+ outsidePoints: []
1487
+ };
1488
+ }
1489
+ function signedDist(face, point) {
1490
+ return dot(face.normal, point) - face.offset;
1491
+ }
1492
+ function deduplicatePoints(points, tolerance) {
1493
+ const tolSq = tolerance * tolerance;
1494
+ const result = [];
1495
+ for (const p of points) {
1496
+ let isDuplicate = false;
1497
+ for (const q of result) {
1498
+ if (distSq(p, q) < tolSq) {
1499
+ isDuplicate = true;
1500
+ break;
1501
+ }
1502
+ }
1503
+ if (!isDuplicate) result.push(p);
1504
+ }
1505
+ return result;
1506
+ }
1507
+ function findInitialTetrahedron(points) {
1508
+ const n = points.length;
1509
+ if (n < 4) return null;
1510
+ let i0 = 0;
1511
+ let i1 = 1;
1512
+ let maxDist = distSq(at(points, 0), at(points, 1));
1513
+ for (let i = 0; i < n; i++) {
1514
+ for (let j = i + 1; j < n; j++) {
1515
+ const d = distSq(at(points, i), at(points, j));
1516
+ if (d > maxDist) {
1517
+ maxDist = d;
1518
+ i0 = i;
1519
+ i1 = j;
1520
+ }
1521
+ }
1522
+ }
1523
+ if (maxDist < 1e-20) return null;
1524
+ const lineDir = sub(at(points, i1), at(points, i0));
1525
+ let i2 = -1;
1526
+ let maxLineDist = -1;
1527
+ for (let i = 0; i < n; i++) {
1528
+ if (i === i0 || i === i1) continue;
1529
+ const v = sub(at(points, i), at(points, i0));
1530
+ const c = cross(lineDir, v);
1531
+ const d = dot(c, c);
1532
+ if (d > maxLineDist) {
1533
+ maxLineDist = d;
1534
+ i2 = i;
1535
+ }
1536
+ }
1537
+ if (i2 === -1 || maxLineDist < 1e-20) return null;
1538
+ const planeNormal = cross(
1539
+ sub(at(points, i1), at(points, i0)),
1540
+ sub(at(points, i2), at(points, i0))
1541
+ );
1542
+ const planeLen = lengthVec(planeNormal);
1543
+ if (planeLen < 1e-14) return null;
1544
+ const pn = {
1545
+ x: planeNormal.x / planeLen,
1546
+ y: planeNormal.y / planeLen,
1547
+ z: planeNormal.z / planeLen
1548
+ };
1549
+ const planeOffset = dot(pn, at(points, i0));
1550
+ let i3 = -1;
1551
+ let maxPlaneDist = -1;
1552
+ for (let i = 0; i < n; i++) {
1553
+ if (i === i0 || i === i1 || i === i2) continue;
1554
+ const d = Math.abs(dot(pn, at(points, i)) - planeOffset);
1555
+ if (d > maxPlaneDist) {
1556
+ maxPlaneDist = d;
1557
+ i3 = i;
1558
+ }
1559
+ }
1560
+ if (i3 === -1 || maxPlaneDist < 1e-14) return null;
1561
+ const sd = dot(pn, at(points, i3)) - planeOffset;
1562
+ if (sd > 0) {
1563
+ return [i0, i2, i1, i3];
1564
+ }
1565
+ return [i0, i1, i2, i3];
1566
+ }
1567
+ function quickHull(inputPoints, tolerance) {
1568
+ const points = deduplicatePoints(inputPoints, tolerance);
1569
+ if (points.length < 4) {
1570
+ throw new Error(
1571
+ points.length === 0 ? "No points provided for convex hull" : "Fewer than 4 non-coincident points; cannot form a 3D convex hull"
1572
+ );
1573
+ }
1574
+ const tet = findInitialTetrahedron(points);
1575
+ if (tet === null) {
1576
+ throw new Error("All points are coplanar; cannot form a 3D convex hull");
1577
+ }
1578
+ const [t0, t1, t2, t3] = tet;
1579
+ const centroid = {
1580
+ x: (at(points, t0).x + at(points, t1).x + at(points, t2).x + at(points, t3).x) / 4,
1581
+ y: (at(points, t0).y + at(points, t1).y + at(points, t2).y + at(points, t3).y) / 4,
1582
+ z: (at(points, t0).z + at(points, t1).z + at(points, t2).z + at(points, t3).z) / 4
1583
+ };
1584
+ function makeOutwardFace(a, b, c) {
1585
+ const face = makeFace(points, a, b, c);
1586
+ const faceCenter = {
1587
+ x: (at(points, a).x + at(points, b).x + at(points, c).x) / 3,
1588
+ y: (at(points, a).y + at(points, b).y + at(points, c).y) / 3,
1589
+ z: (at(points, a).z + at(points, b).z + at(points, c).z) / 3
1590
+ };
1591
+ const toCentroid = sub(centroid, faceCenter);
1592
+ if (dot(face.normal, toCentroid) > 0) {
1593
+ return makeFace(points, a, c, b);
1594
+ }
1595
+ return face;
1596
+ }
1597
+ const faces = [
1598
+ makeOutwardFace(t0, t1, t2),
1599
+ makeOutwardFace(t0, t2, t3),
1600
+ makeOutwardFace(t0, t3, t1),
1601
+ makeOutwardFace(t1, t3, t2)
1602
+ ];
1603
+ const tetSet = /* @__PURE__ */ new Set([t0, t1, t2, t3]);
1604
+ const epsilon = 1e-10;
1605
+ for (let i = 0; i < points.length; i++) {
1606
+ if (tetSet.has(i)) continue;
1607
+ for (const face of faces) {
1608
+ if (signedDist(face, at(points, i)) > epsilon) {
1609
+ face.outsidePoints.push(i);
1610
+ break;
1611
+ }
1612
+ }
1613
+ }
1614
+ for (let iteration = 0; iteration < points.length * 4; iteration++) {
1615
+ let currentFace = null;
1616
+ for (const face of faces) {
1617
+ if (face.alive && face.outsidePoints.length > 0) {
1618
+ currentFace = face;
1619
+ break;
1620
+ }
1621
+ }
1622
+ if (currentFace === null) break;
1623
+ let furthestIdx = atN(currentFace.outsidePoints, 0);
1624
+ let furthestDist = signedDist(currentFace, at(points, furthestIdx));
1625
+ for (let i = 1; i < currentFace.outsidePoints.length; i++) {
1626
+ const idx = atN(currentFace.outsidePoints, i);
1627
+ const d = signedDist(currentFace, at(points, idx));
1628
+ if (d > furthestDist) {
1629
+ furthestDist = d;
1630
+ furthestIdx = idx;
1631
+ }
1632
+ }
1633
+ const visibleFaces = [];
1634
+ for (const face of faces) {
1635
+ if (face.alive && signedDist(face, at(points, furthestIdx)) > epsilon) {
1636
+ visibleFaces.push(face);
1637
+ }
1638
+ }
1639
+ const edgeCount = /* @__PURE__ */ new Map();
1640
+ for (const face of visibleFaces) {
1641
+ const edges = [
1642
+ [face.a, face.b],
1643
+ [face.b, face.c],
1644
+ [face.c, face.a]
1645
+ ];
1646
+ for (const [ea, eb] of edges) {
1647
+ const key = ea < eb ? `${ea}-${eb}` : `${eb}-${ea}`;
1648
+ const entry = edgeCount.get(key);
1649
+ if (entry) {
1650
+ entry.count++;
1651
+ } else {
1652
+ edgeCount.set(key, { a: ea, b: eb, count: 1 });
1653
+ }
1654
+ }
1655
+ }
1656
+ const horizonEdges = [];
1657
+ for (const entry of edgeCount.values()) {
1658
+ if (entry.count === 1) {
1659
+ horizonEdges.push({ a: entry.a, b: entry.b });
1660
+ }
1661
+ }
1662
+ const orphanedPoints = [];
1663
+ for (const face of visibleFaces) {
1664
+ for (const idx of face.outsidePoints) {
1665
+ if (idx !== furthestIdx) {
1666
+ orphanedPoints.push(idx);
1667
+ }
1668
+ }
1669
+ face.alive = false;
1670
+ face.outsidePoints = [];
1671
+ }
1672
+ const newFaces = [];
1673
+ for (const edge of horizonEdges) {
1674
+ const newFaceObj = makeFace(points, edge.a, edge.b, furthestIdx);
1675
+ newFaces.push(newFaceObj);
1676
+ faces.push(newFaceObj);
1677
+ }
1678
+ for (const idx of orphanedPoints) {
1679
+ for (const face of newFaces) {
1680
+ if (signedDist(face, at(points, idx)) > epsilon) {
1681
+ face.outsidePoints.push(idx);
1682
+ break;
1683
+ }
1684
+ }
1685
+ }
1686
+ }
1687
+ const resultFaces = [];
1688
+ for (const face of faces) {
1689
+ if (face.alive) {
1690
+ resultFaces.push([face.a, face.b, face.c]);
1691
+ }
1692
+ }
1693
+ return { faces: resultFaces, points };
1694
+ }
1695
+ function extractVertices(oc, shapes, tolerance) {
1696
+ const vertices = [];
1697
+ const meshDeflection = Math.max(tolerance, 1);
1698
+ for (const shape of shapes) {
1699
+ const mesh2 = new oc.BRepMesh_IncrementalMesh_2(
1700
+ shape,
1701
+ meshDeflection,
1702
+ false,
1703
+ meshDeflection * 0.5,
1704
+ false
1705
+ );
1706
+ const progress = new oc.Message_ProgressRange_1();
1707
+ mesh2.Perform(progress);
1708
+ progress.delete();
1709
+ mesh2.delete();
1710
+ const explorer = new oc.TopExp_Explorer_2(
1711
+ shape,
1712
+ oc.TopAbs_ShapeEnum.TopAbs_FACE,
1713
+ oc.TopAbs_ShapeEnum.TopAbs_SHAPE
1714
+ );
1715
+ while (explorer.More()) {
1716
+ const face = oc.TopoDS.Face_1(explorer.Current());
1717
+ const location = new oc.TopLoc_Location_1();
1718
+ const tri = oc.BRep_Tool.Triangulation(face, location, 0);
1719
+ if (!tri.IsNull()) {
1720
+ const trsf = location.Transformation();
1721
+ const nbNodes = tri.get().NbNodes();
1722
+ for (let i = 1; i <= nbNodes; i++) {
1723
+ const node = tri.get().Node(i);
1724
+ const transformed = node.Transformed(trsf);
1725
+ vertices.push({
1726
+ x: transformed.X(),
1727
+ y: transformed.Y(),
1728
+ z: transformed.Z()
1729
+ });
1730
+ transformed.delete();
1731
+ node.delete();
1732
+ }
1733
+ trsf.delete();
1734
+ }
1735
+ location.delete();
1736
+ explorer.Next();
1737
+ }
1738
+ explorer.delete();
1739
+ }
1740
+ return vertices;
1741
+ }
1742
+ function buildTriFace(oc, pa, pb, pc) {
1743
+ const gpA = new oc.gp_Pnt_3(pa.x, pa.y, pa.z);
1744
+ const gpB = new oc.gp_Pnt_3(pb.x, pb.y, pb.z);
1745
+ const gpC = new oc.gp_Pnt_3(pc.x, pc.y, pc.z);
1746
+ const e1 = new oc.BRepBuilderAPI_MakeEdge_3(gpA, gpB);
1747
+ const e2 = new oc.BRepBuilderAPI_MakeEdge_3(gpB, gpC);
1748
+ const e3 = new oc.BRepBuilderAPI_MakeEdge_3(gpC, gpA);
1749
+ const wireBuilder = new oc.BRepBuilderAPI_MakeWire_1();
1750
+ wireBuilder.Add_1(e1.Edge());
1751
+ wireBuilder.Add_1(e2.Edge());
1752
+ wireBuilder.Add_1(e3.Edge());
1753
+ let face = null;
1754
+ if (wireBuilder.IsDone()) {
1755
+ const makeFaceBuilder = new oc.BRepBuilderAPI_MakeFace_15(wireBuilder.Wire(), false);
1756
+ if (makeFaceBuilder.IsDone()) {
1757
+ face = makeFaceBuilder.Face();
1758
+ }
1759
+ makeFaceBuilder.delete();
1760
+ }
1761
+ wireBuilder.delete();
1762
+ e1.delete();
1763
+ e2.delete();
1764
+ e3.delete();
1765
+ gpA.delete();
1766
+ gpB.delete();
1767
+ gpC.delete();
1768
+ return face;
1769
+ }
1770
+ function reconstructBrep(oc, hullResult, tolerance) {
1771
+ const { faces: hullFaces, points } = hullResult;
1772
+ const ocFaces = [];
1773
+ for (const [ia, ib, ic] of hullFaces) {
1774
+ const face = buildTriFace(oc, at(points, ia), at(points, ib), at(points, ic));
1775
+ if (face !== null) {
1776
+ ocFaces.push(face);
1777
+ }
1778
+ }
1779
+ if (ocFaces.length < 4) {
1780
+ throw new Error(`hull: only ${ocFaces.length} faces built, need at least 4 for a solid`);
1781
+ }
1782
+ const sewTolerance = Math.max(tolerance, 1e-4);
1783
+ const sewing = new oc.BRepBuilderAPI_Sewing(sewTolerance, true, true, true, false);
1784
+ for (const face of ocFaces) {
1785
+ sewing.Add(face);
1786
+ }
1787
+ const sewProgress = new oc.Message_ProgressRange_1();
1788
+ sewing.Perform(sewProgress);
1789
+ sewProgress.delete();
1790
+ const sewn = sewing.SewedShape();
1791
+ sewing.delete();
1792
+ const shellExplorer = new oc.TopExp_Explorer_2(
1793
+ sewn,
1794
+ oc.TopAbs_ShapeEnum.TopAbs_SHELL,
1795
+ oc.TopAbs_ShapeEnum.TopAbs_SHAPE
1796
+ );
1797
+ if (shellExplorer.More()) {
1798
+ const shell2 = oc.TopoDS.Shell_1(shellExplorer.Current());
1799
+ shellExplorer.delete();
1800
+ const solidMaker = new oc.BRepBuilderAPI_MakeSolid_1();
1801
+ solidMaker.Add(shell2);
1802
+ const solidProgress = new oc.Message_ProgressRange_1();
1803
+ solidMaker.Build(solidProgress);
1804
+ solidProgress.delete();
1805
+ if (solidMaker.IsDone()) {
1806
+ const solid = solidMaker.Solid();
1807
+ solidMaker.delete();
1808
+ shell2.delete();
1809
+ const props = new oc.GProp_GProps_1();
1810
+ oc.BRepGProp.VolumeProperties_1(solid, props, false, false, false);
1811
+ const vol = props.Mass();
1812
+ props.delete();
1813
+ if (vol < 0) {
1814
+ solid.Complement();
1815
+ }
1816
+ return solid;
1817
+ }
1818
+ shell2.delete();
1819
+ solidMaker.delete();
1820
+ return sewn;
1821
+ }
1822
+ shellExplorer.delete();
1823
+ return sewn;
1824
+ }
1825
+ function hull(oc, shapes, tolerance) {
1826
+ if (shapes.length === 0) {
1827
+ throw new Error("hull: no shapes provided");
1828
+ }
1829
+ const vertices = extractVertices(oc, shapes, tolerance);
1830
+ if (vertices.length < 4) {
1831
+ throw new Error("hull: fewer than 4 vertices extracted from input shapes");
1832
+ }
1833
+ const hullResult = quickHull(vertices, tolerance);
1834
+ if (hullResult.faces.length < 4) {
1835
+ throw new Error("hull: degenerate hull (fewer than 4 faces)");
1836
+ }
1837
+ return reconstructBrep(oc, hullResult, tolerance);
1838
+ }
1839
+ function buildSolidFromFaces(oc, points, faces, tolerance) {
1840
+ const hullResult = { points, faces };
1841
+ return reconstructBrep(oc, hullResult, tolerance);
1842
+ }
1843
+ function hullFromPoints(oc, points, tolerance) {
1844
+ if (points.length < 4) {
1845
+ throw new Error("hullFromPoints: fewer than 4 points");
1846
+ }
1847
+ const hullResult = quickHull(points, tolerance);
1848
+ if (hullResult.faces.length < 4) {
1849
+ throw new Error("hullFromPoints: degenerate hull (fewer than 4 faces)");
1850
+ }
1851
+ return reconstructBrep(oc, hullResult, tolerance);
1852
+ }
1443
1853
  class OCCTAdapter {
1444
1854
  oc;
1445
1855
  constructor(oc) {
@@ -1464,6 +1874,25 @@ class OCCTAdapter {
1464
1874
  cutAll(shape, tools, options = {}) {
1465
1875
  return cutAll(this.oc, shape, tools, options);
1466
1876
  }
1877
+ // --- Convex hull ---
1878
+ hull(shapes, tolerance) {
1879
+ return hull(this.oc, shapes, tolerance);
1880
+ }
1881
+ hullFromPoints(points, tolerance) {
1882
+ return hullFromPoints(
1883
+ this.oc,
1884
+ points.map((p) => ({ x: p.x, y: p.y, z: p.z })),
1885
+ tolerance
1886
+ );
1887
+ }
1888
+ buildSolidFromFaces(points, faces, tolerance) {
1889
+ return buildSolidFromFaces(
1890
+ this.oc,
1891
+ points.map((p) => ({ x: p.x, y: p.y, z: p.z })),
1892
+ faces,
1893
+ tolerance
1894
+ );
1895
+ }
1467
1896
  // --- Shape construction (delegates to constructorOps.ts) ---
1468
1897
  makeVertex(x, y, z) {
1469
1898
  return makeVertex(this.oc, x, y, z);
@@ -1475,7 +1904,7 @@ class OCCTAdapter {
1475
1904
  return makeWire(this.oc, edges);
1476
1905
  }
1477
1906
  makeFace(wire, planar = true) {
1478
- return makeFace(this.oc, wire, planar);
1907
+ return makeFace$1(this.oc, wire, planar);
1479
1908
  }
1480
1909
  makeBox(width, height, depth) {
1481
1910
  return makeBox(this.oc, width, height, depth);
@@ -1761,10 +2190,10 @@ function makeOcAx3(origin, zDir, xDir) {
1761
2190
  }
1762
2191
  export {
1763
2192
  toVec3 as a,
1764
- toOcPnt as b,
1765
- toOcVec as c,
1766
- makeOcAx3 as d,
1767
- makeOcAx1 as e,
2193
+ toOcVec as b,
2194
+ makeOcAx2 as c,
2195
+ toOcPnt as d,
2196
+ makeOcAx3 as e,
1768
2197
  fromOcDir as f,
1769
2198
  getKernel as g,
1770
2199
  fromOcPnt as h,
@@ -1772,7 +2201,7 @@ export {
1772
2201
  initFromOC as j,
1773
2202
  withOcPnt as k,
1774
2203
  withOcVec as l,
1775
- makeOcAx2 as m,
2204
+ makeOcAx1 as m,
1776
2205
  uniqueId as n,
1777
2206
  resolveDirection as r,
1778
2207
  surfaceCurvature as s,