okgeometry-api 1.15.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/NurbsCurve.ts CHANGED
@@ -239,6 +239,116 @@ export class NurbsCurve {
239
239
  return pieces;
240
240
  }
241
241
 
242
+ /**
243
+ * 2D REGION boolean between this curve and another, both CLOSED and
244
+ * COPLANAR (Rhino CurveBoolean). Closed planar curves bound regions, so
245
+ * union / subtract / intersect are well defined: the curves are projected
246
+ * onto a common plane (fitted from this curve, coplanarity verified),
247
+ * tessellated to polygons, arranged in 2D, classified by nonzero winding,
248
+ * and the result loops emitted.
249
+ *
250
+ * The result is a list of closed POLYLINE (degree-1 NURBS) curves —
251
+ * Rhino-parity fidelity, so curved input boundaries are approximated to the
252
+ * tessellation tolerance. Tessellation samples include every distinct
253
+ * interior knot value, so degree-1 polygon corners and C0 kinks are
254
+ * preserved EXACTLY, and consecutive collinear points are collapsed so
255
+ * straight runs come back as single segments. OUTER boundaries are
256
+ * counter-clockwise (positive signed area in the fitted plane); HOLE
257
+ * boundaries are clockwise. CCW is measured about a DETERMINISTIC plane
258
+ * normal: the normal fitted from THIS curve, flipped so its dominant
259
+ * world-axis component is positive (for curves in the world XY plane the
260
+ * reference normal is +Z, so outer loops are CCW viewed from +Z). The
261
+ * emitted orientation is therefore independent of either curve's drawing
262
+ * direction. Callers reconstruct the region topology by nesting (a CW loop
263
+ * inside a CCW loop is that region's hole).
264
+ *
265
+ * A valid but empty result (e.g. a disjoint intersect) returns `[]`. Throws
266
+ * on non-coplanar or OPEN input (closure is verified kernel-side: the
267
+ * curves' endpoints must coincide within a scale-relative tolerance).
268
+ *
269
+ * @param other - The other closed coplanar curve
270
+ * @param op - 0 = union, 1 = subtract (this − other), 2 = intersect
271
+ * @returns Result region boundary loops (outer CCW, holes CW)
272
+ */
273
+ private regionBoolean(other: NurbsCurve, op: number): NurbsCurve[] {
274
+ ensureInit();
275
+ const buf = wasm.curve_region_boolean(this._data, other._data, op);
276
+ // An EMPTY buffer signals an error (non-coplanar / malformed); a valid
277
+ // empty result is the non-empty [0] packing.
278
+ if (buf.length === 0) {
279
+ throw new Error(
280
+ "NurbsCurve region boolean failed — curves must be closed and coplanar",
281
+ );
282
+ }
283
+ return NurbsCurve.decodeCurveList(buf);
284
+ }
285
+
286
+ /**
287
+ * Region UNION with another closed coplanar curve. See {@link regionBoolean}.
288
+ * @param other - The other closed coplanar curve
289
+ * @returns Boundary loops of (inside-this OR inside-other), outer CCW / holes CW
290
+ */
291
+ regionUnion(other: NurbsCurve): NurbsCurve[] {
292
+ return this.regionBoolean(other, 0);
293
+ }
294
+
295
+ /**
296
+ * Region SUBTRACT (this − other) of a closed coplanar curve. Order matters.
297
+ * See {@link regionBoolean}.
298
+ * @param other - The curve subtracted from this
299
+ * @returns Boundary loops of (inside-this AND NOT inside-other)
300
+ */
301
+ regionSubtract(other: NurbsCurve): NurbsCurve[] {
302
+ return this.regionBoolean(other, 1);
303
+ }
304
+
305
+ /**
306
+ * Region INTERSECT with another closed coplanar curve. See
307
+ * {@link regionBoolean}.
308
+ * @param other - The other closed coplanar curve
309
+ * @returns Boundary loops of (inside-this AND inside-other)
310
+ */
311
+ regionIntersect(other: NurbsCurve): NurbsCurve[] {
312
+ return this.regionBoolean(other, 2);
313
+ }
314
+
315
+ /**
316
+ * Region SPLIT: partition this curve and another closed coplanar curve into
317
+ * ALL region boundaries (Rhino "region split"). The arrangement partitions
318
+ * the plane into the pieces inside-this-only, inside-other-only and
319
+ * inside-both; every bounded region's outer and hole loops come back as
320
+ * their own closed curves (outer CCW, holes CW). See {@link regionBoolean}
321
+ * for the fidelity and orientation contract.
322
+ *
323
+ * @param other - The other closed coplanar curve
324
+ * @returns All region boundary loops
325
+ */
326
+ regionSplit(other: NurbsCurve): NurbsCurve[] {
327
+ ensureInit();
328
+ const buf = wasm.curve_region_split(this._data, other._data);
329
+ if (buf.length === 0) {
330
+ throw new Error(
331
+ "NurbsCurve region split failed — curves must be closed and coplanar",
332
+ );
333
+ }
334
+ return NurbsCurve.decodeCurveList(buf);
335
+ }
336
+
337
+ /** Parse [count, (bufLen, curveData…)·count] into NurbsCurves. */
338
+ private static decodeCurveList(buf: Float64Array): NurbsCurve[] {
339
+ if (buf.length < 1) return [];
340
+ const out: NurbsCurve[] = [];
341
+ let offset = 1;
342
+ const count = Number(buf[0]);
343
+ for (let k = 0; k < count && offset < buf.length; k++) {
344
+ const len = Number(buf[offset]);
345
+ offset += 1;
346
+ out.push(NurbsCurve.fromData(buf.subarray(offset, offset + len)));
347
+ offset += len;
348
+ }
349
+ return out;
350
+ }
351
+
242
352
  /**
243
353
  * Translate this curve by an offset vector.
244
354
  * @param offset - Translation vector
package/src/index.ts CHANGED
@@ -1,79 +1,88 @@
1
- // Core initialization
2
- export { init, isInitialized } from "./engine.js";
3
-
4
- // Shared types and utilities
5
- export type {
6
- SweepableCurve,
7
- LoftableCurve,
8
- RotationAxis,
9
- CurveSegment,
10
- CurveOffsetJoinStyle,
11
- CurveOffsetOptions,
12
- } from "./types.js";
13
- export { CurveTypeCode, SegmentTypeCode } from "./types.js";
14
- export {
15
- pointsToCoords,
16
- coordsToPoints,
17
- parsePolylineBuffer,
18
- parseIntersectionPoints,
19
- } from "./BufferCodec.js";
20
-
21
- // Primitive types
22
- export { Vec3 } from "./Vec3.js";
23
- export { Point } from "./Point.js";
24
- export { Plane } from "./Plane.js";
25
- export { Ray } from "./Ray.js";
26
-
27
- // Curve types
28
- export { Line } from "./Line.js";
29
- export { Circle } from "./Circle.js";
30
- export { Arc } from "./Arc.js";
31
- export { Polyline } from "./Polyline.js";
32
- export { Polygon } from "./Polygon.js";
33
- export { PolyCurve } from "./PolyCurve.js";
34
- export { NurbsCurve } from "./NurbsCurve.js";
35
- export { NurbsSurface } from "./NurbsSurface.js";
36
- export { MeshSurface } from "./MeshSurface.js";
37
- export type { Surface } from "./Surface.js";
38
-
39
- // Boundary representation
40
- export { Brep } from "./Brep.js";
41
- export type {
42
- BrepInfo,
43
- BrepValidationReport,
44
- BrepBooleanOptions,
45
- BrepParametricBooleanOptions,
46
- MeshToBrepConversionOptions,
47
- BrepSplitSolidResult,
48
- } from "./Brep.js";
49
-
50
- // Mesh and operations
51
- export { Mesh, MeshBooleanExecutionError } from "./Mesh.js";
52
- export type {
53
- MeshBooleanOperation,
54
- MeshBooleanDebugProbeId,
55
- MeshBooleanDebugOptions,
56
- MeshBooleanDebugProbe,
57
- MeshBooleanDebugProbeSummary,
58
- MeshBooleanDebugReport,
59
- MeshBooleanReproOperand,
60
- MeshBooleanReproResult,
61
- MeshBooleanReproError,
62
- MeshBooleanReproPayload,
63
- MeshBooleanReproOptions,
64
- MeshSplitResult,
65
- MeshPlaneSplitResult,
66
- MeshPlaneSplitOptions,
67
- MeshCurveSplitOptions,
68
- MeshPlanarFace,
69
- MeshDebugBounds,
70
- MeshDebugRayHit,
71
- MeshDebugSummary,
72
- MeshBooleanLimits,
73
- MeshBooleanOptions,
74
- MeshBooleanAsyncOptions,
75
- MeshBooleanErrorCode,
76
- MeshBooleanErrorPayload,
77
- MeshBooleanProgressEvent,
78
- } from "./Mesh.js";
79
- export { intersect } from "./Geometry.js";
1
+ // Core initialization
2
+ export { init, isInitialized } from "./engine.js";
3
+
4
+ // Shared types and utilities
5
+ export type {
6
+ SweepableCurve,
7
+ LoftableCurve,
8
+ RotationAxis,
9
+ CurveSegment,
10
+ CurveOffsetJoinStyle,
11
+ CurveOffsetOptions,
12
+ } from "./types.js";
13
+ export { CurveTypeCode, SegmentTypeCode } from "./types.js";
14
+ export {
15
+ pointsToCoords,
16
+ coordsToPoints,
17
+ parsePolylineBuffer,
18
+ parseIntersectionPoints,
19
+ } from "./BufferCodec.js";
20
+
21
+ // Primitive types
22
+ export { Vec3 } from "./Vec3.js";
23
+ export { Point } from "./Point.js";
24
+ export { Plane } from "./Plane.js";
25
+ export { Ray } from "./Ray.js";
26
+
27
+ // Curve types
28
+ export { Line } from "./Line.js";
29
+ export { Circle } from "./Circle.js";
30
+ export { Arc } from "./Arc.js";
31
+ export { Polyline } from "./Polyline.js";
32
+ export { Polygon } from "./Polygon.js";
33
+ export { PolyCurve } from "./PolyCurve.js";
34
+ export { NurbsCurve } from "./NurbsCurve.js";
35
+ export { NurbsSurface } from "./NurbsSurface.js";
36
+ export { MeshSurface } from "./MeshSurface.js";
37
+ export type { Surface } from "./Surface.js";
38
+
39
+ // Boundary representation
40
+ export { Brep } from "./Brep.js";
41
+ export type {
42
+ BrepInfo,
43
+ BrepValidationReport,
44
+ BrepBooleanOptions,
45
+ BrepParametricBooleanOptions,
46
+ MeshToBrepConversionOptions,
47
+ BrepSplitSolidResult,
48
+ } from "./Brep.js";
49
+
50
+ // Mesh and operations
51
+ export { Mesh, MeshBooleanExecutionError } from "./Mesh.js";
52
+ export type {
53
+ MeshBooleanOperation,
54
+ MeshBooleanDebugProbeId,
55
+ MeshBooleanDebugOptions,
56
+ MeshBooleanDebugProbe,
57
+ MeshBooleanDebugProbeSummary,
58
+ MeshBooleanDebugReport,
59
+ MeshBooleanReproOperand,
60
+ MeshBooleanReproResult,
61
+ MeshBooleanReproError,
62
+ MeshBooleanReproPayload,
63
+ MeshBooleanReproOptions,
64
+ MeshSplitResult,
65
+ MeshPlaneSplitResult,
66
+ MeshPlaneSplitOptions,
67
+ MeshCurveSplitOptions,
68
+ MeshPlanarFace,
69
+ MeshDebugBounds,
70
+ MeshDebugRayHit,
71
+ MeshDebugSummary,
72
+ MeshBooleanLimits,
73
+ MeshBooleanOptions,
74
+ MeshBooleanAsyncOptions,
75
+ MeshBooleanErrorCode,
76
+ MeshBooleanErrorPayload,
77
+ MeshBooleanProgressEvent,
78
+ } from "./Mesh.js";
79
+ export { intersect } from "./Geometry.js";
80
+
81
+ // Universal geometry boolean dispatcher
82
+ export { geometryBoolean, geometrySplit } from "./GeometryBoolean.js";
83
+ export type {
84
+ BooleanOpKind,
85
+ BooleanOperand,
86
+ GeometryBooleanOptions,
87
+ GeometryBooleanResult,
88
+ } from "./GeometryBoolean.js";