brepkit-wasm 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/brepkit_wasm.d.ts CHANGED
@@ -99,6 +99,14 @@ export class BrepKernel {
99
99
  * Returns an error if distance is non-positive or edges are invalid.
100
100
  */
101
101
  chamfer(solid: number, edge_handles: Uint32Array, distance: number): number;
102
+ /**
103
+ * Cut corners of a 2D polygon with flat bevels.
104
+ *
105
+ * `coords` is a flat array `[x,y, x,y, ...]`.
106
+ * `distance` is the chamfer distance from each corner.
107
+ * Returns a flat array of the chamfered polygon coordinates.
108
+ */
109
+ chamfer2d(coords: Float64Array, distance: number): Float64Array;
102
110
  /**
103
111
  * Create a circular pattern of a solid around an axis.
104
112
  *
@@ -127,6 +135,25 @@ export class BrepKernel {
127
135
  * Returns "inside", "outside", or "boundary".
128
136
  */
129
137
  classifyPointWinding(solid: number, x: number, y: number, z: number, tolerance: number): string;
138
+ /**
139
+ * Find common (shared) edges between two adjacent 2D polygons.
140
+ *
141
+ * Both polygons are flat arrays `[x,y, x,y, ...]`.
142
+ * Returns a flat array of common segment endpoints `[x1,y1, x2,y2, ...]`,
143
+ * or an empty array if no common segments exist.
144
+ */
145
+ commonSegment2d(coords_a: Float64Array, coords_b: Float64Array): Float64Array;
146
+ /**
147
+ * Compose (multiply) two 4x4 transformation matrices.
148
+ *
149
+ * Returns the composed matrix as a flat 16-element array (row-major).
150
+ * This computes `a * b`, meaning `b` is applied first, then `a`.
151
+ *
152
+ * # Errors
153
+ *
154
+ * Returns an error if either matrix doesn't have 16 elements.
155
+ */
156
+ composeTransforms(matrix_a: Float64Array, matrix_b: Float64Array): Float64Array;
130
157
  /**
131
158
  * Build a convex hull solid from a point cloud.
132
159
  *
@@ -424,6 +451,14 @@ export class BrepKernel {
424
451
  * Returns an error if radius is non-positive or edges are invalid.
425
452
  */
426
453
  fillet(solid: number, edge_handles: Uint32Array, radius: number): number;
454
+ /**
455
+ * Round corners of a 2D polygon by inserting arc-approximation vertices.
456
+ *
457
+ * `coords` is a flat array `[x,y, x,y, ...]`.
458
+ * `radius` is the fillet radius.
459
+ * Returns a flat array of the filleted polygon coordinates.
460
+ */
461
+ fillet2d(coords: Float64Array, radius: number): Float64Array;
427
462
  /**
428
463
  * Apply variable-radius fillets to edges.
429
464
  *
@@ -487,6 +522,10 @@ export class BrepKernel {
487
522
  * Get the curve type of an edge.
488
523
  *
489
524
  * Returns `"LINE"`, `"BSPLINE_CURVE"`, `"CIRCLE"`, or `"ELLIPSE"`.
525
+ *
526
+ * For NURBS curves that exactly represent analytic curves, this
527
+ * returns the underlying analytic type (e.g. `"CIRCLE"` for a
528
+ * rational NURBS circle).
490
529
  */
491
530
  getEdgeCurveType(edge: number): string;
492
531
  /**
@@ -552,6 +591,13 @@ export class BrepKernel {
552
591
  * Returns an array of vertex handles (`u32[]`).
553
592
  */
554
593
  getFaceVertices(face: number): Uint32Array;
594
+ /**
595
+ * Get all wires of a face (outer wire first, then inner/hole wires).
596
+ *
597
+ * # Errors
598
+ * Returns an error if the face handle is invalid.
599
+ */
600
+ getFaceWires(face: number): Uint32Array;
555
601
  /**
556
602
  * Get the orientation of a shape.
557
603
  *
@@ -610,6 +656,10 @@ export class BrepKernel {
610
656
  *
611
657
  * Returns one of: `"plane"`, `"cylinder"`, `"cone"`, `"sphere"`,
612
658
  * `"torus"`, `"bspline"`.
659
+ *
660
+ * For NURBS surfaces that exactly represent analytic shapes, this
661
+ * returns the underlying analytic type (e.g. `"sphere"` for a NURBS
662
+ * sphere patch).
613
663
  */
614
664
  getSurfaceType(face: number): string;
615
665
  /**
@@ -681,6 +731,18 @@ export class BrepKernel {
681
731
  * Returns an error if the IGES data is malformed.
682
732
  */
683
733
  importIges(data: Uint8Array): Uint32Array;
734
+ /**
735
+ * Import a triangle mesh from flat vertex/index arrays.
736
+ *
737
+ * `positions` is a flat `[x0,y0,z0, x1,y1,z1, ...]` array.
738
+ * `indices` is a flat `[i0,i1,i2, i3,i4,i5, ...]` array of triangle
739
+ * vertex indices. Returns a solid handle.
740
+ *
741
+ * # Errors
742
+ *
743
+ * Returns an error if the arrays are malformed or mesh import fails.
744
+ */
745
+ importIndexedMesh(positions: Float64Array, indices: Uint32Array): number;
684
746
  /**
685
747
  * Import an OBJ file and return a solid handle.
686
748
  *
@@ -735,6 +797,16 @@ export class BrepKernel {
735
797
  * produces an empty result.
736
798
  */
737
799
  intersect(a: number, b: number): number;
800
+ /**
801
+ * Compute the boolean intersection of two 2D polygons.
802
+ *
803
+ * Both polygons are flat arrays `[x,y, x,y, ...]`.
804
+ * Returns a flat array of the intersection polygon coordinates,
805
+ * or an empty array if they don't intersect.
806
+ *
807
+ * Uses the Sutherland-Hodgman algorithm (convex clipper).
808
+ */
809
+ intersectPolygons2d(coords_a: Float64Array, coords_b: Float64Array): Float64Array;
738
810
  /**
739
811
  * Intersect two solids and return evolution tracking data.
740
812
  *
@@ -752,6 +824,10 @@ export class BrepKernel {
752
824
  * Returns `true` if the edge is forward in the wire, `false` if reversed.
753
825
  */
754
826
  isEdgeForwardInWire(edge: number, wire: number): boolean;
827
+ /**
828
+ * Check whether a wire is closed (last edge connects back to first).
829
+ */
830
+ isWireClosed(wire: number): boolean;
755
831
  /**
756
832
  * Create a linear pattern of a solid.
757
833
  *
@@ -788,6 +864,15 @@ export class BrepKernel {
788
864
  * different vertex counts, or surface fitting fails.
789
865
  */
790
866
  loftSmooth(faces: Uint32Array): number;
867
+ /**
868
+ * Loft profiles with options for start/end points and ruled mode.
869
+ *
870
+ * `options` is a JSON string with optional fields:
871
+ * - `startPoint: [x, y, z]` — apex point before first profile
872
+ * - `endPoint: [x, y, z]` — apex point after last profile
873
+ * - `ruled: bool` — true for ruled (linear) surfaces (default), false for smooth
874
+ */
875
+ loftWithOptions(faces: Uint32Array, options: string): number;
791
876
  /**
792
877
  * Create a box solid with the given dimensions, centered at the origin.
793
878
  *
@@ -842,6 +927,16 @@ export class BrepKernel {
842
927
  * Returns an error if radius or height is non-positive.
843
928
  */
844
929
  makeCylinder(radius: number, height: number): number;
930
+ /**
931
+ * Create an ellipsoid solid centered at the origin.
932
+ *
933
+ * Built by creating a unit sphere and scaling it by `(rx, ry, rz)`.
934
+ *
935
+ * # Errors
936
+ *
937
+ * Returns an error if any radius is non-positive.
938
+ */
939
+ makeEllipsoid(rx: number, ry: number, rz: number): number;
845
940
  /**
846
941
  * Create a planar face from a wire (computes normal from first 3 vertices).
847
942
  *
@@ -895,6 +990,13 @@ export class BrepKernel {
895
990
  * Returns a wire handle.
896
991
  */
897
992
  makeRegularPolygonWire(radius: number, n_sides: number): number;
993
+ /**
994
+ * Create a solid from a set of faces by sewing them together.
995
+ *
996
+ * Alias for `sewFaces` with a default tolerance. This is the equivalent
997
+ * of OCCT's `BRepBuilderAPI_MakeSolid`.
998
+ */
999
+ makeSolid(face_handles: Uint32Array): number;
898
1000
  /**
899
1001
  * Create a sphere solid centered at the origin.
900
1002
  *
@@ -927,6 +1029,20 @@ export class BrepKernel {
927
1029
  * Returns a wire handle (`u32`).
928
1030
  */
929
1031
  makeWire(edge_handles: Uint32Array, closed: boolean): number;
1032
+ /**
1033
+ * Measure curvature of an edge curve at parameter `t`.
1034
+ *
1035
+ * Returns `[curvature, tangent_x, tangent_y, tangent_z, normal_x, normal_y, normal_z]`.
1036
+ * Curvature is 1/radius. For lines, curvature is 0.
1037
+ */
1038
+ measureCurvatureAtEdge(edge: number, t: number): Float64Array;
1039
+ /**
1040
+ * Measure principal curvatures at (u, v) on a face surface.
1041
+ *
1042
+ * Returns `[k1, k2, d1x, d1y, d1z, d2x, d2y, d2z]` where k1/k2 are
1043
+ * principal curvatures and d1/d2 are the corresponding direction vectors.
1044
+ */
1045
+ measureCurvatureAtSurface(face: number, u: number, v: number): Float64Array;
930
1046
  /**
931
1047
  * Merge coincident vertices in a solid.
932
1048
  *
@@ -1003,6 +1119,33 @@ export class BrepKernel {
1003
1119
  * Returns an error if the face or path is invalid.
1004
1120
  */
1005
1121
  pipe(face: number, path_degree: number, path_knots: Float64Array, path_control_points: Float64Array, path_weights: Float64Array): number;
1122
+ /**
1123
+ * Test if a 2D point is inside a closed polygon.
1124
+ *
1125
+ * `polygon_coords` is a flat array `[x,y, x,y, ...]`.
1126
+ * Returns `true` if the point is inside the polygon (winding number test).
1127
+ */
1128
+ pointInPolygon2d(polygon_coords: Float64Array, px: number, py: number): boolean;
1129
+ /**
1130
+ * Compute minimum distance from a point to an edge.
1131
+ *
1132
+ * Returns `[distance, closest_x, closest_y, closest_z]`.
1133
+ *
1134
+ * # Errors
1135
+ *
1136
+ * Returns an error if the edge handle is invalid.
1137
+ */
1138
+ pointToEdgeDistance(px: number, py: number, pz: number, edge: number): Float64Array;
1139
+ /**
1140
+ * Compute minimum distance from a point to a face.
1141
+ *
1142
+ * Returns `[distance, closest_x, closest_y, closest_z]`.
1143
+ *
1144
+ * # Errors
1145
+ *
1146
+ * Returns an error if the face handle is invalid.
1147
+ */
1148
+ pointToFaceDistance(px: number, py: number, pz: number, face: number): Float64Array;
1006
1149
  /**
1007
1150
  * Compute minimum distance from a point to a solid.
1008
1151
  *
@@ -1013,6 +1156,14 @@ export class BrepKernel {
1013
1156
  * Returns an error if the solid handle is invalid.
1014
1157
  */
1015
1158
  pointToSolidDistance(px: number, py: number, pz: number, solid: number): Float64Array;
1159
+ /**
1160
+ * Test if two 2D polygons intersect (overlap).
1161
+ *
1162
+ * Both polygons are flat arrays `[x,y, x,y, ...]`.
1163
+ * Returns `true` if any vertex of one polygon is inside the other
1164
+ * or if any edges cross.
1165
+ */
1166
+ polygonsIntersect2d(coords_a: Float64Array, coords_b: Float64Array): boolean;
1016
1167
  /**
1017
1168
  * Project a 3D point onto a face surface using Newton iteration.
1018
1169
  *
@@ -1031,6 +1182,10 @@ export class BrepKernel {
1031
1182
  * Returns the number of edges removed.
1032
1183
  */
1033
1184
  removeDegenerateEdges(solid: number, tolerance: number): number;
1185
+ /**
1186
+ * Remove all holes from a face, returning a new face with only the outer wire.
1187
+ */
1188
+ removeHolesFromFace(face: number): number;
1034
1189
  /**
1035
1190
  * Validate, heal, and re-validate a solid in one pass.
1036
1191
  *
@@ -1241,6 +1396,50 @@ export class BrepKernel {
1241
1396
  * Returns an error if the solid handle is invalid or tessellation fails.
1242
1397
  */
1243
1398
  tessellateSolid(solid: number, deflection: number): JsMesh;
1399
+ /**
1400
+ * Tessellate a solid with per-face triangle grouping.
1401
+ *
1402
+ * Returns a JSON string containing `{ positions, normals, indices, faceOffsets }`.
1403
+ * `faceOffsets` is an array where `faceOffsets[i]` is the start index into
1404
+ * `indices` for face `i`, and the last element is `indices.length`.
1405
+ */
1406
+ tessellateSolidGrouped(solid: number, deflection: number): any;
1407
+ /**
1408
+ * Tessellate a solid and include per-vertex UV coordinates.
1409
+ *
1410
+ * Returns a JSON string containing `{ positions, normals, indices, uvs }`.
1411
+ * `uvs` is a flat array of `[u0, v0, u1, v1, ...]` values, two per vertex.
1412
+ * For analytic and NURBS surfaces, these are the parametric (u, v) values.
1413
+ * For planar faces, UVs are computed by projection onto the face plane.
1414
+ *
1415
+ * # Errors
1416
+ *
1417
+ * Returns an error if the solid handle is invalid or tessellation fails.
1418
+ */
1419
+ tessellateSolidUV(solid: number, deflection: number): any;
1420
+ /**
1421
+ * Thicken a face into a solid by offsetting it by the given distance.
1422
+ *
1423
+ * Creates a solid from a face by extruding it along its normal by
1424
+ * `thickness`. Positive values offset outward, negative inward.
1425
+ *
1426
+ * # Errors
1427
+ *
1428
+ * Returns an error if the face handle is invalid or thickness is zero.
1429
+ */
1430
+ thicken(face: number, thickness: number): number;
1431
+ /**
1432
+ * Serialize a solid's B-Rep topology to JSON.
1433
+ *
1434
+ * Returns a JSON string containing the solid's complete topology:
1435
+ * vertices, edges (with curve types), faces (with surface types), and
1436
+ * connectivity information.
1437
+ *
1438
+ * # Errors
1439
+ *
1440
+ * Returns an error if the solid handle is invalid.
1441
+ */
1442
+ toBREP(solid: number): any;
1244
1443
  /**
1245
1444
  * Apply a 4×4 affine transform to a solid (in place).
1246
1445
  *
@@ -1287,6 +1486,17 @@ export class BrepKernel {
1287
1486
  * Returns an error if the solid handle is invalid or tessellation fails.
1288
1487
  */
1289
1488
  volume(solid: number, deflection: number): number;
1489
+ /**
1490
+ * Weld shells and faces into a single solid by sewing.
1491
+ *
1492
+ * Accepts an array of face handles from potentially different shells.
1493
+ * Sews all faces together into a single solid.
1494
+ */
1495
+ weldShellsAndFaces(face_handles: Uint32Array, tolerance: number): number;
1496
+ /**
1497
+ * Compute the total arc-length of a wire.
1498
+ */
1499
+ wireLength(wire: number): number;
1290
1500
  }
1291
1501
 
1292
1502
  /**
@@ -279,6 +279,27 @@ export class BrepKernel {
279
279
  }
280
280
  return ret[0] >>> 0;
281
281
  }
282
+ /**
283
+ * Cut corners of a 2D polygon with flat bevels.
284
+ *
285
+ * `coords` is a flat array `[x,y, x,y, ...]`.
286
+ * `distance` is the chamfer distance from each corner.
287
+ * Returns a flat array of the chamfered polygon coordinates.
288
+ * @param {Float64Array} coords
289
+ * @param {number} distance
290
+ * @returns {Float64Array}
291
+ */
292
+ chamfer2d(coords, distance) {
293
+ const ptr0 = passArrayF64ToWasm0(coords, wasm.__wbindgen_malloc);
294
+ const len0 = WASM_VECTOR_LEN;
295
+ const ret = wasm.brepkernel_chamfer2d(this.__wbg_ptr, ptr0, len0, distance);
296
+ if (ret[3]) {
297
+ throw takeFromExternrefTable0(ret[2]);
298
+ }
299
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
300
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
301
+ return v2;
302
+ }
282
303
  /**
283
304
  * Create a circular pattern of a solid around an axis.
284
305
  *
@@ -388,6 +409,55 @@ export class BrepKernel {
388
409
  wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
389
410
  }
390
411
  }
412
+ /**
413
+ * Find common (shared) edges between two adjacent 2D polygons.
414
+ *
415
+ * Both polygons are flat arrays `[x,y, x,y, ...]`.
416
+ * Returns a flat array of common segment endpoints `[x1,y1, x2,y2, ...]`,
417
+ * or an empty array if no common segments exist.
418
+ * @param {Float64Array} coords_a
419
+ * @param {Float64Array} coords_b
420
+ * @returns {Float64Array}
421
+ */
422
+ commonSegment2d(coords_a, coords_b) {
423
+ const ptr0 = passArrayF64ToWasm0(coords_a, wasm.__wbindgen_malloc);
424
+ const len0 = WASM_VECTOR_LEN;
425
+ const ptr1 = passArrayF64ToWasm0(coords_b, wasm.__wbindgen_malloc);
426
+ const len1 = WASM_VECTOR_LEN;
427
+ const ret = wasm.brepkernel_commonSegment2d(this.__wbg_ptr, ptr0, len0, ptr1, len1);
428
+ if (ret[3]) {
429
+ throw takeFromExternrefTable0(ret[2]);
430
+ }
431
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
432
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
433
+ return v3;
434
+ }
435
+ /**
436
+ * Compose (multiply) two 4x4 transformation matrices.
437
+ *
438
+ * Returns the composed matrix as a flat 16-element array (row-major).
439
+ * This computes `a * b`, meaning `b` is applied first, then `a`.
440
+ *
441
+ * # Errors
442
+ *
443
+ * Returns an error if either matrix doesn't have 16 elements.
444
+ * @param {Float64Array} matrix_a
445
+ * @param {Float64Array} matrix_b
446
+ * @returns {Float64Array}
447
+ */
448
+ composeTransforms(matrix_a, matrix_b) {
449
+ const ptr0 = passArrayF64ToWasm0(matrix_a, wasm.__wbindgen_malloc);
450
+ const len0 = WASM_VECTOR_LEN;
451
+ const ptr1 = passArrayF64ToWasm0(matrix_b, wasm.__wbindgen_malloc);
452
+ const len1 = WASM_VECTOR_LEN;
453
+ const ret = wasm.brepkernel_composeTransforms(this.__wbg_ptr, ptr0, len0, ptr1, len1);
454
+ if (ret[3]) {
455
+ throw takeFromExternrefTable0(ret[2]);
456
+ }
457
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
458
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
459
+ return v3;
460
+ }
391
461
  /**
392
462
  * Build a convex hull solid from a point cloud.
393
463
  *
@@ -1059,6 +1129,27 @@ export class BrepKernel {
1059
1129
  }
1060
1130
  return ret[0] >>> 0;
1061
1131
  }
1132
+ /**
1133
+ * Round corners of a 2D polygon by inserting arc-approximation vertices.
1134
+ *
1135
+ * `coords` is a flat array `[x,y, x,y, ...]`.
1136
+ * `radius` is the fillet radius.
1137
+ * Returns a flat array of the filleted polygon coordinates.
1138
+ * @param {Float64Array} coords
1139
+ * @param {number} radius
1140
+ * @returns {Float64Array}
1141
+ */
1142
+ fillet2d(coords, radius) {
1143
+ const ptr0 = passArrayF64ToWasm0(coords, wasm.__wbindgen_malloc);
1144
+ const len0 = WASM_VECTOR_LEN;
1145
+ const ret = wasm.brepkernel_fillet2d(this.__wbg_ptr, ptr0, len0, radius);
1146
+ if (ret[3]) {
1147
+ throw takeFromExternrefTable0(ret[2]);
1148
+ }
1149
+ var v2 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1150
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1151
+ return v2;
1152
+ }
1062
1153
  /**
1063
1154
  * Apply variable-radius fillets to edges.
1064
1155
  *
@@ -1198,6 +1289,10 @@ export class BrepKernel {
1198
1289
  * Get the curve type of an edge.
1199
1290
  *
1200
1291
  * Returns `"LINE"`, `"BSPLINE_CURVE"`, `"CIRCLE"`, or `"ELLIPSE"`.
1292
+ *
1293
+ * For NURBS curves that exactly represent analytic curves, this
1294
+ * returns the underlying analytic type (e.g. `"CIRCLE"` for a
1295
+ * rational NURBS circle).
1201
1296
  * @param {number} edge
1202
1297
  * @returns {string}
1203
1298
  */
@@ -1358,6 +1453,23 @@ export class BrepKernel {
1358
1453
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1359
1454
  return v1;
1360
1455
  }
1456
+ /**
1457
+ * Get all wires of a face (outer wire first, then inner/hole wires).
1458
+ *
1459
+ * # Errors
1460
+ * Returns an error if the face handle is invalid.
1461
+ * @param {number} face
1462
+ * @returns {Uint32Array}
1463
+ */
1464
+ getFaceWires(face) {
1465
+ const ret = wasm.brepkernel_getFaceWires(this.__wbg_ptr, face);
1466
+ if (ret[3]) {
1467
+ throw takeFromExternrefTable0(ret[2]);
1468
+ }
1469
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
1470
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1471
+ return v1;
1472
+ }
1361
1473
  /**
1362
1474
  * Get the orientation of a shape.
1363
1475
  *
@@ -1479,6 +1591,10 @@ export class BrepKernel {
1479
1591
  *
1480
1592
  * Returns one of: `"plane"`, `"cylinder"`, `"cone"`, `"sphere"`,
1481
1593
  * `"torus"`, `"bspline"`.
1594
+ *
1595
+ * For NURBS surfaces that exactly represent analytic shapes, this
1596
+ * returns the underlying analytic type (e.g. `"sphere"` for a NURBS
1597
+ * sphere patch).
1482
1598
  * @param {number} face
1483
1599
  * @returns {string}
1484
1600
  */
@@ -1666,6 +1782,31 @@ export class BrepKernel {
1666
1782
  wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
1667
1783
  return v2;
1668
1784
  }
1785
+ /**
1786
+ * Import a triangle mesh from flat vertex/index arrays.
1787
+ *
1788
+ * `positions` is a flat `[x0,y0,z0, x1,y1,z1, ...]` array.
1789
+ * `indices` is a flat `[i0,i1,i2, i3,i4,i5, ...]` array of triangle
1790
+ * vertex indices. Returns a solid handle.
1791
+ *
1792
+ * # Errors
1793
+ *
1794
+ * Returns an error if the arrays are malformed or mesh import fails.
1795
+ * @param {Float64Array} positions
1796
+ * @param {Uint32Array} indices
1797
+ * @returns {number}
1798
+ */
1799
+ importIndexedMesh(positions, indices) {
1800
+ const ptr0 = passArrayF64ToWasm0(positions, wasm.__wbindgen_malloc);
1801
+ const len0 = WASM_VECTOR_LEN;
1802
+ const ptr1 = passArray32ToWasm0(indices, wasm.__wbindgen_malloc);
1803
+ const len1 = WASM_VECTOR_LEN;
1804
+ const ret = wasm.brepkernel_importIndexedMesh(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1805
+ if (ret[2]) {
1806
+ throw takeFromExternrefTable0(ret[1]);
1807
+ }
1808
+ return ret[0] >>> 0;
1809
+ }
1669
1810
  /**
1670
1811
  * Import an OBJ file and return a solid handle.
1671
1812
  *
@@ -1786,6 +1927,31 @@ export class BrepKernel {
1786
1927
  }
1787
1928
  return ret[0] >>> 0;
1788
1929
  }
1930
+ /**
1931
+ * Compute the boolean intersection of two 2D polygons.
1932
+ *
1933
+ * Both polygons are flat arrays `[x,y, x,y, ...]`.
1934
+ * Returns a flat array of the intersection polygon coordinates,
1935
+ * or an empty array if they don't intersect.
1936
+ *
1937
+ * Uses the Sutherland-Hodgman algorithm (convex clipper).
1938
+ * @param {Float64Array} coords_a
1939
+ * @param {Float64Array} coords_b
1940
+ * @returns {Float64Array}
1941
+ */
1942
+ intersectPolygons2d(coords_a, coords_b) {
1943
+ const ptr0 = passArrayF64ToWasm0(coords_a, wasm.__wbindgen_malloc);
1944
+ const len0 = WASM_VECTOR_LEN;
1945
+ const ptr1 = passArrayF64ToWasm0(coords_b, wasm.__wbindgen_malloc);
1946
+ const len1 = WASM_VECTOR_LEN;
1947
+ const ret = wasm.brepkernel_intersectPolygons2d(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1948
+ if (ret[3]) {
1949
+ throw takeFromExternrefTable0(ret[2]);
1950
+ }
1951
+ var v3 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
1952
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
1953
+ return v3;
1954
+ }
1789
1955
  /**
1790
1956
  * Intersect two solids and return evolution tracking data.
1791
1957
  *
@@ -1821,6 +1987,18 @@ export class BrepKernel {
1821
1987
  }
1822
1988
  return ret[0] !== 0;
1823
1989
  }
1990
+ /**
1991
+ * Check whether a wire is closed (last edge connects back to first).
1992
+ * @param {number} wire
1993
+ * @returns {boolean}
1994
+ */
1995
+ isWireClosed(wire) {
1996
+ const ret = wasm.brepkernel_isWireClosed(this.__wbg_ptr, wire);
1997
+ if (ret[2]) {
1998
+ throw takeFromExternrefTable0(ret[1]);
1999
+ }
2000
+ return ret[0] !== 0;
2001
+ }
1824
2002
  /**
1825
2003
  * Create a linear pattern of a solid.
1826
2004
  *
@@ -1890,6 +2068,28 @@ export class BrepKernel {
1890
2068
  }
1891
2069
  return ret[0] >>> 0;
1892
2070
  }
2071
+ /**
2072
+ * Loft profiles with options for start/end points and ruled mode.
2073
+ *
2074
+ * `options` is a JSON string with optional fields:
2075
+ * - `startPoint: [x, y, z]` — apex point before first profile
2076
+ * - `endPoint: [x, y, z]` — apex point after last profile
2077
+ * - `ruled: bool` — true for ruled (linear) surfaces (default), false for smooth
2078
+ * @param {Uint32Array} faces
2079
+ * @param {string} options
2080
+ * @returns {number}
2081
+ */
2082
+ loftWithOptions(faces, options) {
2083
+ const ptr0 = passArray32ToWasm0(faces, wasm.__wbindgen_malloc);
2084
+ const len0 = WASM_VECTOR_LEN;
2085
+ const ptr1 = passStringToWasm0(options, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
2086
+ const len1 = WASM_VECTOR_LEN;
2087
+ const ret = wasm.brepkernel_loftWithOptions(this.__wbg_ptr, ptr0, len0, ptr1, len1);
2088
+ if (ret[2]) {
2089
+ throw takeFromExternrefTable0(ret[1]);
2090
+ }
2091
+ return ret[0] >>> 0;
2092
+ }
1893
2093
  /**
1894
2094
  * Create a box solid with the given dimensions, centered at the origin.
1895
2095
  *
@@ -2001,6 +2201,26 @@ export class BrepKernel {
2001
2201
  }
2002
2202
  return ret[0] >>> 0;
2003
2203
  }
2204
+ /**
2205
+ * Create an ellipsoid solid centered at the origin.
2206
+ *
2207
+ * Built by creating a unit sphere and scaling it by `(rx, ry, rz)`.
2208
+ *
2209
+ * # Errors
2210
+ *
2211
+ * Returns an error if any radius is non-positive.
2212
+ * @param {number} rx
2213
+ * @param {number} ry
2214
+ * @param {number} rz
2215
+ * @returns {number}
2216
+ */
2217
+ makeEllipsoid(rx, ry, rz) {
2218
+ const ret = wasm.brepkernel_makeEllipsoid(this.__wbg_ptr, rx, ry, rz);
2219
+ if (ret[2]) {
2220
+ throw takeFromExternrefTable0(ret[1]);
2221
+ }
2222
+ return ret[0] >>> 0;
2223
+ }
2004
2224
  /**
2005
2225
  * Create a planar face from a wire (computes normal from first 3 vertices).
2006
2226
  *
@@ -2136,6 +2356,23 @@ export class BrepKernel {
2136
2356
  }
2137
2357
  return ret[0] >>> 0;
2138
2358
  }
2359
+ /**
2360
+ * Create a solid from a set of faces by sewing them together.
2361
+ *
2362
+ * Alias for `sewFaces` with a default tolerance. This is the equivalent
2363
+ * of OCCT's `BRepBuilderAPI_MakeSolid`.
2364
+ * @param {Uint32Array} face_handles
2365
+ * @returns {number}
2366
+ */
2367
+ makeSolid(face_handles) {
2368
+ const ptr0 = passArray32ToWasm0(face_handles, wasm.__wbindgen_malloc);
2369
+ const len0 = WASM_VECTOR_LEN;
2370
+ const ret = wasm.brepkernel_makeSolid(this.__wbg_ptr, ptr0, len0);
2371
+ if (ret[2]) {
2372
+ throw takeFromExternrefTable0(ret[1]);
2373
+ }
2374
+ return ret[0] >>> 0;
2375
+ }
2139
2376
  /**
2140
2377
  * Create a sphere solid centered at the origin.
2141
2378
  *
@@ -2208,6 +2445,43 @@ export class BrepKernel {
2208
2445
  }
2209
2446
  return ret[0] >>> 0;
2210
2447
  }
2448
+ /**
2449
+ * Measure curvature of an edge curve at parameter `t`.
2450
+ *
2451
+ * Returns `[curvature, tangent_x, tangent_y, tangent_z, normal_x, normal_y, normal_z]`.
2452
+ * Curvature is 1/radius. For lines, curvature is 0.
2453
+ * @param {number} edge
2454
+ * @param {number} t
2455
+ * @returns {Float64Array}
2456
+ */
2457
+ measureCurvatureAtEdge(edge, t) {
2458
+ const ret = wasm.brepkernel_measureCurvatureAtEdge(this.__wbg_ptr, edge, t);
2459
+ if (ret[3]) {
2460
+ throw takeFromExternrefTable0(ret[2]);
2461
+ }
2462
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
2463
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
2464
+ return v1;
2465
+ }
2466
+ /**
2467
+ * Measure principal curvatures at (u, v) on a face surface.
2468
+ *
2469
+ * Returns `[k1, k2, d1x, d1y, d1z, d2x, d2y, d2z]` where k1/k2 are
2470
+ * principal curvatures and d1/d2 are the corresponding direction vectors.
2471
+ * @param {number} face
2472
+ * @param {number} u
2473
+ * @param {number} v
2474
+ * @returns {Float64Array}
2475
+ */
2476
+ measureCurvatureAtSurface(face, u, v) {
2477
+ const ret = wasm.brepkernel_measureCurvatureAtSurface(this.__wbg_ptr, face, u, v);
2478
+ if (ret[3]) {
2479
+ throw takeFromExternrefTable0(ret[2]);
2480
+ }
2481
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
2482
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
2483
+ return v1;
2484
+ }
2211
2485
  /**
2212
2486
  * Merge coincident vertices in a solid.
2213
2487
  *
@@ -2404,6 +2678,71 @@ export class BrepKernel {
2404
2678
  }
2405
2679
  return ret[0] >>> 0;
2406
2680
  }
2681
+ /**
2682
+ * Test if a 2D point is inside a closed polygon.
2683
+ *
2684
+ * `polygon_coords` is a flat array `[x,y, x,y, ...]`.
2685
+ * Returns `true` if the point is inside the polygon (winding number test).
2686
+ * @param {Float64Array} polygon_coords
2687
+ * @param {number} px
2688
+ * @param {number} py
2689
+ * @returns {boolean}
2690
+ */
2691
+ pointInPolygon2d(polygon_coords, px, py) {
2692
+ const ptr0 = passArrayF64ToWasm0(polygon_coords, wasm.__wbindgen_malloc);
2693
+ const len0 = WASM_VECTOR_LEN;
2694
+ const ret = wasm.brepkernel_pointInPolygon2d(this.__wbg_ptr, ptr0, len0, px, py);
2695
+ if (ret[2]) {
2696
+ throw takeFromExternrefTable0(ret[1]);
2697
+ }
2698
+ return ret[0] !== 0;
2699
+ }
2700
+ /**
2701
+ * Compute minimum distance from a point to an edge.
2702
+ *
2703
+ * Returns `[distance, closest_x, closest_y, closest_z]`.
2704
+ *
2705
+ * # Errors
2706
+ *
2707
+ * Returns an error if the edge handle is invalid.
2708
+ * @param {number} px
2709
+ * @param {number} py
2710
+ * @param {number} pz
2711
+ * @param {number} edge
2712
+ * @returns {Float64Array}
2713
+ */
2714
+ pointToEdgeDistance(px, py, pz, edge) {
2715
+ const ret = wasm.brepkernel_pointToEdgeDistance(this.__wbg_ptr, px, py, pz, edge);
2716
+ if (ret[3]) {
2717
+ throw takeFromExternrefTable0(ret[2]);
2718
+ }
2719
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
2720
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
2721
+ return v1;
2722
+ }
2723
+ /**
2724
+ * Compute minimum distance from a point to a face.
2725
+ *
2726
+ * Returns `[distance, closest_x, closest_y, closest_z]`.
2727
+ *
2728
+ * # Errors
2729
+ *
2730
+ * Returns an error if the face handle is invalid.
2731
+ * @param {number} px
2732
+ * @param {number} py
2733
+ * @param {number} pz
2734
+ * @param {number} face
2735
+ * @returns {Float64Array}
2736
+ */
2737
+ pointToFaceDistance(px, py, pz, face) {
2738
+ const ret = wasm.brepkernel_pointToFaceDistance(this.__wbg_ptr, px, py, pz, face);
2739
+ if (ret[3]) {
2740
+ throw takeFromExternrefTable0(ret[2]);
2741
+ }
2742
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
2743
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
2744
+ return v1;
2745
+ }
2407
2746
  /**
2408
2747
  * Compute minimum distance from a point to a solid.
2409
2748
  *
@@ -2427,6 +2766,27 @@ export class BrepKernel {
2427
2766
  wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
2428
2767
  return v1;
2429
2768
  }
2769
+ /**
2770
+ * Test if two 2D polygons intersect (overlap).
2771
+ *
2772
+ * Both polygons are flat arrays `[x,y, x,y, ...]`.
2773
+ * Returns `true` if any vertex of one polygon is inside the other
2774
+ * or if any edges cross.
2775
+ * @param {Float64Array} coords_a
2776
+ * @param {Float64Array} coords_b
2777
+ * @returns {boolean}
2778
+ */
2779
+ polygonsIntersect2d(coords_a, coords_b) {
2780
+ const ptr0 = passArrayF64ToWasm0(coords_a, wasm.__wbindgen_malloc);
2781
+ const len0 = WASM_VECTOR_LEN;
2782
+ const ptr1 = passArrayF64ToWasm0(coords_b, wasm.__wbindgen_malloc);
2783
+ const len1 = WASM_VECTOR_LEN;
2784
+ const ret = wasm.brepkernel_polygonsIntersect2d(this.__wbg_ptr, ptr0, len0, ptr1, len1);
2785
+ if (ret[2]) {
2786
+ throw takeFromExternrefTable0(ret[1]);
2787
+ }
2788
+ return ret[0] !== 0;
2789
+ }
2430
2790
  /**
2431
2791
  * Project a 3D point onto a face surface using Newton iteration.
2432
2792
  *
@@ -2487,6 +2847,18 @@ export class BrepKernel {
2487
2847
  }
2488
2848
  return ret[0] >>> 0;
2489
2849
  }
2850
+ /**
2851
+ * Remove all holes from a face, returning a new face with only the outer wire.
2852
+ * @param {number} face
2853
+ * @returns {number}
2854
+ */
2855
+ removeHolesFromFace(face) {
2856
+ const ret = wasm.brepkernel_removeHolesFromFace(this.__wbg_ptr, face);
2857
+ if (ret[2]) {
2858
+ throw takeFromExternrefTable0(ret[1]);
2859
+ }
2860
+ return ret[0] >>> 0;
2861
+ }
2490
2862
  /**
2491
2863
  * Validate, heal, and re-validate a solid in one pass.
2492
2864
  *
@@ -2957,6 +3329,85 @@ export class BrepKernel {
2957
3329
  }
2958
3330
  return JsMesh.__wrap(ret[0]);
2959
3331
  }
3332
+ /**
3333
+ * Tessellate a solid with per-face triangle grouping.
3334
+ *
3335
+ * Returns a JSON string containing `{ positions, normals, indices, faceOffsets }`.
3336
+ * `faceOffsets` is an array where `faceOffsets[i]` is the start index into
3337
+ * `indices` for face `i`, and the last element is `indices.length`.
3338
+ * @param {number} solid
3339
+ * @param {number} deflection
3340
+ * @returns {any}
3341
+ */
3342
+ tessellateSolidGrouped(solid, deflection) {
3343
+ const ret = wasm.brepkernel_tessellateSolidGrouped(this.__wbg_ptr, solid, deflection);
3344
+ if (ret[2]) {
3345
+ throw takeFromExternrefTable0(ret[1]);
3346
+ }
3347
+ return takeFromExternrefTable0(ret[0]);
3348
+ }
3349
+ /**
3350
+ * Tessellate a solid and include per-vertex UV coordinates.
3351
+ *
3352
+ * Returns a JSON string containing `{ positions, normals, indices, uvs }`.
3353
+ * `uvs` is a flat array of `[u0, v0, u1, v1, ...]` values, two per vertex.
3354
+ * For analytic and NURBS surfaces, these are the parametric (u, v) values.
3355
+ * For planar faces, UVs are computed by projection onto the face plane.
3356
+ *
3357
+ * # Errors
3358
+ *
3359
+ * Returns an error if the solid handle is invalid or tessellation fails.
3360
+ * @param {number} solid
3361
+ * @param {number} deflection
3362
+ * @returns {any}
3363
+ */
3364
+ tessellateSolidUV(solid, deflection) {
3365
+ const ret = wasm.brepkernel_tessellateSolidUV(this.__wbg_ptr, solid, deflection);
3366
+ if (ret[2]) {
3367
+ throw takeFromExternrefTable0(ret[1]);
3368
+ }
3369
+ return takeFromExternrefTable0(ret[0]);
3370
+ }
3371
+ /**
3372
+ * Thicken a face into a solid by offsetting it by the given distance.
3373
+ *
3374
+ * Creates a solid from a face by extruding it along its normal by
3375
+ * `thickness`. Positive values offset outward, negative inward.
3376
+ *
3377
+ * # Errors
3378
+ *
3379
+ * Returns an error if the face handle is invalid or thickness is zero.
3380
+ * @param {number} face
3381
+ * @param {number} thickness
3382
+ * @returns {number}
3383
+ */
3384
+ thicken(face, thickness) {
3385
+ const ret = wasm.brepkernel_thicken(this.__wbg_ptr, face, thickness);
3386
+ if (ret[2]) {
3387
+ throw takeFromExternrefTable0(ret[1]);
3388
+ }
3389
+ return ret[0] >>> 0;
3390
+ }
3391
+ /**
3392
+ * Serialize a solid's B-Rep topology to JSON.
3393
+ *
3394
+ * Returns a JSON string containing the solid's complete topology:
3395
+ * vertices, edges (with curve types), faces (with surface types), and
3396
+ * connectivity information.
3397
+ *
3398
+ * # Errors
3399
+ *
3400
+ * Returns an error if the solid handle is invalid.
3401
+ * @param {number} solid
3402
+ * @returns {any}
3403
+ */
3404
+ toBREP(solid) {
3405
+ const ret = wasm.brepkernel_toBREP(this.__wbg_ptr, solid);
3406
+ if (ret[2]) {
3407
+ throw takeFromExternrefTable0(ret[1]);
3408
+ }
3409
+ return takeFromExternrefTable0(ret[0]);
3410
+ }
2960
3411
  /**
2961
3412
  * Apply a 4×4 affine transform to a solid (in place).
2962
3413
  *
@@ -3048,6 +3499,36 @@ export class BrepKernel {
3048
3499
  }
3049
3500
  return ret[0];
3050
3501
  }
3502
+ /**
3503
+ * Weld shells and faces into a single solid by sewing.
3504
+ *
3505
+ * Accepts an array of face handles from potentially different shells.
3506
+ * Sews all faces together into a single solid.
3507
+ * @param {Uint32Array} face_handles
3508
+ * @param {number} tolerance
3509
+ * @returns {number}
3510
+ */
3511
+ weldShellsAndFaces(face_handles, tolerance) {
3512
+ const ptr0 = passArray32ToWasm0(face_handles, wasm.__wbindgen_malloc);
3513
+ const len0 = WASM_VECTOR_LEN;
3514
+ const ret = wasm.brepkernel_weldShellsAndFaces(this.__wbg_ptr, ptr0, len0, tolerance);
3515
+ if (ret[2]) {
3516
+ throw takeFromExternrefTable0(ret[1]);
3517
+ }
3518
+ return ret[0] >>> 0;
3519
+ }
3520
+ /**
3521
+ * Compute the total arc-length of a wire.
3522
+ * @param {number} wire
3523
+ * @returns {number}
3524
+ */
3525
+ wireLength(wire) {
3526
+ const ret = wasm.brepkernel_wireLength(this.__wbg_ptr, wire);
3527
+ if (ret[2]) {
3528
+ throw takeFromExternrefTable0(ret[1]);
3529
+ }
3530
+ return ret[0];
3531
+ }
3051
3532
  }
3052
3533
  if (Symbol.dispose) BrepKernel.prototype[Symbol.dispose] = BrepKernel.prototype.free;
3053
3534
 
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "brepkit-wasm",
3
3
  "type": "module",
4
4
  "description": "WebAssembly bindings for brepkit — browser-native B-Rep solid modeling",
5
- "version": "0.5.1",
5
+ "version": "0.5.3",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",