@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.cjs
CHANGED
|
@@ -57,7 +57,7 @@ __export(index_exports, {
|
|
|
57
57
|
PluginSpaceCreateFromProfileResult: () => PluginSpaceCreateFromProfileResult,
|
|
58
58
|
PluginSpaceCreateRectangularArgs: () => PluginSpaceCreateRectangularArgs,
|
|
59
59
|
PluginSpaceCreateRectangularResult: () => PluginSpaceCreateRectangularResult,
|
|
60
|
-
|
|
60
|
+
PluginSpaceDeleteArgs: () => PluginSpaceDeleteArgs,
|
|
61
61
|
PluginSpaceGetAllResult: () => PluginSpaceGetAllResult,
|
|
62
62
|
PluginSpaceGetArgs: () => PluginSpaceGetArgs,
|
|
63
63
|
PluginSpaceGetProperty: () => PluginSpaceGetProperty,
|
|
@@ -87,27 +87,78 @@ var z = __toESM(require("zod"), 1);
|
|
|
87
87
|
var PluginVec3Api = class {
|
|
88
88
|
constructor() {
|
|
89
89
|
}
|
|
90
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Create a new 3D vector.
|
|
92
|
+
*
|
|
93
|
+
* @param x - The X component
|
|
94
|
+
* @param y - The Y component
|
|
95
|
+
* @param z - The Z component
|
|
96
|
+
* @returns A new {@linkcode PVec3}
|
|
97
|
+
*
|
|
98
|
+
* # Example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const position = snaptrude.core.math.vec3.new(1, 2, 3)
|
|
101
|
+
* // { x: 1, y: 2, z: 3 }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
91
104
|
new(x, y, z12) {
|
|
92
105
|
return { x, y, z: z12 };
|
|
93
106
|
}
|
|
94
|
-
/**
|
|
107
|
+
/**
|
|
108
|
+
* Add two vectors component-wise.
|
|
109
|
+
*
|
|
110
|
+
* @param a - First vector
|
|
111
|
+
* @param b - Second vector
|
|
112
|
+
* @returns A new {@linkcode PVec3} where each component is `a[i] + b[i]`
|
|
113
|
+
*/
|
|
95
114
|
add(a, b) {
|
|
96
115
|
return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
|
|
97
116
|
}
|
|
98
|
-
/**
|
|
117
|
+
/**
|
|
118
|
+
* Subtract vector {@linkcode b} from vector {@linkcode a} component-wise.
|
|
119
|
+
*
|
|
120
|
+
* @param a - Vector to subtract from
|
|
121
|
+
* @param b - Vector to subtract
|
|
122
|
+
* @returns A new {@linkcode PVec3} where each component is `a[i] - b[i]`
|
|
123
|
+
*/
|
|
99
124
|
subtract(a, b) {
|
|
100
125
|
return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
|
|
101
126
|
}
|
|
102
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* Scale a vector by a scalar value.
|
|
129
|
+
*
|
|
130
|
+
* @param v - The vector to scale
|
|
131
|
+
* @param scalar - The scalar multiplier
|
|
132
|
+
* @returns A new {@linkcode PVec3} where each component is `v[i] * scalar`
|
|
133
|
+
*/
|
|
103
134
|
scale(v, scalar) {
|
|
104
135
|
return { x: v.x * scalar, y: v.y * scalar, z: v.z * scalar };
|
|
105
136
|
}
|
|
106
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Compute the dot product of two vectors.
|
|
139
|
+
*
|
|
140
|
+
* The dot product equals `|a| * |b| * cos(θ)` where `θ` is the angle
|
|
141
|
+
* between the vectors. Useful for checking orthogonality (result = 0)
|
|
142
|
+
* or projection.
|
|
143
|
+
*
|
|
144
|
+
* @param a - First vector
|
|
145
|
+
* @param b - Second vector
|
|
146
|
+
* @returns The scalar dot product
|
|
147
|
+
*/
|
|
107
148
|
dot(a, b) {
|
|
108
149
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
109
150
|
}
|
|
110
|
-
/**
|
|
151
|
+
/**
|
|
152
|
+
* Compute the cross product of two vectors.
|
|
153
|
+
*
|
|
154
|
+
* The result is a vector perpendicular to both inputs, with magnitude
|
|
155
|
+
* equal to the area of the parallelogram they span. Useful for computing
|
|
156
|
+
* surface normals.
|
|
157
|
+
*
|
|
158
|
+
* @param a - First vector
|
|
159
|
+
* @param b - Second vector
|
|
160
|
+
* @returns A new {@linkcode PVec3} perpendicular to both {@linkcode a} and {@linkcode b}
|
|
161
|
+
*/
|
|
111
162
|
cross(a, b) {
|
|
112
163
|
return {
|
|
113
164
|
x: a.y * b.z - a.z * b.y,
|
|
@@ -115,25 +166,57 @@ var PluginVec3Api = class {
|
|
|
115
166
|
z: a.x * b.y - a.y * b.x
|
|
116
167
|
};
|
|
117
168
|
}
|
|
118
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Compute the length (magnitude) of a vector.
|
|
171
|
+
*
|
|
172
|
+
* @param v - The vector
|
|
173
|
+
* @returns The Euclidean length `√(x² + y² + z²)`
|
|
174
|
+
*/
|
|
119
175
|
length(v) {
|
|
120
176
|
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
|
121
177
|
}
|
|
122
|
-
/**
|
|
178
|
+
/**
|
|
179
|
+
* Compute the squared length of a vector.
|
|
180
|
+
*
|
|
181
|
+
* Avoids the `sqrt` call — prefer this over {@linkcode PluginVec3Api.length}
|
|
182
|
+
* when comparing relative magnitudes.
|
|
183
|
+
*
|
|
184
|
+
* @param v - The vector
|
|
185
|
+
* @returns The squared length `x² + y² + z²`
|
|
186
|
+
*/
|
|
123
187
|
lengthSquared(v) {
|
|
124
188
|
return v.x * v.x + v.y * v.y + v.z * v.z;
|
|
125
189
|
}
|
|
126
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* Normalize a vector to unit length.
|
|
192
|
+
*
|
|
193
|
+
* @param v - The vector to normalize
|
|
194
|
+
* @returns A new unit-length {@linkcode PVec3} in the same direction,
|
|
195
|
+
* or a zero vector `(0, 0, 0)` if the input has zero length
|
|
196
|
+
*/
|
|
127
197
|
normalize(v) {
|
|
128
198
|
const len = this.length(v);
|
|
129
199
|
if (len === 0) return { x: 0, y: 0, z: 0 };
|
|
130
200
|
return { x: v.x / len, y: v.y / len, z: v.z / len };
|
|
131
201
|
}
|
|
132
|
-
/**
|
|
202
|
+
/**
|
|
203
|
+
* Compute the Euclidean distance between two points.
|
|
204
|
+
*
|
|
205
|
+
* @param a - First point
|
|
206
|
+
* @param b - Second point
|
|
207
|
+
* @returns The distance `|a - b|`
|
|
208
|
+
*/
|
|
133
209
|
distance(a, b) {
|
|
134
210
|
return this.length(this.subtract(a, b));
|
|
135
211
|
}
|
|
136
|
-
/**
|
|
212
|
+
/**
|
|
213
|
+
* Linearly interpolate between two vectors.
|
|
214
|
+
*
|
|
215
|
+
* @param a - Start vector (returned when `t = 0`)
|
|
216
|
+
* @param b - End vector (returned when `t = 1`)
|
|
217
|
+
* @param t - Interpolation factor, typically in `[0, 1]`
|
|
218
|
+
* @returns A new {@linkcode PVec3} at `a + (b - a) * t`
|
|
219
|
+
*/
|
|
137
220
|
lerp(a, b, t) {
|
|
138
221
|
return {
|
|
139
222
|
x: a.x + (b.x - a.x) * t,
|
|
@@ -141,15 +224,35 @@ var PluginVec3Api = class {
|
|
|
141
224
|
z: a.z + (b.z - a.z) * t
|
|
142
225
|
};
|
|
143
226
|
}
|
|
144
|
-
/**
|
|
227
|
+
/**
|
|
228
|
+
* Negate a vector (reverse its direction).
|
|
229
|
+
*
|
|
230
|
+
* @param v - The vector to negate
|
|
231
|
+
* @returns A new {@linkcode PVec3} with all components negated
|
|
232
|
+
*/
|
|
145
233
|
negate(v) {
|
|
146
234
|
return { x: -v.x, y: -v.y, z: -v.z };
|
|
147
235
|
}
|
|
148
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Check if two vectors are exactly equal (strict equality per component).
|
|
238
|
+
*
|
|
239
|
+
* For floating-point comparisons, prefer {@linkcode PluginVec3Api.equalsApprox}.
|
|
240
|
+
*
|
|
241
|
+
* @param a - First vector
|
|
242
|
+
* @param b - Second vector
|
|
243
|
+
* @returns `true` if all components match exactly
|
|
244
|
+
*/
|
|
149
245
|
equals(a, b) {
|
|
150
246
|
return a.x === b.x && a.y === b.y && a.z === b.z;
|
|
151
247
|
}
|
|
152
|
-
/**
|
|
248
|
+
/**
|
|
249
|
+
* Check if two vectors are approximately equal within a tolerance.
|
|
250
|
+
*
|
|
251
|
+
* @param a - First vector
|
|
252
|
+
* @param b - Second vector
|
|
253
|
+
* @param epsilon - Maximum allowed difference per component (default `1e-6`)
|
|
254
|
+
* @returns `true` if `|a[i] - b[i]| < epsilon` for all components
|
|
255
|
+
*/
|
|
153
256
|
equalsApprox(a, b, epsilon = 1e-6) {
|
|
154
257
|
return Math.abs(a.x - b.x) < epsilon && Math.abs(a.y - b.y) < epsilon && Math.abs(a.z - b.z) < epsilon;
|
|
155
258
|
}
|
|
@@ -165,15 +268,43 @@ var z2 = __toESM(require("zod"), 1);
|
|
|
165
268
|
var PluginQuatApi = class {
|
|
166
269
|
constructor() {
|
|
167
270
|
}
|
|
168
|
-
/**
|
|
271
|
+
/**
|
|
272
|
+
* Create a new quaternion from raw components.
|
|
273
|
+
*
|
|
274
|
+
* For most use cases prefer {@linkcode PluginQuatApi.fromAxisAngle}
|
|
275
|
+
* or {@linkcode PluginQuatApi.fromEuler} instead.
|
|
276
|
+
*
|
|
277
|
+
* @param x - The X component
|
|
278
|
+
* @param y - The Y component
|
|
279
|
+
* @param z - The Z component
|
|
280
|
+
* @param w - The W (scalar) component
|
|
281
|
+
* @returns A new {@linkcode PQuat}
|
|
282
|
+
*/
|
|
169
283
|
new(x, y, z12, w) {
|
|
170
284
|
return { x, y, z: z12, w };
|
|
171
285
|
}
|
|
172
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* Create an identity quaternion representing no rotation.
|
|
288
|
+
*
|
|
289
|
+
* @returns `{ x: 0, y: 0, z: 0, w: 1 }`
|
|
290
|
+
*/
|
|
173
291
|
identity() {
|
|
174
292
|
return { x: 0, y: 0, z: 0, w: 1 };
|
|
175
293
|
}
|
|
176
|
-
/**
|
|
294
|
+
/**
|
|
295
|
+
* Create a quaternion from an axis and an angle.
|
|
296
|
+
*
|
|
297
|
+
* @param axis - The rotation axis as a {@linkcode PVec3} (will be normalized internally)
|
|
298
|
+
* @param angle - The rotation angle in **radians**
|
|
299
|
+
* @returns A new unit {@linkcode PQuat}, or identity if {@linkcode axis} has zero length
|
|
300
|
+
*
|
|
301
|
+
* # Example
|
|
302
|
+
* ```ts
|
|
303
|
+
* const { vec3, quat } = snaptrude.core.math
|
|
304
|
+
* // 90° rotation around the Y axis
|
|
305
|
+
* const rot = quat.fromAxisAngle(vec3.new(0, 1, 0), Math.PI / 2)
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
177
308
|
fromAxisAngle(axis, angle) {
|
|
178
309
|
const halfAngle = angle / 2;
|
|
179
310
|
const s = Math.sin(halfAngle);
|
|
@@ -186,7 +317,14 @@ var PluginQuatApi = class {
|
|
|
186
317
|
w: Math.cos(halfAngle)
|
|
187
318
|
};
|
|
188
319
|
}
|
|
189
|
-
/**
|
|
320
|
+
/**
|
|
321
|
+
* Create a quaternion from Euler angles in **XYZ** rotation order.
|
|
322
|
+
*
|
|
323
|
+
* @param x - Rotation around X axis in **radians**
|
|
324
|
+
* @param y - Rotation around Y axis in **radians**
|
|
325
|
+
* @param z - Rotation around Z axis in **radians**
|
|
326
|
+
* @returns A new {@linkcode PQuat}
|
|
327
|
+
*/
|
|
190
328
|
fromEuler(x, y, z12) {
|
|
191
329
|
const cx = Math.cos(x / 2);
|
|
192
330
|
const sx = Math.sin(x / 2);
|
|
@@ -201,7 +339,16 @@ var PluginQuatApi = class {
|
|
|
201
339
|
w: cx * cy * cz - sx * sy * sz
|
|
202
340
|
};
|
|
203
341
|
}
|
|
204
|
-
/**
|
|
342
|
+
/**
|
|
343
|
+
* Multiply two quaternions, combining their rotations.
|
|
344
|
+
*
|
|
345
|
+
* Quaternion multiplication is **not commutative**: `a * b ≠ b * a`.
|
|
346
|
+
* The result applies rotation {@linkcode b} first, then {@linkcode a}.
|
|
347
|
+
*
|
|
348
|
+
* @param a - First quaternion (applied second)
|
|
349
|
+
* @param b - Second quaternion (applied first)
|
|
350
|
+
* @returns A new {@linkcode PQuat} representing the combined rotation
|
|
351
|
+
*/
|
|
205
352
|
multiply(a, b) {
|
|
206
353
|
return {
|
|
207
354
|
x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
|
|
@@ -210,34 +357,83 @@ var PluginQuatApi = class {
|
|
|
210
357
|
w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z
|
|
211
358
|
};
|
|
212
359
|
}
|
|
213
|
-
/**
|
|
360
|
+
/**
|
|
361
|
+
* Compute the conjugate of a quaternion.
|
|
362
|
+
*
|
|
363
|
+
* For unit quaternions the conjugate equals the inverse.
|
|
364
|
+
*
|
|
365
|
+
* @param q - The quaternion
|
|
366
|
+
* @returns A new {@linkcode PQuat} with negated vector part `(-x, -y, -z, w)`
|
|
367
|
+
*/
|
|
214
368
|
conjugate(q) {
|
|
215
369
|
return { x: -q.x, y: -q.y, z: -q.z, w: q.w };
|
|
216
370
|
}
|
|
217
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* Compute the length (magnitude) of a quaternion.
|
|
373
|
+
*
|
|
374
|
+
* @param q - The quaternion
|
|
375
|
+
* @returns The magnitude `√(x² + y² + z² + w²)`
|
|
376
|
+
*/
|
|
218
377
|
length(q) {
|
|
219
378
|
return Math.sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
|
|
220
379
|
}
|
|
221
|
-
/**
|
|
380
|
+
/**
|
|
381
|
+
* Normalize a quaternion to unit length.
|
|
382
|
+
*
|
|
383
|
+
* @param q - The quaternion to normalize
|
|
384
|
+
* @returns A new unit-length {@linkcode PQuat}, or identity if the input has zero length
|
|
385
|
+
*/
|
|
222
386
|
normalize(q) {
|
|
223
387
|
const len = this.length(q);
|
|
224
388
|
if (len === 0) return { x: 0, y: 0, z: 0, w: 1 };
|
|
225
389
|
return { x: q.x / len, y: q.y / len, z: q.z / len, w: q.w / len };
|
|
226
390
|
}
|
|
227
|
-
/**
|
|
391
|
+
/**
|
|
392
|
+
* Compute the inverse of a quaternion.
|
|
393
|
+
*
|
|
394
|
+
* The inverse satisfies `q * inverse(q) = identity`.
|
|
395
|
+
*
|
|
396
|
+
* @param q - The quaternion to invert
|
|
397
|
+
* @returns A new {@linkcode PQuat} that is the multiplicative inverse,
|
|
398
|
+
* or identity if the input has zero length
|
|
399
|
+
*/
|
|
228
400
|
inverse(q) {
|
|
229
401
|
const lenSq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
|
|
230
402
|
if (lenSq === 0) return { x: 0, y: 0, z: 0, w: 1 };
|
|
231
403
|
return { x: -q.x / lenSq, y: -q.y / lenSq, z: -q.z / lenSq, w: q.w / lenSq };
|
|
232
404
|
}
|
|
233
|
-
/**
|
|
405
|
+
/**
|
|
406
|
+
* Rotate a 3D vector by a quaternion.
|
|
407
|
+
*
|
|
408
|
+
* Computes `q * v * conjugate(q)` using the Hamilton product.
|
|
409
|
+
*
|
|
410
|
+
* @param q - The rotation quaternion (should be unit-length)
|
|
411
|
+
* @param v - The vector to rotate as a {@linkcode PVec3}
|
|
412
|
+
* @returns A new rotated {@linkcode PVec3}
|
|
413
|
+
*
|
|
414
|
+
* # Example
|
|
415
|
+
* ```ts
|
|
416
|
+
* const { vec3, quat } = snaptrude.core.math
|
|
417
|
+
* const rot = quat.fromAxisAngle(vec3.new(0, 1, 0), Math.PI / 2)
|
|
418
|
+
* const rotated = quat.rotateVec3(rot, vec3.new(1, 0, 0))
|
|
419
|
+
* // ≈ { x: 0, y: 0, z: -1 }
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
234
422
|
rotateVec3(q, v) {
|
|
235
423
|
const vq = { x: v.x, y: v.y, z: v.z, w: 0 };
|
|
236
424
|
const conj = this.conjugate(q);
|
|
237
425
|
const result = this.multiply(this.multiply(q, vq), conj);
|
|
238
426
|
return { x: result.x, y: result.y, z: result.z };
|
|
239
427
|
}
|
|
240
|
-
/**
|
|
428
|
+
/**
|
|
429
|
+
* Convert a quaternion to axis-angle representation.
|
|
430
|
+
*
|
|
431
|
+
* @param q - The quaternion to convert
|
|
432
|
+
* @returns An object with:
|
|
433
|
+
* - `axis` — The rotation axis as a unit {@linkcode PVec3}
|
|
434
|
+
* (defaults to `(1, 0, 0)` when angle is zero)
|
|
435
|
+
* - `angle` — The rotation angle in **radians**
|
|
436
|
+
*/
|
|
241
437
|
toAxisAngle(q) {
|
|
242
438
|
const nq = this.normalize(q);
|
|
243
439
|
const angle = 2 * Math.acos(Math.min(1, Math.max(-1, nq.w)));
|
|
@@ -250,7 +446,16 @@ var PluginQuatApi = class {
|
|
|
250
446
|
angle
|
|
251
447
|
};
|
|
252
448
|
}
|
|
253
|
-
/**
|
|
449
|
+
/**
|
|
450
|
+
* Spherical linear interpolation between two quaternions.
|
|
451
|
+
*
|
|
452
|
+
* Produces smooth constant-speed rotation between {@linkcode a} and {@linkcode b}.
|
|
453
|
+
*
|
|
454
|
+
* @param a - Start quaternion (returned when `t = 0`)
|
|
455
|
+
* @param b - End quaternion (returned when `t = 1`)
|
|
456
|
+
* @param t - Interpolation factor, typically in `[0, 1]`
|
|
457
|
+
* @returns A new interpolated {@linkcode PQuat}
|
|
458
|
+
*/
|
|
254
459
|
slerp(a, b, t) {
|
|
255
460
|
let cosHalf = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
|
256
461
|
let bx = b.x, by = b.y, bz = b.z, bw = b.w;
|
|
@@ -275,15 +480,39 @@ var PluginQuatApi = class {
|
|
|
275
480
|
w: a.w * ratioA + bw * ratioB
|
|
276
481
|
};
|
|
277
482
|
}
|
|
278
|
-
/**
|
|
483
|
+
/**
|
|
484
|
+
* Compute the dot product of two quaternions.
|
|
485
|
+
*
|
|
486
|
+
* A value close to `1` or `-1` indicates similar orientations;
|
|
487
|
+
* a value close to `0` indicates maximally different orientations.
|
|
488
|
+
*
|
|
489
|
+
* @param a - First quaternion
|
|
490
|
+
* @param b - Second quaternion
|
|
491
|
+
* @returns The scalar dot product
|
|
492
|
+
*/
|
|
279
493
|
dot(a, b) {
|
|
280
494
|
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
|
281
495
|
}
|
|
282
|
-
/**
|
|
496
|
+
/**
|
|
497
|
+
* Check if two quaternions are exactly equal (strict equality per component).
|
|
498
|
+
*
|
|
499
|
+
* For floating-point comparisons, prefer {@linkcode PluginQuatApi.equalsApprox}.
|
|
500
|
+
*
|
|
501
|
+
* @param a - First quaternion
|
|
502
|
+
* @param b - Second quaternion
|
|
503
|
+
* @returns `true` if all components match exactly
|
|
504
|
+
*/
|
|
283
505
|
equals(a, b) {
|
|
284
506
|
return a.x === b.x && a.y === b.y && a.z === b.z && a.w === b.w;
|
|
285
507
|
}
|
|
286
|
-
/**
|
|
508
|
+
/**
|
|
509
|
+
* Check if two quaternions are approximately equal within a tolerance.
|
|
510
|
+
*
|
|
511
|
+
* @param a - First quaternion
|
|
512
|
+
* @param b - Second quaternion
|
|
513
|
+
* @param epsilon - Maximum allowed difference per component (default `1e-6`)
|
|
514
|
+
* @returns `true` if `|a[i] - b[i]| < epsilon` for all components
|
|
515
|
+
*/
|
|
287
516
|
equalsApprox(a, b, epsilon = 1e-6) {
|
|
288
517
|
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;
|
|
289
518
|
}
|
|
@@ -306,7 +535,21 @@ var z3 = __toESM(require("zod"), 1);
|
|
|
306
535
|
var PluginLineApi = class {
|
|
307
536
|
constructor() {
|
|
308
537
|
}
|
|
309
|
-
/**
|
|
538
|
+
/**
|
|
539
|
+
* Create a new line segment between two points.
|
|
540
|
+
*
|
|
541
|
+
* @param startPoint - The start point as a {@linkcode PVec3}
|
|
542
|
+
* @param endPoint - The end point as a {@linkcode PVec3}
|
|
543
|
+
* @returns A new {@linkcode PLine}
|
|
544
|
+
*
|
|
545
|
+
* # Example
|
|
546
|
+
* ```ts
|
|
547
|
+
* const { vec3 } = snaptrude.core.math
|
|
548
|
+
* const { line } = snaptrude.core.geom
|
|
549
|
+
*
|
|
550
|
+
* const edge = line.new(vec3.new(0, 0, 0), vec3.new(5, 0, 0))
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
310
553
|
new(startPoint, endPoint) {
|
|
311
554
|
return { curveType: "Line", startPoint, endPoint };
|
|
312
555
|
}
|
|
@@ -322,7 +565,34 @@ var z4 = __toESM(require("zod"), 1);
|
|
|
322
565
|
var PluginArcApi = class {
|
|
323
566
|
constructor() {
|
|
324
567
|
}
|
|
325
|
-
/**
|
|
568
|
+
/**
|
|
569
|
+
* Create a new arc from start, end, centre, and axis.
|
|
570
|
+
*
|
|
571
|
+
* The arc sweeps from {@linkcode startPoint} to {@linkcode endPoint}
|
|
572
|
+
* along the circle centred at {@linkcode centrePoint}, in the
|
|
573
|
+
* direction determined by the right-hand rule around {@linkcode axis}.
|
|
574
|
+
*
|
|
575
|
+
* @param startPoint - The start point as a {@linkcode PVec3}
|
|
576
|
+
* @param endPoint - The end point as a {@linkcode PVec3}
|
|
577
|
+
* @param centrePoint - The centre of the arc's circle as a {@linkcode PVec3}
|
|
578
|
+
* @param axis - The arc's rotation axis as a {@linkcode PVec3}
|
|
579
|
+
* (perpendicular to the arc's plane)
|
|
580
|
+
* @returns A new {@linkcode PArc}
|
|
581
|
+
*
|
|
582
|
+
* # Example
|
|
583
|
+
* ```ts
|
|
584
|
+
* const { vec3 } = snaptrude.core.math
|
|
585
|
+
* const { arc } = snaptrude.core.geom
|
|
586
|
+
*
|
|
587
|
+
* // Quarter-circle arc on the XZ plane
|
|
588
|
+
* const a = arc.new(
|
|
589
|
+
* vec3.new(1, 0, 0), // start
|
|
590
|
+
* vec3.new(0, 0, 1), // end
|
|
591
|
+
* vec3.new(0, 0, 0), // centre
|
|
592
|
+
* vec3.new(0, 1, 0), // Y-up axis
|
|
593
|
+
* )
|
|
594
|
+
* ```
|
|
595
|
+
*/
|
|
326
596
|
new(startPoint, endPoint, centrePoint, axis) {
|
|
327
597
|
return { curveType: "Arc", startPoint, endPoint, centrePoint, axis };
|
|
328
598
|
}
|
|
@@ -340,7 +610,15 @@ var z5 = __toESM(require("zod"), 1);
|
|
|
340
610
|
var PluginCurveApi = class {
|
|
341
611
|
constructor() {
|
|
342
612
|
}
|
|
343
|
-
/**
|
|
613
|
+
/**
|
|
614
|
+
* Wrap a {@linkcode PLine} or {@linkcode PArc} as a {@linkcode PCurve}.
|
|
615
|
+
*
|
|
616
|
+
* This is an identity operation — it simply returns the input unchanged.
|
|
617
|
+
* It exists for type-level clarity when building mixed curve lists.
|
|
618
|
+
*
|
|
619
|
+
* @param curve - A {@linkcode PLine} or {@linkcode PArc} to wrap
|
|
620
|
+
* @returns The same value typed as {@linkcode PCurve}
|
|
621
|
+
*/
|
|
344
622
|
new(curve) {
|
|
345
623
|
return curve;
|
|
346
624
|
}
|
|
@@ -352,7 +630,15 @@ var z6 = __toESM(require("zod"), 1);
|
|
|
352
630
|
var PluginProfileApi = class {
|
|
353
631
|
constructor() {
|
|
354
632
|
}
|
|
355
|
-
/**
|
|
633
|
+
/**
|
|
634
|
+
* Create a profile from an ordered list of curves.
|
|
635
|
+
*
|
|
636
|
+
* The curves should form a closed loop — the end point of each curve
|
|
637
|
+
* should coincide with the start point of the next.
|
|
638
|
+
*
|
|
639
|
+
* @param curves - An ordered array of {@linkcode PCurve}s forming a closed loop
|
|
640
|
+
* @returns A new {@linkcode PProfile}
|
|
641
|
+
*/
|
|
356
642
|
new(curves) {
|
|
357
643
|
return { curves };
|
|
358
644
|
}
|
|
@@ -432,7 +718,7 @@ var PluginSpaceGetResult = z7.object({
|
|
|
432
718
|
var PluginSpaceGetAllResult = z7.object({
|
|
433
719
|
spacesIds: z7.array(z7.string())
|
|
434
720
|
});
|
|
435
|
-
var
|
|
721
|
+
var PluginSpaceDeleteArgs = z7.object({
|
|
436
722
|
spaceId: z7.string()
|
|
437
723
|
});
|
|
438
724
|
|
|
@@ -595,7 +881,7 @@ var PluginApi = class {
|
|
|
595
881
|
PluginSpaceCreateFromProfileResult,
|
|
596
882
|
PluginSpaceCreateRectangularArgs,
|
|
597
883
|
PluginSpaceCreateRectangularResult,
|
|
598
|
-
|
|
884
|
+
PluginSpaceDeleteArgs,
|
|
599
885
|
PluginSpaceGetAllResult,
|
|
600
886
|
PluginSpaceGetArgs,
|
|
601
887
|
PluginSpaceGetProperty,
|