brepjs 15.2.0 → 15.2.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 (70) hide show
  1. package/dist/2d/lib/curve2D.d.ts.map +1 -1
  2. package/dist/2d.cjs +5 -5
  3. package/dist/2d.js +5 -5
  4. package/dist/{blueprint-DpfTrOOt.cjs → blueprint-CVDdCwvY.cjs} +10 -8
  5. package/dist/{blueprint-CY11BkHM.js → blueprint-DiLT1cjs.js} +10 -8
  6. package/dist/{blueprintFns-C-XRp3LD.js → blueprintFns-CW6dHRRS.js} +2 -2
  7. package/dist/{blueprintFns-DTGzK_O3.cjs → blueprintFns-DxNSrAv4.cjs} +2 -2
  8. package/dist/{boolean2D-CNan_aDM.cjs → boolean2D-C5SvcSk5.cjs} +8 -8
  9. package/dist/{boolean2D-Dj0eTZfG.js → boolean2D-Dqt81-kF.js} +8 -8
  10. package/dist/{booleanFns-B86ltlZD.cjs → booleanFns-C7c98iPH.cjs} +4 -4
  11. package/dist/{booleanFns-CiiCf7YH.js → booleanFns-QZtMt5Aa.js} +4 -4
  12. package/dist/brepjs.cjs +20 -20
  13. package/dist/brepjs.js +20 -20
  14. package/dist/core.cjs +1 -1
  15. package/dist/core.js +1 -1
  16. package/dist/{cornerFinder-lO-ySgHJ.js → cornerFinder-CvF2SrsV.js} +1 -1
  17. package/dist/{cornerFinder-DNmYCgaQ.cjs → cornerFinder-DP1-TfDV.cjs} +1 -1
  18. package/dist/{curveFns-B_pwrAMv.cjs → curveFns-Bukd9jhv.cjs} +1 -1
  19. package/dist/{curveFns-Dv0wz8Zm.js → curveFns-Dn4gbNzG.js} +1 -1
  20. package/dist/{drawFns-BNSmHZXu.cjs → drawFns-6LwCyiCt.cjs} +10 -10
  21. package/dist/{drawFns-CJxFWoi9.js → drawFns-D94ONnuu.js} +10 -10
  22. package/dist/{extrudeFns-B9muBNIT.cjs → extrudeFns-B588lxcH.cjs} +1 -1
  23. package/dist/{extrudeFns-lgSsOjwq.js → extrudeFns-DjfHvYJe.js} +1 -1
  24. package/dist/{faceFns-DnIpKBex.cjs → faceFns-CKL9Us23.cjs} +1 -1
  25. package/dist/{faceFns-CauBoVg1.js → faceFns-DMFG-piP.js} +1 -1
  26. package/dist/{helpers-B_-mIteL.js → helpers-B2J4sg4l.js} +5 -5
  27. package/dist/{helpers-kil7evW4.cjs → helpers-B48K8Z6B.cjs} +5 -5
  28. package/dist/{historyFns-DYrliEQE.js → historyFns-BpfArwQu.js} +4 -4
  29. package/dist/{historyFns-D7UojEn3.cjs → historyFns-Bxg4_ieD.cjs} +4 -4
  30. package/dist/{importFns-CPzDHVKm.js → importFns-D6eumXiz.js} +2 -2
  31. package/dist/{importFns-Y4wgn0rJ.cjs → importFns-UkXALkBs.cjs} +2 -2
  32. package/dist/io.cjs +2 -2
  33. package/dist/io.js +2 -2
  34. package/dist/kernel/geometry2d.d.ts.map +1 -1
  35. package/dist/kernel/occt/defaultAdapter.d.ts.map +1 -1
  36. package/dist/kernel/occt/kernel2dOps.d.ts +61 -68
  37. package/dist/kernel/occt/kernel2dOps.d.ts.map +1 -1
  38. package/dist/kernel/occtWasm/occtWasmAdapter.cjs +1 -1
  39. package/dist/kernel/occtWasm/occtWasmAdapter.js +1 -1
  40. package/dist/{measureFns-Bt0Rd9q9.cjs → measureFns-C2SnZLhD.cjs} +2 -2
  41. package/dist/{measureFns-Bey2EmNQ.js → measureFns-Zc5RWsI4.js} +2 -2
  42. package/dist/measurement.cjs +1 -1
  43. package/dist/measurement.js +1 -1
  44. package/dist/{meshFns-Cxs6gU44.cjs → meshFns-CO9qVJ24.cjs} +2 -2
  45. package/dist/{meshFns-DO58R94T.js → meshFns-gTPomZkK.js} +2 -2
  46. package/dist/{occtWasmAdapter-BBr9e9ej.js → occtWasmAdapter-BRiWV_v0.js} +65 -14
  47. package/dist/{occtWasmAdapter-DcGOi3MQ.cjs → occtWasmAdapter-CPINzXxh.cjs} +65 -14
  48. package/dist/operations.cjs +2 -2
  49. package/dist/operations.js +2 -2
  50. package/dist/{primitiveFns-CWiHuJw9.cjs → primitiveFns-CriBoS7M.cjs} +5 -5
  51. package/dist/{primitiveFns-Rpdnd3FK.js → primitiveFns-CtWBTFPI.js} +5 -5
  52. package/dist/query.cjs +2 -2
  53. package/dist/query.js +2 -2
  54. package/dist/{shapeFns-CBRy0V_S.cjs → shapeFns-DkFzoJav.cjs} +2 -2
  55. package/dist/{shapeFns-4ySHDRyO.js → shapeFns-QGgHStIU.js} +2 -2
  56. package/dist/shapeRef.cjs +1 -1
  57. package/dist/shapeRef.js +1 -1
  58. package/dist/{shapeRefFns-D21Yl4Eu.js → shapeRefFns-Gv4-NGJD.js} +3 -3
  59. package/dist/{shapeRefFns-oAyQxHO1.cjs → shapeRefFns-t-5-Aqku.cjs} +3 -3
  60. package/dist/{shapeTypes-CaSWO-Hg.cjs → shapeTypes-Bfw136X-.cjs} +772 -589
  61. package/dist/{shapeTypes-BLV4Ktdb.js → shapeTypes-Ct7W6h2X.js} +768 -589
  62. package/dist/sketching.cjs +2 -2
  63. package/dist/sketching.js +2 -2
  64. package/dist/{solidBuilders-BexZFemn.js → solidBuilders-CQipZFOw.js} +2 -2
  65. package/dist/{solidBuilders-BZFaM6nk.cjs → solidBuilders-DI9d6ZIx.cjs} +2 -2
  66. package/dist/{surfaceBuilders-Bixz70pj.cjs → surfaceBuilders-DzTJA3fK.cjs} +2 -2
  67. package/dist/{surfaceBuilders-AnSYsNAb.js → surfaceBuilders-Im6Xef27.js} +2 -2
  68. package/dist/topology.cjs +6 -6
  69. package/dist/topology.js +6 -6
  70. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { _ as serializeCurve2d$2, a as curveTypeName, c as intersectCurves2dFn, d as makeEllipse2d$2, f as makeLine2d$2, g as scaleCurve2d$2, h as rotateCurve2d$2, i as curveBounds, l as makeBezier2d$2, m as mirrorAtPoint, n as addCurveToBBox, o as deserializeCurve2d$2, p as mirrorAcrossAxis, r as createBBox2d, s as evaluateCurve2d$2, u as makeCircle2d$2, v as tangentCurve2d, y as translateCurve2d$2 } from "./occtWasmAdapter-BBr9e9ej.js";
1
+ import { _ as serializeCurve2d$2, a as curveTypeName, c as intersectCurves2dFn, d as makeEllipse2d$2, f as makeLine2d$2, g as scaleCurve2d$2, h as rotateCurve2d$2, i as curveBounds, l as makeBezier2d$2, m as mirrorAtPoint, n as addCurveToBBox, o as deserializeCurve2d$2, p as mirrorAcrossAxis, r as createBBox2d, s as evaluateCurve2d$2, u as makeCircle2d$2, v as tangentCurve2d, y as translateCurve2d$2 } from "./occtWasmAdapter-BRiWV_v0.js";
2
2
  import { A as ok, b as err } from "./errors-DboJwVCf.js";
3
3
  //#region src/kernel/kernel2dTypes.ts
4
4
  /** Check if the kernel supports 2D geometry operations. */
@@ -3197,612 +3197,793 @@ function createAxis3$1(oc, ox, oy, oz, zx, zy, zz, xx, xy, xz) {
3197
3197
  }
3198
3198
  //#endregion
3199
3199
  //#region src/kernel/occt/kernel2dOps.ts
3200
- function mapContinuity(oc, continuity) {
3201
- switch (continuity) {
3202
- case "C0": return oc.GeomAbs_Shape.GeomAbs_C0;
3203
- case "C1": return oc.GeomAbs_Shape.GeomAbs_C1;
3204
- case "C2": return oc.GeomAbs_Shape.GeomAbs_C2;
3205
- case "C3": return oc.GeomAbs_Shape.GeomAbs_C3;
3206
- }
3200
+ var noop$1 = () => {};
3201
+ /** Cast opaque Curve2dHandle to internal Curve2dObj. */
3202
+ function c2d$1(handle) {
3203
+ return handle;
3207
3204
  }
3208
- /**
3209
- * Extract a numeric value from an OCCT Emscripten enum.
3210
- * Emscripten returns enum objects with a `.value` property, not raw numbers.
3211
- */
3212
- function unwrapOcctEnum(val) {
3213
- return typeof val === "number" ? val : Number(val?.value ?? val);
3205
+ /** Unwrap trimmed curve wrappers to get the basis geometry. */
3206
+ function c2dBasis$1(handle) {
3207
+ let c = c2d$1(handle);
3208
+ while (c.__bk2d === "trimmed") c = c.basis;
3209
+ return c;
3214
3210
  }
3215
- /**
3216
- * Get the GeomAbs_CurveType index for a 2D curve via a temporary adaptor.
3217
- * Caller avoids repeating the adaptor-create / GetType / unwrap / delete cycle.
3218
- */
3219
- function getCurve2dTypeIndex(oc, curve) {
3220
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3221
- const idx = unwrapOcctEnum(adaptor.GetType());
3222
- adaptor.delete();
3223
- return idx;
3211
+ /** Cast opaque BBox2dHandle to internal BBox2d. */
3212
+ function bb2d$1(handle) {
3213
+ return handle;
3224
3214
  }
3225
- /** Wrap a raw Geom2d_Curve in a Handle_Geom2d_Curve. */
3226
- function wrapCurve2dHandle$1(oc, handle) {
3227
- const inner = handle.get();
3228
- return new oc.Handle_Geom2d_Curve_2(inner);
3215
+ function createPoint2d$1(x, y) {
3216
+ return {
3217
+ x,
3218
+ y
3219
+ };
3229
3220
  }
3230
- /** Create a Geom2dAdaptor_Curve for algorithmic queries. Caller must delete. */
3231
- function createCurve2dAdaptor$1(oc, handle) {
3232
- return new oc.Geom2dAdaptor_Curve_2(handle);
3221
+ function createDirection2d$1(x, y) {
3222
+ const l = Math.sqrt(x * x + y * y);
3223
+ if (l < 1e-15) throw new Error("occt: createDirection2d called with zero-length vector");
3224
+ return {
3225
+ x: x / l,
3226
+ y: y / l
3227
+ };
3233
3228
  }
3234
- function createPoint2d$1(oc, x, y) {
3235
- return new oc.gp_Pnt2d_3(x, y);
3229
+ function createVector2d$1(x, y) {
3230
+ return {
3231
+ x,
3232
+ y
3233
+ };
3236
3234
  }
3237
- function createDirection2d$1(oc, x, y) {
3238
- return new oc.gp_Dir2d_5(x, y);
3235
+ function createAxis2d$1(px, py, dx, dy) {
3236
+ return {
3237
+ px,
3238
+ py,
3239
+ dx,
3240
+ dy,
3241
+ delete: noop$1
3242
+ };
3239
3243
  }
3240
- function createVector2d$1(oc, x, y) {
3241
- return new oc.gp_Vec2d_4(x, y);
3244
+ function wrapCurve2dHandle$1(handle) {
3245
+ return handle;
3242
3246
  }
3243
- function createAxis2d$1(oc, px, py, dx, dy) {
3244
- const pnt = new oc.gp_Pnt2d_3(px, py);
3245
- const dir = new oc.gp_Dir2d_5(dx, dy);
3246
- const axis = new oc.gp_Ax2d_2(pnt, dir);
3247
- pnt.delete();
3248
- dir.delete();
3249
- return axis;
3247
+ function createCurve2dAdaptor$1(handle) {
3248
+ return handle;
3250
3249
  }
3251
- function makeLine2d$1(oc, x1, y1, x2, y2) {
3252
- const p1 = new oc.gp_Pnt2d_3(x1, y1);
3253
- const p2 = new oc.gp_Pnt2d_3(x2, y2);
3254
- const maker = new oc.GCE2d_MakeSegment_1(p1, p2);
3255
- const curve = maker.Value();
3256
- maker.delete();
3257
- p1.delete();
3258
- p2.delete();
3259
- return curve;
3250
+ function makeLine2d$1(x1, y1, x2, y2) {
3251
+ return makeLine2d$2(x1, y1, x2, y2);
3260
3252
  }
3261
- function makeCircle2d$1(oc, cx, cy, radius, sense = true) {
3262
- const center = new oc.gp_Pnt2d_3(cx, cy);
3263
- const maker = new oc.GCE2d_MakeCircle_7(center, radius, sense);
3264
- const curve = maker.Value();
3265
- maker.delete();
3266
- center.delete();
3267
- return curve;
3253
+ function makeCircle2d$1(cx, cy, radius, sense) {
3254
+ return makeCircle2d$2(cx, cy, radius, sense);
3268
3255
  }
3269
- function makeArc2dThreePoints$1(oc, x1, y1, xm, ym, x2, y2) {
3270
- const p1 = new oc.gp_Pnt2d_3(x1, y1);
3271
- const pm = new oc.gp_Pnt2d_3(xm, ym);
3272
- const p2 = new oc.gp_Pnt2d_3(x2, y2);
3273
- const maker = new oc.GCE2d_MakeArcOfCircle_4(p1, pm, p2);
3274
- try {
3275
- if (!maker.IsDone()) throw new Error("makeArc2dThreePoints: construction failed (collinear points?)");
3276
- return maker.Value();
3277
- } finally {
3278
- maker.delete();
3279
- p2.delete();
3280
- pm.delete();
3281
- p1.delete();
3256
+ function makeArc2dThreePoints$1(x1, y1, xm, ym, x2, y2) {
3257
+ const d = 2 * (x1 * (ym - y2) + xm * (y2 - y1) + x2 * (y1 - ym));
3258
+ if (Math.abs(d) < 1e-12) return makeLine2d$2(x1, y1, x2, y2);
3259
+ const cx = ((x1 * x1 + y1 * y1) * (ym - y2) + (xm * xm + ym * ym) * (y2 - y1) + (x2 * x2 + y2 * y2) * (y1 - ym)) / d;
3260
+ const cy = ((x1 * x1 + y1 * y1) * (x2 - xm) + (xm * xm + ym * ym) * (x1 - x2) + (x2 * x2 + y2 * y2) * (xm - x1)) / d;
3261
+ const radius = Math.sqrt((x1 - cx) ** 2 + (y1 - cy) ** 2);
3262
+ const a1 = Math.atan2(y1 - cy, x1 - cx);
3263
+ const am = Math.atan2(ym - cy, xm - cx);
3264
+ const a2 = Math.atan2(y2 - cy, x2 - cx);
3265
+ let da1m = am - a1;
3266
+ if (da1m < 0) da1m += 2 * Math.PI;
3267
+ let da12 = a2 - a1;
3268
+ if (da12 < 0) da12 += 2 * Math.PI;
3269
+ const sense = da1m < da12;
3270
+ const circle = makeCircle2d$2(cx, cy, radius, sense);
3271
+ if (!sense) {
3272
+ const tStart = -a1;
3273
+ let tEnd = -a2;
3274
+ if (tEnd < tStart - 1e-9) tEnd += 2 * Math.PI;
3275
+ return {
3276
+ __bk2d: "trimmed",
3277
+ basis: circle,
3278
+ tStart,
3279
+ tEnd
3280
+ };
3282
3281
  }
3282
+ let tEnd = a2;
3283
+ if (tEnd < a1 - 1e-9) tEnd += 2 * Math.PI;
3284
+ return {
3285
+ __bk2d: "trimmed",
3286
+ basis: circle,
3287
+ tStart: a1,
3288
+ tEnd
3289
+ };
3283
3290
  }
3284
- function makeArc2dTangent$1(oc, startX, startY, tangentX, tangentY, endX, endY) {
3285
- const start = new oc.gp_Pnt2d_3(startX, startY);
3286
- const tangent = new oc.gp_Vec2d_4(tangentX, tangentY);
3287
- const end = new oc.gp_Pnt2d_3(endX, endY);
3288
- const maker = new oc.GCE2d_MakeArcOfCircle_5(start, tangent, end);
3289
- try {
3290
- if (!maker.IsDone()) throw new Error("makeArc2dTangent: construction failed");
3291
- return maker.Value();
3292
- } finally {
3293
- maker.delete();
3294
- end.delete();
3295
- tangent.delete();
3296
- start.delete();
3291
+ function makeArc2dTangent$1(sx, sy, tx, ty, ex, ey) {
3292
+ const len = Math.sqrt(tx * tx + ty * ty);
3293
+ const ntx = len > 0 ? tx / len : 0;
3294
+ const nty = len > 0 ? ty / len : 0;
3295
+ const dx = sx - ex;
3296
+ const dy = sy - ey;
3297
+ const denom = 2 * (dy * ntx - dx * nty);
3298
+ if (Math.abs(denom) < 1e-12) return makeLine2d$2(sx, sy, ex, ey);
3299
+ const t = -(dx * dx + dy * dy) / denom;
3300
+ const cx = sx - t * nty;
3301
+ const cy = sy + t * ntx;
3302
+ const radius = Math.abs(t);
3303
+ const a1 = Math.atan2(sy - cy, sx - cx);
3304
+ const a2 = Math.atan2(ey - cy, ex - cx);
3305
+ const ccwTanX = -(sy - cy) / radius;
3306
+ const ccwTanY = (sx - cx) / radius;
3307
+ const dotCcw = ntx * ccwTanX + nty * ccwTanY;
3308
+ let aMid;
3309
+ if (dotCcw > 0) {
3310
+ let da = a2 - a1;
3311
+ if (da <= 0) da += 2 * Math.PI;
3312
+ aMid = a1 + da / 2;
3313
+ } else {
3314
+ let da = a2 - a1;
3315
+ if (da >= 0) da -= 2 * Math.PI;
3316
+ aMid = a1 + da / 2;
3297
3317
  }
3318
+ return makeArc2dThreePoints$1(sx, sy, cx + radius * Math.cos(aMid), cy + radius * Math.sin(aMid), ex, ey);
3298
3319
  }
3299
- function makeEllipse2d$1(oc, cx, cy, majorRadius, minorRadius, xDirX = 1, xDirY = 0, sense = true) {
3300
- const center = new oc.gp_Pnt2d_3(cx, cy);
3301
- const dir = new oc.gp_Dir2d_5(xDirX, xDirY);
3302
- const ax = new oc.gp_Ax2d_2(center, dir);
3303
- const elips = new oc.gp_Elips2d_2(ax, majorRadius, minorRadius, sense);
3304
- const maker = new oc.GCE2d_MakeEllipse_1(elips);
3305
- try {
3306
- if (!maker.IsDone()) throw new Error("makeEllipse2d: construction failed");
3307
- return maker.Value();
3308
- } finally {
3309
- maker.delete();
3310
- elips.delete();
3311
- ax.delete();
3312
- dir.delete();
3313
- center.delete();
3314
- }
3320
+ function makeEllipse2d$1(cx, cy, major, minor, xDirX, xDirY, sense) {
3321
+ return makeEllipse2d$2(cx, cy, major, minor, xDirX, xDirY, sense);
3315
3322
  }
3316
- function makeEllipseArc2d$1(oc, cx, cy, majorRadius, minorRadius, startAngle, endAngle, xDirX = 1, xDirY = 0, sense = true) {
3317
- const center = new oc.gp_Pnt2d_3(cx, cy);
3318
- const dir = new oc.gp_Dir2d_5(xDirX, xDirY);
3319
- const ax = new oc.gp_Ax2d_2(center, dir);
3320
- const elips = new oc.gp_Elips2d_2(ax, majorRadius, minorRadius, true);
3321
- const maker = new oc.GCE2d_MakeArcOfEllipse_1(elips, startAngle, endAngle, sense);
3322
- try {
3323
- if (!maker.IsDone()) throw new Error("makeEllipseArc2d: construction failed");
3324
- return maker.Value();
3325
- } finally {
3326
- maker.delete();
3327
- elips.delete();
3328
- ax.delete();
3329
- dir.delete();
3330
- center.delete();
3331
- }
3323
+ function makeEllipseArc2d$1(cx, cy, major, minor, start, end, xDirX, xDirY, sense) {
3324
+ return {
3325
+ __bk2d: "trimmed",
3326
+ basis: makeEllipse2d$2(cx, cy, major, minor, xDirX, xDirY, sense),
3327
+ tStart: start,
3328
+ tEnd: end
3329
+ };
3332
3330
  }
3333
- function makeBezier2d$1(oc, points) {
3334
- const arr = new oc.TColgp_Array1OfPnt2d_2(1, points.length);
3335
- for (let i = 0; i < points.length; i++) {
3336
- const p = points[i];
3337
- const gpPnt = new oc.gp_Pnt2d_3(p[0], p[1]);
3338
- arr.SetValue_1(i + 1, gpPnt);
3339
- gpPnt.delete();
3340
- }
3341
- const bezier = new oc.Geom2d_BezierCurve_1(arr);
3342
- arr.delete();
3343
- return new oc.Handle_Geom2d_Curve_2(bezier);
3331
+ function makeBezier2d$1(points) {
3332
+ return makeBezier2d$2(points);
3344
3333
  }
3345
- function makeBSpline2d$1(oc, points, options = {}) {
3346
- const { degMin = 1, degMax = 3, continuity = "C2", tolerance = .001, smoothing = null } = options;
3347
- const pnts = new oc.TColgp_Array1OfPnt2d_2(1, points.length);
3348
- for (let i = 0; i < points.length; i++) {
3349
- const p = points[i];
3350
- const gpPnt = new oc.gp_Pnt2d_3(p[0], p[1]);
3351
- pnts.SetValue_1(i + 1, gpPnt);
3352
- gpPnt.delete();
3353
- }
3354
- let splineBuilder;
3355
- if (smoothing) splineBuilder = new oc.Geom2dAPI_PointsToBSpline_6(pnts, smoothing[0], smoothing[1], smoothing[2], degMax, mapContinuity(oc, continuity), tolerance);
3356
- else splineBuilder = new oc.Geom2dAPI_PointsToBSpline_2(pnts, degMin, degMax, mapContinuity(oc, continuity), tolerance);
3357
- pnts.delete();
3358
- if (!splineBuilder.IsDone()) {
3359
- splineBuilder.delete();
3360
- throw new Error("B-spline 2D approximation failed");
3334
+ function makeBSpline2d$1(points, _options) {
3335
+ const n = points.length;
3336
+ const degree = Math.min(3, n - 1);
3337
+ const knots = [];
3338
+ const mults = [];
3339
+ knots.push(0);
3340
+ mults.push(degree + 1);
3341
+ const nInternal = n - degree - 1;
3342
+ for (let i = 1; i <= nInternal; i++) {
3343
+ knots.push(i / (nInternal + 1));
3344
+ mults.push(1);
3361
3345
  }
3362
- const curve = splineBuilder.Curve();
3363
- splineBuilder.delete();
3364
- return curve;
3346
+ knots.push(1);
3347
+ mults.push(degree + 1);
3348
+ return {
3349
+ __bk2d: "bspline",
3350
+ poles: [...points],
3351
+ knots,
3352
+ multiplicities: mults,
3353
+ degree,
3354
+ isPeriodic: false
3355
+ };
3365
3356
  }
3366
- function evaluateCurve2d$1(_oc, curve, param) {
3367
- const p = curve.get().Value(param);
3368
- const result = [p.X(), p.Y()];
3369
- p.delete();
3370
- return result;
3357
+ function evaluateCurve2d$1(curve, param) {
3358
+ return evaluateCurve2d$2(c2d$1(curve), param);
3371
3359
  }
3372
- function evaluateCurve2dD1$1(oc, curve, param) {
3373
- const inner = curve.get();
3374
- const pnt = new oc.gp_Pnt2d_1();
3375
- const vec = new oc.gp_Vec2d_1();
3376
- inner.D1(param, pnt, vec);
3377
- const result = {
3378
- point: [pnt.X(), pnt.Y()],
3379
- tangent: [vec.X(), vec.Y()]
3360
+ function evaluateCurve2dD1$1(curve, param) {
3361
+ return {
3362
+ point: evaluateCurve2d$2(c2d$1(curve), param),
3363
+ tangent: tangentCurve2d(c2d$1(curve), param)
3380
3364
  };
3381
- pnt.delete();
3382
- vec.delete();
3383
- return result;
3384
3365
  }
3385
- function getCurve2dBounds$1(_oc, curve) {
3386
- const inner = curve.get();
3366
+ function getCurve2dBounds$1(curve) {
3367
+ return curveBounds(c2d$1(curve));
3368
+ }
3369
+ function getCurve2dType$1(curve) {
3370
+ return curveTypeName(c2dBasis$1(curve));
3371
+ }
3372
+ function trimCurve2d$1(curve, start, end) {
3387
3373
  return {
3388
- first: inner.FirstParameter(),
3389
- last: inner.LastParameter()
3374
+ __bk2d: "trimmed",
3375
+ basis: c2d$1(curve),
3376
+ tStart: start,
3377
+ tEnd: end
3390
3378
  };
3391
3379
  }
3392
- var CURVE_TYPE_NAMES = [
3393
- "LINE",
3394
- "CIRCLE",
3395
- "ELLIPSE",
3396
- "HYPERBOLA",
3397
- "PARABOLA",
3398
- "BEZIER_CURVE",
3399
- "BSPLINE_CURVE",
3400
- "OFFSET_CURVE",
3401
- "OTHER_CURVE"
3402
- ];
3403
- function getCurve2dType$1(oc, curve) {
3404
- return CURVE_TYPE_NAMES[getCurve2dTypeIndex(oc, curve)] ?? "OTHER_CURVE";
3380
+ function copyCurve2d$1(curve) {
3381
+ return JSON.parse(JSON.stringify(curve));
3405
3382
  }
3406
- function trimCurve2d$1(oc, curve, start, end) {
3407
- const trimmed = new oc.Geom2d_TrimmedCurve(curve, start, end, true, true);
3408
- return new oc.Handle_Geom2d_Curve_2(trimmed);
3383
+ function offsetCurve2d$1(curve, offset) {
3384
+ const c = c2d$1(curve);
3385
+ const bounds = curveBounds(c);
3386
+ const N = 30;
3387
+ const poles = [];
3388
+ for (let i = 0; i <= N; i++) {
3389
+ const t = bounds.first + (bounds.last - bounds.first) * i / N;
3390
+ const [px, py] = evaluateCurve2d$2(c, t);
3391
+ const [tvx, tvy] = tangentCurve2d(c, t);
3392
+ const tLen = Math.sqrt(tvx * tvx + tvy * tvy);
3393
+ if (tLen > 1e-12) poles.push([px - tvy / tLen * offset, py + tvx / tLen * offset]);
3394
+ else poles.push([px, py]);
3395
+ }
3396
+ return makeBSpline2d$1(poles);
3409
3397
  }
3410
- function reverseCurve2d$1(_oc, curve) {
3411
- curve.get().Reverse();
3398
+ function translateCurve2d$1(curve, dx, dy) {
3399
+ return translateCurve2d$2(c2d$1(curve), dx, dy);
3412
3400
  }
3413
- function copyCurve2d$1(_oc, curve) {
3414
- return curve.get().Copy();
3401
+ function rotateCurve2d$1(curve, angle, cx, cy) {
3402
+ return rotateCurve2d$2(c2d$1(curve), angle, cx, cy);
3415
3403
  }
3416
- function offsetCurve2d$1(oc, curve, offset) {
3417
- const offsetCurve = new oc.Geom2d_OffsetCurve_1(curve, offset, true);
3418
- return new oc.Handle_Geom2d_Curve_2(offsetCurve);
3404
+ function scaleCurve2d$1(curve, factor, cx, cy) {
3405
+ return scaleCurve2d$2(c2d$1(curve), factor, cx, cy);
3419
3406
  }
3420
- function transformCurve(oc, curve, trsf) {
3421
- const gtrsf = new oc.gp_GTrsf2d_2(trsf);
3422
- const result = oc.GeomLib.GTransform(curve, gtrsf);
3423
- gtrsf.delete();
3424
- trsf.delete();
3425
- return result;
3407
+ function mirrorCurve2dAtPoint$1(curve, cx, cy) {
3408
+ return mirrorAtPoint(c2d$1(curve), cx, cy);
3426
3409
  }
3427
- function translateCurve2d$1(oc, curve, dx, dy) {
3428
- const v = new oc.gp_Vec2d_4(dx, dy);
3429
- const trsf = new oc.gp_Trsf2d_1();
3430
- trsf.SetTranslation_1(v);
3431
- v.delete();
3432
- return transformCurve(oc, curve, trsf);
3433
- }
3434
- function rotateCurve2d$1(oc, curve, angle, cx, cy) {
3435
- const center = new oc.gp_Pnt2d_3(cx, cy);
3436
- const trsf = new oc.gp_Trsf2d_1();
3437
- trsf.SetRotation(center, angle);
3438
- center.delete();
3439
- return transformCurve(oc, curve, trsf);
3410
+ function mirrorCurve2dAcrossAxis$1(curve, ox, oy, dx, dy) {
3411
+ return mirrorAcrossAxis(c2d$1(curve), ox, oy, dx, dy);
3440
3412
  }
3441
- function scaleCurve2d$1(oc, curve, factor, cx, cy) {
3442
- const center = new oc.gp_Pnt2d_3(cx, cy);
3443
- const trsf = new oc.gp_Trsf2d_1();
3444
- trsf.SetScale(center, factor);
3445
- center.delete();
3446
- return transformCurve(oc, curve, trsf);
3413
+ function affinityTransform2d$1(curve, ox, oy, dx, dy, ratio) {
3414
+ return transformCurve2dGeneral$1(curve, createAffinityGTrsf2d$1(ox, oy, dx, dy, ratio));
3447
3415
  }
3448
- function mirrorCurve2dAtPoint$1(oc, curve, cx, cy) {
3449
- const center = new oc.gp_Pnt2d_3(cx, cy);
3450
- const trsf = new oc.gp_Trsf2d_1();
3451
- trsf.SetMirror_1(center);
3452
- center.delete();
3453
- return transformCurve(oc, curve, trsf);
3454
- }
3455
- function mirrorCurve2dAcrossAxis$1(oc, curve, originX, originY, dirX, dirY) {
3456
- const origin = new oc.gp_Pnt2d_3(originX, originY);
3457
- const dir = new oc.gp_Dir2d_5(dirX, dirY);
3458
- const ax = new oc.gp_Ax2d_2(origin, dir);
3459
- const trsf = new oc.gp_Trsf2d_1();
3460
- trsf.SetMirror_2(ax);
3461
- ax.delete();
3462
- dir.delete();
3463
- origin.delete();
3464
- return transformCurve(oc, curve, trsf);
3465
- }
3466
- function affinityTransform2d$1(oc, curve, axisOriginX, axisOriginY, axisDirX, axisDirY, ratio) {
3467
- const origin = new oc.gp_Pnt2d_3(axisOriginX, axisOriginY);
3468
- const dir = new oc.gp_Dir2d_5(axisDirX, axisDirY);
3469
- const ax = new oc.gp_Ax2d_2(origin, dir);
3470
- const gtrsf = new oc.gp_GTrsf2d_1();
3471
- gtrsf.SetAffinity(ax, ratio);
3472
- ax.delete();
3473
- dir.delete();
3474
- origin.delete();
3475
- const result = oc.GeomLib.GTransform(curve, gtrsf);
3476
- gtrsf.delete();
3477
- return result;
3416
+ function _gtrsf$1(m, tx, ty) {
3417
+ return {
3418
+ m,
3419
+ tx,
3420
+ ty,
3421
+ delete: noop$1
3422
+ };
3478
3423
  }
3479
- /** Helper: wrap a gp_Trsf2d in a gp_GTrsf2d and delete the trsf. */
3480
- function wrapTrsf2dAsGTrsf2d(oc, trsf) {
3481
- const gtrsf = new oc.gp_GTrsf2d_2(trsf);
3482
- trsf.delete();
3483
- return gtrsf;
3424
+ function createIdentityGTrsf2d$1() {
3425
+ return _gtrsf$1([
3426
+ 1,
3427
+ 0,
3428
+ 0,
3429
+ 0,
3430
+ 1,
3431
+ 0,
3432
+ 0,
3433
+ 0,
3434
+ 1
3435
+ ], 0, 0);
3484
3436
  }
3485
- function createIdentityGTrsf2d$1(oc) {
3486
- return new oc.gp_GTrsf2d_1();
3437
+ function createAffinityGTrsf2d$1(ox, oy, dx, dy, ratio) {
3438
+ const len = Math.sqrt(dx * dx + dy * dy);
3439
+ if (len < 1e-15) return createIdentityGTrsf2d$1();
3440
+ const px = -dy / len, py = dx / len;
3441
+ const k = ratio - 1;
3442
+ const m = [
3443
+ 1 + k * px * px,
3444
+ k * px * py,
3445
+ 0,
3446
+ k * py * px,
3447
+ 1 + k * py * py,
3448
+ 0,
3449
+ 0,
3450
+ 0,
3451
+ 1
3452
+ ];
3453
+ return _gtrsf$1(m, ox - m[0] * ox - m[1] * oy, oy - m[3] * ox - m[4] * oy);
3487
3454
  }
3488
- function createAffinityGTrsf2d$1(oc, originX, originY, dirX, dirY, ratio) {
3489
- const origin = new oc.gp_Pnt2d_3(originX, originY);
3490
- const dir = new oc.gp_Dir2d_5(dirX, dirY);
3491
- const ax = new oc.gp_Ax2d_2(origin, dir);
3492
- const gtrsf = new oc.gp_GTrsf2d_1();
3493
- gtrsf.SetAffinity(ax, ratio);
3494
- ax.delete();
3495
- dir.delete();
3496
- origin.delete();
3497
- return gtrsf;
3498
- }
3499
- function createTranslationGTrsf2d$1(oc, dx, dy) {
3500
- const v = new oc.gp_Vec2d_4(dx, dy);
3501
- const trsf = new oc.gp_Trsf2d_1();
3502
- trsf.SetTranslation_1(v);
3503
- v.delete();
3504
- return wrapTrsf2dAsGTrsf2d(oc, trsf);
3505
- }
3506
- function createMirrorGTrsf2d$1(oc, cx, cy, mode, originX = 0, originY = 0, dirX = 1, dirY = 0) {
3507
- const trsf = new oc.gp_Trsf2d_1();
3508
- if (mode === "point") {
3509
- const p = new oc.gp_Pnt2d_3(cx, cy);
3510
- trsf.SetMirror_1(p);
3511
- p.delete();
3512
- } else {
3513
- const p = new oc.gp_Pnt2d_3(originX, originY);
3514
- const dir = new oc.gp_Dir2d_5(dirX, dirY);
3515
- const ax = new oc.gp_Ax2d_2(p, dir);
3516
- trsf.SetMirror_2(ax);
3517
- ax.delete();
3518
- dir.delete();
3519
- p.delete();
3520
- }
3521
- return wrapTrsf2dAsGTrsf2d(oc, trsf);
3522
- }
3523
- function createRotationGTrsf2d$1(oc, angle, cx, cy) {
3524
- const p = new oc.gp_Pnt2d_3(cx, cy);
3525
- const trsf = new oc.gp_Trsf2d_1();
3526
- trsf.SetRotation(p, angle);
3527
- p.delete();
3528
- return wrapTrsf2dAsGTrsf2d(oc, trsf);
3529
- }
3530
- function createScaleGTrsf2d$1(oc, factor, cx, cy) {
3531
- const p = new oc.gp_Pnt2d_3(cx, cy);
3532
- const trsf = new oc.gp_Trsf2d_1();
3533
- trsf.SetScale(p, factor);
3534
- p.delete();
3535
- return wrapTrsf2dAsGTrsf2d(oc, trsf);
3536
- }
3537
- function setGTrsf2dTranslationPart$1(oc, gtrsf, dx, dy) {
3538
- const xy = new oc.gp_XY_2(dx, dy);
3539
- gtrsf.SetTranslationPart(xy);
3540
- xy.delete();
3455
+ function createTranslationGTrsf2d$1(dx, dy) {
3456
+ return _gtrsf$1([
3457
+ 1,
3458
+ 0,
3459
+ 0,
3460
+ 0,
3461
+ 1,
3462
+ 0,
3463
+ 0,
3464
+ 0,
3465
+ 1
3466
+ ], dx, dy);
3541
3467
  }
3542
- function multiplyGTrsf2d$1(_oc, base, other) {
3543
- base.Multiply(other);
3468
+ function createMirrorGTrsf2d$1(cx, cy, mode, ox, oy, dx, dy) {
3469
+ if (mode === "axis" && dx !== void 0 && dy !== void 0) {
3470
+ const len = Math.sqrt(dx * dx + dy * dy);
3471
+ const nx = dx / len, ny = dy / len;
3472
+ const m = [
3473
+ 2 * nx * nx - 1,
3474
+ 2 * nx * ny,
3475
+ 0,
3476
+ 2 * nx * ny,
3477
+ 2 * ny * ny - 1,
3478
+ 0,
3479
+ 0,
3480
+ 0,
3481
+ 1
3482
+ ];
3483
+ const apx = ox ?? cx, apy = oy ?? cy;
3484
+ return _gtrsf$1(m, apx - m[0] * apx - m[1] * apy, apy - m[3] * apx - m[4] * apy);
3485
+ }
3486
+ return _gtrsf$1([
3487
+ -1,
3488
+ 0,
3489
+ 0,
3490
+ 0,
3491
+ -1,
3492
+ 0,
3493
+ 0,
3494
+ 0,
3495
+ 1
3496
+ ], 2 * cx, 2 * cy);
3544
3497
  }
3545
- function transformCurve2dGeneral$1(oc, curve, gtrsf) {
3546
- return oc.GeomLib.GTransform(curve, gtrsf);
3498
+ function createRotationGTrsf2d$1(angle, cx, cy) {
3499
+ const c = Math.cos(angle), s = Math.sin(angle);
3500
+ return _gtrsf$1([
3501
+ c,
3502
+ -s,
3503
+ 0,
3504
+ s,
3505
+ c,
3506
+ 0,
3507
+ 0,
3508
+ 0,
3509
+ 1
3510
+ ], cx - c * cx + s * cy, cy - s * cx - c * cy);
3511
+ }
3512
+ function createScaleGTrsf2d$1(factor, cx, cy) {
3513
+ return _gtrsf$1([
3514
+ factor,
3515
+ 0,
3516
+ 0,
3517
+ 0,
3518
+ factor,
3519
+ 0,
3520
+ 0,
3521
+ 0,
3522
+ 1
3523
+ ], cx * (1 - factor), cy * (1 - factor));
3524
+ }
3525
+ function setGTrsf2dTranslationPart$1(gtrsf, dx, dy) {
3526
+ gtrsf.tx = dx;
3527
+ gtrsf.ty = dy;
3528
+ }
3529
+ function multiplyGTrsf2d$1(base, other) {
3530
+ const a = base.m, b = other.m;
3531
+ base.m = [
3532
+ a[0] * b[0] + a[1] * b[3] + a[2] * b[6],
3533
+ a[0] * b[1] + a[1] * b[4] + a[2] * b[7],
3534
+ a[0] * b[2] + a[1] * b[5] + a[2] * b[8],
3535
+ a[3] * b[0] + a[4] * b[3] + a[5] * b[6],
3536
+ a[3] * b[1] + a[4] * b[4] + a[5] * b[7],
3537
+ a[3] * b[2] + a[4] * b[5] + a[5] * b[8],
3538
+ a[6] * b[0] + a[7] * b[3] + a[8] * b[6],
3539
+ a[6] * b[1] + a[7] * b[4] + a[8] * b[7],
3540
+ a[6] * b[2] + a[7] * b[5] + a[8] * b[8]
3541
+ ];
3542
+ const oldTx = base.tx, oldTy = base.ty;
3543
+ const otx = Number(other.tx) || 0, oty = Number(other.ty) || 0;
3544
+ base.tx = a[0] * otx + a[1] * oty + oldTx;
3545
+ base.ty = a[3] * otx + a[4] * oty + oldTy;
3546
+ }
3547
+ function transformCurve2dGeneral$1(curve, gtrsf) {
3548
+ const c = c2d$1(curve);
3549
+ const m = gtrsf.m ?? [
3550
+ 1,
3551
+ 0,
3552
+ 0,
3553
+ 0,
3554
+ 1,
3555
+ 0,
3556
+ 0,
3557
+ 0,
3558
+ 1
3559
+ ];
3560
+ const tx = Number(gtrsf.tx) || 0, ty = Number(gtrsf.ty) || 0;
3561
+ if (Math.abs(m[0] - 1) < 1e-12 && Math.abs(m[4] - 1) < 1e-12 && Math.abs(m[1]) < 1e-12 && Math.abs(m[3]) < 1e-12) return translateCurve2d$2(c, tx, ty);
3562
+ const bounds = curveBounds(c);
3563
+ const N = 20;
3564
+ const pts = [];
3565
+ for (let i = 0; i <= N; i++) {
3566
+ const [px, py] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * i / N);
3567
+ pts.push([m[0] * px + m[1] * py + tx, m[3] * px + m[4] * py + ty]);
3568
+ }
3569
+ return makeBezier2d$2(pts);
3570
+ }
3571
+ function intersectCurves2d$1(c1, c2, tolerance) {
3572
+ const result = intersectCurves2dFn(c2d$1(c1), c2d$1(c2), tolerance);
3573
+ const segments = result.segments.map((s) => Object.assign(s, { delete() {} }));
3574
+ return {
3575
+ points: result.points,
3576
+ segments
3577
+ };
3578
+ }
3579
+ function projectPointOnCurve2d$1(curve, x, y) {
3580
+ const c = c2d$1(curve);
3581
+ const bounds = curveBounds(c);
3582
+ if (c.__bk2d === "line") {
3583
+ const ddx = x - c.ox;
3584
+ const ddy = y - c.oy;
3585
+ const t = Math.max(bounds.first, Math.min(bounds.last, ddx * c.dx + ddy * c.dy));
3586
+ const [px, py] = evaluateCurve2d$2(c, t);
3587
+ return {
3588
+ param: t,
3589
+ distance: Math.sqrt((px - x) ** 2 + (py - y) ** 2)
3590
+ };
3591
+ }
3592
+ if (c.__bk2d === "circle") {
3593
+ const angle = Math.atan2(y - c.cy, x - c.cx);
3594
+ let t = c.sense ? angle : -angle;
3595
+ while (t < 0) t += 2 * Math.PI;
3596
+ while (t > 2 * Math.PI) t -= 2 * Math.PI;
3597
+ const [px, py] = evaluateCurve2d$2(c, t);
3598
+ return {
3599
+ param: t,
3600
+ distance: Math.sqrt((px - x) ** 2 + (py - y) ** 2)
3601
+ };
3602
+ }
3603
+ if (!isFinite(bounds.first) || !isFinite(bounds.last)) return null;
3604
+ let bestT = bounds.first;
3605
+ let bestDist = Infinity;
3606
+ const N = 200;
3607
+ const dt = (bounds.last - bounds.first) / N;
3608
+ for (let i = 0; i <= N; i++) {
3609
+ const t = bounds.first + i * dt;
3610
+ const [px, py] = evaluateCurve2d$2(c, t);
3611
+ const dd = (px - x) ** 2 + (py - y) ** 2;
3612
+ if (dd < bestDist) {
3613
+ bestDist = dd;
3614
+ bestT = t;
3615
+ }
3616
+ }
3617
+ for (let iter = 0; iter < 10; iter++) {
3618
+ const [px, py] = evaluateCurve2d$2(c, bestT);
3619
+ const [tvx, tvy] = tangentCurve2d(c, bestT);
3620
+ const dot = (px - x) * tvx + (py - y) * tvy;
3621
+ const ddenom = tvx * tvx + tvy * tvy;
3622
+ if (ddenom < 1e-20) break;
3623
+ const step = dot / ddenom;
3624
+ const newT = Math.max(bounds.first, Math.min(bounds.last, bestT - step));
3625
+ if (Math.abs(newT - bestT) < 1e-14) break;
3626
+ bestT = newT;
3627
+ }
3628
+ const [fx, fy] = evaluateCurve2d$2(c, bestT);
3629
+ return {
3630
+ param: bestT,
3631
+ distance: Math.sqrt((fx - x) ** 2 + (fy - y) ** 2)
3632
+ };
3633
+ }
3634
+ function distanceBetweenCurves2d$1(c1, c2, p1s, p1e, p2s, p2e) {
3635
+ const curve1 = c2d$1(c1);
3636
+ const curve2 = c2d$1(c2);
3637
+ let bestT1 = p1s;
3638
+ let bestT2 = p2s;
3639
+ let minDistSq = Infinity;
3640
+ const N = 50;
3641
+ for (let i = 0; i <= N; i++) {
3642
+ const t1 = p1s + (p1e - p1s) * i / N;
3643
+ const [x1, y1] = evaluateCurve2d$2(curve1, t1);
3644
+ for (let j = 0; j <= N; j++) {
3645
+ const t2 = p2s + (p2e - p2s) * j / N;
3646
+ const [x2, y2] = evaluateCurve2d$2(curve2, t2);
3647
+ const dd = (x2 - x1) ** 2 + (y2 - y1) ** 2;
3648
+ if (dd < minDistSq) {
3649
+ minDistSq = dd;
3650
+ bestT1 = t1;
3651
+ bestT2 = t2;
3652
+ }
3653
+ }
3654
+ }
3655
+ let t1 = bestT1;
3656
+ let t2 = bestT2;
3657
+ for (let iter = 0; iter < 20; iter++) {
3658
+ const [x2, y2] = evaluateCurve2d$2(curve2, t2);
3659
+ const proj1 = projectPointOnCurve2d$1(c1, x2, y2);
3660
+ if (proj1) {
3661
+ const newT1 = Math.max(p1s, Math.min(p1e, proj1.param));
3662
+ const converged1 = Math.abs(newT1 - t1) < 1e-12;
3663
+ t1 = newT1;
3664
+ if (converged1) break;
3665
+ }
3666
+ const [x1, y1] = evaluateCurve2d$2(curve1, t1);
3667
+ const proj2 = projectPointOnCurve2d$1(c2, x1, y1);
3668
+ if (proj2) {
3669
+ const newT2 = Math.max(p2s, Math.min(p2e, proj2.param));
3670
+ const converged2 = Math.abs(newT2 - t2) < 1e-12;
3671
+ t2 = newT2;
3672
+ if (converged2) break;
3673
+ }
3674
+ }
3675
+ const [fx1, fy1] = evaluateCurve2d$2(curve1, t1);
3676
+ const [fx2, fy2] = evaluateCurve2d$2(curve2, t2);
3677
+ return Math.sqrt((fx2 - fx1) ** 2 + (fy2 - fy1) ** 2);
3547
3678
  }
3548
- function intersectCurves2d$1(oc, c1, c2, tolerance) {
3549
- const intersector = new oc.Geom2dAPI_InterCurveCurve_1();
3550
- intersector.Init_1(c1, c2, tolerance);
3551
- const points = [];
3552
- const nPoints = intersector.NbPoints();
3553
- for (let i = 1; i <= nPoints; i++) {
3554
- const p = intersector.Point(i);
3555
- points.push([p.X(), p.Y()]);
3556
- p.delete();
3557
- }
3558
- const segments = [];
3559
- const nSegments = intersector.NbSegments();
3560
- for (let i = 1; i <= nSegments; i++) {
3561
- const h1 = new oc.Handle_Geom2d_Curve_1();
3562
- const h2 = new oc.Handle_Geom2d_Curve_1();
3563
- try {
3564
- intersector.Segment(i, h1, h2);
3565
- segments.push(h1);
3566
- h2.delete();
3567
- } catch {
3568
- h1.delete();
3569
- h2.delete();
3679
+ function approximateCurve2dAsBSpline$1(curve, tol, cont, maxSeg) {
3680
+ const c = c2d$1(curve);
3681
+ const bounds = curveBounds(c);
3682
+ const degree = Math.max(3, {
3683
+ C0: 1,
3684
+ C1: 2,
3685
+ C2: 3,
3686
+ C3: 4
3687
+ }[cont] ?? 4);
3688
+ let curN = Math.max(100, maxSeg * 10);
3689
+ let poles = [];
3690
+ let maxErr = Infinity;
3691
+ for (let attempt = 0; attempt < 3 && maxErr > tol; attempt++) {
3692
+ poles = [];
3693
+ for (let i = 0; i <= curN; i++) {
3694
+ const t = bounds.first + (bounds.last - bounds.first) * i / curN;
3695
+ poles.push(evaluateCurve2d$2(c, t));
3696
+ }
3697
+ maxErr = 0;
3698
+ for (let i = 0; i < curN; i++) {
3699
+ const [ex, ey] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * (i + .5) / curN);
3700
+ const p0 = poles[i];
3701
+ const p1 = poles[i + 1];
3702
+ const mx = (p0[0] + p1[0]) / 2;
3703
+ const my = (p0[1] + p1[1]) / 2;
3704
+ const err = Math.sqrt((ex - mx) ** 2 + (ey - my) ** 2);
3705
+ if (err > maxErr) maxErr = err;
3570
3706
  }
3707
+ if (maxErr > tol) curN = Math.min(curN * 2, 500);
3571
3708
  }
3572
- intersector.delete();
3573
- return {
3574
- points,
3575
- segments
3576
- };
3709
+ return makeBSpline2d$1(poles, { degMax: degree });
3577
3710
  }
3578
- function projectPointOnCurve2d$1(oc, curve, x, y) {
3579
- const pnt = new oc.gp_Pnt2d_3(x, y);
3580
- const projector = new oc.Geom2dAPI_ProjectPointOnCurve_2(pnt, curve);
3581
- pnt.delete();
3582
- let result = null;
3583
- try {
3584
- if (projector.NbPoints() > 0) result = {
3585
- param: projector.LowerDistanceParameter(),
3586
- distance: projector.LowerDistance()
3711
+ function decomposeBSpline2dToBeziers$1(curve) {
3712
+ const c = c2dBasis$1(curve);
3713
+ if (c.__bk2d === "bezier") return [curve];
3714
+ if (c.__bk2d !== "bspline") return decomposeBSpline2dToBeziers$1(approximateCurve2dAsBSpline$1(curve, 1e-6, "C2", 10));
3715
+ const trimBounds = curveBounds(c2d$1(curve));
3716
+ const first = trimBounds.first;
3717
+ const last = trimBounds.last;
3718
+ const internalKnots = [];
3719
+ for (const k of c.knots) if (k > first + 1e-12 && k < last - 1e-12) internalKnots.push(k);
3720
+ const breakpoints = [
3721
+ first,
3722
+ ...internalKnots,
3723
+ last
3724
+ ];
3725
+ const result = [];
3726
+ for (let i = 0; i < breakpoints.length - 1; i++) {
3727
+ const t0 = breakpoints[i];
3728
+ const t1 = breakpoints[i + 1];
3729
+ const span = t1 - t0;
3730
+ if (span < 1e-15) continue;
3731
+ const p0 = evaluateCurve2d$2(c, t0);
3732
+ const p3 = evaluateCurve2d$2(c, t1);
3733
+ const tan0 = tangentCurve2d(c, t0);
3734
+ const tan3 = tangentCurve2d(c, t1);
3735
+ const s = span / 3;
3736
+ const bezier = {
3737
+ __bk2d: "bezier",
3738
+ poles: [
3739
+ p0,
3740
+ [p0[0] + tan0[0] * s, p0[1] + tan0[1] * s],
3741
+ [p3[0] - tan3[0] * s, p3[1] - tan3[1] * s],
3742
+ p3
3743
+ ]
3587
3744
  };
3588
- } catch {}
3589
- projector.delete();
3590
- return result;
3591
- }
3592
- function distanceBetweenCurves2d$1(oc, c1, c2, p1Start, p1End, p2Start, p2End) {
3593
- const extrema = new oc.Geom2dAPI_ExtremaCurveCurve(c1, c2, p1Start, p1End, p2Start, p2End);
3594
- let distance;
3595
- try {
3596
- distance = extrema.LowerDistance();
3597
- } catch {
3598
- distance = Infinity;
3745
+ result.push(bezier);
3599
3746
  }
3600
- extrema.delete();
3601
- return distance;
3602
- }
3603
- function approximateCurve2dAsBSpline$1(oc, curve, tolerance, continuity, maxSegments) {
3604
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3605
- const convert = new oc.Geom2dConvert_ApproxCurve_2(adaptor.ShallowCopy(), tolerance, mapContinuity(oc, continuity), maxSegments, 3);
3606
- const result = convert.Curve();
3607
- convert.delete();
3608
- adaptor.delete();
3609
- return result;
3610
- }
3611
- function decomposeBSpline2dToBeziers$1(oc, curve) {
3612
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3613
- const handle = adaptor.BSpline();
3614
- adaptor.delete();
3615
- const convert = new oc.Geom2dConvert_BSplineCurveToBezierCurve_1(handle);
3616
- const arcs = [];
3617
- const nArcs = convert.NbArcs();
3618
- for (let i = 1; i <= nArcs; i++) arcs.push(convert.Arc(i));
3619
- convert.delete();
3620
- return arcs;
3747
+ return result.length > 0 ? result : [curve];
3621
3748
  }
3622
- function createBoundingBox2d$1(oc) {
3623
- return new oc.Bnd_Box2d();
3749
+ function createBoundingBox2d$1() {
3750
+ return createBBox2d();
3624
3751
  }
3625
- function addCurveToBBox2d$1(oc, bbox, curve, tolerance) {
3626
- oc.BndLib_Add2dCurve.Add_3(curve, tolerance, bbox);
3752
+ function addCurveToBBox2d$1(bbox, curve, tol) {
3753
+ addCurveToBBox(bb2d$1(bbox), c2d$1(curve), tol);
3627
3754
  }
3628
- function getBBox2dBounds$1(_oc, bbox) {
3755
+ function getBBox2dBounds$1(bbox) {
3756
+ const b = bb2d$1(bbox);
3629
3757
  return {
3630
- xMin: bbox.GetXMin(),
3631
- yMin: bbox.GetYMin(),
3632
- xMax: bbox.GetXMax(),
3633
- yMax: bbox.GetYMax()
3758
+ xMin: b.xMin,
3759
+ yMin: b.yMin,
3760
+ xMax: b.xMax,
3761
+ yMax: b.yMax
3634
3762
  };
3635
3763
  }
3636
- function mergeBBox2d$1(_oc, target, other) {
3637
- target.Add_1(other);
3764
+ function mergeBBox2d$1(target, other) {
3765
+ const t = bb2d$1(target), o = bb2d$1(other);
3766
+ t.xMin = Math.min(t.xMin, o.xMin);
3767
+ t.yMin = Math.min(t.yMin, o.yMin);
3768
+ t.xMax = Math.max(t.xMax, o.xMax);
3769
+ t.yMax = Math.max(t.yMax, o.yMax);
3638
3770
  }
3639
- function isBBox2dOut$1(_oc, a, b) {
3640
- return a.IsOut_4(b);
3771
+ function isBBox2dOut$1(a, b) {
3772
+ const ba = bb2d$1(a), bbb = bb2d$1(b);
3773
+ return ba.xMax < bbb.xMin || bbb.xMax < ba.xMin || ba.yMax < bbb.yMin || bbb.yMax < ba.yMin;
3641
3774
  }
3642
- function isBBox2dOutPoint$1(oc, bbox, x, y) {
3643
- const pnt = new oc.gp_Pnt2d_3(x, y);
3644
- const result = bbox.IsOut_1(pnt);
3645
- pnt.delete();
3646
- return result;
3775
+ function isBBox2dOutPoint$1(bbox, x, y) {
3776
+ const b = bb2d$1(bbox);
3777
+ return x < b.xMin || x > b.xMax || y < b.yMin || y > b.yMax;
3647
3778
  }
3648
- function getCurve2dCircleData$1(oc, curve) {
3649
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3650
- if (unwrapOcctEnum(adaptor.GetType()) !== 1) {
3651
- adaptor.delete();
3652
- return null;
3653
- }
3654
- const circle = adaptor.Circle();
3655
- const center = circle.Location();
3656
- const result = {
3657
- cx: center.X(),
3658
- cy: center.Y(),
3659
- radius: circle.Radius(),
3660
- isDirect: circle.IsDirect()
3779
+ function getCurve2dCircleData$1(curve) {
3780
+ const c = c2dBasis$1(curve);
3781
+ if (c.__bk2d === "circle") return {
3782
+ cx: c.cx,
3783
+ cy: c.cy,
3784
+ radius: c.radius,
3785
+ isDirect: c.sense
3661
3786
  };
3662
- center.delete();
3663
- circle.delete();
3664
- adaptor.delete();
3665
- return result;
3787
+ return null;
3666
3788
  }
3667
- function getCurve2dEllipseData$1(oc, curve) {
3668
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3669
- if (unwrapOcctEnum(adaptor.GetType()) !== 2) {
3670
- adaptor.delete();
3671
- return null;
3672
- }
3673
- const elips = adaptor.Ellipse();
3674
- const xAxis = elips.XAxis();
3675
- const xDir = xAxis.Direction();
3676
- const result = {
3677
- majorRadius: elips.MajorRadius(),
3678
- minorRadius: elips.MinorRadius(),
3679
- xAxisAngle: Math.atan2(xDir.Y(), xDir.X()),
3680
- isDirect: elips.IsDirect()
3789
+ function getCurve2dEllipseData$1(curve) {
3790
+ const c = c2dBasis$1(curve);
3791
+ if (c.__bk2d === "ellipse") return {
3792
+ majorRadius: c.majorRadius,
3793
+ minorRadius: c.minorRadius,
3794
+ xAxisAngle: c.xDirAngle,
3795
+ isDirect: c.sense
3681
3796
  };
3682
- xDir.delete();
3683
- xAxis.delete();
3684
- elips.delete();
3685
- adaptor.delete();
3686
- return result;
3797
+ return null;
3687
3798
  }
3688
- function getCurve2dBezierPoles$1(oc, curve) {
3689
- if (getCurve2dTypeIndex(oc, curve) !== 5) return null;
3690
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3691
- const bezier = adaptor.Bezier().get();
3692
- const poles = [];
3693
- const nbPoles = bezier.NbPoles();
3694
- for (let i = 1; i <= nbPoles; i++) {
3695
- const p = bezier.Pole(i);
3696
- poles.push([p.X(), p.Y()]);
3697
- p.delete();
3698
- }
3699
- adaptor.delete();
3700
- return poles;
3799
+ function getCurve2dBezierPoles$1(curve) {
3800
+ const c = c2dBasis$1(curve);
3801
+ if (c.__bk2d === "bezier") return [...c.poles];
3802
+ return null;
3701
3803
  }
3702
- function getCurve2dBezierDegree$1(oc, curve) {
3703
- if (getCurve2dTypeIndex(oc, curve) !== 5) return null;
3704
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3705
- const degree = adaptor.Bezier().get().Degree();
3706
- adaptor.delete();
3707
- return degree;
3804
+ function getCurve2dBezierDegree$1(curve) {
3805
+ const c = c2dBasis$1(curve);
3806
+ if (c.__bk2d === "bezier") return c.poles.length - 1;
3807
+ return null;
3708
3808
  }
3709
- function getCurve2dBSplineData$1(oc, curve) {
3710
- if (getCurve2dTypeIndex(oc, curve) !== 6) return null;
3711
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3712
- const bspline = adaptor.BSpline().get();
3713
- const poles = [];
3714
- const polesArr = bspline.Poles_2();
3715
- for (let i = polesArr.Lower(); i <= polesArr.Upper(); i++) {
3716
- const p = polesArr.Value(i);
3717
- poles.push([p.X(), p.Y()]);
3718
- }
3719
- const knots = [];
3720
- const knotsArr = bspline.Knots_2();
3721
- for (let i = knotsArr.Lower(); i <= knotsArr.Upper(); i++) knots.push(knotsArr.Value(i));
3722
- const multiplicities = [];
3723
- const multsArr = bspline.Multiplicities_2();
3724
- for (let i = multsArr.Lower(); i <= multsArr.Upper(); i++) multiplicities.push(multsArr.Value(i));
3725
- const result = {
3726
- poles,
3727
- knots,
3728
- multiplicities,
3729
- degree: bspline.Degree(),
3730
- isPeriodic: bspline.IsPeriodic()
3809
+ function getCurve2dBSplineData$1(curve) {
3810
+ const c = c2dBasis$1(curve);
3811
+ if (c.__bk2d === "bspline") return {
3812
+ poles: [...c.poles],
3813
+ knots: [...c.knots],
3814
+ multiplicities: [...c.multiplicities],
3815
+ degree: c.degree,
3816
+ isPeriodic: c.isPeriodic
3731
3817
  };
3732
- adaptor.delete();
3733
- return result;
3818
+ return null;
3734
3819
  }
3735
- function serializeCurve2d$1(oc, curve) {
3736
- return oc.GeomToolsWrapper.Write(curve);
3737
- }
3738
- function deserializeCurve2d$1(oc, data) {
3739
- return oc.GeomToolsWrapper.Read(data);
3740
- }
3741
- function splitCurve2d$1(oc, curve, params) {
3742
- const inner = curve.get();
3743
- const first = inner.FirstParameter();
3744
- const last = inner.LastParameter();
3745
- const sorted = [...params].sort((a, b) => a - b);
3746
- const boundaries = [];
3747
- let prev = first;
3748
- for (const p of sorted) if (p > first && p < last) {
3749
- boundaries.push([prev, p]);
3750
- prev = p;
3751
- }
3752
- boundaries.push([prev, last]);
3753
- const adaptor = new oc.Geom2dAdaptor_Curve_2(curve);
3754
- const geomType = unwrapOcctEnum(adaptor.GetType());
3755
- const results = boundaries.map(([start, end]) => {
3756
- if (geomType === 5) {
3757
- const curveCopy = new oc.Geom2d_BezierCurve_1(adaptor.Bezier().get().Poles_2());
3758
- curveCopy.Segment(start, end);
3759
- return new oc.Handle_Geom2d_Curve_2(curveCopy);
3760
- }
3761
- if (geomType === 6) {
3762
- const bspline = adaptor.BSpline().get();
3763
- const curveCopy = new oc.Geom2d_BSplineCurve_1(bspline.Poles_2(), bspline.Knots_2(), bspline.Multiplicities_2(), bspline.Degree(), bspline.IsPeriodic());
3764
- curveCopy.Segment(start, end, 1e-9);
3765
- return new oc.Handle_Geom2d_Curve_2(curveCopy);
3766
- }
3767
- const trimmed = new oc.Geom2d_TrimmedCurve(curve, start, end, true, true);
3768
- return new oc.Handle_Geom2d_Curve_2(trimmed);
3820
+ function serializeCurve2d$1(curve) {
3821
+ return serializeCurve2d$2(c2d$1(curve));
3822
+ }
3823
+ function deserializeCurve2d$1(data) {
3824
+ return deserializeCurve2d$2(data);
3825
+ }
3826
+ function splitCurve2d$1(curve, params) {
3827
+ const c = c2d$1(curve);
3828
+ const bounds = curveBounds(c);
3829
+ const sortedParams = [
3830
+ bounds.first,
3831
+ ...[...params].sort((a, b) => a - b),
3832
+ bounds.last
3833
+ ];
3834
+ const result = [];
3835
+ for (let i = 0; i < sortedParams.length - 1; i++) result.push({
3836
+ __bk2d: "trimmed",
3837
+ basis: c,
3838
+ tStart: sortedParams[i],
3839
+ tEnd: sortedParams[i + 1]
3769
3840
  });
3770
- adaptor.delete();
3771
- return results;
3841
+ return result;
3772
3842
  }
3773
- function liftCurve2dToPlane$1(oc, curve, planeOrigin, planeZ, planeX) {
3774
- const origin = new oc.gp_Pnt_3(planeOrigin[0], planeOrigin[1], planeOrigin[2]);
3775
- const zDir = new oc.gp_Dir_5(planeZ[0], planeZ[1], planeZ[2]);
3776
- const xDir = new oc.gp_Dir_5(planeX[0], planeX[1], planeX[2]);
3777
- const ax = new oc.gp_Ax2_2(origin, zDir, xDir);
3778
- const curve3d = oc.GeomLib.To3d(ax, curve);
3779
- const edgeBuilder = new oc.BRepBuilderAPI_MakeEdge_24(curve3d);
3843
+ /** Create a straight 3D edge between two points. */
3844
+ function makeLineEdge3d(oc, p1, p2) {
3845
+ const gp1 = new oc.gp_Pnt_3(p1[0], p1[1], p1[2]);
3846
+ const gp2 = new oc.gp_Pnt_3(p2[0], p2[1], p2[2]);
3847
+ const builder = new oc.BRepBuilderAPI_MakeEdge_3(gp1, gp2);
3848
+ const edge = builder.Edge();
3849
+ builder.delete();
3850
+ gp1.delete();
3851
+ gp2.delete();
3852
+ return edge;
3853
+ }
3854
+ /** Create a circular arc edge through 3 points. */
3855
+ function makeCircleArcEdge3d(oc, startPt, midPt, endPt) {
3856
+ const gpStart = new oc.gp_Pnt_3(startPt[0], startPt[1], startPt[2]);
3857
+ const gpMid = new oc.gp_Pnt_3(midPt[0], midPt[1], midPt[2]);
3858
+ const gpEnd = new oc.gp_Pnt_3(endPt[0], endPt[1], endPt[2]);
3859
+ const arcGeom = new oc.GC_MakeArcOfCircle_4(gpStart, gpMid, gpEnd).Value().get();
3860
+ const curveHandle = new oc.Handle_Geom_Curve_2(arcGeom);
3861
+ const edgeBuilder = new oc.BRepBuilderAPI_MakeEdge_24(curveHandle);
3780
3862
  const edge = edgeBuilder.Edge();
3781
3863
  edgeBuilder.delete();
3782
- curve3d.delete();
3783
- ax.delete();
3784
- xDir.delete();
3785
- zDir.delete();
3786
- origin.delete();
3864
+ curveHandle.delete();
3865
+ gpStart.delete();
3866
+ gpMid.delete();
3867
+ gpEnd.delete();
3787
3868
  return edge;
3788
3869
  }
3789
- function buildEdgeOnSurface$1(oc, curve, surface) {
3790
- const edgeMaker = new oc.BRepBuilderAPI_MakeEdge_30(curve, surface);
3791
- const edge = edgeMaker.Edge();
3792
- edgeMaker.delete();
3870
+ /** Interpolate a 3D BSpline through the given points and return an edge. */
3871
+ function interpolatePoints3d(oc, points) {
3872
+ const pnts = new oc.TColgp_Array1OfPnt_2(1, points.length);
3873
+ const reusePnt = new oc.gp_Pnt_1();
3874
+ for (let i = 0; i < points.length; i++) {
3875
+ const p = points[i];
3876
+ reusePnt.SetCoord_2(p[0], p[1], p[2]);
3877
+ pnts.SetValue_1(i + 1, reusePnt);
3878
+ }
3879
+ reusePnt.delete();
3880
+ const interp = new oc.GeomAPI_PointsToBSpline_2(pnts, 3, 8, oc.GeomAbs_Shape.GeomAbs_C2, 1e-6);
3881
+ pnts.delete();
3882
+ if (!interp.IsDone()) {
3883
+ interp.delete();
3884
+ throw new Error("Interpolation failed — GeomAPI_PointsToBSpline did not converge");
3885
+ }
3886
+ const curve3d = interp.Curve();
3887
+ const geomHandle = new oc.Handle_Geom_Curve_2(curve3d.get());
3888
+ const builder = new oc.BRepBuilderAPI_MakeEdge_24(geomHandle);
3889
+ const edge = builder.Edge();
3890
+ builder.delete();
3891
+ interp.delete();
3793
3892
  return edge;
3794
3893
  }
3894
+ function liftCurve2dToPlane$1(oc, curve, planeOrigin, planeZ, planeX) {
3895
+ const c = c2d$1(curve);
3896
+ const y = [
3897
+ planeZ[1] * planeX[2] - planeZ[2] * planeX[1],
3898
+ planeZ[2] * planeX[0] - planeZ[0] * planeX[2],
3899
+ planeZ[0] * planeX[1] - planeZ[1] * planeX[0]
3900
+ ];
3901
+ const lift = (u, v) => [
3902
+ planeOrigin[0] + u * planeX[0] + v * y[0],
3903
+ planeOrigin[1] + u * planeX[1] + v * y[1],
3904
+ planeOrigin[2] + u * planeX[2] + v * y[2]
3905
+ ];
3906
+ if (c.__bk2d === "line") return makeLineEdge3d(oc, lift(c.ox, c.oy), lift(c.ox + c.dx * c.len, c.oy + c.dy * c.len));
3907
+ if (c.__bk2d === "circle" || c.__bk2d === "trimmed") {
3908
+ let basis = c;
3909
+ while (basis.__bk2d === "trimmed") basis = basis.basis;
3910
+ if (basis.__bk2d === "circle") {
3911
+ const circ = basis;
3912
+ const center3d = lift(circ.cx, circ.cy);
3913
+ const axisDir = circ.sense ? planeZ : [
3914
+ -planeZ[0],
3915
+ -planeZ[1],
3916
+ -planeZ[2]
3917
+ ];
3918
+ if (c.__bk2d === "circle") {
3919
+ const gpCenter = new oc.gp_Pnt_3(center3d[0], center3d[1], center3d[2]);
3920
+ const gpDir = new oc.gp_Dir_5(axisDir[0], axisDir[1], axisDir[2]);
3921
+ const gpAx2 = new oc.gp_Ax2_4(gpCenter, gpDir);
3922
+ const gpCirc = new oc.gp_Circ_2(gpAx2, circ.radius);
3923
+ const builder = new oc.BRepBuilderAPI_MakeEdge_8(gpCirc);
3924
+ const edge = builder.Edge();
3925
+ builder.delete();
3926
+ gpCirc.delete();
3927
+ gpAx2.delete();
3928
+ gpDir.delete();
3929
+ gpCenter.delete();
3930
+ return edge;
3931
+ }
3932
+ const bounds = curveBounds(c);
3933
+ const [su, sv] = evaluateCurve2d$2(c, bounds.first);
3934
+ const [mu, mv] = evaluateCurve2d$2(c, (bounds.first + bounds.last) / 2);
3935
+ const [eu, ev] = evaluateCurve2d$2(c, bounds.last);
3936
+ return makeCircleArcEdge3d(oc, lift(su, sv), lift(mu, mv), lift(eu, ev));
3937
+ }
3938
+ }
3939
+ if (c.__bk2d === "bezier" || c.__bk2d === "bspline") {
3940
+ const pts3d = c.poles.map(([u, v]) => lift(u, v));
3941
+ if (pts3d.length === 2) return makeLineEdge3d(oc, pts3d[0], pts3d[1]);
3942
+ return interpolatePoints3d(oc, pts3d);
3943
+ }
3944
+ const bounds = curveBounds(c);
3945
+ const nSamples = 60;
3946
+ const pts3d = [];
3947
+ for (let i = 0; i <= nSamples; i++) {
3948
+ const [u, v] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * i / nSamples);
3949
+ pts3d.push(lift(u, v));
3950
+ }
3951
+ return interpolatePoints3d(oc, pts3d);
3952
+ }
3953
+ function buildEdgeOnSurface$1(oc, curve, surface) {
3954
+ const c = c2d$1(curve);
3955
+ const bounds = curveBounds(c);
3956
+ const N = 60;
3957
+ const pts3d = [];
3958
+ for (let i = 0; i <= N; i++) {
3959
+ const [u, v] = evaluateCurve2d$2(c, bounds.first + (bounds.last - bounds.first) * i / N);
3960
+ const gpPnt = surface.get().Value(u, v);
3961
+ pts3d.push([
3962
+ gpPnt.X(),
3963
+ gpPnt.Y(),
3964
+ gpPnt.Z()
3965
+ ]);
3966
+ gpPnt.delete();
3967
+ }
3968
+ return interpolatePoints3d(oc, pts3d);
3969
+ }
3795
3970
  function extractSurfaceFromFace$1(oc, face) {
3796
3971
  return oc.BRep_Tool.Surface_2(face);
3797
3972
  }
3798
3973
  function extractCurve2dFromEdge$1(oc, edge, face) {
3799
3974
  const adaptor = new oc.BRepAdaptor_Curve2d_2(edge, face);
3800
- const curveHandle = adaptor.Curve();
3801
- const first = adaptor.FirstParameter();
3802
- const last = adaptor.LastParameter();
3975
+ const first = Number(adaptor.FirstParameter());
3976
+ const last = Number(adaptor.LastParameter());
3977
+ const N = 30;
3978
+ const points = [];
3979
+ for (let i = 0; i <= N; i++) {
3980
+ const t = first + (last - first) * i / N;
3981
+ const pt = adaptor.Value(t);
3982
+ points.push([pt.X(), pt.Y()]);
3983
+ pt.delete();
3984
+ }
3803
3985
  adaptor.delete();
3804
- const trimmed = new oc.Geom2d_TrimmedCurve(curveHandle, first, last, true, true);
3805
- return new oc.Handle_Geom2d_Curve_2(trimmed);
3986
+ return makeBSpline2d$1(points);
3806
3987
  }
3807
3988
  function buildCurves3d$1(oc, wire) {
3808
3989
  oc.BRepLib.BuildCurves3d_2(wire);
@@ -5486,172 +5667,170 @@ var DefaultAdapter = class {
5486
5667
  return exportSTEPConfigured$1(this.oc, shapes, options);
5487
5668
  }
5488
5669
  wrapCurve2dHandle(handle) {
5489
- return wrapCurve2dHandle$1(this.oc, handle);
5670
+ return wrapCurve2dHandle$1(handle);
5490
5671
  }
5491
5672
  createCurve2dAdaptor(handle) {
5492
- return createCurve2dAdaptor$1(this.oc, handle);
5673
+ return createCurve2dAdaptor$1(handle);
5493
5674
  }
5494
5675
  createPoint2d(x, y) {
5495
- return createPoint2d$1(this.oc, x, y);
5676
+ return createPoint2d$1(x, y);
5496
5677
  }
5497
5678
  createDirection2d(x, y) {
5498
- return createDirection2d$1(this.oc, x, y);
5679
+ return createDirection2d$1(x, y);
5499
5680
  }
5500
5681
  createVector2d(x, y) {
5501
- return createVector2d$1(this.oc, x, y);
5682
+ return createVector2d$1(x, y);
5502
5683
  }
5503
5684
  createAxis2d(px, py, dx, dy) {
5504
- return createAxis2d$1(this.oc, px, py, dx, dy);
5685
+ return createAxis2d$1(px, py, dx, dy);
5505
5686
  }
5506
5687
  makeLine2d(x1, y1, x2, y2) {
5507
- return makeLine2d$1(this.oc, x1, y1, x2, y2);
5688
+ return makeLine2d$1(x1, y1, x2, y2);
5508
5689
  }
5509
5690
  makeCircle2d(cx, cy, radius, sense) {
5510
- return makeCircle2d$1(this.oc, cx, cy, radius, sense);
5691
+ return makeCircle2d$1(cx, cy, radius, sense);
5511
5692
  }
5512
5693
  makeArc2dThreePoints(x1, y1, xm, ym, x2, y2) {
5513
- return makeArc2dThreePoints$1(this.oc, x1, y1, xm, ym, x2, y2);
5694
+ return makeArc2dThreePoints$1(x1, y1, xm, ym, x2, y2);
5514
5695
  }
5515
5696
  makeArc2dTangent(startX, startY, tangentX, tangentY, endX, endY) {
5516
- return makeArc2dTangent$1(this.oc, startX, startY, tangentX, tangentY, endX, endY);
5697
+ return makeArc2dTangent$1(startX, startY, tangentX, tangentY, endX, endY);
5517
5698
  }
5518
5699
  makeEllipse2d(cx, cy, majorRadius, minorRadius, xDirX, xDirY, sense) {
5519
- return makeEllipse2d$1(this.oc, cx, cy, majorRadius, minorRadius, xDirX, xDirY, sense);
5700
+ return makeEllipse2d$1(cx, cy, majorRadius, minorRadius, xDirX, xDirY, sense);
5520
5701
  }
5521
5702
  makeEllipseArc2d(cx, cy, majorRadius, minorRadius, startAngle, endAngle, xDirX, xDirY, sense) {
5522
- return makeEllipseArc2d$1(this.oc, cx, cy, majorRadius, minorRadius, startAngle, endAngle, xDirX, xDirY, sense);
5703
+ return makeEllipseArc2d$1(cx, cy, majorRadius, minorRadius, startAngle, endAngle, xDirX, xDirY, sense);
5523
5704
  }
5524
5705
  makeBezier2d(points) {
5525
- return makeBezier2d$1(this.oc, points);
5706
+ return makeBezier2d$1(points);
5526
5707
  }
5527
5708
  makeBSpline2d(points, options) {
5528
- return makeBSpline2d$1(this.oc, points, options);
5709
+ return makeBSpline2d$1(points, options);
5529
5710
  }
5530
5711
  evaluateCurve2d(curve, param) {
5531
- return evaluateCurve2d$1(this.oc, curve, param);
5712
+ return evaluateCurve2d$1(curve, param);
5532
5713
  }
5533
5714
  evaluateCurve2dD1(curve, param) {
5534
- return evaluateCurve2dD1$1(this.oc, curve, param);
5715
+ return evaluateCurve2dD1$1(curve, param);
5535
5716
  }
5536
5717
  getCurve2dBounds(curve) {
5537
- return getCurve2dBounds$1(this.oc, curve);
5718
+ return getCurve2dBounds$1(curve);
5538
5719
  }
5539
5720
  getCurve2dType(curve) {
5540
- return getCurve2dType$1(this.oc, curve);
5721
+ return getCurve2dType$1(curve);
5541
5722
  }
5542
5723
  trimCurve2d(curve, start, end) {
5543
- return trimCurve2d$1(this.oc, curve, start, end);
5544
- }
5545
- reverseCurve2d(curve) {
5546
- reverseCurve2d$1(this.oc, curve);
5724
+ return trimCurve2d$1(curve, start, end);
5547
5725
  }
5726
+ reverseCurve2d(curve) {}
5548
5727
  copyCurve2d(curve) {
5549
- return copyCurve2d$1(this.oc, curve);
5728
+ return copyCurve2d$1(curve);
5550
5729
  }
5551
5730
  offsetCurve2d(curve, offset) {
5552
- return offsetCurve2d$1(this.oc, curve, offset);
5731
+ return offsetCurve2d$1(curve, offset);
5553
5732
  }
5554
5733
  translateCurve2d(curve, dx, dy) {
5555
- return translateCurve2d$1(this.oc, curve, dx, dy);
5734
+ return translateCurve2d$1(curve, dx, dy);
5556
5735
  }
5557
5736
  rotateCurve2d(curve, angle, cx, cy) {
5558
- return rotateCurve2d$1(this.oc, curve, angle, cx, cy);
5737
+ return rotateCurve2d$1(curve, angle, cx, cy);
5559
5738
  }
5560
5739
  scaleCurve2d(curve, factor, cx, cy) {
5561
- return scaleCurve2d$1(this.oc, curve, factor, cx, cy);
5740
+ return scaleCurve2d$1(curve, factor, cx, cy);
5562
5741
  }
5563
5742
  mirrorCurve2dAtPoint(curve, cx, cy) {
5564
- return mirrorCurve2dAtPoint$1(this.oc, curve, cx, cy);
5743
+ return mirrorCurve2dAtPoint$1(curve, cx, cy);
5565
5744
  }
5566
5745
  mirrorCurve2dAcrossAxis(curve, originX, originY, dirX, dirY) {
5567
- return mirrorCurve2dAcrossAxis$1(this.oc, curve, originX, originY, dirX, dirY);
5746
+ return mirrorCurve2dAcrossAxis$1(curve, originX, originY, dirX, dirY);
5568
5747
  }
5569
5748
  affinityTransform2d(curve, axisOriginX, axisOriginY, axisDirX, axisDirY, ratio) {
5570
- return affinityTransform2d$1(this.oc, curve, axisOriginX, axisOriginY, axisDirX, axisDirY, ratio);
5749
+ return affinityTransform2d$1(curve, axisOriginX, axisOriginY, axisDirX, axisDirY, ratio);
5571
5750
  }
5572
5751
  createIdentityGTrsf2d() {
5573
- return createIdentityGTrsf2d$1(this.oc);
5752
+ return createIdentityGTrsf2d$1();
5574
5753
  }
5575
5754
  createAffinityGTrsf2d(originX, originY, dirX, dirY, ratio) {
5576
- return createAffinityGTrsf2d$1(this.oc, originX, originY, dirX, dirY, ratio);
5755
+ return createAffinityGTrsf2d$1(originX, originY, dirX, dirY, ratio);
5577
5756
  }
5578
5757
  createTranslationGTrsf2d(dx, dy) {
5579
- return createTranslationGTrsf2d$1(this.oc, dx, dy);
5758
+ return createTranslationGTrsf2d$1(dx, dy);
5580
5759
  }
5581
5760
  createMirrorGTrsf2d(cx, cy, mode, originX, originY, dirX, dirY) {
5582
- return createMirrorGTrsf2d$1(this.oc, cx, cy, mode, originX, originY, dirX, dirY);
5761
+ return createMirrorGTrsf2d$1(cx, cy, mode, originX, originY, dirX, dirY);
5583
5762
  }
5584
5763
  createRotationGTrsf2d(angle, cx, cy) {
5585
- return createRotationGTrsf2d$1(this.oc, angle, cx, cy);
5764
+ return createRotationGTrsf2d$1(angle, cx, cy);
5586
5765
  }
5587
5766
  createScaleGTrsf2d(factor, cx, cy) {
5588
- return createScaleGTrsf2d$1(this.oc, factor, cx, cy);
5767
+ return createScaleGTrsf2d$1(factor, cx, cy);
5589
5768
  }
5590
5769
  setGTrsf2dTranslationPart(gtrsf, dx, dy) {
5591
- setGTrsf2dTranslationPart$1(this.oc, gtrsf, dx, dy);
5770
+ setGTrsf2dTranslationPart$1(gtrsf, dx, dy);
5592
5771
  }
5593
5772
  multiplyGTrsf2d(base, other) {
5594
- multiplyGTrsf2d$1(this.oc, base, other);
5773
+ multiplyGTrsf2d$1(base, other);
5595
5774
  }
5596
5775
  transformCurve2dGeneral(curve, gtrsf) {
5597
- return transformCurve2dGeneral$1(this.oc, curve, gtrsf);
5776
+ return transformCurve2dGeneral$1(curve, gtrsf);
5598
5777
  }
5599
5778
  intersectCurves2d(c1, c2, tolerance) {
5600
- return intersectCurves2d$1(this.oc, c1, c2, tolerance);
5779
+ return intersectCurves2d$1(c1, c2, tolerance);
5601
5780
  }
5602
5781
  projectPointOnCurve2d(curve, x, y) {
5603
- return projectPointOnCurve2d$1(this.oc, curve, x, y);
5782
+ return projectPointOnCurve2d$1(curve, x, y);
5604
5783
  }
5605
5784
  distanceBetweenCurves2d(c1, c2, p1Start, p1End, p2Start, p2End) {
5606
- return distanceBetweenCurves2d$1(this.oc, c1, c2, p1Start, p1End, p2Start, p2End);
5785
+ return distanceBetweenCurves2d$1(c1, c2, p1Start, p1End, p2Start, p2End);
5607
5786
  }
5608
5787
  approximateCurve2dAsBSpline(curve, tolerance, continuity, maxSegments) {
5609
- return approximateCurve2dAsBSpline$1(this.oc, curve, tolerance, continuity, maxSegments);
5788
+ return approximateCurve2dAsBSpline$1(curve, tolerance, continuity, maxSegments);
5610
5789
  }
5611
5790
  decomposeBSpline2dToBeziers(curve) {
5612
- return decomposeBSpline2dToBeziers$1(this.oc, curve);
5791
+ return decomposeBSpline2dToBeziers$1(curve);
5613
5792
  }
5614
5793
  createBoundingBox2d() {
5615
- return createBoundingBox2d$1(this.oc);
5794
+ return createBoundingBox2d$1();
5616
5795
  }
5617
5796
  addCurveToBBox2d(bbox, curve, tolerance) {
5618
- addCurveToBBox2d$1(this.oc, bbox, curve, tolerance);
5797
+ addCurveToBBox2d$1(bbox, curve, tolerance);
5619
5798
  }
5620
5799
  getBBox2dBounds(bbox) {
5621
- return getBBox2dBounds$1(this.oc, bbox);
5800
+ return getBBox2dBounds$1(bbox);
5622
5801
  }
5623
5802
  mergeBBox2d(target, other) {
5624
- mergeBBox2d$1(this.oc, target, other);
5803
+ mergeBBox2d$1(target, other);
5625
5804
  }
5626
5805
  isBBox2dOut(a, b) {
5627
- return isBBox2dOut$1(this.oc, a, b);
5806
+ return isBBox2dOut$1(a, b);
5628
5807
  }
5629
5808
  isBBox2dOutPoint(bbox, x, y) {
5630
- return isBBox2dOutPoint$1(this.oc, bbox, x, y);
5809
+ return isBBox2dOutPoint$1(bbox, x, y);
5631
5810
  }
5632
5811
  getCurve2dCircleData(curve) {
5633
- return getCurve2dCircleData$1(this.oc, curve);
5812
+ return getCurve2dCircleData$1(curve);
5634
5813
  }
5635
5814
  getCurve2dEllipseData(curve) {
5636
- return getCurve2dEllipseData$1(this.oc, curve);
5815
+ return getCurve2dEllipseData$1(curve);
5637
5816
  }
5638
5817
  getCurve2dBezierPoles(curve) {
5639
- return getCurve2dBezierPoles$1(this.oc, curve);
5818
+ return getCurve2dBezierPoles$1(curve);
5640
5819
  }
5641
5820
  getCurve2dBezierDegree(curve) {
5642
- return getCurve2dBezierDegree$1(this.oc, curve);
5821
+ return getCurve2dBezierDegree$1(curve);
5643
5822
  }
5644
5823
  getCurve2dBSplineData(curve) {
5645
- return getCurve2dBSplineData$1(this.oc, curve);
5824
+ return getCurve2dBSplineData$1(curve);
5646
5825
  }
5647
5826
  serializeCurve2d(curve) {
5648
- return serializeCurve2d$1(this.oc, curve);
5827
+ return serializeCurve2d$1(curve);
5649
5828
  }
5650
5829
  deserializeCurve2d(data) {
5651
- return deserializeCurve2d$1(this.oc, data);
5830
+ return deserializeCurve2d$1(data);
5652
5831
  }
5653
5832
  splitCurve2d(curve, params) {
5654
- return splitCurve2d$1(this.oc, curve, params);
5833
+ return splitCurve2d$1(curve, params);
5655
5834
  }
5656
5835
  liftCurve2dToPlane(curve, planeOrigin, planeZ, planeX) {
5657
5836
  return liftCurve2dToPlane$1(this.oc, curve, planeOrigin, planeZ, planeX);