brepjs 8.0.1 → 8.0.3

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 (131) hide show
  1. package/dist/2d/blueprints/booleanHelpers.d.ts +32 -0
  2. package/dist/2d/blueprints/booleanHelpers.d.ts.map +1 -0
  3. package/dist/2d/blueprints/booleanOperations.d.ts +5 -3
  4. package/dist/2d/blueprints/booleanOperations.d.ts.map +1 -1
  5. package/dist/2d/blueprints/intersectionSegments.d.ts +12 -0
  6. package/dist/2d/blueprints/intersectionSegments.d.ts.map +1 -0
  7. package/dist/2d/blueprints/segmentAssembly.d.ts +31 -0
  8. package/dist/2d/blueprints/segmentAssembly.d.ts.map +1 -0
  9. package/dist/2d.cjs +2 -2
  10. package/dist/2d.js +8 -8
  11. package/dist/{Blueprint-D3JfGJTz.js → Blueprint-DnAO3gr5.js} +116 -30
  12. package/dist/{Blueprint-CVctc41Z.cjs → Blueprint-FxmMji4s.cjs} +110 -24
  13. package/dist/{boolean2D-hOw5Qay5.js → boolean2D-BnZKKBWU.js} +391 -310
  14. package/dist/{boolean2D-BdZATaHs.cjs → boolean2D-BrjHZfWn.cjs} +426 -345
  15. package/dist/{booleanFns-CqehfzcK.js → booleanFns-Ct3wDnhc.js} +14 -18
  16. package/dist/{booleanFns-BBSVKhL2.cjs → booleanFns-ND7sZvhu.cjs} +12 -16
  17. package/dist/brepjs.cjs +171 -101
  18. package/dist/brepjs.js +315 -244
  19. package/dist/{cast-DQaUibmm.js → cast-BEg1mN7n.js} +2 -2
  20. package/dist/{cast-DkB0GKmQ.cjs → cast-CqDc8oFW.cjs} +2 -2
  21. package/dist/core/disposal.d.ts +1 -1
  22. package/dist/core/disposal.d.ts.map +1 -1
  23. package/dist/core.cjs +3 -3
  24. package/dist/core.js +3 -3
  25. package/dist/cornerFinder-89obDwGi.js +59 -0
  26. package/dist/cornerFinder-BKsCkrXd.cjs +58 -0
  27. package/dist/curveBuilders-BjtdNw1B.cjs +196 -0
  28. package/dist/curveBuilders-U26XDfxg.js +197 -0
  29. package/dist/curveFns-BoG_iA07.cjs +375 -0
  30. package/dist/curveFns-Cg99XKe2.js +376 -0
  31. package/dist/{drawFns-CUyx50gi.cjs → drawFns-C-MCkYj6.cjs} +60 -62
  32. package/dist/{drawFns-921SkhDL.js → drawFns-DJV-nOox.js} +12 -14
  33. package/dist/{faceFns-DHu-2JpA.js → faceFns-CyokaCDr.js} +3 -3
  34. package/dist/{faceFns-BwK7FP7N.cjs → faceFns-DcSCjDG0.cjs} +3 -3
  35. package/dist/helpers--iZxPeJg.cjs +203 -0
  36. package/dist/helpers-CRx_ks-u.js +204 -0
  37. package/dist/io.cjs +4 -4
  38. package/dist/io.js +4 -4
  39. package/dist/kernel/curveOps.d.ts.map +1 -1
  40. package/dist/kernel/meshOps.d.ts.map +1 -1
  41. package/dist/kernel/modifierOps.d.ts.map +1 -1
  42. package/dist/kernel/occtAdapter.d.ts +1 -0
  43. package/dist/kernel/occtAdapter.d.ts.map +1 -1
  44. package/dist/kernel/sweepOps.d.ts +8 -0
  45. package/dist/kernel/sweepOps.d.ts.map +1 -1
  46. package/dist/kernel/types.d.ts +1 -0
  47. package/dist/kernel/types.d.ts.map +1 -1
  48. package/dist/loft-8asn63t4.cjs +372 -0
  49. package/dist/loft-jIkZRqHm.js +373 -0
  50. package/dist/{measurement-C5JGCuUP.js → measurement-DWv8kK6J.js} +3 -3
  51. package/dist/{measurement-fxm_pW7x.cjs → measurement-lRLwaoqD.cjs} +3 -3
  52. package/dist/measurement.cjs +1 -1
  53. package/dist/measurement.js +1 -1
  54. package/dist/{meshFns-BhrZGi6w.cjs → meshFns-DWuLC3fk.cjs} +29 -9
  55. package/dist/{meshFns-AqAjTTVl.js → meshFns-DgAIL1B-.js} +29 -9
  56. package/dist/{occtBoundary-du8_ex-p.cjs → occtBoundary-DHtzU4tz.cjs} +93 -61
  57. package/dist/{occtBoundary-CwegMzqc.js → occtBoundary-DYsksDtE.js} +98 -66
  58. package/dist/operations/extrude.d.ts.map +1 -1
  59. package/dist/operations/extrudeFns.d.ts.map +1 -1
  60. package/dist/operations/extrudeUtils.d.ts +17 -0
  61. package/dist/operations/extrudeUtils.d.ts.map +1 -1
  62. package/dist/operations/patternFns.d.ts.map +1 -1
  63. package/dist/{operations-C1rWoba2.js → operations-B8FHVC22.js} +54 -9
  64. package/dist/{operations-BP1wVDw0.cjs → operations-CCFPvtd-.cjs} +54 -9
  65. package/dist/operations.cjs +2 -2
  66. package/dist/operations.js +4 -4
  67. package/dist/query/cornerFinder.d.ts +48 -0
  68. package/dist/query/cornerFinder.d.ts.map +1 -0
  69. package/dist/query/directionUtils.d.ts +6 -0
  70. package/dist/query/directionUtils.d.ts.map +1 -0
  71. package/dist/query/edgeFinder.d.ts +15 -0
  72. package/dist/query/edgeFinder.d.ts.map +1 -0
  73. package/dist/query/faceFinder.d.ts +15 -0
  74. package/dist/query/faceFinder.d.ts.map +1 -0
  75. package/dist/query/finderCore.d.ts +35 -0
  76. package/dist/query/finderCore.d.ts.map +1 -0
  77. package/dist/query/finderFns.d.ts +21 -106
  78. package/dist/query/finderFns.d.ts.map +1 -1
  79. package/dist/query/shapeDistanceFilter.d.ts +11 -0
  80. package/dist/query/shapeDistanceFilter.d.ts.map +1 -0
  81. package/dist/query/vertexFinder.d.ts +16 -0
  82. package/dist/query/vertexFinder.d.ts.map +1 -0
  83. package/dist/query/wireFinder.d.ts +10 -0
  84. package/dist/query/wireFinder.d.ts.map +1 -0
  85. package/dist/query.cjs +42 -5
  86. package/dist/query.js +40 -2
  87. package/dist/{shapeTypes-DKhwEnUM.cjs → shapeTypes-b_lhwQB7.cjs} +24 -20
  88. package/dist/{shapeTypes-BlSElW8z.js → shapeTypes-i7VwMRwc.js} +32 -28
  89. package/dist/sketching/Sketcher.d.ts.map +1 -1
  90. package/dist/sketching/Sketcher2d.d.ts +12 -4
  91. package/dist/sketching/Sketcher2d.d.ts.map +1 -1
  92. package/dist/sketching/ellipseUtils.d.ts +29 -0
  93. package/dist/sketching/ellipseUtils.d.ts.map +1 -0
  94. package/dist/sketching.cjs +2 -2
  95. package/dist/sketching.js +2 -2
  96. package/dist/topology/booleanFns.d.ts.map +1 -1
  97. package/dist/topology/curveBuilders.d.ts +75 -0
  98. package/dist/topology/curveBuilders.d.ts.map +1 -0
  99. package/dist/topology/curveFns.d.ts.map +1 -1
  100. package/dist/topology/meshFns.d.ts.map +1 -1
  101. package/dist/topology/primitiveFns.d.ts.map +1 -1
  102. package/dist/topology/shapeFns.d.ts.map +1 -1
  103. package/dist/topology/shapeHelpers.d.ts +6 -173
  104. package/dist/topology/shapeHelpers.d.ts.map +1 -1
  105. package/dist/topology/shapeUtils.d.ts +13 -0
  106. package/dist/topology/shapeUtils.d.ts.map +1 -0
  107. package/dist/topology/solidBuilders.d.ts +70 -0
  108. package/dist/topology/solidBuilders.d.ts.map +1 -0
  109. package/dist/topology/surfaceBuilders.d.ts +35 -0
  110. package/dist/topology/surfaceBuilders.d.ts.map +1 -0
  111. package/dist/topology/wrapperFns.d.ts +1 -0
  112. package/dist/topology/wrapperFns.d.ts.map +1 -1
  113. package/dist/{topology-tFzqSrGH.js → topology-Bh-aPIxA.js} +7 -8
  114. package/dist/{topology-CIooytHH.cjs → topology-ByOn_z3E.cjs} +12 -13
  115. package/dist/topology.cjs +33 -34
  116. package/dist/topology.js +54 -55
  117. package/dist/{vectors-CBuaMeZv.js → vectors-DWLjb9-P.js} +1 -1
  118. package/dist/{vectors-ChWEZPwy.cjs → vectors-aQBZK0Sb.cjs} +1 -1
  119. package/dist/vectors.cjs +2 -2
  120. package/dist/vectors.js +2 -2
  121. package/package.json +1 -1
  122. package/dist/curveFns-BilyYL_s.cjs +0 -190
  123. package/dist/curveFns-CdVE4da7.js +0 -191
  124. package/dist/loft-BzWFokmC.cjs +0 -178
  125. package/dist/loft-CtG5nMq5.js +0 -179
  126. package/dist/query-V6nV-VfL.js +0 -396
  127. package/dist/query-hMSmOWJP.cjs +0 -395
  128. package/dist/shapeFns-BrF97sKt.js +0 -204
  129. package/dist/shapeFns-BvOndshS.cjs +0 -203
  130. package/dist/shapeHelpers-B2SXz1p4.cjs +0 -488
  131. package/dist/shapeHelpers-BcoZf2N9.js +0 -489
@@ -1,203 +0,0 @@
1
- "use strict";
2
- const occtBoundary = require("./occtBoundary-du8_ex-p.cjs");
3
- const shapeTypes = require("./shapeTypes-DKhwEnUM.cjs");
4
- const vecOps = require("./vecOps-CjRL1jau.cjs");
5
- const cast = require("./cast-DkB0GKmQ.cjs");
6
- const errors = require("./errors-DK1VAdP4.cjs");
7
- function clone(shape) {
8
- return shapeTypes.castShape(errors.unwrap(cast.downcast(shape.wrapped)));
9
- }
10
- function toBREP(shape) {
11
- const oc = occtBoundary.getKernel().oc;
12
- return oc.BRepToolsWrapper.Write(shape.wrapped);
13
- }
14
- function getHashCode(shape) {
15
- return shape.wrapped.HashCode(vecOps.HASH_CODE_MAX);
16
- }
17
- function isEmpty(shape) {
18
- return shape.wrapped.IsNull();
19
- }
20
- function isSameShape(a, b) {
21
- return a.wrapped.IsSame(b.wrapped);
22
- }
23
- function isEqualShape(a, b) {
24
- return a.wrapped.IsEqual(b.wrapped);
25
- }
26
- function simplify(shape) {
27
- const oc = occtBoundary.getKernel().oc;
28
- const upgrader = new oc.ShapeUpgrade_UnifySameDomain_2(shape.wrapped, true, true, false);
29
- upgrader.Build();
30
- const result = shapeTypes.castShape(upgrader.Shape());
31
- upgrader.delete();
32
- return result;
33
- }
34
- function translate(shape, v) {
35
- const oc = occtBoundary.getKernel().oc;
36
- const trsf = new oc.gp_Trsf_1();
37
- const vec = occtBoundary.toOcVec(v);
38
- trsf.SetTranslation_1(vec);
39
- const transformer = new oc.BRepBuilderAPI_Transform_2(shape.wrapped, trsf, true);
40
- const result = shapeTypes.castShape(transformer.Shape());
41
- transformer.delete();
42
- trsf.delete();
43
- vec.delete();
44
- return result;
45
- }
46
- function rotate(shape, angle, position = [0, 0, 0], direction = [0, 0, 1]) {
47
- const oc = occtBoundary.getKernel().oc;
48
- const trsf = new oc.gp_Trsf_1();
49
- const ax1 = occtBoundary.makeOcAx1(position, direction);
50
- trsf.SetRotation_1(ax1, angle * vecOps.DEG2RAD);
51
- const transformer = new oc.BRepBuilderAPI_Transform_2(shape.wrapped, trsf, true);
52
- const result = shapeTypes.castShape(transformer.Shape());
53
- transformer.delete();
54
- trsf.delete();
55
- ax1.delete();
56
- return result;
57
- }
58
- function mirror(shape, planeNormal = [0, 1, 0], planeOrigin = [0, 0, 0]) {
59
- const oc = occtBoundary.getKernel().oc;
60
- const trsf = new oc.gp_Trsf_1();
61
- const ax2 = occtBoundary.makeOcAx2(planeOrigin, planeNormal);
62
- trsf.SetMirror_3(ax2);
63
- const transformer = new oc.BRepBuilderAPI_Transform_2(shape.wrapped, trsf, true);
64
- const result = shapeTypes.castShape(transformer.Shape());
65
- transformer.delete();
66
- trsf.delete();
67
- ax2.delete();
68
- return result;
69
- }
70
- function scale(shape, factor, center = [0, 0, 0]) {
71
- const oc = occtBoundary.getKernel().oc;
72
- const trsf = new oc.gp_Trsf_1();
73
- const pnt = occtBoundary.toOcPnt(center);
74
- trsf.SetScale(pnt, factor);
75
- const transformer = new oc.BRepBuilderAPI_Transform_2(shape.wrapped, trsf, true);
76
- const result = shapeTypes.castShape(transformer.Shape());
77
- transformer.delete();
78
- trsf.delete();
79
- pnt.delete();
80
- return result;
81
- }
82
- const topoCache = /* @__PURE__ */ new WeakMap();
83
- function getOrCreateCache(shape) {
84
- let entry = topoCache.get(shape.wrapped);
85
- if (!entry) {
86
- entry = {};
87
- topoCache.set(shape.wrapped, entry);
88
- }
89
- return entry;
90
- }
91
- function getEdges(shape) {
92
- const cache = getOrCreateCache(shape);
93
- if (cache.edges) return cache.edges;
94
- const edges = Array.from(cast.iterTopo(shape.wrapped, "edge")).map(
95
- (e) => shapeTypes.castShape(errors.unwrap(cast.downcast(e)))
96
- );
97
- cache.edges = edges;
98
- return edges;
99
- }
100
- function getFaces(shape) {
101
- const cache = getOrCreateCache(shape);
102
- if (cache.faces) return cache.faces;
103
- const faces = Array.from(cast.iterTopo(shape.wrapped, "face")).map(
104
- (e) => shapeTypes.castShape(errors.unwrap(cast.downcast(e)))
105
- );
106
- cache.faces = faces;
107
- return faces;
108
- }
109
- function getWires(shape) {
110
- const cache = getOrCreateCache(shape);
111
- if (cache.wires) return cache.wires;
112
- const wires = Array.from(cast.iterTopo(shape.wrapped, "wire")).map(
113
- (e) => shapeTypes.castShape(errors.unwrap(cast.downcast(e)))
114
- );
115
- cache.wires = wires;
116
- return wires;
117
- }
118
- function getVertices(shape) {
119
- return Array.from(cast.iterTopo(shape.wrapped, "vertex")).map(
120
- (e) => shapeTypes.castShape(errors.unwrap(cast.downcast(e)))
121
- );
122
- }
123
- function* iterEdges(shape) {
124
- for (const e of cast.iterTopo(shape.wrapped, "edge")) {
125
- yield shapeTypes.castShape(errors.unwrap(cast.downcast(e)));
126
- }
127
- }
128
- function* iterFaces(shape) {
129
- for (const f of cast.iterTopo(shape.wrapped, "face")) {
130
- yield shapeTypes.castShape(errors.unwrap(cast.downcast(f)));
131
- }
132
- }
133
- function* iterWires(shape) {
134
- for (const w of cast.iterTopo(shape.wrapped, "wire")) {
135
- yield shapeTypes.castShape(errors.unwrap(cast.downcast(w)));
136
- }
137
- }
138
- function* iterVertices(shape) {
139
- for (const v of cast.iterTopo(shape.wrapped, "vertex")) {
140
- yield shapeTypes.castShape(errors.unwrap(cast.downcast(v)));
141
- }
142
- }
143
- function getBounds(shape) {
144
- const oc = occtBoundary.getKernel().oc;
145
- const bbox = new oc.Bnd_Box_1();
146
- oc.BRepBndLib.Add(shape.wrapped, bbox, true);
147
- const xMin = { current: 0 };
148
- const yMin = { current: 0 };
149
- const zMin = { current: 0 };
150
- const xMax = { current: 0 };
151
- const yMax = { current: 0 };
152
- const zMax = { current: 0 };
153
- bbox.Get(xMin, yMin, zMin, xMax, yMax, zMax);
154
- bbox.delete();
155
- return {
156
- xMin: xMin.current,
157
- xMax: xMax.current,
158
- yMin: yMin.current,
159
- yMax: yMax.current,
160
- zMin: zMin.current,
161
- zMax: zMax.current
162
- };
163
- }
164
- function describe(shape) {
165
- return {
166
- kind: shapeTypes.getShapeKind(shape),
167
- faceCount: getFaces(shape).length,
168
- edgeCount: getEdges(shape).length,
169
- wireCount: getWires(shape).length,
170
- vertexCount: getVertices(shape).length,
171
- valid: occtBoundary.getKernel().isValid(shape.wrapped),
172
- bounds: getBounds(shape)
173
- };
174
- }
175
- function vertexPosition(vertex) {
176
- const oc = occtBoundary.getKernel().oc;
177
- const pnt = oc.BRep_Tool.Pnt(vertex.wrapped);
178
- const result = [pnt.X(), pnt.Y(), pnt.Z()];
179
- pnt.delete();
180
- return result;
181
- }
182
- exports.clone = clone;
183
- exports.describe = describe;
184
- exports.getBounds = getBounds;
185
- exports.getEdges = getEdges;
186
- exports.getFaces = getFaces;
187
- exports.getHashCode = getHashCode;
188
- exports.getVertices = getVertices;
189
- exports.getWires = getWires;
190
- exports.isEmpty = isEmpty;
191
- exports.isEqualShape = isEqualShape;
192
- exports.isSameShape = isSameShape;
193
- exports.iterEdges = iterEdges;
194
- exports.iterFaces = iterFaces;
195
- exports.iterVertices = iterVertices;
196
- exports.iterWires = iterWires;
197
- exports.mirror = mirror;
198
- exports.rotate = rotate;
199
- exports.scale = scale;
200
- exports.simplify = simplify;
201
- exports.toBREP = toBREP;
202
- exports.translate = translate;
203
- exports.vertexPosition = vertexPosition;
@@ -1,488 +0,0 @@
1
- "use strict";
2
- const occtBoundary = require("./occtBoundary-du8_ex-p.cjs");
3
- const cast = require("./cast-DkB0GKmQ.cjs");
4
- const errors = require("./errors-DK1VAdP4.cjs");
5
- const shapeTypes = require("./shapeTypes-DKhwEnUM.cjs");
6
- const shapeFns = require("./shapeFns-BvOndshS.cjs");
7
- function range(len) {
8
- return Array.from(Array(len).keys());
9
- }
10
- function zip(arrays) {
11
- const minLength = Math.min(...arrays.map((arr) => arr.length));
12
- return range(minLength).map((i) => arrays.map((arr) => arr[i]));
13
- }
14
- const makeLine = (v1, v2) => {
15
- const oc = occtBoundary.getKernel().oc;
16
- const [r, gc] = shapeTypes.localGC();
17
- const p1 = r(occtBoundary.toOcPnt(v1));
18
- const p2 = r(occtBoundary.toOcPnt(v2));
19
- const maker = r(new oc.BRepBuilderAPI_MakeEdge_3(p1, p2));
20
- const edge = shapeTypes.createEdge(maker.Edge());
21
- gc();
22
- return edge;
23
- };
24
- const makeCircle = (radius, center = [0, 0, 0], normal = [0, 0, 1]) => {
25
- const oc = occtBoundary.getKernel().oc;
26
- const [r, gc] = shapeTypes.localGC();
27
- const ax = r(occtBoundary.makeOcAx2(center, normal));
28
- const circleGp = r(new oc.gp_Circ_2(ax, radius));
29
- const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_8(circleGp));
30
- const shape = shapeTypes.createEdge(edgeMaker.Edge());
31
- gc();
32
- return shape;
33
- };
34
- const makeEllipse = (majorRadius, minorRadius, center = [0, 0, 0], normal = [0, 0, 1], xDir) => {
35
- const oc = occtBoundary.getKernel().oc;
36
- const [r, gc] = shapeTypes.localGC();
37
- const ax = r(occtBoundary.makeOcAx2(center, normal, xDir));
38
- if (minorRadius > majorRadius) {
39
- gc();
40
- return errors.err(
41
- errors.validationError("ELLIPSE_RADII", "The minor radius must be smaller than the major one")
42
- );
43
- }
44
- const ellipseGp = r(new oc.gp_Elips_2(ax, majorRadius, minorRadius));
45
- const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_12(ellipseGp));
46
- const shape = shapeTypes.createEdge(edgeMaker.Edge());
47
- gc();
48
- return errors.ok(shape);
49
- };
50
- const makeHelix = (pitch, height, radius, center = [0, 0, 0], dir = [0, 0, 1], lefthand = false) => {
51
- const oc = occtBoundary.getKernel().oc;
52
- const [r, gc] = shapeTypes.localGC();
53
- let myDir = 2 * Math.PI;
54
- if (lefthand) {
55
- myDir = -2 * Math.PI;
56
- }
57
- const geomLine = r(
58
- new oc.Geom2d_Line_3(r(new oc.gp_Pnt2d_3(0, 0)), r(new oc.gp_Dir2d_4(myDir, pitch)))
59
- );
60
- const nTurns = height / pitch;
61
- const uStart = r(geomLine.Value(0));
62
- const uStop = r(geomLine.Value(nTurns * Math.sqrt((2 * Math.PI) ** 2 + pitch ** 2)));
63
- const geomSeg = r(new oc.GCE2d_MakeSegment_1(uStart, uStop));
64
- const geomSurf = new oc.Geom_CylindricalSurface_1(r(occtBoundary.makeOcAx3(center, dir)), radius);
65
- const e = r(
66
- new oc.BRepBuilderAPI_MakeEdge_30(
67
- r(new oc.Handle_Geom2d_Curve_2(geomSeg.Value().get())),
68
- r(new oc.Handle_Geom_Surface_2(geomSurf))
69
- )
70
- ).Edge();
71
- const w = r(new oc.BRepBuilderAPI_MakeWire_2(e)).Wire();
72
- oc.BRepLib.BuildCurves3d_2(w);
73
- gc();
74
- return shapeTypes.createWire(w);
75
- };
76
- const makeThreePointArc = (v1, v2, v3) => {
77
- const oc = occtBoundary.getKernel().oc;
78
- const [r, gc] = shapeTypes.localGC();
79
- const p1 = r(occtBoundary.toOcPnt(v1));
80
- const p2 = r(occtBoundary.toOcPnt(v2));
81
- const p3 = r(occtBoundary.toOcPnt(v3));
82
- const arcMaker = r(new oc.GC_MakeArcOfCircle_4(p1, p2, p3));
83
- const circleGeom = r(arcMaker.Value());
84
- const curve = r(new oc.Handle_Geom_Curve_2(circleGeom.get()));
85
- const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
86
- const edge = shapeTypes.createEdge(edgeMaker.Edge());
87
- gc();
88
- return edge;
89
- };
90
- const makeEllipseArc = (majorRadius, minorRadius, startAngle, endAngle, center = [0, 0, 0], normal = [0, 0, 1], xDir) => {
91
- const oc = occtBoundary.getKernel().oc;
92
- const [r, gc] = shapeTypes.localGC();
93
- const ax = r(occtBoundary.makeOcAx2(center, normal, xDir));
94
- if (minorRadius > majorRadius) {
95
- gc();
96
- return errors.err(
97
- errors.validationError("ELLIPSE_RADII", "The minor radius must be smaller than the major one")
98
- );
99
- }
100
- const ellipseGp = r(new oc.gp_Elips_2(ax, majorRadius, minorRadius));
101
- const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_13(ellipseGp, startAngle, endAngle));
102
- const shape = shapeTypes.createEdge(edgeMaker.Edge());
103
- gc();
104
- return errors.ok(shape);
105
- };
106
- const makeBSplineApproximation = function makeBSplineApproximation2(points, { tolerance = 1e-3, smoothing = null, degMax = 6, degMin = 1 } = {}) {
107
- const oc = occtBoundary.getKernel().oc;
108
- const [r, gc] = shapeTypes.localGC();
109
- const pnts = r(new oc.TColgp_Array1OfPnt_2(1, points.length));
110
- points.forEach((point, index) => {
111
- pnts.SetValue(index + 1, r(occtBoundary.toOcPnt(point)));
112
- });
113
- let splineBuilder;
114
- if (smoothing) {
115
- splineBuilder = r(
116
- new oc.GeomAPI_PointsToBSpline_5(
117
- pnts,
118
- smoothing[0],
119
- smoothing[1],
120
- smoothing[2],
121
- degMax,
122
- oc.GeomAbs_Shape.GeomAbs_C2,
123
- tolerance
124
- )
125
- );
126
- } else {
127
- splineBuilder = r(
128
- new oc.GeomAPI_PointsToBSpline_2(
129
- pnts,
130
- degMin,
131
- degMax,
132
- oc.GeomAbs_Shape.GeomAbs_C2,
133
- tolerance
134
- )
135
- );
136
- }
137
- if (!splineBuilder.IsDone()) {
138
- gc();
139
- return errors.err(errors.occtError("BSPLINE_FAILED", "B-spline approximation failed"));
140
- }
141
- const splineGeom = r(splineBuilder.Curve());
142
- const curve = r(new oc.Handle_Geom_Curve_2(splineGeom.get()));
143
- const edge = shapeTypes.createEdge(new oc.BRepBuilderAPI_MakeEdge_24(curve).Edge());
144
- gc();
145
- return errors.ok(edge);
146
- };
147
- const makeBezierCurve = (points) => {
148
- if (points.length < 2) {
149
- return errors.err(
150
- errors.validationError(
151
- "BEZIER_MIN_POINTS",
152
- `Need at least 2 points for a Bezier curve, got ${points.length}`,
153
- void 0,
154
- {
155
- pointCount: points.length
156
- }
157
- )
158
- );
159
- }
160
- const oc = occtBoundary.getKernel().oc;
161
- const [r, gc] = shapeTypes.localGC();
162
- const arrayOfPoints = r(new oc.TColgp_Array1OfPnt_2(1, points.length));
163
- points.forEach((p, i) => {
164
- arrayOfPoints.SetValue(i + 1, r(occtBoundary.toOcPnt(p)));
165
- });
166
- const bezCurve = new oc.Geom_BezierCurve_1(arrayOfPoints);
167
- const curve = r(new oc.Handle_Geom_Curve_2(bezCurve));
168
- const edgeMaker = r(new oc.BRepBuilderAPI_MakeEdge_24(curve));
169
- const edge = shapeTypes.createEdge(edgeMaker.Edge());
170
- gc();
171
- return errors.ok(edge);
172
- };
173
- const makeTangentArc = (startPoint, startTgt, endPoint) => {
174
- const oc = occtBoundary.getKernel().oc;
175
- const [r, gc] = shapeTypes.localGC();
176
- const circleGeom = r(
177
- new oc.GC_MakeArcOfCircle_5(
178
- r(occtBoundary.toOcPnt(startPoint)),
179
- r(occtBoundary.toOcVec(startTgt)),
180
- r(occtBoundary.toOcPnt(endPoint))
181
- ).Value()
182
- );
183
- const curve = r(new oc.Handle_Geom_Curve_2(circleGeom.get()));
184
- const edge = shapeTypes.createEdge(r(new oc.BRepBuilderAPI_MakeEdge_24(curve)).Edge());
185
- gc();
186
- return edge;
187
- };
188
- const assembleWire = (listOfEdges) => {
189
- const oc = occtBoundary.getKernel().oc;
190
- const [r, gc] = shapeTypes.localGC();
191
- const wireBuilder = r(new oc.BRepBuilderAPI_MakeWire_1());
192
- listOfEdges.forEach((e) => {
193
- if (shapeTypes.isEdge(e)) {
194
- wireBuilder.Add_1(e.wrapped);
195
- }
196
- if (shapeTypes.isWire(e)) {
197
- wireBuilder.Add_2(e.wrapped);
198
- }
199
- });
200
- const progress = r(new oc.Message_ProgressRange_1());
201
- wireBuilder.Build(progress);
202
- const res = wireBuilder.Error();
203
- if (res !== oc.BRepBuilderAPI_WireError.BRepBuilderAPI_WireDone) {
204
- const errorNames = /* @__PURE__ */ new Map([
205
- [oc.BRepBuilderAPI_WireError.BRepBuilderAPI_EmptyWire, "empty wire"],
206
- [oc.BRepBuilderAPI_WireError.BRepBuilderAPI_NonManifoldWire, "non manifold wire"],
207
- [oc.BRepBuilderAPI_WireError.BRepBuilderAPI_DisconnectedWire, "disconnected wire"]
208
- ]);
209
- gc();
210
- return errors.err(
211
- errors.occtError(
212
- "WIRE_BUILD_FAILED",
213
- `Failed to build the wire, ${errorNames.get(res) || "unknown error"}`
214
- )
215
- );
216
- }
217
- const wire = shapeTypes.createWire(wireBuilder.Wire());
218
- gc();
219
- return errors.ok(wire);
220
- };
221
- const makeFace = (wire, holes) => {
222
- const oc = occtBoundary.getKernel().oc;
223
- const faceBuilder = new oc.BRepBuilderAPI_MakeFace_15(wire.wrapped, false);
224
- holes?.forEach((hole) => {
225
- faceBuilder.Add(hole.wrapped);
226
- });
227
- if (!faceBuilder.IsDone()) {
228
- faceBuilder.delete();
229
- return errors.err(
230
- errors.occtError("FACE_BUILD_FAILED", "Failed to build the face. Your wire might be non planar.")
231
- );
232
- }
233
- const face = faceBuilder.Face();
234
- faceBuilder.delete();
235
- return errors.ok(shapeTypes.createFace(face));
236
- };
237
- const makeNewFaceWithinFace = (originFace, wire) => {
238
- const oc = occtBoundary.getKernel().oc;
239
- const [r, gc] = shapeTypes.localGC();
240
- const surface = r(oc.BRep_Tool.Surface_2(originFace.wrapped));
241
- const faceBuilder = r(new oc.BRepBuilderAPI_MakeFace_21(surface, wire.wrapped, true));
242
- const face = faceBuilder.Face();
243
- gc();
244
- return shapeTypes.createFace(face);
245
- };
246
- const makeNonPlanarFace = (wire) => {
247
- const oc = occtBoundary.getKernel().oc;
248
- const [r, gc] = shapeTypes.localGC();
249
- const faceBuilder = r(
250
- new oc.BRepOffsetAPI_MakeFilling(3, 15, 2, false, 1e-5, 1e-4, 0.01, 0.1, 8, 9)
251
- );
252
- shapeFns.getEdges(wire).forEach((edge) => {
253
- faceBuilder.Add_1(
254
- edge.wrapped,
255
- oc.GeomAbs_Shape.GeomAbs_C0,
256
- true
257
- );
258
- });
259
- const progress = r(new oc.Message_ProgressRange_1());
260
- faceBuilder.Build(progress);
261
- return errors.andThen(cast.cast(faceBuilder.Shape()), (newFace) => {
262
- gc();
263
- if (!shapeTypes.isFace(newFace)) {
264
- return errors.err(errors.occtError("FACE_BUILD_FAILED", "Failed to create a face"));
265
- }
266
- return errors.ok(newFace);
267
- });
268
- };
269
- const makeCylinder = (radius, height, location = [0, 0, 0], direction = [0, 0, 1]) => {
270
- const oc = occtBoundary.getKernel().oc;
271
- const [r, gc] = shapeTypes.localGC();
272
- const axis = r(occtBoundary.makeOcAx2(location, direction));
273
- const cylinder = r(new oc.BRepPrimAPI_MakeCylinder_3(axis, radius, height));
274
- const solid = shapeTypes.createSolid(cylinder.Shape());
275
- gc();
276
- return solid;
277
- };
278
- const makeSphere = (radius) => {
279
- const oc = occtBoundary.getKernel().oc;
280
- const [r, gc] = shapeTypes.localGC();
281
- const sphereMaker = r(new oc.BRepPrimAPI_MakeSphere_1(radius));
282
- const sphere = shapeTypes.createSolid(sphereMaker.Shape());
283
- gc();
284
- return sphere;
285
- };
286
- const makeCone = (radius1, radius2, height, location = [0, 0, 0], direction = [0, 0, 1]) => {
287
- const oc = occtBoundary.getKernel().oc;
288
- const [r, gc] = shapeTypes.localGC();
289
- const axis = r(occtBoundary.makeOcAx2(location, direction));
290
- const coneMaker = r(new oc.BRepPrimAPI_MakeCone_3(axis, radius1, radius2, height));
291
- const solid = shapeTypes.createSolid(coneMaker.Shape());
292
- gc();
293
- return solid;
294
- };
295
- const makeTorus = (majorRadius, minorRadius, location = [0, 0, 0], direction = [0, 0, 1]) => {
296
- const oc = occtBoundary.getKernel().oc;
297
- const [r, gc] = shapeTypes.localGC();
298
- const axis = r(occtBoundary.makeOcAx2(location, direction));
299
- const torusMaker = r(new oc.BRepPrimAPI_MakeTorus_5(axis, majorRadius, minorRadius));
300
- const solid = shapeTypes.createSolid(torusMaker.Shape());
301
- gc();
302
- return solid;
303
- };
304
- function makeEllipsoidTransform(x, y, z) {
305
- const oc = occtBoundary.getKernel().oc;
306
- const r = shapeTypes.gcWithScope();
307
- const xyRatio = Math.sqrt(x * y / z);
308
- const xzRatio = x / xyRatio;
309
- const yzRatio = y / xyRatio;
310
- const ax1 = r(occtBoundary.makeOcAx1([0, 0, 0], [0, 1, 0]));
311
- const ax2 = r(occtBoundary.makeOcAx1([0, 0, 0], [0, 0, 1]));
312
- const ax3 = r(occtBoundary.makeOcAx1([0, 0, 0], [1, 0, 0]));
313
- const transform = new oc.gp_GTrsf_1();
314
- transform.SetAffinity_1(ax1, xzRatio);
315
- const xy = r(new oc.gp_GTrsf_1());
316
- xy.SetAffinity_1(ax2, xyRatio);
317
- const yz = r(new oc.gp_GTrsf_1());
318
- yz.SetAffinity_1(ax3, yzRatio);
319
- transform.Multiply(xy);
320
- transform.Multiply(yz);
321
- return {
322
- transform,
323
- applyToPoint(p) {
324
- const r2 = shapeTypes.gcWithScope();
325
- const coords = r2(p.XYZ());
326
- transform.Transforms_1(coords);
327
- return new oc.gp_Pnt_2(coords);
328
- }
329
- };
330
- }
331
- function convertToJSArray(arrayOfPoints) {
332
- const newArray = [];
333
- for (let row = arrayOfPoints.LowerRow(); row <= arrayOfPoints.UpperRow(); row++) {
334
- const rowArr = [];
335
- newArray.push(rowArr);
336
- for (let c = arrayOfPoints.LowerCol(); c <= arrayOfPoints.UpperCol(); c++) {
337
- const pnt = arrayOfPoints.Value(row, c);
338
- rowArr.push(pnt);
339
- }
340
- }
341
- return newArray;
342
- }
343
- const makeEllipsoid = (aLength, bLength, cLength) => {
344
- const oc = occtBoundary.getKernel().oc;
345
- const r = shapeTypes.gcWithScope();
346
- const sphere = r(new oc.gp_Sphere_1());
347
- sphere.SetRadius(1);
348
- const sphericalSurface = r(new oc.Geom_SphericalSurface_2(sphere));
349
- const baseSurface = oc.GeomConvert.SurfaceToBSplineSurface(sphericalSurface.UReversed()).get();
350
- try {
351
- const poles = convertToJSArray(baseSurface.Poles_2());
352
- const ellipsoid = makeEllipsoidTransform(aLength, bLength, cLength);
353
- poles.forEach((columns, rowIdx) => {
354
- columns.forEach((value, colIdx) => {
355
- const newPoint = ellipsoid.applyToPoint(value);
356
- baseSurface.SetPole_1(rowIdx + 1, colIdx + 1, newPoint);
357
- newPoint.delete();
358
- });
359
- });
360
- ellipsoid.transform.delete();
361
- const shell = errors.unwrap(
362
- cast.cast(r(new oc.BRepBuilderAPI_MakeShell_2(baseSurface.UReversed(), false)).Shell())
363
- );
364
- return errors.unwrap(makeSolid([shell]));
365
- } finally {
366
- baseSurface.delete();
367
- }
368
- };
369
- const makeVertex = (point) => {
370
- const oc = occtBoundary.getKernel().oc;
371
- const [r, gc] = shapeTypes.localGC();
372
- const pnt = r(occtBoundary.toOcPnt(point));
373
- const vertexMaker = r(new oc.BRepBuilderAPI_MakeVertex(pnt));
374
- const vertex = vertexMaker.Vertex();
375
- gc();
376
- return shapeTypes.createVertex(vertex);
377
- };
378
- const makeOffset = (face, offset, tolerance = 1e-6) => {
379
- const oc = occtBoundary.getKernel().oc;
380
- const progress = new oc.Message_ProgressRange_1();
381
- const offsetBuilder = new oc.BRepOffsetAPI_MakeOffsetShape();
382
- try {
383
- offsetBuilder.PerformByJoin(
384
- face.wrapped,
385
- offset,
386
- tolerance,
387
- oc.BRepOffset_Mode.BRepOffset_Skin,
388
- false,
389
- false,
390
- oc.GeomAbs_JoinType.GeomAbs_Arc,
391
- false,
392
- progress
393
- );
394
- return errors.andThen(
395
- cast.downcast(offsetBuilder.Shape()),
396
- (downcasted) => errors.andThen(cast.cast(downcasted), (newShape) => {
397
- if (!shapeTypes.isShape3D(newShape))
398
- return errors.err(errors.typeCastError("OFFSET_NOT_3D", "Could not offset to a 3d shape"));
399
- return errors.ok(newShape);
400
- })
401
- );
402
- } finally {
403
- offsetBuilder.delete();
404
- progress.delete();
405
- }
406
- };
407
- const makeCompound = (shapeArray) => {
408
- const oc = occtBoundary.getKernel().oc;
409
- const builder = new oc.TopoDS_Builder();
410
- const compound = new oc.TopoDS_Compound();
411
- builder.MakeCompound(compound);
412
- for (const s of shapeArray) {
413
- builder.Add(compound, s.wrapped);
414
- }
415
- builder.delete();
416
- return shapeTypes.createCompound(compound);
417
- };
418
- function _weld(facesOrShells) {
419
- const sewn = occtBoundary.getKernel().sew(facesOrShells.map((s) => s.wrapped));
420
- return errors.unwrap(cast.cast(errors.unwrap(cast.downcast(sewn))));
421
- }
422
- function weldShellsAndFaces(facesOrShells, ignoreType = false) {
423
- const shell = _weld(facesOrShells);
424
- if (!ignoreType && !shapeTypes.isShell(shell))
425
- return errors.err(errors.typeCastError("WELD_NOT_SHELL", "Could not make a shell from faces and shells"));
426
- return errors.ok(shell);
427
- }
428
- function makeSolid(facesOrShells) {
429
- const r = shapeTypes.gcWithScope();
430
- const oc = occtBoundary.getKernel().oc;
431
- const shell = _weld(facesOrShells);
432
- return errors.andThen(cast.cast(r(new oc.ShapeFix_Solid_1()).SolidFromShell(shell.wrapped)), (solid) => {
433
- if (!shapeTypes.isSolid(solid))
434
- return errors.err(errors.typeCastError("SOLID_BUILD_FAILED", "Could not make a solid of faces and shells"));
435
- return errors.ok(solid);
436
- });
437
- }
438
- const addHolesInFace = (face, holes) => {
439
- const oc = occtBoundary.getKernel().oc;
440
- const [r, gc] = shapeTypes.localGC();
441
- const faceMaker = r(new oc.BRepBuilderAPI_MakeFace_2(face.wrapped));
442
- holes.forEach((wire) => {
443
- faceMaker.Add(wire.wrapped);
444
- });
445
- const builtFace = r(faceMaker.Face());
446
- const fixer = r(new oc.ShapeFix_Face_2(builtFace));
447
- fixer.FixOrientation_1();
448
- const newFace = fixer.Face();
449
- gc();
450
- return shapeTypes.createFace(newFace);
451
- };
452
- const makePolygon = (points) => {
453
- if (points.length < 3)
454
- return errors.err(
455
- errors.validationError("POLYGON_MIN_POINTS", "You need at least 3 points to make a polygon")
456
- );
457
- const edges = zip([points, [...points.slice(1), points[0]]]).map(
458
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- zip returns untyped pairs
459
- ([p1, p2]) => makeLine(p1, p2)
460
- );
461
- return errors.andThen(assembleWire(edges), (wire) => makeFace(wire));
462
- };
463
- exports.addHolesInFace = addHolesInFace;
464
- exports.assembleWire = assembleWire;
465
- exports.makeBSplineApproximation = makeBSplineApproximation;
466
- exports.makeBezierCurve = makeBezierCurve;
467
- exports.makeCircle = makeCircle;
468
- exports.makeCompound = makeCompound;
469
- exports.makeCone = makeCone;
470
- exports.makeCylinder = makeCylinder;
471
- exports.makeEllipse = makeEllipse;
472
- exports.makeEllipseArc = makeEllipseArc;
473
- exports.makeEllipsoid = makeEllipsoid;
474
- exports.makeFace = makeFace;
475
- exports.makeHelix = makeHelix;
476
- exports.makeLine = makeLine;
477
- exports.makeNewFaceWithinFace = makeNewFaceWithinFace;
478
- exports.makeNonPlanarFace = makeNonPlanarFace;
479
- exports.makeOffset = makeOffset;
480
- exports.makePolygon = makePolygon;
481
- exports.makeSolid = makeSolid;
482
- exports.makeSphere = makeSphere;
483
- exports.makeTangentArc = makeTangentArc;
484
- exports.makeThreePointArc = makeThreePointArc;
485
- exports.makeTorus = makeTorus;
486
- exports.makeVertex = makeVertex;
487
- exports.weldShellsAndFaces = weldShellsAndFaces;
488
- exports.zip = zip;