okgeometry-api 1.6.0 → 1.9.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/dist/Brep.d.ts ADDED
@@ -0,0 +1,177 @@
1
+ import { Point } from "./Point.js";
2
+ import { Vec3 } from "./Vec3.js";
3
+ import { Plane } from "./Plane.js";
4
+ import { Mesh, type MeshBooleanOptions } from "./Mesh.js";
5
+ import { Polyline } from "./Polyline.js";
6
+ import { NurbsCurve } from "./NurbsCurve.js";
7
+ import { NurbsSurface } from "./NurbsSurface.js";
8
+ /** Options for Brep boolean operations. */
9
+ export interface BrepBooleanOptions extends MeshBooleanOptions {
10
+ /**
11
+ * Chordal deviation tolerance used to tessellate BREP operands before the
12
+ * boolean runs (model units). Defaults to 0.005, matching `toMesh()`.
13
+ */
14
+ tolerance?: number;
15
+ }
16
+ /** Options for PARAMETRIC Brep booleans (exact SSI, BREP result). */
17
+ export interface BrepParametricBooleanOptions {
18
+ /**
19
+ * Absolute geometric tolerance for intersection edges and coincident-face
20
+ * classification (model units). Defaults to 1e-6.
21
+ */
22
+ tolerance?: number;
23
+ }
24
+ /** Validation report for a BREP body. */
25
+ export interface BrepValidationReport {
26
+ isClosed: boolean;
27
+ boundaryEdgeCount: number;
28
+ maxCoherenceError: number;
29
+ issues: string[];
30
+ }
31
+ /** Structure summary of a BREP body. */
32
+ export interface BrepInfo {
33
+ faceCount: number;
34
+ edgeCount: number;
35
+ vertexCount: number;
36
+ isClosed: boolean;
37
+ }
38
+ /**
39
+ * Boundary representation (BREP) solid or sheet backed by the WASM kernel.
40
+ *
41
+ * A Brep is a graph of faces (trimmed exact surfaces — planes or NURBS),
42
+ * edges (exact 3D curves shared between faces) and vertices. Unlike a Mesh,
43
+ * the geometry stays EXACT: a cylinder face is a true rational surface, and
44
+ * tessellation density is a display decision made at query time.
45
+ *
46
+ * Topology is carried as JSON (kernel-defined schema) so it can persist in
47
+ * documents; tessellation and queries are binary WASM calls.
48
+ */
49
+ export declare class Brep {
50
+ readonly json: string;
51
+ private _info;
52
+ private constructor();
53
+ /** Restore a Brep from its JSON representation. */
54
+ static fromJson(json: string): Brep;
55
+ /** Exact BREP box between two corners (6 planar faces, 12 edges, 8 vertices). */
56
+ static box(min: Point, max: Point): Brep;
57
+ /** Exact BREP cylinder (rational side surface + planar caps). */
58
+ static cylinder(base: Point, axis: Vec3, radius: number, height: number): Brep;
59
+ /** Exact BREP sphere (single rational face, degenerate poles). */
60
+ static sphere(center: Point, radius: number): Brep;
61
+ /** Exact BREP cone or frustum (radius1 = 0 produces an apex). */
62
+ static cone(base: Point, axis: Vec3, radius0: number, radius1: number, height: number): Brep;
63
+ /** Exact BREP torus (single rational face, axis +Z through center). */
64
+ static torus(center: Point, major: number, minor: number): Brep;
65
+ private static fromPrimitive;
66
+ /**
67
+ * Extrude a planar profile curve. Closed profiles produce a capped solid
68
+ * with proper shared-edge topology; open profiles produce a sheet.
69
+ */
70
+ static extrude(profile: NurbsCurve, direction: Vec3, height: number): Brep;
71
+ /**
72
+ * Revolve a profile curve around an axis.
73
+ * Full revolutions of closed profiles produce torus-like single-face solids;
74
+ * open profiles with on-axis endpoints close at the poles (sphere/cone style);
75
+ * partial revolutions of closed planar profiles get planar caps.
76
+ */
77
+ static revolve(profile: NurbsCurve, origin: Point, axis: Vec3, angle: number): Brep;
78
+ /** Loft through profile curves (compatibility handled automatically). */
79
+ static loft(profiles: NurbsCurve[]): Brep;
80
+ /** Untrimmed sheet BREP from a NURBS surface (4 boundary edges). */
81
+ static fromSurface(surface: NurbsSurface): Brep;
82
+ /** Face/edge/vertex counts and closedness (cached). */
83
+ get info(): BrepInfo;
84
+ get faceCount(): number;
85
+ get edgeCount(): number;
86
+ /** Whether every non-degenerate edge is shared by exactly two faces (solid). */
87
+ isClosed(): boolean;
88
+ /**
89
+ * Tessellate the whole body into a triangle mesh. Adjacent faces share the
90
+ * same edge samples, so the result is crack-free (watertight for solids).
91
+ * @param tolerance - Chordal deviation tolerance (model units)
92
+ */
93
+ tessellate(tolerance?: number): Mesh;
94
+ /** Tessellate a single face into a triangle mesh. */
95
+ tessellateFace(faceIndex: number, tolerance?: number): Mesh;
96
+ /** Exact model edges sampled as polylines (feature curves for display/selection). */
97
+ edges(tolerance?: number): Polyline[];
98
+ /**
99
+ * Exact backing surface of a face: a NurbsSurface for curved faces, a Plane
100
+ * for planar faces.
101
+ */
102
+ faceSurface(faceIndex: number): NurbsSurface | Plane;
103
+ /**
104
+ * Exact iso-parametric curve of a curved face's backing surface.
105
+ * Returns null for planar faces.
106
+ * @param t - Normalized parameter [0, 1]
107
+ * @param direction - "u" extracts along u at constant v=t; "v" the converse
108
+ */
109
+ faceIsoCurve(faceIndex: number, t: number, direction: "u" | "v"): NurbsCurve | null;
110
+ /** Apply a row-major 4x4 matrix to all geometry (exact). */
111
+ applyMatrix(matrix: number[] | Float64Array): Brep;
112
+ /** Translate the body. */
113
+ translate(offset: Vec3): Brep;
114
+ /** Validate topology and trim coherence. */
115
+ validate(tolerance?: number): BrepValidationReport;
116
+ /** Volume and surface area (from tessellation at the given tolerance). */
117
+ volumeArea(tolerance?: number): {
118
+ volume: number;
119
+ area: number;
120
+ };
121
+ /** Convert to a mesh body (e.g. for boolean operations with meshes). */
122
+ toMesh(tolerance?: number): Mesh;
123
+ private static resolveBooleanOperand;
124
+ private runBoolean;
125
+ /**
126
+ * Boolean union with another Brep or Mesh.
127
+ *
128
+ * Both operands are tessellated at `options.tolerance` (BREP tessellation
129
+ * is crack-free, so closed bodies stay watertight) and combined with the
130
+ * mesh CSG pipeline. The result is a Mesh — exact trimmed-BREP boolean
131
+ * output is not supported. Requires both bodies to be closed solids.
132
+ */
133
+ union(other: Brep | Mesh, options?: BrepBooleanOptions): Mesh;
134
+ /**
135
+ * Boolean subtraction (this − other) with another Brep or Mesh.
136
+ *
137
+ * Closed − closed runs full CSG; an open sheet Brep minus a closed solid
138
+ * trims the sheet (split, keep outside). The result is a Mesh.
139
+ */
140
+ subtract(other: Brep | Mesh, options?: BrepBooleanOptions): Mesh;
141
+ /**
142
+ * Boolean intersection with another Brep or Mesh.
143
+ *
144
+ * Closed ∩ closed returns the shared volume; an open sheet Brep ∩ a closed
145
+ * solid trims the sheet (split, keep inside). The result is a Mesh.
146
+ */
147
+ intersect(other: Brep | Mesh, options?: BrepBooleanOptions): Mesh;
148
+ /**
149
+ * Intersection CURVES with another Brep or Mesh — the polylines where the
150
+ * two surfaces cross (no volume classification). Tolerance controls the
151
+ * tessellation density of both operands.
152
+ */
153
+ intersectCurves(other: Brep | Mesh, tolerance?: number): Polyline[];
154
+ private runParametricBoolean;
155
+ /**
156
+ * PARAMETRIC boolean union: exact surface–surface intersection curves with
157
+ * trimmed-surface output. Result faces keep their parents' exact surfaces
158
+ * (planes/NURBS, untessellated); intersection edges are Newton-refined SSI
159
+ * curves stored as tolerant NURBS edges with matched pcurves on both
160
+ * adjacent faces. Both operands must be CLOSED solids.
161
+ *
162
+ * `options.tolerance` is the absolute geometric tolerance of intersection
163
+ * edges and coincident-face classification (default 1e-6).
164
+ *
165
+ * Known limitation: exactly tangential surface contact (e.g. equal-radius
166
+ * cylinders touching along a line/point) is not resolved into pinch
167
+ * topology; transversal and coincident (coplanar) configurations are exact.
168
+ */
169
+ unionBrep(other: Brep, options?: BrepParametricBooleanOptions): Brep;
170
+ /** PARAMETRIC boolean subtraction (this − other). See {@link unionBrep}. */
171
+ subtractBrep(other: Brep, options?: BrepParametricBooleanOptions): Brep;
172
+ /** PARAMETRIC boolean intersection. See {@link unionBrep}. */
173
+ intersectBrep(other: Brep, options?: BrepParametricBooleanOptions): Brep;
174
+ /** JSON representation (persistence). */
175
+ toJson(): string;
176
+ }
177
+ //# sourceMappingURL=Brep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Brep.d.ts","sourceRoot":"","sources":["../src/Brep.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,IAAI,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,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,4BAA4B,GAAG,IAAI;IAIpE,4EAA4E;IAC5E,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,4BAA4B,GAAG,IAAI;IAIvE,8DAA8D;IAC9D,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,4BAA4B,GAAG,IAAI;IAIxE,yCAAyC;IACzC,MAAM,IAAI,MAAM;CAGjB"}
package/dist/Brep.js ADDED
@@ -0,0 +1,368 @@
1
+ import { ensureInit } from "./engine.js";
2
+ import { Point } from "./Point.js";
3
+ import { Vec3 } from "./Vec3.js";
4
+ import { Plane } from "./Plane.js";
5
+ import { Mesh } from "./Mesh.js";
6
+ import { Polyline } from "./Polyline.js";
7
+ import { NurbsCurve } from "./NurbsCurve.js";
8
+ import { NurbsSurface } from "./NurbsSurface.js";
9
+ import * as wasm from "./wasm-bindings.js";
10
+ /**
11
+ * Boundary representation (BREP) solid or sheet backed by the WASM kernel.
12
+ *
13
+ * A Brep is a graph of faces (trimmed exact surfaces — planes or NURBS),
14
+ * edges (exact 3D curves shared between faces) and vertices. Unlike a Mesh,
15
+ * the geometry stays EXACT: a cylinder face is a true rational surface, and
16
+ * tessellation density is a display decision made at query time.
17
+ *
18
+ * Topology is carried as JSON (kernel-defined schema) so it can persist in
19
+ * documents; tessellation and queries are binary WASM calls.
20
+ */
21
+ export class Brep {
22
+ constructor(json) {
23
+ this.json = json;
24
+ this._info = null;
25
+ if (!json)
26
+ throw new Error("Brep: empty body");
27
+ }
28
+ // ── Constructors ──
29
+ /** Restore a Brep from its JSON representation. */
30
+ static fromJson(json) {
31
+ return new Brep(json);
32
+ }
33
+ /** Exact BREP box between two corners (6 planar faces, 12 edges, 8 vertices). */
34
+ static box(min, max) {
35
+ ensureInit();
36
+ return Brep.fromPrimitive("box", [min.x, min.y, min.z, max.x, max.y, max.z]);
37
+ }
38
+ /** Exact BREP cylinder (rational side surface + planar caps). */
39
+ static cylinder(base, axis, radius, height) {
40
+ ensureInit();
41
+ return Brep.fromPrimitive("cylinder", [
42
+ base.x, base.y, base.z, axis.x, axis.y, axis.z, radius, height,
43
+ ]);
44
+ }
45
+ /** Exact BREP sphere (single rational face, degenerate poles). */
46
+ static sphere(center, radius) {
47
+ ensureInit();
48
+ return Brep.fromPrimitive("sphere", [center.x, center.y, center.z, radius]);
49
+ }
50
+ /** Exact BREP cone or frustum (radius1 = 0 produces an apex). */
51
+ static cone(base, axis, radius0, radius1, height) {
52
+ ensureInit();
53
+ return Brep.fromPrimitive("cone", [
54
+ base.x, base.y, base.z, axis.x, axis.y, axis.z, radius0, radius1, height,
55
+ ]);
56
+ }
57
+ /** Exact BREP torus (single rational face, axis +Z through center). */
58
+ static torus(center, major, minor) {
59
+ ensureInit();
60
+ return Brep.fromPrimitive("torus", [center.x, center.y, center.z, major, minor]);
61
+ }
62
+ static fromPrimitive(kind, params) {
63
+ const json = wasm.brep_primitive(kind, new Float64Array(params));
64
+ if (!json)
65
+ throw new Error(`Brep.${kind} construction failed`);
66
+ return new Brep(json);
67
+ }
68
+ /**
69
+ * Extrude a planar profile curve. Closed profiles produce a capped solid
70
+ * with proper shared-edge topology; open profiles produce a sheet.
71
+ */
72
+ static extrude(profile, direction, height) {
73
+ ensureInit();
74
+ const json = wasm.brep_extrude_curve(profile.data, direction.x, direction.y, direction.z, height);
75
+ if (!json)
76
+ throw new Error("Brep.extrude failed (profile must be planar)");
77
+ return new Brep(json);
78
+ }
79
+ /**
80
+ * Revolve a profile curve around an axis.
81
+ * Full revolutions of closed profiles produce torus-like single-face solids;
82
+ * open profiles with on-axis endpoints close at the poles (sphere/cone style);
83
+ * partial revolutions of closed planar profiles get planar caps.
84
+ */
85
+ static revolve(profile, origin, axis, angle) {
86
+ ensureInit();
87
+ const json = wasm.brep_revolve_curve(profile.data, origin.x, origin.y, origin.z, axis.x, axis.y, axis.z, angle);
88
+ if (!json)
89
+ throw new Error("Brep.revolve failed");
90
+ return new Brep(json);
91
+ }
92
+ /** Loft through profile curves (compatibility handled automatically). */
93
+ static loft(profiles) {
94
+ ensureInit();
95
+ if (profiles.length < 2)
96
+ throw new Error("Brep.loft needs at least 2 profiles");
97
+ const parts = [profiles.length];
98
+ for (const c of profiles) {
99
+ const d = c.data;
100
+ for (let i = 0; i < d.length; i++)
101
+ parts.push(d[i]);
102
+ }
103
+ const json = wasm.brep_loft_curves(new Float64Array(parts));
104
+ if (!json)
105
+ throw new Error("Brep.loft failed");
106
+ return new Brep(json);
107
+ }
108
+ /** Untrimmed sheet BREP from a NURBS surface (4 boundary edges). */
109
+ static fromSurface(surface) {
110
+ ensureInit();
111
+ const json = wasm.brep_sheet_from_surface(surface.data);
112
+ if (!json)
113
+ throw new Error("Brep.fromSurface failed");
114
+ return new Brep(json);
115
+ }
116
+ // ── Structure ──
117
+ /** Face/edge/vertex counts and closedness (cached). */
118
+ get info() {
119
+ if (!this._info) {
120
+ ensureInit();
121
+ const r = wasm.brep_info(this.json);
122
+ if (r.length < 4)
123
+ throw new Error("Brep.info failed");
124
+ this._info = {
125
+ faceCount: Number(r[0]),
126
+ edgeCount: Number(r[1]),
127
+ vertexCount: Number(r[2]),
128
+ isClosed: r[3] > 0.5,
129
+ };
130
+ }
131
+ return this._info;
132
+ }
133
+ get faceCount() {
134
+ return this.info.faceCount;
135
+ }
136
+ get edgeCount() {
137
+ return this.info.edgeCount;
138
+ }
139
+ /** Whether every non-degenerate edge is shared by exactly two faces (solid). */
140
+ isClosed() {
141
+ return this.info.isClosed;
142
+ }
143
+ // ── Tessellation / display ──
144
+ /**
145
+ * Tessellate the whole body into a triangle mesh. Adjacent faces share the
146
+ * same edge samples, so the result is crack-free (watertight for solids).
147
+ * @param tolerance - Chordal deviation tolerance (model units)
148
+ */
149
+ tessellate(tolerance = 0.01) {
150
+ ensureInit();
151
+ const buf = wasm.brep_tessellate(this.json, tolerance);
152
+ if (buf.length < 1)
153
+ throw new Error("Brep.tessellate failed");
154
+ return Mesh.fromBuffer(buf);
155
+ }
156
+ /** Tessellate a single face into a triangle mesh. */
157
+ tessellateFace(faceIndex, tolerance = 0.01) {
158
+ ensureInit();
159
+ const buf = wasm.brep_face_tessellate(this.json, faceIndex, tolerance);
160
+ if (buf.length < 1)
161
+ throw new Error(`Brep.tessellateFace(${faceIndex}) failed`);
162
+ return Mesh.fromBuffer(buf);
163
+ }
164
+ /** Exact model edges sampled as polylines (feature curves for display/selection). */
165
+ edges(tolerance = 0.01) {
166
+ ensureInit();
167
+ const buf = wasm.brep_edges(this.json, tolerance);
168
+ if (buf.length < 1)
169
+ return [];
170
+ const out = [];
171
+ let idx = 1;
172
+ const count = Number(buf[0]);
173
+ for (let i = 0; i < count; i++) {
174
+ const n = Number(buf[idx++]);
175
+ const pts = [];
176
+ for (let k = 0; k < n; k++) {
177
+ pts.push(new Point(buf[idx], buf[idx + 1], buf[idx + 2]));
178
+ idx += 3;
179
+ }
180
+ if (pts.length >= 2)
181
+ out.push(new Polyline(pts));
182
+ }
183
+ return out;
184
+ }
185
+ // ── Face geometry ──
186
+ /**
187
+ * Exact backing surface of a face: a NurbsSurface for curved faces, a Plane
188
+ * for planar faces.
189
+ */
190
+ faceSurface(faceIndex) {
191
+ ensureInit();
192
+ const buf = wasm.brep_face_surface(this.json, faceIndex);
193
+ if (buf.length < 1)
194
+ throw new Error(`Brep.faceSurface(${faceIndex}) failed`);
195
+ if (Number(buf[0]) === 0) {
196
+ if (buf.length < 10)
197
+ throw new Error("Brep.faceSurface: bad plane data");
198
+ const origin = new Point(buf[1], buf[2], buf[3]);
199
+ const uDir = new Vec3(buf[4], buf[5], buf[6]);
200
+ const vDir = new Vec3(buf[7], buf[8], buf[9]);
201
+ const normal = uDir.cross(vDir);
202
+ return new Plane(origin, normal, uDir);
203
+ }
204
+ return NurbsSurface.fromData(buf.slice(1));
205
+ }
206
+ /**
207
+ * Exact iso-parametric curve of a curved face's backing surface.
208
+ * Returns null for planar faces.
209
+ * @param t - Normalized parameter [0, 1]
210
+ * @param direction - "u" extracts along u at constant v=t; "v" the converse
211
+ */
212
+ faceIsoCurve(faceIndex, t, direction) {
213
+ ensureInit();
214
+ const buf = wasm.brep_face_iso_curve(this.json, faceIndex, t, direction === "u");
215
+ if (buf.length < 2)
216
+ return null;
217
+ return NurbsCurve.fromData(buf);
218
+ }
219
+ // ── Transforms ──
220
+ /** Apply a row-major 4x4 matrix to all geometry (exact). */
221
+ applyMatrix(matrix) {
222
+ ensureInit();
223
+ if (matrix.length < 16)
224
+ throw new Error("Brep.applyMatrix: need 16 entries");
225
+ const json = wasm.brep_transform(this.json, new Float64Array(matrix));
226
+ if (!json)
227
+ throw new Error("Brep.applyMatrix failed");
228
+ return new Brep(json);
229
+ }
230
+ /** Translate the body. */
231
+ translate(offset) {
232
+ return this.applyMatrix([
233
+ 1, 0, 0, offset.x,
234
+ 0, 1, 0, offset.y,
235
+ 0, 0, 1, offset.z,
236
+ 0, 0, 0, 1,
237
+ ]);
238
+ }
239
+ // ── Analysis ──
240
+ /** Validate topology and trim coherence. */
241
+ validate(tolerance = 1e-7) {
242
+ ensureInit();
243
+ const json = wasm.brep_validate(this.json, tolerance);
244
+ if (!json)
245
+ throw new Error("Brep.validate failed");
246
+ return JSON.parse(json);
247
+ }
248
+ /** Volume and surface area (from tessellation at the given tolerance). */
249
+ volumeArea(tolerance = 0.001) {
250
+ ensureInit();
251
+ const r = wasm.brep_volume_area(this.json, tolerance);
252
+ if (r.length < 2)
253
+ throw new Error("Brep.volumeArea failed");
254
+ return { volume: r[0], area: r[1] };
255
+ }
256
+ /** Convert to a mesh body (e.g. for boolean operations with meshes). */
257
+ toMesh(tolerance = 0.005) {
258
+ return this.tessellate(tolerance);
259
+ }
260
+ // ── Booleans ──
261
+ static resolveBooleanOperand(other, tolerance) {
262
+ return other instanceof Mesh ? other : other.toMesh(tolerance);
263
+ }
264
+ runBoolean(other, op, options) {
265
+ const tolerance = options?.tolerance ?? 0.005;
266
+ // The mesh CSG pipeline is sensitive to specific tessellation densities on
267
+ // curved (especially rational) surfaces; a failed run usually succeeds at
268
+ // a slightly perturbed density. Retry with nudged (coarser — finer risks
269
+ // the face-count safety limits) tolerances before giving up; accuracy
270
+ // stays within the requested band.
271
+ const attempts = [1.0, 1.12, 1.25, 1.4];
272
+ let lastError;
273
+ for (const factor of attempts) {
274
+ const tol = tolerance * factor;
275
+ try {
276
+ const lhs = this.toMesh(tol);
277
+ const rhs = Brep.resolveBooleanOperand(other, tol);
278
+ return lhs[op](rhs, options);
279
+ }
280
+ catch (e) {
281
+ lastError = e;
282
+ }
283
+ }
284
+ throw lastError;
285
+ }
286
+ /**
287
+ * Boolean union with another Brep or Mesh.
288
+ *
289
+ * Both operands are tessellated at `options.tolerance` (BREP tessellation
290
+ * is crack-free, so closed bodies stay watertight) and combined with the
291
+ * mesh CSG pipeline. The result is a Mesh — exact trimmed-BREP boolean
292
+ * output is not supported. Requires both bodies to be closed solids.
293
+ */
294
+ union(other, options) {
295
+ return this.runBoolean(other, "union", options);
296
+ }
297
+ /**
298
+ * Boolean subtraction (this − other) with another Brep or Mesh.
299
+ *
300
+ * Closed − closed runs full CSG; an open sheet Brep minus a closed solid
301
+ * trims the sheet (split, keep outside). The result is a Mesh.
302
+ */
303
+ subtract(other, options) {
304
+ return this.runBoolean(other, "subtract", options);
305
+ }
306
+ /**
307
+ * Boolean intersection with another Brep or Mesh.
308
+ *
309
+ * Closed ∩ closed returns the shared volume; an open sheet Brep ∩ a closed
310
+ * solid trims the sheet (split, keep inside). The result is a Mesh.
311
+ */
312
+ intersect(other, options) {
313
+ return this.runBoolean(other, "intersect", options);
314
+ }
315
+ /**
316
+ * Intersection CURVES with another Brep or Mesh — the polylines where the
317
+ * two surfaces cross (no volume classification). Tolerance controls the
318
+ * tessellation density of both operands.
319
+ */
320
+ intersectCurves(other, tolerance = 0.005) {
321
+ const lhs = this.toMesh(tolerance);
322
+ const rhs = Brep.resolveBooleanOperand(other, tolerance);
323
+ return lhs.intersectMesh(rhs);
324
+ }
325
+ // ── Parametric booleans (BREP → BREP) ──
326
+ runParametricBoolean(other, op, options) {
327
+ ensureInit();
328
+ const tolerance = options?.tolerance ?? 1e-6;
329
+ const json = wasm.brep_boolean_op(this.json, other.json, op, tolerance);
330
+ if (!json)
331
+ throw new Error(`Brep.${op}Brep failed`);
332
+ if (json.startsWith('{"error"')) {
333
+ const parsed = JSON.parse(json);
334
+ throw new Error(`Brep.${op}Brep failed: ${parsed.error}`);
335
+ }
336
+ return new Brep(json);
337
+ }
338
+ /**
339
+ * PARAMETRIC boolean union: exact surface–surface intersection curves with
340
+ * trimmed-surface output. Result faces keep their parents' exact surfaces
341
+ * (planes/NURBS, untessellated); intersection edges are Newton-refined SSI
342
+ * curves stored as tolerant NURBS edges with matched pcurves on both
343
+ * adjacent faces. Both operands must be CLOSED solids.
344
+ *
345
+ * `options.tolerance` is the absolute geometric tolerance of intersection
346
+ * edges and coincident-face classification (default 1e-6).
347
+ *
348
+ * Known limitation: exactly tangential surface contact (e.g. equal-radius
349
+ * cylinders touching along a line/point) is not resolved into pinch
350
+ * topology; transversal and coincident (coplanar) configurations are exact.
351
+ */
352
+ unionBrep(other, options) {
353
+ return this.runParametricBoolean(other, "union", options);
354
+ }
355
+ /** PARAMETRIC boolean subtraction (this − other). See {@link unionBrep}. */
356
+ subtractBrep(other, options) {
357
+ return this.runParametricBoolean(other, "subtract", options);
358
+ }
359
+ /** PARAMETRIC boolean intersection. See {@link unionBrep}. */
360
+ intersectBrep(other, options) {
361
+ return this.runParametricBoolean(other, "intersect", options);
362
+ }
363
+ /** JSON representation (persistence). */
364
+ toJson() {
365
+ return this.json;
366
+ }
367
+ }
368
+ //# sourceMappingURL=Brep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Brep.js","sourceRoot":"","sources":["../src/Brep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC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,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,KAAW,EAAE,OAAsC;QAC3D,OAAO,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED,4EAA4E;IAC5E,YAAY,CAAC,KAAW,EAAE,OAAsC;QAC9D,OAAO,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC;IAED,8DAA8D;IAC9D,aAAa,CAAC,KAAW,EAAE,OAAsC;QAC/D,OAAO,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IAED,yCAAyC;IACzC,MAAM;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF"}
package/dist/Mesh.d.ts CHANGED
@@ -497,7 +497,12 @@ export declare class Mesh {
497
497
  static sweepCurves(profile: SweepableCurve, path: SweepableCurve, segments?: number, caps?: boolean): Mesh;
498
498
  /** Encode a curve into the WASM format for sweep_curves. */
499
499
  private static encodeCurve;
500
- private static mergeMeshes;
500
+ /**
501
+ * Concatenate meshes into one multi-component mesh (buffer merge with
502
+ * index offsetting — no welding and no CSG). Useful for collecting split
503
+ * pieces back into a single body.
504
+ */
505
+ static mergeMeshes(meshes: Mesh[]): Mesh;
501
506
  /**
502
507
  * Raycast against many meshes and return all hits sorted by distance.
503
508
  */
@@ -656,6 +661,21 @@ export declare class Mesh {
656
661
  * @returns Array of polylines representing intersection curves
657
662
  */
658
663
  intersectMesh(other: Mesh): Polyline[];
664
+ /**
665
+ * Clip a polyline against this CLOSED mesh volume — boolean intersection
666
+ * semantics for curves. The polyline is split at every crossing with the
667
+ * mesh surface; pieces inside the volume land in `inside`, the rest in
668
+ * `outside`. Closed loops merge the piece spanning the loop seam, and a
669
+ * loop that never crosses the mesh comes back as one closed polyline.
670
+ *
671
+ * @param polyline - Polyline (closedness inferred) or raw point list
672
+ * @param closed - Treat the points as a closed loop (defaults to the
673
+ * polyline's own closedness; required when passing a raw point list)
674
+ */
675
+ clipPolyline(polyline: Polyline | Point[], closed?: boolean): {
676
+ inside: Polyline[];
677
+ outside: Polyline[];
678
+ };
659
679
  /**
660
680
  * Apply a 4x4 transformation matrix.
661
681
  * @param matrix - Row-major flat array of 16 numbers