@snaptrude/plugin-core 0.0.5 → 0.0.6
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/api/core/geom/arc.d.ts +50 -1
- package/dist/api/core/geom/arc.d.ts.map +1 -1
- package/dist/api/core/geom/curve.d.ts +26 -1
- package/dist/api/core/geom/curve.d.ts.map +1 -1
- package/dist/api/core/geom/index.d.ts +16 -0
- package/dist/api/core/geom/index.d.ts.map +1 -1
- package/dist/api/core/geom/line.d.ts +35 -1
- package/dist/api/core/geom/line.d.ts.map +1 -1
- package/dist/api/core/geom/profile.d.ts +66 -2
- package/dist/api/core/geom/profile.d.ts.map +1 -1
- package/dist/api/core/index.d.ts +8 -0
- package/dist/api/core/index.d.ts.map +1 -1
- package/dist/api/core/math/index.d.ts +8 -0
- package/dist/api/core/math/index.d.ts.map +1 -1
- package/dist/api/core/math/quat.d.ts +156 -15
- package/dist/api/core/math/quat.d.ts.map +1 -1
- package/dist/api/core/math/vec3.d.ts +131 -14
- package/dist/api/core/math/vec3.d.ts.map +1 -1
- package/dist/api/entity/index.d.ts +8 -0
- package/dist/api/entity/index.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +217 -4
- package/dist/api/entity/space.d.ts.map +1 -1
- package/dist/api/entity/story.d.ts +166 -0
- package/dist/api/entity/story.d.ts.map +1 -1
- package/dist/api/index.d.ts +14 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/tools/index.d.ts +8 -0
- package/dist/api/tools/index.d.ts.map +1 -1
- package/dist/api/tools/selection.d.ts +37 -0
- package/dist/api/tools/selection.d.ts.map +1 -1
- package/dist/api/tools/transform.d.ts +82 -0
- package/dist/api/tools/transform.d.ts.map +1 -1
- package/dist/api/units/index.d.ts +72 -13
- package/dist/api/units/index.d.ts.map +1 -1
- package/dist/index.cjs +322 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +321 -35
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/api/core/geom/arc.ts +50 -1
- package/src/api/core/geom/curve.ts +26 -1
- package/src/api/core/geom/index.ts +16 -0
- package/src/api/core/geom/line.ts +35 -1
- package/src/api/core/geom/profile.ts +66 -2
- package/src/api/core/index.ts +8 -0
- package/src/api/core/math/index.ts +8 -0
- package/src/api/core/math/quat.ts +156 -15
- package/src/api/core/math/vec3.ts +131 -14
- package/src/api/entity/index.ts +8 -0
- package/src/api/entity/space.ts +218 -5
- package/src/api/entity/story.ts +166 -0
- package/src/api/index.ts +14 -0
- package/src/api/tools/index.ts +8 -0
- package/src/api/tools/selection.ts +37 -0
- package/src/api/tools/transform.ts +82 -0
- package/src/api/units/index.ts +72 -13
- package/src/types.ts +8 -1
package/dist/index.js
CHANGED
|
@@ -3,27 +3,78 @@ import * as z from "zod";
|
|
|
3
3
|
var PluginVec3Api = class {
|
|
4
4
|
constructor() {
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Create a new 3D vector.
|
|
8
|
+
*
|
|
9
|
+
* @param x - The X component
|
|
10
|
+
* @param y - The Y component
|
|
11
|
+
* @param z - The Z component
|
|
12
|
+
* @returns A new {@linkcode PVec3}
|
|
13
|
+
*
|
|
14
|
+
* # Example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const position = snaptrude.core.math.vec3.new(1, 2, 3)
|
|
17
|
+
* // { x: 1, y: 2, z: 3 }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
7
20
|
new(x, y, z12) {
|
|
8
21
|
return { x, y, z: z12 };
|
|
9
22
|
}
|
|
10
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Add two vectors component-wise.
|
|
25
|
+
*
|
|
26
|
+
* @param a - First vector
|
|
27
|
+
* @param b - Second vector
|
|
28
|
+
* @returns A new {@linkcode PVec3} where each component is `a[i] + b[i]`
|
|
29
|
+
*/
|
|
11
30
|
add(a, b) {
|
|
12
31
|
return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
|
|
13
32
|
}
|
|
14
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* Subtract vector {@linkcode b} from vector {@linkcode a} component-wise.
|
|
35
|
+
*
|
|
36
|
+
* @param a - Vector to subtract from
|
|
37
|
+
* @param b - Vector to subtract
|
|
38
|
+
* @returns A new {@linkcode PVec3} where each component is `a[i] - b[i]`
|
|
39
|
+
*/
|
|
15
40
|
subtract(a, b) {
|
|
16
41
|
return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
|
|
17
42
|
}
|
|
18
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Scale a vector by a scalar value.
|
|
45
|
+
*
|
|
46
|
+
* @param v - The vector to scale
|
|
47
|
+
* @param scalar - The scalar multiplier
|
|
48
|
+
* @returns A new {@linkcode PVec3} where each component is `v[i] * scalar`
|
|
49
|
+
*/
|
|
19
50
|
scale(v, scalar) {
|
|
20
51
|
return { x: v.x * scalar, y: v.y * scalar, z: v.z * scalar };
|
|
21
52
|
}
|
|
22
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Compute the dot product of two vectors.
|
|
55
|
+
*
|
|
56
|
+
* The dot product equals `|a| * |b| * cos(θ)` where `θ` is the angle
|
|
57
|
+
* between the vectors. Useful for checking orthogonality (result = 0)
|
|
58
|
+
* or projection.
|
|
59
|
+
*
|
|
60
|
+
* @param a - First vector
|
|
61
|
+
* @param b - Second vector
|
|
62
|
+
* @returns The scalar dot product
|
|
63
|
+
*/
|
|
23
64
|
dot(a, b) {
|
|
24
65
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
25
66
|
}
|
|
26
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Compute the cross product of two vectors.
|
|
69
|
+
*
|
|
70
|
+
* The result is a vector perpendicular to both inputs, with magnitude
|
|
71
|
+
* equal to the area of the parallelogram they span. Useful for computing
|
|
72
|
+
* surface normals.
|
|
73
|
+
*
|
|
74
|
+
* @param a - First vector
|
|
75
|
+
* @param b - Second vector
|
|
76
|
+
* @returns A new {@linkcode PVec3} perpendicular to both {@linkcode a} and {@linkcode b}
|
|
77
|
+
*/
|
|
27
78
|
cross(a, b) {
|
|
28
79
|
return {
|
|
29
80
|
x: a.y * b.z - a.z * b.y,
|
|
@@ -31,25 +82,57 @@ var PluginVec3Api = class {
|
|
|
31
82
|
z: a.x * b.y - a.y * b.x
|
|
32
83
|
};
|
|
33
84
|
}
|
|
34
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Compute the length (magnitude) of a vector.
|
|
87
|
+
*
|
|
88
|
+
* @param v - The vector
|
|
89
|
+
* @returns The Euclidean length `√(x² + y² + z²)`
|
|
90
|
+
*/
|
|
35
91
|
length(v) {
|
|
36
92
|
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
|
37
93
|
}
|
|
38
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Compute the squared length of a vector.
|
|
96
|
+
*
|
|
97
|
+
* Avoids the `sqrt` call — prefer this over {@linkcode PluginVec3Api.length}
|
|
98
|
+
* when comparing relative magnitudes.
|
|
99
|
+
*
|
|
100
|
+
* @param v - The vector
|
|
101
|
+
* @returns The squared length `x² + y² + z²`
|
|
102
|
+
*/
|
|
39
103
|
lengthSquared(v) {
|
|
40
104
|
return v.x * v.x + v.y * v.y + v.z * v.z;
|
|
41
105
|
}
|
|
42
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Normalize a vector to unit length.
|
|
108
|
+
*
|
|
109
|
+
* @param v - The vector to normalize
|
|
110
|
+
* @returns A new unit-length {@linkcode PVec3} in the same direction,
|
|
111
|
+
* or a zero vector `(0, 0, 0)` if the input has zero length
|
|
112
|
+
*/
|
|
43
113
|
normalize(v) {
|
|
44
114
|
const len = this.length(v);
|
|
45
115
|
if (len === 0) return { x: 0, y: 0, z: 0 };
|
|
46
116
|
return { x: v.x / len, y: v.y / len, z: v.z / len };
|
|
47
117
|
}
|
|
48
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* Compute the Euclidean distance between two points.
|
|
120
|
+
*
|
|
121
|
+
* @param a - First point
|
|
122
|
+
* @param b - Second point
|
|
123
|
+
* @returns The distance `|a - b|`
|
|
124
|
+
*/
|
|
49
125
|
distance(a, b) {
|
|
50
126
|
return this.length(this.subtract(a, b));
|
|
51
127
|
}
|
|
52
|
-
/**
|
|
128
|
+
/**
|
|
129
|
+
* Linearly interpolate between two vectors.
|
|
130
|
+
*
|
|
131
|
+
* @param a - Start vector (returned when `t = 0`)
|
|
132
|
+
* @param b - End vector (returned when `t = 1`)
|
|
133
|
+
* @param t - Interpolation factor, typically in `[0, 1]`
|
|
134
|
+
* @returns A new {@linkcode PVec3} at `a + (b - a) * t`
|
|
135
|
+
*/
|
|
53
136
|
lerp(a, b, t) {
|
|
54
137
|
return {
|
|
55
138
|
x: a.x + (b.x - a.x) * t,
|
|
@@ -57,15 +140,35 @@ var PluginVec3Api = class {
|
|
|
57
140
|
z: a.z + (b.z - a.z) * t
|
|
58
141
|
};
|
|
59
142
|
}
|
|
60
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Negate a vector (reverse its direction).
|
|
145
|
+
*
|
|
146
|
+
* @param v - The vector to negate
|
|
147
|
+
* @returns A new {@linkcode PVec3} with all components negated
|
|
148
|
+
*/
|
|
61
149
|
negate(v) {
|
|
62
150
|
return { x: -v.x, y: -v.y, z: -v.z };
|
|
63
151
|
}
|
|
64
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* Check if two vectors are exactly equal (strict equality per component).
|
|
154
|
+
*
|
|
155
|
+
* For floating-point comparisons, prefer {@linkcode PluginVec3Api.equalsApprox}.
|
|
156
|
+
*
|
|
157
|
+
* @param a - First vector
|
|
158
|
+
* @param b - Second vector
|
|
159
|
+
* @returns `true` if all components match exactly
|
|
160
|
+
*/
|
|
65
161
|
equals(a, b) {
|
|
66
162
|
return a.x === b.x && a.y === b.y && a.z === b.z;
|
|
67
163
|
}
|
|
68
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Check if two vectors are approximately equal within a tolerance.
|
|
166
|
+
*
|
|
167
|
+
* @param a - First vector
|
|
168
|
+
* @param b - Second vector
|
|
169
|
+
* @param epsilon - Maximum allowed difference per component (default `1e-6`)
|
|
170
|
+
* @returns `true` if `|a[i] - b[i]| < epsilon` for all components
|
|
171
|
+
*/
|
|
69
172
|
equalsApprox(a, b, epsilon = 1e-6) {
|
|
70
173
|
return Math.abs(a.x - b.x) < epsilon && Math.abs(a.y - b.y) < epsilon && Math.abs(a.z - b.z) < epsilon;
|
|
71
174
|
}
|
|
@@ -81,15 +184,43 @@ import * as z2 from "zod";
|
|
|
81
184
|
var PluginQuatApi = class {
|
|
82
185
|
constructor() {
|
|
83
186
|
}
|
|
84
|
-
/**
|
|
187
|
+
/**
|
|
188
|
+
* Create a new quaternion from raw components.
|
|
189
|
+
*
|
|
190
|
+
* For most use cases prefer {@linkcode PluginQuatApi.fromAxisAngle}
|
|
191
|
+
* or {@linkcode PluginQuatApi.fromEuler} instead.
|
|
192
|
+
*
|
|
193
|
+
* @param x - The X component
|
|
194
|
+
* @param y - The Y component
|
|
195
|
+
* @param z - The Z component
|
|
196
|
+
* @param w - The W (scalar) component
|
|
197
|
+
* @returns A new {@linkcode PQuat}
|
|
198
|
+
*/
|
|
85
199
|
new(x, y, z12, w) {
|
|
86
200
|
return { x, y, z: z12, w };
|
|
87
201
|
}
|
|
88
|
-
/**
|
|
202
|
+
/**
|
|
203
|
+
* Create an identity quaternion representing no rotation.
|
|
204
|
+
*
|
|
205
|
+
* @returns `{ x: 0, y: 0, z: 0, w: 1 }`
|
|
206
|
+
*/
|
|
89
207
|
identity() {
|
|
90
208
|
return { x: 0, y: 0, z: 0, w: 1 };
|
|
91
209
|
}
|
|
92
|
-
/**
|
|
210
|
+
/**
|
|
211
|
+
* Create a quaternion from an axis and an angle.
|
|
212
|
+
*
|
|
213
|
+
* @param axis - The rotation axis as a {@linkcode PVec3} (will be normalized internally)
|
|
214
|
+
* @param angle - The rotation angle in **radians**
|
|
215
|
+
* @returns A new unit {@linkcode PQuat}, or identity if {@linkcode axis} has zero length
|
|
216
|
+
*
|
|
217
|
+
* # Example
|
|
218
|
+
* ```ts
|
|
219
|
+
* const { vec3, quat } = snaptrude.core.math
|
|
220
|
+
* // 90° rotation around the Y axis
|
|
221
|
+
* const rot = quat.fromAxisAngle(vec3.new(0, 1, 0), Math.PI / 2)
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
93
224
|
fromAxisAngle(axis, angle) {
|
|
94
225
|
const halfAngle = angle / 2;
|
|
95
226
|
const s = Math.sin(halfAngle);
|
|
@@ -102,7 +233,14 @@ var PluginQuatApi = class {
|
|
|
102
233
|
w: Math.cos(halfAngle)
|
|
103
234
|
};
|
|
104
235
|
}
|
|
105
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Create a quaternion from Euler angles in **XYZ** rotation order.
|
|
238
|
+
*
|
|
239
|
+
* @param x - Rotation around X axis in **radians**
|
|
240
|
+
* @param y - Rotation around Y axis in **radians**
|
|
241
|
+
* @param z - Rotation around Z axis in **radians**
|
|
242
|
+
* @returns A new {@linkcode PQuat}
|
|
243
|
+
*/
|
|
106
244
|
fromEuler(x, y, z12) {
|
|
107
245
|
const cx = Math.cos(x / 2);
|
|
108
246
|
const sx = Math.sin(x / 2);
|
|
@@ -117,7 +255,16 @@ var PluginQuatApi = class {
|
|
|
117
255
|
w: cx * cy * cz - sx * sy * sz
|
|
118
256
|
};
|
|
119
257
|
}
|
|
120
|
-
/**
|
|
258
|
+
/**
|
|
259
|
+
* Multiply two quaternions, combining their rotations.
|
|
260
|
+
*
|
|
261
|
+
* Quaternion multiplication is **not commutative**: `a * b ≠ b * a`.
|
|
262
|
+
* The result applies rotation {@linkcode b} first, then {@linkcode a}.
|
|
263
|
+
*
|
|
264
|
+
* @param a - First quaternion (applied second)
|
|
265
|
+
* @param b - Second quaternion (applied first)
|
|
266
|
+
* @returns A new {@linkcode PQuat} representing the combined rotation
|
|
267
|
+
*/
|
|
121
268
|
multiply(a, b) {
|
|
122
269
|
return {
|
|
123
270
|
x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
|
|
@@ -126,34 +273,83 @@ var PluginQuatApi = class {
|
|
|
126
273
|
w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z
|
|
127
274
|
};
|
|
128
275
|
}
|
|
129
|
-
/**
|
|
276
|
+
/**
|
|
277
|
+
* Compute the conjugate of a quaternion.
|
|
278
|
+
*
|
|
279
|
+
* For unit quaternions the conjugate equals the inverse.
|
|
280
|
+
*
|
|
281
|
+
* @param q - The quaternion
|
|
282
|
+
* @returns A new {@linkcode PQuat} with negated vector part `(-x, -y, -z, w)`
|
|
283
|
+
*/
|
|
130
284
|
conjugate(q) {
|
|
131
285
|
return { x: -q.x, y: -q.y, z: -q.z, w: q.w };
|
|
132
286
|
}
|
|
133
|
-
/**
|
|
287
|
+
/**
|
|
288
|
+
* Compute the length (magnitude) of a quaternion.
|
|
289
|
+
*
|
|
290
|
+
* @param q - The quaternion
|
|
291
|
+
* @returns The magnitude `√(x² + y² + z² + w²)`
|
|
292
|
+
*/
|
|
134
293
|
length(q) {
|
|
135
294
|
return Math.sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
|
|
136
295
|
}
|
|
137
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Normalize a quaternion to unit length.
|
|
298
|
+
*
|
|
299
|
+
* @param q - The quaternion to normalize
|
|
300
|
+
* @returns A new unit-length {@linkcode PQuat}, or identity if the input has zero length
|
|
301
|
+
*/
|
|
138
302
|
normalize(q) {
|
|
139
303
|
const len = this.length(q);
|
|
140
304
|
if (len === 0) return { x: 0, y: 0, z: 0, w: 1 };
|
|
141
305
|
return { x: q.x / len, y: q.y / len, z: q.z / len, w: q.w / len };
|
|
142
306
|
}
|
|
143
|
-
/**
|
|
307
|
+
/**
|
|
308
|
+
* Compute the inverse of a quaternion.
|
|
309
|
+
*
|
|
310
|
+
* The inverse satisfies `q * inverse(q) = identity`.
|
|
311
|
+
*
|
|
312
|
+
* @param q - The quaternion to invert
|
|
313
|
+
* @returns A new {@linkcode PQuat} that is the multiplicative inverse,
|
|
314
|
+
* or identity if the input has zero length
|
|
315
|
+
*/
|
|
144
316
|
inverse(q) {
|
|
145
317
|
const lenSq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
|
|
146
318
|
if (lenSq === 0) return { x: 0, y: 0, z: 0, w: 1 };
|
|
147
319
|
return { x: -q.x / lenSq, y: -q.y / lenSq, z: -q.z / lenSq, w: q.w / lenSq };
|
|
148
320
|
}
|
|
149
|
-
/**
|
|
321
|
+
/**
|
|
322
|
+
* Rotate a 3D vector by a quaternion.
|
|
323
|
+
*
|
|
324
|
+
* Computes `q * v * conjugate(q)` using the Hamilton product.
|
|
325
|
+
*
|
|
326
|
+
* @param q - The rotation quaternion (should be unit-length)
|
|
327
|
+
* @param v - The vector to rotate as a {@linkcode PVec3}
|
|
328
|
+
* @returns A new rotated {@linkcode PVec3}
|
|
329
|
+
*
|
|
330
|
+
* # Example
|
|
331
|
+
* ```ts
|
|
332
|
+
* const { vec3, quat } = snaptrude.core.math
|
|
333
|
+
* const rot = quat.fromAxisAngle(vec3.new(0, 1, 0), Math.PI / 2)
|
|
334
|
+
* const rotated = quat.rotateVec3(rot, vec3.new(1, 0, 0))
|
|
335
|
+
* // ≈ { x: 0, y: 0, z: -1 }
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
150
338
|
rotateVec3(q, v) {
|
|
151
339
|
const vq = { x: v.x, y: v.y, z: v.z, w: 0 };
|
|
152
340
|
const conj = this.conjugate(q);
|
|
153
341
|
const result = this.multiply(this.multiply(q, vq), conj);
|
|
154
342
|
return { x: result.x, y: result.y, z: result.z };
|
|
155
343
|
}
|
|
156
|
-
/**
|
|
344
|
+
/**
|
|
345
|
+
* Convert a quaternion to axis-angle representation.
|
|
346
|
+
*
|
|
347
|
+
* @param q - The quaternion to convert
|
|
348
|
+
* @returns An object with:
|
|
349
|
+
* - `axis` — The rotation axis as a unit {@linkcode PVec3}
|
|
350
|
+
* (defaults to `(1, 0, 0)` when angle is zero)
|
|
351
|
+
* - `angle` — The rotation angle in **radians**
|
|
352
|
+
*/
|
|
157
353
|
toAxisAngle(q) {
|
|
158
354
|
const nq = this.normalize(q);
|
|
159
355
|
const angle = 2 * Math.acos(Math.min(1, Math.max(-1, nq.w)));
|
|
@@ -166,7 +362,16 @@ var PluginQuatApi = class {
|
|
|
166
362
|
angle
|
|
167
363
|
};
|
|
168
364
|
}
|
|
169
|
-
/**
|
|
365
|
+
/**
|
|
366
|
+
* Spherical linear interpolation between two quaternions.
|
|
367
|
+
*
|
|
368
|
+
* Produces smooth constant-speed rotation between {@linkcode a} and {@linkcode b}.
|
|
369
|
+
*
|
|
370
|
+
* @param a - Start quaternion (returned when `t = 0`)
|
|
371
|
+
* @param b - End quaternion (returned when `t = 1`)
|
|
372
|
+
* @param t - Interpolation factor, typically in `[0, 1]`
|
|
373
|
+
* @returns A new interpolated {@linkcode PQuat}
|
|
374
|
+
*/
|
|
170
375
|
slerp(a, b, t) {
|
|
171
376
|
let cosHalf = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
|
172
377
|
let bx = b.x, by = b.y, bz = b.z, bw = b.w;
|
|
@@ -191,15 +396,39 @@ var PluginQuatApi = class {
|
|
|
191
396
|
w: a.w * ratioA + bw * ratioB
|
|
192
397
|
};
|
|
193
398
|
}
|
|
194
|
-
/**
|
|
399
|
+
/**
|
|
400
|
+
* Compute the dot product of two quaternions.
|
|
401
|
+
*
|
|
402
|
+
* A value close to `1` or `-1` indicates similar orientations;
|
|
403
|
+
* a value close to `0` indicates maximally different orientations.
|
|
404
|
+
*
|
|
405
|
+
* @param a - First quaternion
|
|
406
|
+
* @param b - Second quaternion
|
|
407
|
+
* @returns The scalar dot product
|
|
408
|
+
*/
|
|
195
409
|
dot(a, b) {
|
|
196
410
|
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
|
197
411
|
}
|
|
198
|
-
/**
|
|
412
|
+
/**
|
|
413
|
+
* Check if two quaternions are exactly equal (strict equality per component).
|
|
414
|
+
*
|
|
415
|
+
* For floating-point comparisons, prefer {@linkcode PluginQuatApi.equalsApprox}.
|
|
416
|
+
*
|
|
417
|
+
* @param a - First quaternion
|
|
418
|
+
* @param b - Second quaternion
|
|
419
|
+
* @returns `true` if all components match exactly
|
|
420
|
+
*/
|
|
199
421
|
equals(a, b) {
|
|
200
422
|
return a.x === b.x && a.y === b.y && a.z === b.z && a.w === b.w;
|
|
201
423
|
}
|
|
202
|
-
/**
|
|
424
|
+
/**
|
|
425
|
+
* Check if two quaternions are approximately equal within a tolerance.
|
|
426
|
+
*
|
|
427
|
+
* @param a - First quaternion
|
|
428
|
+
* @param b - Second quaternion
|
|
429
|
+
* @param epsilon - Maximum allowed difference per component (default `1e-6`)
|
|
430
|
+
* @returns `true` if `|a[i] - b[i]| < epsilon` for all components
|
|
431
|
+
*/
|
|
203
432
|
equalsApprox(a, b, epsilon = 1e-6) {
|
|
204
433
|
return Math.abs(a.x - b.x) < epsilon && Math.abs(a.y - b.y) < epsilon && Math.abs(a.z - b.z) < epsilon && Math.abs(a.w - b.w) < epsilon;
|
|
205
434
|
}
|
|
@@ -222,7 +451,21 @@ import * as z3 from "zod";
|
|
|
222
451
|
var PluginLineApi = class {
|
|
223
452
|
constructor() {
|
|
224
453
|
}
|
|
225
|
-
/**
|
|
454
|
+
/**
|
|
455
|
+
* Create a new line segment between two points.
|
|
456
|
+
*
|
|
457
|
+
* @param startPoint - The start point as a {@linkcode PVec3}
|
|
458
|
+
* @param endPoint - The end point as a {@linkcode PVec3}
|
|
459
|
+
* @returns A new {@linkcode PLine}
|
|
460
|
+
*
|
|
461
|
+
* # Example
|
|
462
|
+
* ```ts
|
|
463
|
+
* const { vec3 } = snaptrude.core.math
|
|
464
|
+
* const { line } = snaptrude.core.geom
|
|
465
|
+
*
|
|
466
|
+
* const edge = line.new(vec3.new(0, 0, 0), vec3.new(5, 0, 0))
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
226
469
|
new(startPoint, endPoint) {
|
|
227
470
|
return { curveType: "Line", startPoint, endPoint };
|
|
228
471
|
}
|
|
@@ -238,7 +481,34 @@ import * as z4 from "zod";
|
|
|
238
481
|
var PluginArcApi = class {
|
|
239
482
|
constructor() {
|
|
240
483
|
}
|
|
241
|
-
/**
|
|
484
|
+
/**
|
|
485
|
+
* Create a new arc from start, end, centre, and axis.
|
|
486
|
+
*
|
|
487
|
+
* The arc sweeps from {@linkcode startPoint} to {@linkcode endPoint}
|
|
488
|
+
* along the circle centred at {@linkcode centrePoint}, in the
|
|
489
|
+
* direction determined by the right-hand rule around {@linkcode axis}.
|
|
490
|
+
*
|
|
491
|
+
* @param startPoint - The start point as a {@linkcode PVec3}
|
|
492
|
+
* @param endPoint - The end point as a {@linkcode PVec3}
|
|
493
|
+
* @param centrePoint - The centre of the arc's circle as a {@linkcode PVec3}
|
|
494
|
+
* @param axis - The arc's rotation axis as a {@linkcode PVec3}
|
|
495
|
+
* (perpendicular to the arc's plane)
|
|
496
|
+
* @returns A new {@linkcode PArc}
|
|
497
|
+
*
|
|
498
|
+
* # Example
|
|
499
|
+
* ```ts
|
|
500
|
+
* const { vec3 } = snaptrude.core.math
|
|
501
|
+
* const { arc } = snaptrude.core.geom
|
|
502
|
+
*
|
|
503
|
+
* // Quarter-circle arc on the XZ plane
|
|
504
|
+
* const a = arc.new(
|
|
505
|
+
* vec3.new(1, 0, 0), // start
|
|
506
|
+
* vec3.new(0, 0, 1), // end
|
|
507
|
+
* vec3.new(0, 0, 0), // centre
|
|
508
|
+
* vec3.new(0, 1, 0), // Y-up axis
|
|
509
|
+
* )
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
242
512
|
new(startPoint, endPoint, centrePoint, axis) {
|
|
243
513
|
return { curveType: "Arc", startPoint, endPoint, centrePoint, axis };
|
|
244
514
|
}
|
|
@@ -256,7 +526,15 @@ import * as z5 from "zod";
|
|
|
256
526
|
var PluginCurveApi = class {
|
|
257
527
|
constructor() {
|
|
258
528
|
}
|
|
259
|
-
/**
|
|
529
|
+
/**
|
|
530
|
+
* Wrap a {@linkcode PLine} or {@linkcode PArc} as a {@linkcode PCurve}.
|
|
531
|
+
*
|
|
532
|
+
* This is an identity operation — it simply returns the input unchanged.
|
|
533
|
+
* It exists for type-level clarity when building mixed curve lists.
|
|
534
|
+
*
|
|
535
|
+
* @param curve - A {@linkcode PLine} or {@linkcode PArc} to wrap
|
|
536
|
+
* @returns The same value typed as {@linkcode PCurve}
|
|
537
|
+
*/
|
|
260
538
|
new(curve) {
|
|
261
539
|
return curve;
|
|
262
540
|
}
|
|
@@ -268,7 +546,15 @@ import * as z6 from "zod";
|
|
|
268
546
|
var PluginProfileApi = class {
|
|
269
547
|
constructor() {
|
|
270
548
|
}
|
|
271
|
-
/**
|
|
549
|
+
/**
|
|
550
|
+
* Create a profile from an ordered list of curves.
|
|
551
|
+
*
|
|
552
|
+
* The curves should form a closed loop — the end point of each curve
|
|
553
|
+
* should coincide with the start point of the next.
|
|
554
|
+
*
|
|
555
|
+
* @param curves - An ordered array of {@linkcode PCurve}s forming a closed loop
|
|
556
|
+
* @returns A new {@linkcode PProfile}
|
|
557
|
+
*/
|
|
272
558
|
new(curves) {
|
|
273
559
|
return { curves };
|
|
274
560
|
}
|
|
@@ -348,7 +634,7 @@ var PluginSpaceGetResult = z7.object({
|
|
|
348
634
|
var PluginSpaceGetAllResult = z7.object({
|
|
349
635
|
spacesIds: z7.array(z7.string())
|
|
350
636
|
});
|
|
351
|
-
var
|
|
637
|
+
var PluginSpaceDeleteArgs = z7.object({
|
|
352
638
|
spaceId: z7.string()
|
|
353
639
|
});
|
|
354
640
|
|
|
@@ -510,7 +796,7 @@ export {
|
|
|
510
796
|
PluginSpaceCreateFromProfileResult,
|
|
511
797
|
PluginSpaceCreateRectangularArgs,
|
|
512
798
|
PluginSpaceCreateRectangularResult,
|
|
513
|
-
|
|
799
|
+
PluginSpaceDeleteArgs,
|
|
514
800
|
PluginSpaceGetAllResult,
|
|
515
801
|
PluginSpaceGetArgs,
|
|
516
802
|
PluginSpaceGetProperty,
|