okgeometry-api 1.1.5 → 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 +104 -7
  8. package/dist/Mesh.d.ts.map +1 -1
  9. package/dist/Mesh.js +106 -8
  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 -5
  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 +663 -444
  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
@@ -1 +1 @@
1
- {"version":3,"file":"wasm-base64.js","sourceRoot":"","sources":["../src/wasm-base64.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,MAAM,CAAC,MAAM,QAAQ,GAAG,kl+tDAAkl+tD,CAAC"}
1
+ {"version":3,"file":"wasm-base64.js","sourceRoot":"","sources":["../src/wasm-base64.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,MAAM,CAAC,MAAM,QAAQ,GAAG,86lvDAA86lvD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okgeometry-api",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Geometry engine API for AEC applications — NURBS, meshes, booleans, intersections. Powered by Rust/WASM.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,10 +16,12 @@
16
16
  "src/",
17
17
  "wasm/"
18
18
  ],
19
- "scripts": {
20
- "inline-wasm": "tsx scripts/inline-wasm.ts",
21
- "build": "npm run inline-wasm && tsc",
22
- "bench:boolean-manifold-baseline": "npm run build && tsx scripts/bench-boolean-manifold-baseline.ts",
19
+ "scripts": {
20
+ "build:wasm": "node -e \"require('fs').rmSync('wasm',{recursive:true,force:true})\" && cd .. && wasm-pack build --target web --out-dir okgeometry-api/wasm",
21
+ "inline-wasm": "tsx scripts/inline-wasm.ts",
22
+ "build": "npm run build:wasm && npm run inline-wasm && tsc",
23
+ "check:primitive-parity": "npm run build:wasm && tsx scripts/check-primitive-parity.ts",
24
+ "bench:boolean-manifold-baseline": "npm run build && tsx scripts/bench-boolean-manifold-baseline.ts",
23
25
  "bench:boolean-replacement-heavy": "npm run build && tsx scripts/bench-boolean-replacement-heavy.ts",
24
26
  "bench:boolean-deterministic": "npm run build && tsx scripts/bench-boolean-deterministic.ts",
25
27
  "bench:boolean-ab": "npm run build && tsx scripts/bench-boolean-ab.ts",
package/src/Arc.ts CHANGED
@@ -1,117 +1,117 @@
1
- import { ensureInit } from "./engine.js";
2
- import { Point } from "./Point.js";
3
- import { Vec3 } from "./Vec3.js";
4
- import { Polyline } from "./Polyline.js";
5
- import type { Plane } from "./Plane.js";
6
- import type { RotationAxis } from "./types.js";
7
- import * as wasm from "../wasm/okgeometrycore_bg.js";
8
-
9
- /**
10
- * Immutable circular arc defined by center, radius, and angular span.
11
- * Angles are in radians, measured counter-clockwise from the positive X axis
12
- * in the plane defined by the normal.
13
- */
14
- export class Arc {
15
- /**
16
- * Create a new arc.
17
- * @param center - Center point
18
- * @param radius - Arc radius
19
- * @param startAngle - Start angle in radians
20
- * @param endAngle - End angle in radians
21
- * @param normal - Normal vector defining the arc's plane (default Z axis)
22
- */
23
- constructor(
24
- public readonly center: Point,
25
- public readonly radius: number,
26
- public readonly startAngle: number,
27
- public readonly endAngle: number,
28
- public readonly normal: Vec3 = Vec3.Z
29
- ) {}
30
-
31
- /**
32
- * Evaluate a point on the arc at normalized parameter t.
33
- * @param t - Parameter in [0, 1] (0 = start angle, 1 = end angle)
34
- * @returns Point on arc at parameter t
35
- */
36
- pointAt(t: number): Point {
37
- ensureInit();
38
- const r = wasm.arc_point_at(
39
- this.center.x, this.center.y, this.center.z,
40
- this.normal.x, this.normal.y, this.normal.z,
41
- this.radius, this.startAngle, this.endAngle, t
42
- );
43
- return new Point(r[0], r[1], r[2]);
44
- }
45
-
46
- /**
47
- * Get the arc length.
48
- * @returns Arc length = radius * angular span
49
- */
50
- length(): number {
51
- ensureInit();
52
- return wasm.arc_length(this.radius, this.startAngle, this.endAngle);
53
- }
54
-
55
- /**
56
- * Translate this arc by an offset vector.
57
- * @param offset - Translation vector
58
- * @returns New translated arc
59
- */
60
- translate(offset: Vec3): Arc {
61
- return new Arc(this.center.add(offset), this.radius, this.startAngle, this.endAngle, this.normal);
62
- }
63
-
64
- /**
65
- * Rotate this arc around an axis.
66
- * @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
67
- * @param angle - Rotation angle in radians
68
- * @returns New rotated arc
69
- */
70
- rotate(axis: RotationAxis, angle: number): Arc {
71
- const n = this.normal;
72
- const dirAxis = 'start' in axis ? new Vec3(axis.end.x - axis.start.x, axis.end.y - axis.start.y, axis.end.z - axis.start.z) : axis;
73
- const rn = new Point(n.x, n.y, n.z).rotate(dirAxis, angle);
74
- return new Arc(this.center.rotate(axis, angle), this.radius, this.startAngle, this.endAngle, new Vec3(rn.x, rn.y, rn.z));
75
- }
76
-
77
- /**
78
- * Offset this arc by changing its radius.
79
- * @param distance - Distance to offset (positive = larger, negative = smaller)
80
- * @returns New arc with adjusted radius
81
- */
82
- offset(distance: number): Arc {
83
- return new Arc(this.center, this.radius + distance, this.startAngle, this.endAngle, this.normal);
84
- }
85
-
86
- /**
87
- * Project onto plane. Returns a Polyline because a tilted arc projects to an elliptical arc.
88
- * @param plane - Target plane
89
- * @param direction - Optional projection direction (default: perpendicular to plane)
90
- * @param samples - Number of sample points for approximation (default 64)
91
- * @returns Polyline approximating the projected arc
92
- */
93
- projectOntoPlane(plane: Plane, direction?: Vec3, samples = 64): Polyline {
94
- const pts = this.sample(samples);
95
- const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
96
- return new Polyline(pts.map(proj));
97
- }
98
-
99
- /**
100
- * Sample the arc into evenly-spaced points.
101
- * @param n - Number of points to generate
102
- * @returns Array of n points along the arc
103
- */
104
- sample(n: number): Point[] {
105
- ensureInit();
106
- const buf = wasm.create_arc(
107
- this.center.x, this.center.y, this.center.z,
108
- this.normal.x, this.normal.y, this.normal.z,
109
- this.radius, this.startAngle, this.endAngle, n
110
- );
111
- const pts: Point[] = [];
112
- for (let i = 0; i < buf.length; i += 3) {
113
- pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
114
- }
115
- return pts;
116
- }
117
- }
1
+ import { ensureInit } from "./engine.js";
2
+ import { Point } from "./Point.js";
3
+ import { Vec3 } from "./Vec3.js";
4
+ import { Polyline } from "./Polyline.js";
5
+ import type { Plane } from "./Plane.js";
6
+ import type { RotationAxis } from "./types.js";
7
+ import * as wasm from "../wasm/okgeometrycore.js";
8
+
9
+ /**
10
+ * Immutable circular arc defined by center, radius, and angular span.
11
+ * Angles are in radians, measured counter-clockwise from the positive X axis
12
+ * in the plane defined by the normal.
13
+ */
14
+ export class Arc {
15
+ /**
16
+ * Create a new arc.
17
+ * @param center - Center point
18
+ * @param radius - Arc radius
19
+ * @param startAngle - Start angle in radians
20
+ * @param endAngle - End angle in radians
21
+ * @param normal - Normal vector defining the arc's plane (default Z axis)
22
+ */
23
+ constructor(
24
+ public readonly center: Point,
25
+ public readonly radius: number,
26
+ public readonly startAngle: number,
27
+ public readonly endAngle: number,
28
+ public readonly normal: Vec3 = Vec3.Z
29
+ ) {}
30
+
31
+ /**
32
+ * Evaluate a point on the arc at normalized parameter t.
33
+ * @param t - Parameter in [0, 1] (0 = start angle, 1 = end angle)
34
+ * @returns Point on arc at parameter t
35
+ */
36
+ pointAt(t: number): Point {
37
+ ensureInit();
38
+ const r = wasm.arc_point_at(
39
+ this.center.x, this.center.y, this.center.z,
40
+ this.normal.x, this.normal.y, this.normal.z,
41
+ this.radius, this.startAngle, this.endAngle, t
42
+ );
43
+ return new Point(r[0], r[1], r[2]);
44
+ }
45
+
46
+ /**
47
+ * Get the arc length.
48
+ * @returns Arc length = radius * angular span
49
+ */
50
+ length(): number {
51
+ ensureInit();
52
+ return wasm.arc_length(this.radius, this.startAngle, this.endAngle);
53
+ }
54
+
55
+ /**
56
+ * Translate this arc by an offset vector.
57
+ * @param offset - Translation vector
58
+ * @returns New translated arc
59
+ */
60
+ translate(offset: Vec3): Arc {
61
+ return new Arc(this.center.add(offset), this.radius, this.startAngle, this.endAngle, this.normal);
62
+ }
63
+
64
+ /**
65
+ * Rotate this arc around an axis.
66
+ * @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
67
+ * @param angle - Rotation angle in radians
68
+ * @returns New rotated arc
69
+ */
70
+ rotate(axis: RotationAxis, angle: number): Arc {
71
+ const n = this.normal;
72
+ const dirAxis = 'start' in axis ? new Vec3(axis.end.x - axis.start.x, axis.end.y - axis.start.y, axis.end.z - axis.start.z) : axis;
73
+ const rn = new Point(n.x, n.y, n.z).rotate(dirAxis, angle);
74
+ return new Arc(this.center.rotate(axis, angle), this.radius, this.startAngle, this.endAngle, new Vec3(rn.x, rn.y, rn.z));
75
+ }
76
+
77
+ /**
78
+ * Offset this arc by changing its radius.
79
+ * @param distance - Distance to offset (positive = larger, negative = smaller)
80
+ * @returns New arc with adjusted radius
81
+ */
82
+ offset(distance: number): Arc {
83
+ return new Arc(this.center, this.radius + distance, this.startAngle, this.endAngle, this.normal);
84
+ }
85
+
86
+ /**
87
+ * Project onto plane. Returns a Polyline because a tilted arc projects to an elliptical arc.
88
+ * @param plane - Target plane
89
+ * @param direction - Optional projection direction (default: perpendicular to plane)
90
+ * @param samples - Number of sample points for approximation (default 64)
91
+ * @returns Polyline approximating the projected arc
92
+ */
93
+ projectOntoPlane(plane: Plane, direction?: Vec3, samples = 64): Polyline {
94
+ const pts = this.sample(samples);
95
+ const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
96
+ return new Polyline(pts.map(proj));
97
+ }
98
+
99
+ /**
100
+ * Sample the arc into evenly-spaced points.
101
+ * @param n - Number of points to generate
102
+ * @returns Array of n points along the arc
103
+ */
104
+ sample(n: number): Point[] {
105
+ ensureInit();
106
+ const buf = wasm.create_arc(
107
+ this.center.x, this.center.y, this.center.z,
108
+ this.normal.x, this.normal.y, this.normal.z,
109
+ this.radius, this.startAngle, this.endAngle, n
110
+ );
111
+ const pts: Point[] = [];
112
+ for (let i = 0; i < buf.length; i += 3) {
113
+ pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
114
+ }
115
+ return pts;
116
+ }
117
+ }
package/src/Circle.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 { Polygon } from "./Polygon.js";
6
- import { Plane } from "./Plane.js";
7
- import type { RotationAxis } from "./types.js";
8
- import * as wasm from "../wasm/okgeometrycore_bg.js";
9
-
10
- /**
11
- * Immutable circle defined by center, radius, and normal.
12
- * Supports evaluation, transformation, extrusion, and projection.
13
- */
14
- export class Circle {
15
- /**
16
- * Create a new circle.
17
- * @param center - Center point
18
- * @param radius - Circle radius
19
- * @param normal - Normal vector defining the circle's plane (default Z axis)
20
- * @param uAxis - Optional reference direction defining where t=0 starts.
21
- * Critical for sweep operations to maintain consistent profile orientation.
22
- */
23
- constructor(
24
- public readonly center: Point,
25
- public readonly radius: number,
26
- public readonly normal: Vec3 = Vec3.Z,
27
- public readonly uAxis?: Vec3
28
- ) {}
29
-
30
- /**
31
- * Create a Circle from a Plane, automatically using the plane's xAxis
32
- * as the circle's uAxis for consistent orientation in sweep operations.
33
- * @param plane - Plane defining circle's position and orientation
34
- * @param radius - Circle radius
35
- * @returns New Circle at plane origin with plane normal
36
- */
37
- static fromPlane(plane: Plane, radius: number): Circle {
38
- return new Circle(plane.origin, radius, plane.normal, plane.getXAxis());
39
- }
40
-
41
- /**
42
- * Evaluate a point on the circle at normalized parameter t.
43
- * @param t - Parameter in [0, 1] (0 and 1 are the same point for closed circle)
44
- * @returns Point on circle at parameter t
45
- */
46
- pointAt(t: number): Point {
47
- ensureInit();
48
- const r = wasm.circle_point_at(
49
- this.center.x, this.center.y, this.center.z,
50
- this.normal.x, this.normal.y, this.normal.z,
51
- this.radius, t
52
- );
53
- return new Point(r[0], r[1], r[2]);
54
- }
55
-
56
- /**
57
- * Get the circumference of this circle.
58
- * @returns 2 * PI * radius
59
- */
60
- length(): number {
61
- ensureInit();
62
- return wasm.circle_length(this.radius);
63
- }
64
-
65
- /**
66
- * Sample the circle into evenly-spaced points.
67
- * @param n - Number of points to generate
68
- * @returns Array of n points around the circle
69
- */
70
- sample(n: number): Point[] {
71
- ensureInit();
72
- const buf = wasm.create_circle(
73
- this.center.x, this.center.y, this.center.z,
74
- this.normal.x, this.normal.y, this.normal.z,
75
- this.radius, n
76
- );
77
- const pts: Point[] = [];
78
- for (let i = 0; i < buf.length; i += 3) {
79
- pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
80
- }
81
- return pts;
82
- }
83
-
84
- /**
85
- * Translate this circle by an offset vector.
86
- * @param offset - Translation vector
87
- * @returns New translated circle
88
- */
89
- translate(offset: Vec3): Circle {
90
- return new Circle(this.center.add(offset), this.radius, this.normal, this.uAxis);
91
- }
92
-
93
- /**
94
- * Rotate this circle around an axis.
95
- * @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
96
- * @param angle - Rotation angle in radians
97
- * @returns New rotated circle
98
- */
99
- rotate(axis: RotationAxis, angle: number): Circle {
100
- const n = this.normal;
101
- // Normal is a direction — always rotate around origin regardless of axis type
102
- const dirAxis = 'start' in axis ? new Vec3(axis.end.x - axis.start.x, axis.end.y - axis.start.y, axis.end.z - axis.start.z) : axis;
103
- const rn = new Point(n.x, n.y, n.z).rotate(dirAxis, angle);
104
- // Also rotate the uAxis if present
105
- let rotatedUAxis: Vec3 | undefined;
106
- if (this.uAxis) {
107
- const ru = new Point(this.uAxis.x, this.uAxis.y, this.uAxis.z).rotate(dirAxis, angle);
108
- rotatedUAxis = new Vec3(ru.x, ru.y, ru.z);
109
- }
110
- return new Circle(this.center.rotate(axis, angle), this.radius, new Vec3(rn.x, rn.y, rn.z), rotatedUAxis);
111
- }
112
-
113
- /**
114
- * Offset this circle by changing its radius.
115
- * @param distance - Distance to offset (positive = larger, negative = smaller)
116
- * @returns New circle with adjusted radius
117
- */
118
- offset(distance: number): Circle {
119
- return new Circle(this.center, this.radius + distance, this.normal, this.uAxis);
120
- }
121
-
122
- /**
123
- * Project onto plane. Returns a Polygon because a tilted circle projects to an ellipse.
124
- * @param plane - Target plane
125
- * @param direction - Optional projection direction (default: perpendicular to plane)
126
- * @param samples - Number of sample points for approximation (default 64)
127
- * @returns Polygon approximating the projected circle
128
- */
129
- projectOntoPlane(plane: Plane, direction?: Vec3, samples = 64): Polygon {
130
- const pts = this.sample(samples);
131
- const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
132
- return new Polygon(pts.map(proj));
133
- }
134
-
135
- /**
136
- * Extrude this circle along a direction vector to create a cylindrical mesh.
137
- * @param direction - Extrusion direction and magnitude
138
- * @param segments - Number of circumferential segments (default 16)
139
- * @param caps - Whether to cap the ends (default true)
140
- * @returns Mesh representing the extruded cylinder
141
- */
142
- extrude(direction: Vec3, segments = 16, caps = true): Mesh {
143
- ensureInit();
144
- const buf = wasm.extrude_circle(
145
- this.center.x, this.center.y, this.center.z,
146
- this.normal.x, this.normal.y, this.normal.z,
147
- this.radius,
148
- direction.x, direction.y, direction.z,
149
- segments, caps
150
- );
151
- return Mesh.fromBuffer(buf);
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 { Polygon } from "./Polygon.js";
6
+ import { Plane } from "./Plane.js";
7
+ import type { RotationAxis } from "./types.js";
8
+ import * as wasm from "../wasm/okgeometrycore.js";
9
+
10
+ /**
11
+ * Immutable circle defined by center, radius, and normal.
12
+ * Supports evaluation, transformation, extrusion, and projection.
13
+ */
14
+ export class Circle {
15
+ /**
16
+ * Create a new circle.
17
+ * @param center - Center point
18
+ * @param radius - Circle radius
19
+ * @param normal - Normal vector defining the circle's plane (default Z axis)
20
+ * @param uAxis - Optional reference direction defining where t=0 starts.
21
+ * Critical for sweep operations to maintain consistent profile orientation.
22
+ */
23
+ constructor(
24
+ public readonly center: Point,
25
+ public readonly radius: number,
26
+ public readonly normal: Vec3 = Vec3.Z,
27
+ public readonly uAxis?: Vec3
28
+ ) {}
29
+
30
+ /**
31
+ * Create a Circle from a Plane, automatically using the plane's xAxis
32
+ * as the circle's uAxis for consistent orientation in sweep operations.
33
+ * @param plane - Plane defining circle's position and orientation
34
+ * @param radius - Circle radius
35
+ * @returns New Circle at plane origin with plane normal
36
+ */
37
+ static fromPlane(plane: Plane, radius: number): Circle {
38
+ return new Circle(plane.origin, radius, plane.normal, plane.getXAxis());
39
+ }
40
+
41
+ /**
42
+ * Evaluate a point on the circle at normalized parameter t.
43
+ * @param t - Parameter in [0, 1] (0 and 1 are the same point for closed circle)
44
+ * @returns Point on circle at parameter t
45
+ */
46
+ pointAt(t: number): Point {
47
+ ensureInit();
48
+ const r = wasm.circle_point_at(
49
+ this.center.x, this.center.y, this.center.z,
50
+ this.normal.x, this.normal.y, this.normal.z,
51
+ this.radius, t
52
+ );
53
+ return new Point(r[0], r[1], r[2]);
54
+ }
55
+
56
+ /**
57
+ * Get the circumference of this circle.
58
+ * @returns 2 * PI * radius
59
+ */
60
+ length(): number {
61
+ ensureInit();
62
+ return wasm.circle_length(this.radius);
63
+ }
64
+
65
+ /**
66
+ * Sample the circle into evenly-spaced points.
67
+ * @param n - Number of points to generate
68
+ * @returns Array of n points around the circle
69
+ */
70
+ sample(n: number): Point[] {
71
+ ensureInit();
72
+ const buf = wasm.create_circle(
73
+ this.center.x, this.center.y, this.center.z,
74
+ this.normal.x, this.normal.y, this.normal.z,
75
+ this.radius, n
76
+ );
77
+ const pts: Point[] = [];
78
+ for (let i = 0; i < buf.length; i += 3) {
79
+ pts.push(new Point(buf[i], buf[i + 1], buf[i + 2]));
80
+ }
81
+ return pts;
82
+ }
83
+
84
+ /**
85
+ * Translate this circle by an offset vector.
86
+ * @param offset - Translation vector
87
+ * @returns New translated circle
88
+ */
89
+ translate(offset: Vec3): Circle {
90
+ return new Circle(this.center.add(offset), this.radius, this.normal, this.uAxis);
91
+ }
92
+
93
+ /**
94
+ * Rotate this circle around an axis.
95
+ * @param axis - Rotation axis (Vec3 through origin, or Line for arbitrary axis)
96
+ * @param angle - Rotation angle in radians
97
+ * @returns New rotated circle
98
+ */
99
+ rotate(axis: RotationAxis, angle: number): Circle {
100
+ const n = this.normal;
101
+ // Normal is a direction — always rotate around origin regardless of axis type
102
+ const dirAxis = 'start' in axis ? new Vec3(axis.end.x - axis.start.x, axis.end.y - axis.start.y, axis.end.z - axis.start.z) : axis;
103
+ const rn = new Point(n.x, n.y, n.z).rotate(dirAxis, angle);
104
+ // Also rotate the uAxis if present
105
+ let rotatedUAxis: Vec3 | undefined;
106
+ if (this.uAxis) {
107
+ const ru = new Point(this.uAxis.x, this.uAxis.y, this.uAxis.z).rotate(dirAxis, angle);
108
+ rotatedUAxis = new Vec3(ru.x, ru.y, ru.z);
109
+ }
110
+ return new Circle(this.center.rotate(axis, angle), this.radius, new Vec3(rn.x, rn.y, rn.z), rotatedUAxis);
111
+ }
112
+
113
+ /**
114
+ * Offset this circle by changing its radius.
115
+ * @param distance - Distance to offset (positive = larger, negative = smaller)
116
+ * @returns New circle with adjusted radius
117
+ */
118
+ offset(distance: number): Circle {
119
+ return new Circle(this.center, this.radius + distance, this.normal, this.uAxis);
120
+ }
121
+
122
+ /**
123
+ * Project onto plane. Returns a Polygon because a tilted circle projects to an ellipse.
124
+ * @param plane - Target plane
125
+ * @param direction - Optional projection direction (default: perpendicular to plane)
126
+ * @param samples - Number of sample points for approximation (default 64)
127
+ * @returns Polygon approximating the projected circle
128
+ */
129
+ projectOntoPlane(plane: Plane, direction?: Vec3, samples = 64): Polygon {
130
+ const pts = this.sample(samples);
131
+ const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
132
+ return new Polygon(pts.map(proj));
133
+ }
134
+
135
+ /**
136
+ * Extrude this circle along a direction vector to create a cylindrical mesh.
137
+ * @param direction - Extrusion direction and magnitude
138
+ * @param segments - Number of circumferential segments (default 16)
139
+ * @param caps - Whether to cap the ends (default true)
140
+ * @returns Mesh representing the extruded cylinder
141
+ */
142
+ extrude(direction: Vec3, segments = 16, caps = true): Mesh {
143
+ ensureInit();
144
+ const buf = wasm.extrude_circle(
145
+ this.center.x, this.center.y, this.center.z,
146
+ this.normal.x, this.normal.y, this.normal.z,
147
+ this.radius,
148
+ direction.x, direction.y, direction.z,
149
+ segments, caps
150
+ );
151
+ return Mesh.fromBuffer(buf);
152
+ }
153
+ }