okgeometry-api 1.26.1 → 1.27.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/Arc.js +1 -1
- package/dist/Arc.js.map +1 -1
- package/dist/Brep.js +1 -1
- package/dist/Brep.js.map +1 -1
- package/dist/Circle.js +1 -1
- package/dist/Circle.js.map +1 -1
- package/dist/Line.js +1 -1
- package/dist/Line.js.map +1 -1
- package/dist/Mesh.d.ts +41 -0
- package/dist/Mesh.d.ts.map +1 -1
- package/dist/Mesh.js +235 -21
- package/dist/Mesh.js.map +1 -1
- package/dist/MeshSurface.js +1 -1
- package/dist/MeshSurface.js.map +1 -1
- package/dist/NurbsCurve.js +1 -1
- package/dist/NurbsCurve.js.map +1 -1
- package/dist/NurbsSurface.js +1 -1
- package/dist/NurbsSurface.js.map +1 -1
- package/dist/PolyCurve.js +1 -1
- package/dist/PolyCurve.js.map +1 -1
- package/dist/Polyline.js +1 -1
- package/dist/Polyline.js.map +1 -1
- package/dist/Ray.js +1 -1
- package/dist/Ray.js.map +1 -1
- package/dist/SculptSession.js +1 -1
- package/dist/SculptSession.js.map +1 -1
- package/dist/engine-threaded.d.ts +2 -0
- package/dist/engine-threaded.d.ts.map +1 -0
- package/dist/engine-threaded.js +33 -0
- package/dist/engine-threaded.js.map +1 -0
- package/dist/engine.d.ts +21 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +42 -0
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mesh-boolean.pool.d.ts +23 -1
- package/dist/mesh-boolean.pool.d.ts.map +1 -1
- package/dist/mesh-boolean.pool.js +97 -12
- package/dist/mesh-boolean.pool.js.map +1 -1
- package/dist/mesh-boolean.protocol.d.ts +21 -1
- package/dist/mesh-boolean.protocol.d.ts.map +1 -1
- package/dist/mesh-boolean.protocol.js.map +1 -1
- package/dist/mesh-boolean.worker.d.ts.map +1 -1
- package/dist/mesh-boolean.worker.js +94 -1
- package/dist/mesh-boolean.worker.js.map +1 -1
- package/dist/wasm-active.d.ts +20 -0
- package/dist/wasm-active.d.ts.map +1 -0
- package/dist/wasm-active.js +26 -0
- package/dist/wasm-active.js.map +1 -0
- package/dist/wasm-base64-threaded.d.ts +2 -0
- package/dist/wasm-base64-threaded.d.ts.map +1 -0
- package/dist/wasm-base64-threaded.js +3 -0
- package/dist/wasm-base64-threaded.js.map +1 -0
- package/dist/wasm-base64.d.ts +1 -1
- package/dist/wasm-base64.d.ts.map +1 -1
- package/dist/wasm-base64.js +1 -1
- package/dist/wasm-base64.js.map +1 -1
- package/dist/wasm-bindings-threaded.d.ts +2664 -0
- package/dist/wasm-bindings-threaded.d.ts.map +1 -0
- package/dist/wasm-bindings-threaded.js +5008 -0
- package/dist/wasm-bindings-threaded.js.map +1 -0
- package/dist/wasm-bindings.d.ts +130 -0
- package/dist/wasm-bindings.d.ts.map +1 -1
- package/dist/wasm-bindings.js +208 -0
- package/dist/wasm-bindings.js.map +1 -1
- package/dist/workerHelpers-threaded.d.ts +2 -0
- package/dist/workerHelpers-threaded.d.ts.map +1 -0
- package/dist/workerHelpers-threaded.js +100 -0
- package/dist/workerHelpers-threaded.js.map +1 -0
- package/package.json +8 -3
- package/src/Arc.ts +117 -117
- package/src/Brep.ts +1 -1
- package/src/Circle.ts +166 -166
- package/src/Line.ts +171 -171
- package/src/Mesh.ts +300 -45
- package/src/MeshSurface.ts +1 -1
- package/src/NurbsCurve.ts +655 -655
- package/src/NurbsSurface.ts +721 -721
- package/src/PolyCurve.ts +203 -203
- package/src/Polyline.ts +316 -316
- package/src/Ray.ts +90 -90
- package/src/SculptSession.ts +377 -377
- package/src/engine-threaded.ts +39 -0
- package/src/engine.ts +46 -0
- package/src/index.ts +1 -1
- package/src/mesh-boolean.pool.ts +208 -86
- package/src/mesh-boolean.protocol.ts +44 -1
- package/src/mesh-boolean.worker.ts +170 -56
- package/src/wasm-active.ts +31 -0
- package/src/wasm-base64-threaded.ts +2 -0
- package/src/wasm-base64.ts +1 -1
- package/src/wasm-bindings-threaded.d.ts +1989 -0
- package/src/wasm-bindings-threaded.js +5235 -0
- package/src/wasm-bindings.d.ts +104 -0
- package/src/wasm-bindings.js +225 -0
- package/src/workerHelpers-threaded.js +107 -0
package/src/PolyCurve.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ensureInit } from "./engine.js";
|
|
2
|
-
import { Point } from "./Point.js";
|
|
3
|
-
import { Line } from "./Line.js";
|
|
1
|
+
import { ensureInit } from "./engine.js";
|
|
2
|
+
import { Point } from "./Point.js";
|
|
3
|
+
import { Line } from "./Line.js";
|
|
4
4
|
import { Arc } from "./Arc.js";
|
|
5
5
|
import { Vec3 } from "./Vec3.js";
|
|
6
6
|
import { Mesh } from "./Mesh.js";
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
} from "./types.js";
|
|
15
15
|
import { SegmentTypeCode } from "./types.js";
|
|
16
16
|
import { pointsToCoords } from "./BufferCodec.js";
|
|
17
|
-
import
|
|
17
|
+
import { wasm } from "./wasm-active.js";
|
|
18
18
|
|
|
19
19
|
function offsetJoinStyleCode(style: CurveOffsetJoinStyle | undefined): number {
|
|
20
20
|
switch (style ?? "miter") {
|
|
@@ -31,113 +31,113 @@ function offsetJoinStyleCode(style: CurveOffsetJoinStyle | undefined): number {
|
|
|
31
31
|
* Composite curve made of sequential Line and Arc segments.
|
|
32
32
|
*/
|
|
33
33
|
export class PolyCurve {
|
|
34
|
-
public readonly segments: CurveSegment[];
|
|
35
|
-
|
|
36
|
-
constructor(segments: CurveSegment[]) {
|
|
37
|
-
this.segments = segments;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Create a PolyCurve by connecting points with line segments */
|
|
41
|
-
static byPoints(points: Point[]): PolyCurve {
|
|
42
|
-
if (points.length < 2) return new PolyCurve([]);
|
|
43
|
-
const segs: CurveSegment[] = [];
|
|
44
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
45
|
-
segs.push(new Line(points[i], points[i + 1]));
|
|
46
|
-
}
|
|
47
|
-
return new PolyCurve(segs);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get startPoint(): Point {
|
|
51
|
-
if (this.segments.length === 0) return Point.ORIGIN;
|
|
52
|
-
const s = this.segments[0];
|
|
53
|
-
return s instanceof Line ? s.start : s.pointAt(0);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get endPoint(): Point {
|
|
57
|
-
if (this.segments.length === 0) return Point.ORIGIN;
|
|
58
|
-
const s = this.segments[this.segments.length - 1];
|
|
59
|
-
return s instanceof Line ? s.end : s.pointAt(1);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Returns all constituent curves (Line and Arc segments) in order. */
|
|
63
|
-
get curves(): CurveSegment[] {
|
|
64
|
-
return this.segments;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Sample all segments into a flat array of points for rendering.
|
|
69
|
-
* Line segments produce 2 points; Arc segments are sampled with `arcSamples` points.
|
|
70
|
-
* Consecutive duplicate junction points are removed.
|
|
71
|
-
*/
|
|
72
|
-
sample(arcSamples = 32): Point[] {
|
|
73
|
-
const pts: Point[] = [];
|
|
74
|
-
for (const seg of this.segments) {
|
|
75
|
-
let segPts: Point[];
|
|
76
|
-
if (seg instanceof Line) {
|
|
77
|
-
segPts = [seg.start, seg.end];
|
|
78
|
-
} else {
|
|
79
|
-
// Arc: sample into multiple points for smooth rendering
|
|
80
|
-
segPts = seg.sample(arcSamples);
|
|
81
|
-
}
|
|
82
|
-
for (const p of segPts) {
|
|
83
|
-
// Skip duplicate junction points
|
|
84
|
-
if (pts.length > 0 && pts[pts.length - 1].equals(p)) continue;
|
|
85
|
-
pts.push(p);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return pts;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** Evaluate a point on the curve at normalized parameter t (0 = start, 1 = end). */
|
|
92
|
-
pointAt(t: number): Point {
|
|
93
|
-
if (this.segments.length === 0) return Point.ORIGIN;
|
|
94
|
-
if (t <= 0) return this.startPoint;
|
|
95
|
-
if (t >= 1) return this.endPoint;
|
|
96
|
-
|
|
97
|
-
const lengths = this.segments.map(s => s.length());
|
|
98
|
-
const total = lengths.reduce((a, b) => a + b, 0);
|
|
99
|
-
if (total === 0) return this.startPoint;
|
|
100
|
-
|
|
101
|
-
let target = t * total;
|
|
102
|
-
for (let i = 0; i < this.segments.length; i++) {
|
|
103
|
-
if (target <= lengths[i] || i === this.segments.length - 1) {
|
|
104
|
-
const localT = lengths[i] > 0 ? target / lengths[i] : 0;
|
|
105
|
-
return this.segments[i].pointAt(Math.min(localT, 1));
|
|
106
|
-
}
|
|
107
|
-
target -= lengths[i];
|
|
108
|
-
}
|
|
109
|
-
return this.endPoint;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
isClosed(eps = 1e-10): boolean {
|
|
113
|
-
return this.startPoint.equals(this.endPoint, eps);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
length(): number {
|
|
117
|
-
return this.segments.reduce((sum, s) => sum + s.length(), 0);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
rotate(axis: RotationAxis, angle: number): PolyCurve {
|
|
121
|
-
return new PolyCurve(this.segments.map(s => s.rotate(axis, angle)));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
translate(offset: Vec3): PolyCurve {
|
|
125
|
-
return new PolyCurve(this.segments.map(s => s.translate(offset)));
|
|
126
|
-
}
|
|
127
|
-
|
|
34
|
+
public readonly segments: CurveSegment[];
|
|
35
|
+
|
|
36
|
+
constructor(segments: CurveSegment[]) {
|
|
37
|
+
this.segments = segments;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Create a PolyCurve by connecting points with line segments */
|
|
41
|
+
static byPoints(points: Point[]): PolyCurve {
|
|
42
|
+
if (points.length < 2) return new PolyCurve([]);
|
|
43
|
+
const segs: CurveSegment[] = [];
|
|
44
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
45
|
+
segs.push(new Line(points[i], points[i + 1]));
|
|
46
|
+
}
|
|
47
|
+
return new PolyCurve(segs);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get startPoint(): Point {
|
|
51
|
+
if (this.segments.length === 0) return Point.ORIGIN;
|
|
52
|
+
const s = this.segments[0];
|
|
53
|
+
return s instanceof Line ? s.start : s.pointAt(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get endPoint(): Point {
|
|
57
|
+
if (this.segments.length === 0) return Point.ORIGIN;
|
|
58
|
+
const s = this.segments[this.segments.length - 1];
|
|
59
|
+
return s instanceof Line ? s.end : s.pointAt(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Returns all constituent curves (Line and Arc segments) in order. */
|
|
63
|
+
get curves(): CurveSegment[] {
|
|
64
|
+
return this.segments;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Sample all segments into a flat array of points for rendering.
|
|
69
|
+
* Line segments produce 2 points; Arc segments are sampled with `arcSamples` points.
|
|
70
|
+
* Consecutive duplicate junction points are removed.
|
|
71
|
+
*/
|
|
72
|
+
sample(arcSamples = 32): Point[] {
|
|
73
|
+
const pts: Point[] = [];
|
|
74
|
+
for (const seg of this.segments) {
|
|
75
|
+
let segPts: Point[];
|
|
76
|
+
if (seg instanceof Line) {
|
|
77
|
+
segPts = [seg.start, seg.end];
|
|
78
|
+
} else {
|
|
79
|
+
// Arc: sample into multiple points for smooth rendering
|
|
80
|
+
segPts = seg.sample(arcSamples);
|
|
81
|
+
}
|
|
82
|
+
for (const p of segPts) {
|
|
83
|
+
// Skip duplicate junction points
|
|
84
|
+
if (pts.length > 0 && pts[pts.length - 1].equals(p)) continue;
|
|
85
|
+
pts.push(p);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return pts;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Evaluate a point on the curve at normalized parameter t (0 = start, 1 = end). */
|
|
92
|
+
pointAt(t: number): Point {
|
|
93
|
+
if (this.segments.length === 0) return Point.ORIGIN;
|
|
94
|
+
if (t <= 0) return this.startPoint;
|
|
95
|
+
if (t >= 1) return this.endPoint;
|
|
96
|
+
|
|
97
|
+
const lengths = this.segments.map(s => s.length());
|
|
98
|
+
const total = lengths.reduce((a, b) => a + b, 0);
|
|
99
|
+
if (total === 0) return this.startPoint;
|
|
100
|
+
|
|
101
|
+
let target = t * total;
|
|
102
|
+
for (let i = 0; i < this.segments.length; i++) {
|
|
103
|
+
if (target <= lengths[i] || i === this.segments.length - 1) {
|
|
104
|
+
const localT = lengths[i] > 0 ? target / lengths[i] : 0;
|
|
105
|
+
return this.segments[i].pointAt(Math.min(localT, 1));
|
|
106
|
+
}
|
|
107
|
+
target -= lengths[i];
|
|
108
|
+
}
|
|
109
|
+
return this.endPoint;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
isClosed(eps = 1e-10): boolean {
|
|
113
|
+
return this.startPoint.equals(this.endPoint, eps);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
length(): number {
|
|
117
|
+
return this.segments.reduce((sum, s) => sum + s.length(), 0);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
rotate(axis: RotationAxis, angle: number): PolyCurve {
|
|
121
|
+
return new PolyCurve(this.segments.map(s => s.rotate(axis, angle)));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
translate(offset: Vec3): PolyCurve {
|
|
125
|
+
return new PolyCurve(this.segments.map(s => s.translate(offset)));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
128
|
projectOntoPlane(plane: Plane, direction?: Vec3, arcSamples = 32): PolyCurve {
|
|
129
129
|
const proj = (p: Point) => direction ? plane.projectPointAlongDirection(p, direction) : plane.projectPoint(p);
|
|
130
130
|
const segs: CurveSegment[] = [];
|
|
131
131
|
for (const s of this.segments) {
|
|
132
|
-
if (s instanceof Line) {
|
|
133
|
-
segs.push(new Line(proj(s.start), proj(s.end)));
|
|
134
|
-
} else {
|
|
135
|
-
// Arc projects to elliptical arc — approximate with line segments
|
|
136
|
-
const pts = s.sample(arcSamples);
|
|
137
|
-
for (let i = 0; i < pts.length - 1; i++) {
|
|
138
|
-
segs.push(new Line(proj(pts[i]), proj(pts[i + 1])));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
132
|
+
if (s instanceof Line) {
|
|
133
|
+
segs.push(new Line(proj(s.start), proj(s.end)));
|
|
134
|
+
} else {
|
|
135
|
+
// Arc projects to elliptical arc — approximate with line segments
|
|
136
|
+
const pts = s.sample(arcSamples);
|
|
137
|
+
for (let i = 0; i < pts.length - 1; i++) {
|
|
138
|
+
segs.push(new Line(proj(pts[i]), proj(pts[i + 1])));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
141
|
}
|
|
142
142
|
return new PolyCurve(segs);
|
|
143
143
|
}
|
|
@@ -177,66 +177,66 @@ export class PolyCurve {
|
|
|
177
177
|
* Fillet corners of this PolyCurve with arcs of the given radius.
|
|
178
178
|
* Extracts the vertex points, calls WASM fillet_corners, returns a new PolyCurve.
|
|
179
179
|
*/
|
|
180
|
-
fillet(radius: number, normal?: Vec3): PolyCurve {
|
|
181
|
-
ensureInit();
|
|
182
|
-
if (this.segments.length < 2) {
|
|
183
|
-
throw new Error("PolyCurve.fillet() requires at least 2 segments");
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Extract all vertex points from segments
|
|
187
|
-
const pts: Point[] = [];
|
|
188
|
-
for (const seg of this.segments) {
|
|
189
|
-
if (seg instanceof Line) {
|
|
190
|
-
if (pts.length === 0) pts.push(seg.start);
|
|
191
|
-
pts.push(seg.end);
|
|
192
|
-
} else {
|
|
193
|
-
// Arc: use start and end points
|
|
194
|
-
if (pts.length === 0) pts.push(seg.pointAt(0));
|
|
195
|
-
pts.push(seg.pointAt(1));
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (pts.length < 3) {
|
|
199
|
-
throw new Error("PolyCurve.fillet() requires at least 3 vertices");
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const coords = new Float64Array(pts.length * 3);
|
|
203
|
-
for (let i = 0; i < pts.length; i++) {
|
|
204
|
-
coords[i * 3] = pts[i].x;
|
|
205
|
-
coords[i * 3 + 1] = pts[i].y;
|
|
206
|
-
coords[i * 3 + 2] = pts[i].z;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const nx = normal?.x ?? 0, ny = normal?.y ?? 0, nz = normal?.z ?? 0;
|
|
210
|
-
const buf = wasm.fillet_polycurve(coords, radius, nx, ny, nz);
|
|
211
|
-
if (buf.length < 1) {
|
|
212
|
-
throw new Error("PolyCurve.fillet() failed - WASM returned empty result");
|
|
213
|
-
}
|
|
214
|
-
return PolyCurve.fromSegmentData(buf);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/** Decode a PolyCurve from WASM segment buffer [count, type, ...data, ...] */
|
|
180
|
+
fillet(radius: number, normal?: Vec3): PolyCurve {
|
|
181
|
+
ensureInit();
|
|
182
|
+
if (this.segments.length < 2) {
|
|
183
|
+
throw new Error("PolyCurve.fillet() requires at least 2 segments");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Extract all vertex points from segments
|
|
187
|
+
const pts: Point[] = [];
|
|
188
|
+
for (const seg of this.segments) {
|
|
189
|
+
if (seg instanceof Line) {
|
|
190
|
+
if (pts.length === 0) pts.push(seg.start);
|
|
191
|
+
pts.push(seg.end);
|
|
192
|
+
} else {
|
|
193
|
+
// Arc: use start and end points
|
|
194
|
+
if (pts.length === 0) pts.push(seg.pointAt(0));
|
|
195
|
+
pts.push(seg.pointAt(1));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (pts.length < 3) {
|
|
199
|
+
throw new Error("PolyCurve.fillet() requires at least 3 vertices");
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const coords = new Float64Array(pts.length * 3);
|
|
203
|
+
for (let i = 0; i < pts.length; i++) {
|
|
204
|
+
coords[i * 3] = pts[i].x;
|
|
205
|
+
coords[i * 3 + 1] = pts[i].y;
|
|
206
|
+
coords[i * 3 + 2] = pts[i].z;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const nx = normal?.x ?? 0, ny = normal?.y ?? 0, nz = normal?.z ?? 0;
|
|
210
|
+
const buf = wasm.fillet_polycurve(coords, radius, nx, ny, nz);
|
|
211
|
+
if (buf.length < 1) {
|
|
212
|
+
throw new Error("PolyCurve.fillet() failed - WASM returned empty result");
|
|
213
|
+
}
|
|
214
|
+
return PolyCurve.fromSegmentData(buf);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Decode a PolyCurve from WASM segment buffer [count, type, ...data, ...] */
|
|
218
218
|
static fromSegmentData(buf: Float64Array | number[]): PolyCurve {
|
|
219
219
|
const count = buf[0];
|
|
220
220
|
const segs: CurveSegment[] = [];
|
|
221
221
|
let idx = 1;
|
|
222
|
-
for (let i = 0; i < count; i++) {
|
|
223
|
-
const type = buf[idx++];
|
|
224
|
-
if (type === SegmentTypeCode.Line) {
|
|
225
|
-
// Line: 6 floats
|
|
226
|
-
const s = new Point(buf[idx], buf[idx + 1], buf[idx + 2]);
|
|
227
|
-
const e = new Point(buf[idx + 3], buf[idx + 4], buf[idx + 5]);
|
|
228
|
-
segs.push(new Line(s, e));
|
|
229
|
-
idx += 6;
|
|
230
|
-
} else if (type === SegmentTypeCode.Arc) {
|
|
231
|
-
// Arc: 9 floats
|
|
232
|
-
const center = new Point(buf[idx], buf[idx + 1], buf[idx + 2]);
|
|
233
|
-
const normal = new Vec3(buf[idx + 3], buf[idx + 4], buf[idx + 5]);
|
|
234
|
-
const radius = buf[idx + 6];
|
|
235
|
-
const startAngle = buf[idx + 7];
|
|
236
|
-
const endAngle = buf[idx + 8];
|
|
237
|
-
segs.push(new Arc(center, radius, startAngle, endAngle, normal));
|
|
238
|
-
idx += 9;
|
|
239
|
-
}
|
|
222
|
+
for (let i = 0; i < count; i++) {
|
|
223
|
+
const type = buf[idx++];
|
|
224
|
+
if (type === SegmentTypeCode.Line) {
|
|
225
|
+
// Line: 6 floats
|
|
226
|
+
const s = new Point(buf[idx], buf[idx + 1], buf[idx + 2]);
|
|
227
|
+
const e = new Point(buf[idx + 3], buf[idx + 4], buf[idx + 5]);
|
|
228
|
+
segs.push(new Line(s, e));
|
|
229
|
+
idx += 6;
|
|
230
|
+
} else if (type === SegmentTypeCode.Arc) {
|
|
231
|
+
// Arc: 9 floats
|
|
232
|
+
const center = new Point(buf[idx], buf[idx + 1], buf[idx + 2]);
|
|
233
|
+
const normal = new Vec3(buf[idx + 3], buf[idx + 4], buf[idx + 5]);
|
|
234
|
+
const radius = buf[idx + 6];
|
|
235
|
+
const startAngle = buf[idx + 7];
|
|
236
|
+
const endAngle = buf[idx + 8];
|
|
237
|
+
segs.push(new Arc(center, radius, startAngle, endAngle, normal));
|
|
238
|
+
idx += 9;
|
|
239
|
+
}
|
|
240
240
|
}
|
|
241
241
|
return new PolyCurve(segs);
|
|
242
242
|
}
|
|
@@ -263,45 +263,45 @@ export class PolyCurve {
|
|
|
263
263
|
|
|
264
264
|
return curves;
|
|
265
265
|
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Chamfer corners of this PolyCurve by cutting each corner with a straight segment.
|
|
269
|
-
* Returns a new PolyCurve of line segments only.
|
|
270
|
-
*/
|
|
271
|
-
chamfer(distance: number): PolyCurve {
|
|
272
|
-
ensureInit();
|
|
273
|
-
if (this.segments.length < 2) {
|
|
274
|
-
throw new Error("PolyCurve.chamfer() requires at least 2 segments");
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const pts: Point[] = [];
|
|
278
|
-
for (const seg of this.segments) {
|
|
279
|
-
if (seg instanceof Line) {
|
|
280
|
-
if (pts.length === 0) pts.push(seg.start);
|
|
281
|
-
pts.push(seg.end);
|
|
282
|
-
} else {
|
|
283
|
-
if (pts.length === 0) pts.push(seg.pointAt(0));
|
|
284
|
-
pts.push(seg.pointAt(1));
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (pts.length < 3) {
|
|
288
|
-
throw new Error("PolyCurve.chamfer() requires at least 3 vertices");
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const coords = new Float64Array(pts.length * 3);
|
|
292
|
-
for (let i = 0; i < pts.length; i++) {
|
|
293
|
-
coords[i * 3] = pts[i].x;
|
|
294
|
-
coords[i * 3 + 1] = pts[i].y;
|
|
295
|
-
coords[i * 3 + 2] = pts[i].z;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const buf = wasm.chamfer_polycurve(coords, distance);
|
|
299
|
-
if (buf.length < 1) {
|
|
300
|
-
throw new Error("PolyCurve.chamfer() failed - WASM returned empty result");
|
|
301
|
-
}
|
|
302
|
-
return PolyCurve.fromSegmentData(buf);
|
|
303
|
-
}
|
|
304
|
-
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Chamfer corners of this PolyCurve by cutting each corner with a straight segment.
|
|
269
|
+
* Returns a new PolyCurve of line segments only.
|
|
270
|
+
*/
|
|
271
|
+
chamfer(distance: number): PolyCurve {
|
|
272
|
+
ensureInit();
|
|
273
|
+
if (this.segments.length < 2) {
|
|
274
|
+
throw new Error("PolyCurve.chamfer() requires at least 2 segments");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const pts: Point[] = [];
|
|
278
|
+
for (const seg of this.segments) {
|
|
279
|
+
if (seg instanceof Line) {
|
|
280
|
+
if (pts.length === 0) pts.push(seg.start);
|
|
281
|
+
pts.push(seg.end);
|
|
282
|
+
} else {
|
|
283
|
+
if (pts.length === 0) pts.push(seg.pointAt(0));
|
|
284
|
+
pts.push(seg.pointAt(1));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (pts.length < 3) {
|
|
288
|
+
throw new Error("PolyCurve.chamfer() requires at least 3 vertices");
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const coords = new Float64Array(pts.length * 3);
|
|
292
|
+
for (let i = 0; i < pts.length; i++) {
|
|
293
|
+
coords[i * 3] = pts[i].x;
|
|
294
|
+
coords[i * 3 + 1] = pts[i].y;
|
|
295
|
+
coords[i * 3 + 2] = pts[i].z;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const buf = wasm.chamfer_polycurve(coords, distance);
|
|
299
|
+
if (buf.length < 1) {
|
|
300
|
+
throw new Error("PolyCurve.chamfer() failed - WASM returned empty result");
|
|
301
|
+
}
|
|
302
|
+
return PolyCurve.fromSegmentData(buf);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
305
|
/**
|
|
306
306
|
* Offset this PolyCurve by a distance in the given plane.
|
|
307
307
|
* Preserves exact line/arc segments where possible and applies the requested outside-corner join style.
|
|
@@ -383,7 +383,7 @@ export class PolyCurve {
|
|
|
383
383
|
* Convert to an exact NURBS curve representation via WASM.
|
|
384
384
|
* Lines become degree-1 NURBS, Arcs become degree-2 rational NURBS.
|
|
385
385
|
* All segments are degree-elevated to a common degree and joined.
|
|
386
|
-
*/
|
|
386
|
+
*/
|
|
387
387
|
toNurbs(): NurbsCurve {
|
|
388
388
|
ensureInit();
|
|
389
389
|
const buf = wasm.polycurve_to_nurbs(this.toSegmentData());
|