okgeometry-api 1.1.6 → 1.1.7

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 (52) hide show
  1. package/dist/Arc.js +1 -1
  2. package/dist/Arc.js.map +1 -1
  3. package/dist/Circle.js +1 -1
  4. package/dist/Circle.js.map +1 -1
  5. package/dist/Line.js +1 -1
  6. package/dist/Line.js.map +1 -1
  7. package/dist/Mesh.d.ts +101 -4
  8. package/dist/Mesh.d.ts.map +1 -1
  9. package/dist/Mesh.js +103 -5
  10. package/dist/Mesh.js.map +1 -1
  11. package/dist/NurbsCurve.js +1 -1
  12. package/dist/NurbsCurve.js.map +1 -1
  13. package/dist/NurbsSurface.d.ts.map +1 -1
  14. package/dist/NurbsSurface.js +10 -7
  15. package/dist/NurbsSurface.js.map +1 -1
  16. package/dist/PolyCurve.js +1 -1
  17. package/dist/PolyCurve.js.map +1 -1
  18. package/dist/Polyline.js +1 -1
  19. package/dist/Polyline.js.map +1 -1
  20. package/dist/Ray.js +1 -1
  21. package/dist/Ray.js.map +1 -1
  22. package/dist/engine.d.ts.map +1 -1
  23. package/dist/engine.js +1 -3
  24. package/dist/engine.js.map +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/wasm-base64.d.ts +1 -1
  29. package/dist/wasm-base64.d.ts.map +1 -1
  30. package/dist/wasm-base64.js +1 -1
  31. package/dist/wasm-base64.js.map +1 -1
  32. package/package.json +7 -6
  33. package/src/Arc.ts +117 -117
  34. package/src/Circle.ts +153 -153
  35. package/src/Line.ts +144 -144
  36. package/src/Mesh.ts +671 -452
  37. package/src/NurbsCurve.ts +240 -240
  38. package/src/NurbsSurface.ts +249 -245
  39. package/src/PolyCurve.ts +306 -306
  40. package/src/Polyline.ts +153 -153
  41. package/src/Ray.ts +90 -90
  42. package/src/engine.ts +9 -11
  43. package/src/index.ts +6 -0
  44. package/src/wasm-base64.ts +1 -1
  45. package/wasm/README.md +0 -104
  46. package/wasm/okgeometrycore.d.ts +0 -754
  47. package/wasm/okgeometrycore.js +0 -2005
  48. package/wasm/okgeometrycore_bg.d.ts +0 -3
  49. package/wasm/okgeometrycore_bg.js +0 -1686
  50. package/wasm/okgeometrycore_bg.wasm +0 -0
  51. package/wasm/okgeometrycore_bg.wasm.d.ts +0 -100
  52. package/wasm/package.json +0 -19
package/src/Polyline.ts CHANGED
@@ -1,153 +1,153 @@
1
- import { ensureInit } from "./engine.js";
2
- import { Point } from "./Point.js";
3
- import { Vec3 } from "./Vec3.js";
4
- import { Mesh } from "./Mesh.js";
5
- import { Line } from "./Line.js";
6
- import { PolyCurve } from "./PolyCurve.js";
7
- import type { Plane } from "./Plane.js";
8
- import type { RotationAxis } from "./types.js";
9
- import { pointsToCoords, coordsToPoints } from "./BufferCodec.js";
10
- import * as wasm from "../wasm/okgeometrycore_bg.js";
11
-
12
- /**
13
- * Open or closed polyline defined by a sequence of points.
14
- * Supports length, evaluation, transformation, and extrusion operations.
15
- */
16
- export class Polyline {
17
- public readonly points: Point[];
18
-
19
- constructor(points: Point[]) {
20
- this.points = points;
21
- }
22
-
23
- /**
24
- * Get the total length of this polyline.
25
- * @returns Sum of segment lengths
26
- */
27
- length(): number {
28
- ensureInit();
29
- return wasm.polyline_length(this.toCoords());
30
- }
31
-
32
- /**
33
- * Evaluate a point on the polyline at normalized parameter t.
34
- * @param t - Parameter in [0, 1] (0 = first point, 1 = last point)
35
- * @returns Point on polyline at parameter t
36
- */
37
- pointAt(t: number): Point {
38
- ensureInit();
39
- const r = wasm.polyline_point_at(this.toCoords(), t);
40
- return new Point(r[0], r[1], r[2]);
41
- }
42
-
43
- /**
44
- * Check if this polyline is closed.
45
- * @param eps - Tolerance for comparing first and last points
46
- * @returns True if first and last points coincide
47
- */
48
- isClosed(eps = 1e-10): boolean {
49
- if (this.points.length < 2) return false;
50
- return this.points[0].equals(this.points[this.points.length - 1], eps);
51
- }
52
-
53
- /**
54
- * Extrude this polyline along a direction vector.
55
- * @param direction - Extrusion direction and magnitude
56
- * @param segments - Number of segments along extrusion (default 1)
57
- * @param caps - Whether to cap the ends (default false)
58
- * @returns Mesh representing the extruded surface
59
- */
60
- extrude(direction: Vec3, segments = 1, caps = false): Mesh {
61
- ensureInit();
62
- const buf = wasm.extrude_polyline(
63
- this.toCoords(),
64
- direction.x, direction.y, direction.z,
65
- segments, caps
66
- );
67
- return Mesh.fromBuffer(buf);
68
- }
69
-
70
- /**
71
- * Translate this polyline by an offset vector.
72
- * @param offset - Translation vector
73
- * @returns New translated polyline
74
- */
75
- translate(offset: Vec3): Polyline {
76
- return new Polyline(this.points.map(p => p.add(offset)));
77
- }
78
-
79
- /**
80
- * Rotate this polyline around an axis.
81
- * @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
82
- * @param angle - Rotation angle in radians
83
- * @returns New rotated polyline
84
- */
85
- rotate(axis: RotationAxis, angle: number): Polyline {
86
- return new Polyline(this.points.map(p => p.rotate(axis, angle)));
87
- }
88
-
89
- /**
90
- * Offset this polyline perpendicular to its segments.
91
- * @param distance - Offset distance
92
- * @param normal - Reference normal for determining offset direction
93
- * @returns New offset polyline
94
- */
95
- offset(distance: number, normal?: Vec3): Polyline {
96
- ensureInit();
97
- const nx = normal?.x ?? 0, ny = normal?.y ?? 0, nz = normal?.z ?? 0;
98
- const result = wasm.offset_polyline_curve(this.toCoords(), distance, nx, ny, nz);
99
- return new Polyline(coordsToPoints(result));
100
- }
101
-
102
- /**
103
- * Project this polyline onto a plane.
104
- * @param plane - Target plane
105
- * @param direction - Optional projection direction (default: perpendicular to plane)
106
- * @returns New projected polyline
107
- */
108
- projectOntoPlane(plane: Plane, direction?: Vec3): Polyline {
109
- const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
110
- return new Polyline(this.points.map(proj));
111
- }
112
-
113
- /**
114
- * Fillet corners of this polyline with arcs of the given radius.
115
- * @param radius - Fillet radius
116
- * @param normal - Reference normal for arc orientation (auto-detected if not provided)
117
- * @returns PolyCurve with Line and Arc segments
118
- */
119
- fillet(radius: number, normal?: Vec3): PolyCurve {
120
- ensureInit();
121
- if (this.points.length < 3) {
122
- throw new Error("Polyline.fillet() requires at least 3 points");
123
- }
124
-
125
- const nx = normal?.x ?? 0, ny = normal?.y ?? 0, nz = normal?.z ?? 0;
126
- const buf = wasm.fillet_polycurve(this.toCoords(), radius, nx, ny, nz);
127
- if (buf.length < 1) {
128
- throw new Error("Polyline.fillet() failed - WASM returned empty result");
129
- }
130
-
131
- return PolyCurve.fromSegmentData(buf);
132
- }
133
-
134
- /**
135
- * Convert this polyline to a PolyCurve (line segments only).
136
- * @returns PolyCurve with Line segments connecting consecutive points
137
- */
138
- toPolyCurve(): PolyCurve {
139
- const segs: Line[] = [];
140
- for (let i = 0; i < this.points.length - 1; i++) {
141
- segs.push(new Line(this.points[i], this.points[i + 1]));
142
- }
143
- return new PolyCurve(segs);
144
- }
145
-
146
- /**
147
- * Convert points to flat coordinate array for WASM.
148
- * @returns Float64Array [x1,y1,z1, x2,y2,z2, ...]
149
- */
150
- private toCoords(): Float64Array {
151
- return pointsToCoords(this.points);
152
- }
153
- }
1
+ import { ensureInit } from "./engine.js";
2
+ import { Point } from "./Point.js";
3
+ import { Vec3 } from "./Vec3.js";
4
+ import { Mesh } from "./Mesh.js";
5
+ import { Line } from "./Line.js";
6
+ import { PolyCurve } from "./PolyCurve.js";
7
+ import type { Plane } from "./Plane.js";
8
+ import type { RotationAxis } from "./types.js";
9
+ import { pointsToCoords, coordsToPoints } from "./BufferCodec.js";
10
+ import * as wasm from "../wasm/okgeometrycore.js";
11
+
12
+ /**
13
+ * Open or closed polyline defined by a sequence of points.
14
+ * Supports length, evaluation, transformation, and extrusion operations.
15
+ */
16
+ export class Polyline {
17
+ public readonly points: Point[];
18
+
19
+ constructor(points: Point[]) {
20
+ this.points = points;
21
+ }
22
+
23
+ /**
24
+ * Get the total length of this polyline.
25
+ * @returns Sum of segment lengths
26
+ */
27
+ length(): number {
28
+ ensureInit();
29
+ return wasm.polyline_length(this.toCoords());
30
+ }
31
+
32
+ /**
33
+ * Evaluate a point on the polyline at normalized parameter t.
34
+ * @param t - Parameter in [0, 1] (0 = first point, 1 = last point)
35
+ * @returns Point on polyline at parameter t
36
+ */
37
+ pointAt(t: number): Point {
38
+ ensureInit();
39
+ const r = wasm.polyline_point_at(this.toCoords(), t);
40
+ return new Point(r[0], r[1], r[2]);
41
+ }
42
+
43
+ /**
44
+ * Check if this polyline is closed.
45
+ * @param eps - Tolerance for comparing first and last points
46
+ * @returns True if first and last points coincide
47
+ */
48
+ isClosed(eps = 1e-10): boolean {
49
+ if (this.points.length < 2) return false;
50
+ return this.points[0].equals(this.points[this.points.length - 1], eps);
51
+ }
52
+
53
+ /**
54
+ * Extrude this polyline along a direction vector.
55
+ * @param direction - Extrusion direction and magnitude
56
+ * @param segments - Number of segments along extrusion (default 1)
57
+ * @param caps - Whether to cap the ends (default false)
58
+ * @returns Mesh representing the extruded surface
59
+ */
60
+ extrude(direction: Vec3, segments = 1, caps = false): Mesh {
61
+ ensureInit();
62
+ const buf = wasm.extrude_polyline(
63
+ this.toCoords(),
64
+ direction.x, direction.y, direction.z,
65
+ segments, caps
66
+ );
67
+ return Mesh.fromBuffer(buf);
68
+ }
69
+
70
+ /**
71
+ * Translate this polyline by an offset vector.
72
+ * @param offset - Translation vector
73
+ * @returns New translated polyline
74
+ */
75
+ translate(offset: Vec3): Polyline {
76
+ return new Polyline(this.points.map(p => p.add(offset)));
77
+ }
78
+
79
+ /**
80
+ * Rotate this polyline around an axis.
81
+ * @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
82
+ * @param angle - Rotation angle in radians
83
+ * @returns New rotated polyline
84
+ */
85
+ rotate(axis: RotationAxis, angle: number): Polyline {
86
+ return new Polyline(this.points.map(p => p.rotate(axis, angle)));
87
+ }
88
+
89
+ /**
90
+ * Offset this polyline perpendicular to its segments.
91
+ * @param distance - Offset distance
92
+ * @param normal - Reference normal for determining offset direction
93
+ * @returns New offset polyline
94
+ */
95
+ offset(distance: number, normal?: Vec3): Polyline {
96
+ ensureInit();
97
+ const nx = normal?.x ?? 0, ny = normal?.y ?? 0, nz = normal?.z ?? 0;
98
+ const result = wasm.offset_polyline_curve(this.toCoords(), distance, nx, ny, nz);
99
+ return new Polyline(coordsToPoints(result));
100
+ }
101
+
102
+ /**
103
+ * Project this polyline onto a plane.
104
+ * @param plane - Target plane
105
+ * @param direction - Optional projection direction (default: perpendicular to plane)
106
+ * @returns New projected polyline
107
+ */
108
+ projectOntoPlane(plane: Plane, direction?: Vec3): Polyline {
109
+ const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
110
+ return new Polyline(this.points.map(proj));
111
+ }
112
+
113
+ /**
114
+ * Fillet corners of this polyline with arcs of the given radius.
115
+ * @param radius - Fillet radius
116
+ * @param normal - Reference normal for arc orientation (auto-detected if not provided)
117
+ * @returns PolyCurve with Line and Arc segments
118
+ */
119
+ fillet(radius: number, normal?: Vec3): PolyCurve {
120
+ ensureInit();
121
+ if (this.points.length < 3) {
122
+ throw new Error("Polyline.fillet() requires at least 3 points");
123
+ }
124
+
125
+ const nx = normal?.x ?? 0, ny = normal?.y ?? 0, nz = normal?.z ?? 0;
126
+ const buf = wasm.fillet_polycurve(this.toCoords(), radius, nx, ny, nz);
127
+ if (buf.length < 1) {
128
+ throw new Error("Polyline.fillet() failed - WASM returned empty result");
129
+ }
130
+
131
+ return PolyCurve.fromSegmentData(buf);
132
+ }
133
+
134
+ /**
135
+ * Convert this polyline to a PolyCurve (line segments only).
136
+ * @returns PolyCurve with Line segments connecting consecutive points
137
+ */
138
+ toPolyCurve(): PolyCurve {
139
+ const segs: Line[] = [];
140
+ for (let i = 0; i < this.points.length - 1; i++) {
141
+ segs.push(new Line(this.points[i], this.points[i + 1]));
142
+ }
143
+ return new PolyCurve(segs);
144
+ }
145
+
146
+ /**
147
+ * Convert points to flat coordinate array for WASM.
148
+ * @returns Float64Array [x1,y1,z1, x2,y2,z2, ...]
149
+ */
150
+ private toCoords(): Float64Array {
151
+ return pointsToCoords(this.points);
152
+ }
153
+ }
package/src/Ray.ts CHANGED
@@ -1,90 +1,90 @@
1
- import { ensureInit } from "./engine.js";
2
- import { Point } from "./Point.js";
3
- import { Vec3 } from "./Vec3.js";
4
- import * as wasm from "../wasm/okgeometrycore_bg.js";
5
-
6
- /**
7
- * 3D ray defined by origin and direction.
8
- * Parametric form: point(t) = origin + t * direction
9
- */
10
- export class Ray {
11
- constructor(
12
- public readonly origin: Point,
13
- public readonly direction: Vec3
14
- ) {}
15
-
16
- /**
17
- * Create a ray from origin and direction, normalizing the direction.
18
- * Returns null if direction is zero-length.
19
- */
20
- static fromOriginDirection(origin: Point, direction: Vec3): Ray | null {
21
- const normalized = direction.normalize();
22
- if (normalized.length() < 1e-10) return null;
23
- return new Ray(origin, normalized);
24
- }
25
-
26
- /**
27
- * Get point along the ray at parameter t.
28
- * Returns origin + t * direction
29
- */
30
- pointAt(t: number): Point {
31
- ensureInit();
32
- const r = wasm.ray_point_at(
33
- this.origin.x, this.origin.y, this.origin.z,
34
- this.direction.x, this.direction.y, this.direction.z,
35
- t
36
- );
37
- return new Point(r[0], r[1], r[2]);
38
- }
39
-
40
- /**
41
- * Find the parameter t for the closest point on the ray to a given point.
42
- * The closest point is at: origin + t * direction
43
- * Note: t can be negative if the closest point is "behind" the ray origin,
44
- * but closestPoint() clamps t >= 0.
45
- */
46
- closestPointParameter(point: Point): number {
47
- ensureInit();
48
- return wasm.ray_closest_point_parameter(
49
- this.origin.x, this.origin.y, this.origin.z,
50
- this.direction.x, this.direction.y, this.direction.z,
51
- point.x, point.y, point.z
52
- );
53
- }
54
-
55
- /**
56
- * Find the closest point on the ray to a given point.
57
- * The result is clamped to the ray (t >= 0), so if the closest
58
- * point would be "behind" the origin, returns the origin.
59
- */
60
- closestPoint(point: Point): Point {
61
- ensureInit();
62
- const r = wasm.ray_closest_point(
63
- this.origin.x, this.origin.y, this.origin.z,
64
- this.direction.x, this.direction.y, this.direction.z,
65
- point.x, point.y, point.z
66
- );
67
- return new Point(r[0], r[1], r[2]);
68
- }
69
-
70
- /**
71
- * Compute the distance from this ray to a point.
72
- * This is the perpendicular distance from the ray to the point,
73
- * clamped so that the closest point is on the ray (t >= 0).
74
- */
75
- distanceToPoint(point: Point): number {
76
- ensureInit();
77
- return wasm.ray_distance_to_point(
78
- this.origin.x, this.origin.y, this.origin.z,
79
- this.direction.x, this.direction.y, this.direction.z,
80
- point.x, point.y, point.z
81
- );
82
- }
83
-
84
- /**
85
- * Translate the ray by an offset vector.
86
- */
87
- translate(offset: Vec3): Ray {
88
- return new Ray(this.origin.add(offset), this.direction);
89
- }
90
- }
1
+ import { ensureInit } from "./engine.js";
2
+ import { Point } from "./Point.js";
3
+ import { Vec3 } from "./Vec3.js";
4
+ import * as wasm from "../wasm/okgeometrycore.js";
5
+
6
+ /**
7
+ * 3D ray defined by origin and direction.
8
+ * Parametric form: point(t) = origin + t * direction
9
+ */
10
+ export class Ray {
11
+ constructor(
12
+ public readonly origin: Point,
13
+ public readonly direction: Vec3
14
+ ) {}
15
+
16
+ /**
17
+ * Create a ray from origin and direction, normalizing the direction.
18
+ * Returns null if direction is zero-length.
19
+ */
20
+ static fromOriginDirection(origin: Point, direction: Vec3): Ray | null {
21
+ const normalized = direction.normalize();
22
+ if (normalized.length() < 1e-10) return null;
23
+ return new Ray(origin, normalized);
24
+ }
25
+
26
+ /**
27
+ * Get point along the ray at parameter t.
28
+ * Returns origin + t * direction
29
+ */
30
+ pointAt(t: number): Point {
31
+ ensureInit();
32
+ const r = wasm.ray_point_at(
33
+ this.origin.x, this.origin.y, this.origin.z,
34
+ this.direction.x, this.direction.y, this.direction.z,
35
+ t
36
+ );
37
+ return new Point(r[0], r[1], r[2]);
38
+ }
39
+
40
+ /**
41
+ * Find the parameter t for the closest point on the ray to a given point.
42
+ * The closest point is at: origin + t * direction
43
+ * Note: t can be negative if the closest point is "behind" the ray origin,
44
+ * but closestPoint() clamps t >= 0.
45
+ */
46
+ closestPointParameter(point: Point): number {
47
+ ensureInit();
48
+ return wasm.ray_closest_point_parameter(
49
+ this.origin.x, this.origin.y, this.origin.z,
50
+ this.direction.x, this.direction.y, this.direction.z,
51
+ point.x, point.y, point.z
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Find the closest point on the ray to a given point.
57
+ * The result is clamped to the ray (t >= 0), so if the closest
58
+ * point would be "behind" the origin, returns the origin.
59
+ */
60
+ closestPoint(point: Point): Point {
61
+ ensureInit();
62
+ const r = wasm.ray_closest_point(
63
+ this.origin.x, this.origin.y, this.origin.z,
64
+ this.direction.x, this.direction.y, this.direction.z,
65
+ point.x, point.y, point.z
66
+ );
67
+ return new Point(r[0], r[1], r[2]);
68
+ }
69
+
70
+ /**
71
+ * Compute the distance from this ray to a point.
72
+ * This is the perpendicular distance from the ray to the point,
73
+ * clamped so that the closest point is on the ray (t >= 0).
74
+ */
75
+ distanceToPoint(point: Point): number {
76
+ ensureInit();
77
+ return wasm.ray_distance_to_point(
78
+ this.origin.x, this.origin.y, this.origin.z,
79
+ this.direction.x, this.direction.y, this.direction.z,
80
+ point.x, point.y, point.z
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Translate the ray by an offset vector.
86
+ */
87
+ translate(offset: Vec3): Ray {
88
+ return new Ray(this.origin.add(offset), this.direction);
89
+ }
90
+ }
package/src/engine.ts CHANGED
@@ -1,25 +1,23 @@
1
1
  import { WASM_B64 } from "./wasm-base64.js";
2
2
  import coreWasmInit from "../wasm/okgeometrycore.js";
3
- import * as bg from "../wasm/okgeometrycore_bg.js";
4
3
 
5
4
  let initialized = false;
6
-
7
- const engineGlobal = globalThis as typeof globalThis & {
8
- __okgeometry_boolean_should_cancel?: () => boolean;
9
- };
10
5
 
11
- if (typeof engineGlobal.__okgeometry_boolean_should_cancel !== "function") {
12
- engineGlobal.__okgeometry_boolean_should_cancel = () => false;
13
- }
14
-
6
+ const engineGlobal = globalThis as typeof globalThis & {
7
+ __okgeometry_boolean_should_cancel?: () => boolean;
8
+ };
9
+
10
+ if (typeof engineGlobal.__okgeometry_boolean_should_cancel !== "function") {
11
+ engineGlobal.__okgeometry_boolean_should_cancel = () => false;
12
+ }
13
+
15
14
  export async function init(): Promise<void> {
16
15
  if (initialized) return;
17
16
  const raw = atob(WASM_B64);
18
17
  const bytes = new Uint8Array(raw.length);
19
18
  for (let i = 0; i < raw.length; i++) bytes[i] = raw.charCodeAt(i);
20
19
 
21
- const exports = await coreWasmInit({ module_or_path: bytes });
22
- (bg as any).__wbg_set_wasm(exports);
20
+ await coreWasmInit({ module_or_path: bytes });
23
21
 
24
22
  initialized = true;
25
23
  }
package/src/index.ts CHANGED
@@ -39,7 +39,13 @@ export type {
39
39
  MeshBooleanDebugProbeId,
40
40
  MeshBooleanDebugOptions,
41
41
  MeshBooleanDebugProbe,
42
+ MeshBooleanDebugProbeSummary,
42
43
  MeshBooleanDebugReport,
44
+ MeshBooleanReproOperand,
45
+ MeshBooleanReproResult,
46
+ MeshBooleanReproError,
47
+ MeshBooleanReproPayload,
48
+ MeshBooleanReproOptions,
43
49
  MeshDebugBounds,
44
50
  MeshDebugRayHit,
45
51
  MeshDebugSummary,