brepjs 8.0.0 → 8.0.2

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