@weasel-js/geom 1.10.0 → 1.11.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.
Files changed (55) hide show
  1. package/README.md +140 -16
  2. package/dist/3d/index.d.ts +29 -2
  3. package/dist/3d/index.js +49 -1
  4. package/dist/3d/index.js.map +1 -1
  5. package/dist/booleans/index.d.ts +34 -10
  6. package/dist/booleans/index.js +344 -352
  7. package/dist/booleans/index.js.map +1 -1
  8. package/dist/{chunk-MDT7F32A.js → chunk-6XSJY3TC.js} +10 -39
  9. package/dist/chunk-6XSJY3TC.js.map +1 -0
  10. package/dist/chunk-7KLJZFBY.js +573 -0
  11. package/dist/chunk-7KLJZFBY.js.map +1 -0
  12. package/dist/chunk-B53BERKG.js +386 -0
  13. package/dist/chunk-B53BERKG.js.map +1 -0
  14. package/dist/chunk-CE7IY7TB.js +104 -0
  15. package/dist/chunk-CE7IY7TB.js.map +1 -0
  16. package/dist/chunk-HGF5OVEN.js +129 -0
  17. package/dist/chunk-HGF5OVEN.js.map +1 -0
  18. package/dist/chunk-J2O2B54M.js +800 -0
  19. package/dist/chunk-J2O2B54M.js.map +1 -0
  20. package/dist/chunk-Q66NA2FU.js +174 -0
  21. package/dist/chunk-Q66NA2FU.js.map +1 -0
  22. package/dist/chunk-SASMXDBE.js +443 -0
  23. package/dist/chunk-SASMXDBE.js.map +1 -0
  24. package/dist/chunk-UI3FUWXM.js +533 -0
  25. package/dist/chunk-UI3FUWXM.js.map +1 -0
  26. package/dist/curvature-PkoLduGc.d.ts +454 -0
  27. package/dist/curves/index.d.ts +14 -5
  28. package/dist/curves/index.js +33 -111
  29. package/dist/curves/index.js.map +1 -1
  30. package/dist/index.d.ts +1697 -205
  31. package/dist/index.js +4729 -1308
  32. package/dist/index.js.map +1 -1
  33. package/dist/nd/index.d.ts +91 -27
  34. package/dist/nd/index.js +282 -0
  35. package/dist/nd/index.js.map +1 -1
  36. package/dist/path-BW8d_2RY.d.ts +157 -0
  37. package/dist/portCurve-C5HDWuuV.d.ts +30 -0
  38. package/dist/tessellate/index.d.ts +18 -4
  39. package/dist/tessellate/index.js +21 -277
  40. package/dist/tessellate/index.js.map +1 -1
  41. package/dist/warp/index.d.ts +252 -0
  42. package/dist/warp/index.js +1316 -0
  43. package/dist/warp/index.js.map +1 -0
  44. package/package.json +5 -1
  45. package/dist/chunk-MDT7F32A.js.map +0 -1
  46. package/dist/chunk-OXH3NOXC.js +0 -62
  47. package/dist/chunk-OXH3NOXC.js.map +0 -1
  48. package/dist/chunk-URQMDR6Q.js +0 -80
  49. package/dist/chunk-URQMDR6Q.js.map +0 -1
  50. package/dist/chunk-WQMYOCFB.js +0 -167
  51. package/dist/chunk-WQMYOCFB.js.map +0 -1
  52. package/dist/chunk-XS6ERH3X.js +0 -34
  53. package/dist/chunk-XS6ERH3X.js.map +0 -1
  54. package/dist/cubicMath-CFXbq6vp.d.ts +0 -116
  55. package/dist/path-Bf9KeVxC.d.ts +0 -44
package/README.md CHANGED
@@ -1,19 +1,13 @@
1
1
  # @weasel-js/geom
2
2
 
3
- Pure 2D geometry kernel for @weasel-js/core: affine, box, curve, polyline, the
4
- `Path` command stream and the math over it (builders, SVG `d` parsing, bounds,
5
- transforms, hit-testing, sampling, curve fitting), and easing curves.
6
- Dependency-free core. Subpaths:
7
-
8
- - `./curves` — alternate curve representations (cubic and quadratic Bezier, NURBS, Spiro)
9
- - `./tessellate` — fill tessellation, polylines and trimming; needs the optional peer `earcut`
10
- - `./booleans` — polygon booleans and path splitting; needs the optional peer `polygon-clipping`
11
- - `./3d` — vectors, quaternions, 4x4 matrices and ray intersection
12
- - `./nd` — the port-curve rule (`portControls`, `portCurvePoints`, `PORT_REACH`) over plain number arrays, for any dimension
3
+ The 2D geometry kernel the rest of weasel is built on: affine transforms, boxes,
4
+ Bezier math, the `Path` shape type and everything that operates on it, and
5
+ easing curves. It is plain functions over numbers and typed arrays, with no
6
+ DOM, no React, and no runtime dependencies in the root entry.
13
7
 
14
8
  Part of [weasel](https://github.com/orochi235/weasel), a domain-agnostic 2D
15
9
  scene-graph canvas kit for React. See the
16
- [API reference](https://orochi235.github.io/weasel/api/).
10
+ [API reference](https://orochi235.github.io/weasel/#pkg/geom).
17
11
 
18
12
  ## Install
19
13
 
@@ -21,13 +15,143 @@ scene-graph canvas kit for React. See the
21
15
  npm install @weasel-js/geom
22
16
  ```
23
17
 
24
- ## Usage
18
+ The `./tessellate` and `./warp` entries use the optional peer `earcut`, and `./booleans` uses
19
+ the optional peer `polygon-clipping`. Install a peer only if you import the
20
+ entry that needs it.
21
+
22
+ ## Value types
23
+
24
+ Most functions take loose `x, y` numbers rather than point objects, so a hot
25
+ loop allocates nothing. The types that do exist are small:
26
+
27
+ | Type | Shape | Notes |
28
+ |---|---|---|
29
+ | `Mat3` | `[a, b, c, d, e, f]` | A 2D affine in canvas and `DOMMatrix` order: `x' = a·x + c·y + e`, `y' = b·x + d·y + f`. |
30
+ | `Box` | `[minX, minY, maxX, maxY]` | An axis-aligned box as a tuple. |
31
+ | `Rect` | `{ x, y, width, height }` | The same box in object form. |
32
+ | `View` | `{ x, y, scale: { x, y } }` | A viewport: the world point drawn at the canvas's top-left corner, and pixels per world unit on each axis. |
33
+ | `GlMat3` | nine-element `Float64Array` or `Float32Array` | The same affine laid out column-major for a WebGL `uniformMatrix3fv` upload. |
34
+ | `Path` | `RectPath \| PolygonPath` | A shape. See below. |
35
+
36
+ `translate`, `scale`, `rotate`, `rotateAboutPoint`, and `boxToBox` build a
37
+ `Mat3`. `multiply(m, n)` composes two, applying `n` first. `invert` returns
38
+ `null` for a singular matrix, and `applyToPoint` maps one point.
39
+
40
+ ```ts
41
+ import { applyToPoint, invert, multiply, scale, translate } from '@weasel-js/geom';
42
+
43
+ // World to screen for a view at (10, 20), zoomed 2x: translate, then scale.
44
+ const worldToScreen = multiply(scale(2, 2), translate(-10, -20));
45
+ applyToPoint(worldToScreen, 15, 25); // [10, 10]
46
+
47
+ const screenToWorld = invert(worldToScreen); // Mat3 | null
48
+ ```
49
+
50
+ The `mat3` namespace holds the `GlMat3` operations (`mat3.fromAffine`,
51
+ `mat3.toAffine`, `mat3.multiply`, `mat3.toUniform`, and others), and
52
+ `viewToMat3(view)` builds the world-to-screen `GlMat3` for a `View`.
53
+
54
+ ## Paths
55
+
56
+ A `Path` is the shape type every weasel package shares. It is either:
57
+
58
+ - A `RectPath`, `{ kind: 'rect', x, y, width, height }`, for the common case of
59
+ an axis-aligned rectangle.
60
+ - A `PolygonPath`, an SVG-style command stream: command codes (`M`, `L`, `C`,
61
+ `Q`, `Z`) in a `Uint8Array`, their coordinates in a parallel `Float32Array`,
62
+ and a `fillRule`. It covers polylines, polygons, Bezier outlines, and shapes
63
+ with holes.
64
+
65
+ What operates on a path:
66
+
67
+ - **Building.** `PathBuilder` for move, line, curve, and close calls;
68
+ `rectPath`, `polygonFromPoints`, `polylineFromPoints`, `ellipsePath`,
69
+ `regularPolygonPath`, `starPath`, `linePath`, `circlePath`, and
70
+ `roundRectPath` for common shapes; `pathFromD` to parse an SVG `d` string;
71
+ `schneiderFit` to fit cubic curves through sampled points.
72
+ - **Measuring.** `boundsOfPath`, `unionBoundsPath`, `pathSignedArea`,
73
+ `pointAlongPath`.
74
+ - **Transforming.** `translatePath`, `transformPath`, `scalePathToBounds`,
75
+ `reversePath`.
76
+ - **Hit-testing.** `pointInPath` for the filled region, `strokeHitTest` for
77
+ the outline, `pathContainsRect`, `pathIntersectsRect`, and the polygon
78
+ variants for marquee and lasso selection, and `nearestOnPath` and
79
+ `pathDistanceToPoint` for the closest point.
80
+ - **Editing.** `pathToAnchors` and `anchorsToPath` convert between the command
81
+ stream and a list of anchors with control handles, the form a pen tool
82
+ edits. `splitSubpaths` and `splitByClosure` take a compound path apart.
83
+ - **Constraining.** A `PathConstraint` holds anchors in a relation: fixed,
84
+ horizontal, vertical, parallel, perpendicular, equal length, a set length,
85
+ or coincident. `solvePathConstraints` moves a path's anchors the least that
86
+ makes a list of them hold, and `constrainPathEdit` finishes an edit so they
87
+ hold again: the anchors the edit moved stay put where they can, and a
88
+ constraint that already failed before the edit is reported rather than
89
+ solved.
90
+ - **Walking the stream.** `forEachSegment` visits each command with its
91
+ coordinate offset and the pen position before it.
92
+
93
+ ```ts
94
+ import {
95
+ boundsOfPath, pathFromD, pointInPath, rotateAboutPoint, strokeHitTest, transformPath,
96
+ } from '@weasel-js/geom';
97
+
98
+ const triangle = pathFromD('M0 0 L100 0 L50 80 Z');
99
+
100
+ boundsOfPath(triangle); // { kind: 'rect', x: 0, y: 0, width: 100, height: 80 }
101
+ pointInPath(triangle, 50, 20); // true: inside the fill
102
+ strokeHitTest(triangle, 50, 3, 4); // true: within 4 units of the outline
103
+
104
+ const turned = transformPath(triangle, rotateAboutPoint(50, 40, Math.PI / 2));
105
+ ```
106
+
107
+ Below the path level, the curve functions work on one segment at a time:
108
+ `cubicEvalAt`, `splitCubicAt`, `cubicBounds`, `flattenCubic`,
109
+ `nearestOnCubic`, and their quadratic and line counterparts.
110
+
111
+ ## Easings
112
+
113
+ An `EasingFn` maps progress `t` in 0..1 to eased progress. The package exports
114
+ the standard families by name (`easeOutCubic`, `easeInOutSine`,
115
+ `easeOutBounce`, and so on), the same set keyed by name in `EASINGS`, and
116
+ `cubicBezierEasing(x1, y1, x2, y2)` for CSS-style control points.
117
+
118
+ `EasingSpec` is an easing as a value that can be stored or serialized: a
119
+ function, a name, or `{ bezier: [x1, y1, x2, y2] }`. `resolveEasing` turns any
120
+ of them into the function.
121
+
122
+ ```ts
123
+ import { resolveEasing } from '@weasel-js/geom';
124
+
125
+ const ease = resolveEasing('easeOutCubic');
126
+ ease(0.5); // 0.875
127
+
128
+ const custom = resolveEasing({ bezier: [0.4, 0, 0.2, 1] });
129
+ ```
130
+
131
+ ## Subpath entries
132
+
133
+ | Entry | What it adds | Optional peer |
134
+ |---|---|---|
135
+ | `@weasel-js/geom/curves` | Curve representations that read one shared anchor list and each produce a `PolygonPath`: `bezierCubic`, `bezierQuadratic`, `nurbs`, and `spiro`, also keyed by kind in `CURVE_REPS`. Each can evaluate a point and the curvature at a parameter. | none |
136
+ | `@weasel-js/geom/tessellate` | `tessellate` turns a path's fill into a triangle `Mesh` (vertices and indices). `extractPolylines` flattens each contour to straight segments, and `trimPolyline` shortens one from either end. | `earcut`, used by `tessellate` |
137
+ | `@weasel-js/geom/warp` | Warping paths: distorts (`bilinearQuad`, `projectiveQuad`), envelopes (`bicubicMesh`, `coonsMesh`), and puppets (`puppetMap`), each as a map of the plane and as `PathWarp` data a shape can hold and `applyPathWarp` remakes. A puppet triangulates the shape's fill (`puppetMesh`) and deforms it as-rigid-as-possible (`createArapSolver`), righting any triangle a hard pull turns over so the outline never folds back on itself; a `trace` option reads every stage of the solve. `warpPath` carries any map over a path and refits it as cubics. | `earcut`, used by puppets |
138
+ | `@weasel-js/geom/booleans` | Boolean operations on path fills: `pathUnion`, `pathIntersect`, `pathSubtract`, `pathExclude`, `pathDivide`, `pathCrop`, `pathTrim`, and `pathMerge`. Also cutting a path with a line or polyline: `splitPathBySegment`, `splitPathByPolyline`, `snipPathByPolyline`. | `polygon-clipping` |
139
+ | `@weasel-js/geom/3d` | The same kind of math one dimension up: `Vec3` and quaternion helpers, `Mat4` with `compose`, `perspective`, and `lookAt`, and ray intersection against planes and axis-aligned boxes. | none |
140
+ | `@weasel-js/geom/nd` | The port-curve rule over plain number arrays of any length: `portControls` returns the two cubic control points that make a curve leave one port along its normal and arrive against the next port's normal, and `portCurvePoints` samples that curve. | none |
141
+
142
+ The `./3d` entry reuses names from the root (`dot`, `scale`, `invert`,
143
+ `identity`), so import from one or the other, or alias at the import.
144
+
145
+ Boolean operations work on what a fill covers, so curves are flattened first
146
+ and the result is a `PolygonPath` of straight segments.
25
147
 
26
148
  ```ts
27
- import { /* … */ } from '@weasel-js/geom';
28
- import { /* … */ } from '@weasel-js/geom/booleans';
29
- import { /* … */ } from '@weasel-js/geom/curves';
30
- import { /* … */ } from '@weasel-js/geom/tessellate';
149
+ import { ellipsePath, rectPath } from '@weasel-js/geom';
150
+ import { pathSubtract } from '@weasel-js/geom/booleans';
151
+
152
+ const plate = rectPath(0, 0, 100, 60);
153
+ const hole = ellipsePath({ x: 30, y: 10, width: 40, height: 40 });
154
+ const cut = pathSubtract(plate, hole); // the plate with the ellipse removed
31
155
  ```
32
156
 
33
157
  ## License
@@ -1,4 +1,4 @@
1
- export { PORT_REACH } from '../nd/index.js';
1
+ export { P as PORT_REACH } from '../portCurve-C5HDWuuV.js';
2
2
 
3
3
  /** Three-component vectors and unit quaternions. `Vec3`'s fields are readonly:
4
4
  * a pose stored in a history snapshot must not be writable through the value
@@ -32,6 +32,12 @@ declare function len(a: Vec3): number;
32
32
  /** A vector with no length, or no finite one, normalizes to the zero vector
33
33
  * rather than to `NaN`. Every other vector keeps its direction, however short. */
34
34
  declare function normalize(a: Vec3): Vec3;
35
+ /** Euclidean distance between two points. */
36
+ declare function distance(a: Vec3, b: Vec3): number;
37
+ /** The point `t` of the way from `a` to `b`; `t` outside [0, 1] extrapolates. */
38
+ declare function lerp(a: Vec3, b: Vec3, t: number): Vec3;
39
+ /** `Vec3` from loose components — the shape `Mat4`'s row math produces. */
40
+ declare function vec3(x: number, y: number, z: number): Vec3;
35
41
  /** The quaternion for no rotation, `[0, 0, 0, 1]`. */
36
42
  declare function quatIdentity(): Quat;
37
43
  /** Rotation by `angle` radians about `axis`, which must be nonzero but need
@@ -94,6 +100,27 @@ declare function intersectRayPlane(ray: Ray, normal: Vec3, offset: number): numb
94
100
  declare function transformAabb(m: Mat4, local: Aabb): Aabb;
95
101
  /** The box centred on `center` reaching `radius` along every axis. */
96
102
  declare function aabbAround(center: Vec3, radius: number): Aabb;
103
+ /** The point `t` direction-lengths along the ray. */
104
+ declare function pointOnRay(ray: Ray, t: number): Vec3;
105
+ /** The smallest box containing every point. No points gives an inverted
106
+ * box, `min` at +Infinity and `max` at -Infinity. */
107
+ declare function aabbOfPoints(points: readonly Vec3[]): Aabb;
108
+ /** The point of the infinite line through `origin` along `direction` nearest
109
+ * `p`. A zero direction makes the line the point `origin`. */
110
+ declare function closestPointOnLine(p: Vec3, origin: Vec3, direction: Vec3): Vec3;
111
+ /** The point of segment `a`–`b` nearest `p`. */
112
+ declare function closestPointOnSegment(p: Vec3, a: Vec3, b: Vec3): Vec3;
113
+ /**
114
+ * The nearest pair of points between a ray and the infinite line through
115
+ * `origin` along `direction`. `t` is the ray parameter (never negative) and
116
+ * `s` the line's. A line parallel to the ray pairs with the ray's origin.
117
+ */
118
+ declare function closestPointsRayLine(ray: Ray, origin: Vec3, direction: Vec3): {
119
+ onRay: Vec3;
120
+ onLine: Vec3;
121
+ t: number;
122
+ s: number;
123
+ };
97
124
 
98
125
  /**
99
126
  * The port-curve rule one dimension up, in `Vec3`. The rule itself lives in
@@ -109,4 +136,4 @@ declare function portCurvePoints(a: Vec3, b: Vec3, outNormal: Vec3 | null | unde
109
136
  /** A cubic evaluated at `t`. The 2D barrel's `cubicEvalAt`, one dimension up. */
110
137
  declare function cubicAt(p0: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, t: number): Vec3;
111
138
 
112
- export { type Aabb, type Mat4, type Quat, type Ray, type Vec3, aabbAround, add, compose, cross, cubicAt, dot, identity, intersectRayAabb, intersectRayPlane, invert, len, len2, lookAt, multiply, normalize, perspective, portControls, portCurvePoints, quatFromAxisAngle, quatIdentity, scale, sub, transformAabb, transformPoint, transformPoint4 };
139
+ export { type Aabb, type Mat4, type Quat, type Ray, type Vec3, aabbAround, aabbOfPoints, add, closestPointOnLine, closestPointOnSegment, closestPointsRayLine, compose, cross, cubicAt, distance, dot, identity, intersectRayAabb, intersectRayPlane, invert, len, len2, lerp, lookAt, multiply, normalize, perspective, pointOnRay, portControls, portCurvePoints, quatFromAxisAngle, quatIdentity, scale, sub, transformAabb, transformPoint, transformPoint4, vec3 };
package/dist/3d/index.js CHANGED
@@ -32,6 +32,12 @@ function normalize(a) {
32
32
  const l = len(a);
33
33
  return l > 0 && l < Infinity ? scale(a, 1 / l) : { x: 0, y: 0, z: 0 };
34
34
  }
35
+ function distance(a, b) {
36
+ return len(sub(a, b));
37
+ }
38
+ function lerp(a, b, t) {
39
+ return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t, z: a.z + (b.z - a.z) * t };
40
+ }
35
41
  function vec3(x, y, z) {
36
42
  return { x, y, z };
37
43
  }
@@ -257,6 +263,48 @@ function aabbAround(center, radius) {
257
263
  max: { x: center.x + radius, y: center.y + radius, z: center.z + radius }
258
264
  };
259
265
  }
266
+ function pointOnRay(ray, t) {
267
+ return add(ray.origin, scale(ray.direction, t));
268
+ }
269
+ function aabbOfPoints(points) {
270
+ const min = { x: Infinity, y: Infinity, z: Infinity };
271
+ const max = { x: -Infinity, y: -Infinity, z: -Infinity };
272
+ for (const p of points) {
273
+ for (const axis of ["x", "y", "z"]) {
274
+ if (p[axis] < min[axis]) min[axis] = p[axis];
275
+ if (p[axis] > max[axis]) max[axis] = p[axis];
276
+ }
277
+ }
278
+ return { min, max };
279
+ }
280
+ function closestPointOnLine(p, origin, direction) {
281
+ const d2 = len2(direction);
282
+ if (!(d2 > 0)) return origin;
283
+ return add(origin, scale(direction, dot(sub(p, origin), direction) / d2));
284
+ }
285
+ function closestPointOnSegment(p, a, b) {
286
+ const ab = sub(b, a);
287
+ const d2 = len2(ab);
288
+ if (!(d2 > 0)) return a;
289
+ const t = Math.min(1, Math.max(0, dot(sub(p, a), ab) / d2));
290
+ return add(a, scale(ab, t));
291
+ }
292
+ function closestPointsRayLine(ray, origin, direction) {
293
+ const u = ray.direction;
294
+ const v = direction;
295
+ const w = sub(ray.origin, origin);
296
+ const a = len2(u);
297
+ const b = dot(u, v);
298
+ const c = len2(v);
299
+ const d = dot(u, w);
300
+ const e = dot(v, w);
301
+ const denom = a * c - b * b;
302
+ let t = 0;
303
+ if (a > 0 && denom > SINGULAR_RATIO * a * c) t = Math.max(0, (b * e - c * d) / denom);
304
+ const onRay = pointOnRay(ray, t);
305
+ const s = c > 0 ? dot(sub(onRay, origin), v) / c : 0;
306
+ return { onRay, onLine: add(origin, scale(v, s)), t, s };
307
+ }
260
308
 
261
309
  // src/3d/portCurve3.ts
262
310
  var comps = (v) => [v.x, v.y, v.z];
@@ -287,6 +335,6 @@ function cubicAt2(p0, p1, p2, p3, t) {
287
335
  return fromComps(p);
288
336
  }
289
337
 
290
- export { aabbAround, add, compose, cross, cubicAt2 as cubicAt, dot, identity, intersectRayAabb, intersectRayPlane, invert, len, len2, lookAt, multiply, normalize, perspective, portControls2 as portControls, portCurvePoints2 as portCurvePoints, quatFromAxisAngle, quatIdentity, scale, sub, transformAabb, transformPoint, transformPoint4 };
338
+ export { aabbAround, aabbOfPoints, add, closestPointOnLine, closestPointOnSegment, closestPointsRayLine, compose, cross, cubicAt2 as cubicAt, distance, dot, identity, intersectRayAabb, intersectRayPlane, invert, len, len2, lerp, lookAt, multiply, normalize, perspective, pointOnRay, portControls2 as portControls, portCurvePoints2 as portCurvePoints, quatFromAxisAngle, quatIdentity, scale, sub, transformAabb, transformPoint, transformPoint4, vec3 };
291
339
  //# sourceMappingURL=index.js.map
292
340
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/3d/vec3.ts","../../src/3d/mat4.ts","../../src/3d/ray3.ts","../../src/3d/portCurve3.ts"],"names":["scale","portControls","portCurvePoints","cubicAt"],"mappings":";;;;;AAmBO,SAAS,GAAA,CAAI,GAAS,CAAA,EAAe;AAC1C,EAAA,OAAO,EAAE,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAE;AACpD;AAGO,SAAS,GAAA,CAAI,GAAS,CAAA,EAAe;AAC1C,EAAA,OAAO,EAAE,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAG,CAAA,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AI,OAAA,CAAS,KAAA,CAAM,EAAE,GAAG,KAAA,CAAM,EAAE,CAAA,EAAG,KAAA,CAAM,EAAE,CAAA,EAAG,KAAA,CAAM,EAAE,GAAG,CAAC,CAAA;AAChE,EAAA,OAAO,UAAU,CAAC,CAAA;AACpB","file":"index.js","sourcesContent":["/** Three-component vectors and unit quaternions. `Vec3`'s fields are readonly:\n * a pose stored in a history snapshot must not be writable through the value\n * handed to a renderer.\n *\n * Named fields rather than a tuple, matching `Vec2` one tier up, so a\n * consumer writing both dimensions says `p.x` in each. `Quat` stays a tuple —\n * it is not a point, and `[x, y, z, w]` is the layout three.js and glMatrix\n * both use. */\n\nexport interface Vec3 {\n readonly x: number;\n readonly y: number;\n readonly z: number;\n}\n\n/** `[x, y, z, w]`, w last — the layout three.js and glMatrix both use. */\nexport type Quat = readonly [number, number, number, number];\n\n/** `a + b`. */\nexport function add(a: Vec3, b: Vec3): Vec3 {\n return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };\n}\n\n/** `a - b`. */\nexport function sub(a: Vec3, b: Vec3): Vec3 {\n return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };\n}\n\n/** `a` multiplied by the scalar `k`. */\nexport function scale(a: Vec3, k: number): Vec3 {\n return { x: a.x * k, y: a.y * k, z: a.z * k };\n}\n\n/** Dot product. */\nexport function dot(a: Vec3, b: Vec3): number {\n return a.x * b.x + a.y * b.y + a.z * b.z;\n}\n\n/** Cross product `a × b`. */\nexport function cross(a: Vec3, b: Vec3): Vec3 {\n return {\n x: a.y * b.z - a.z * b.y,\n y: a.z * b.x - a.x * b.z,\n z: a.x * b.y - a.y * b.x,\n };\n}\n\n/** Squared length. Compare distances with this and skip the square root. */\nexport function len2(a: Vec3): number {\n return dot(a, a);\n}\n\n/** Euclidean length. */\nexport function len(a: Vec3): number {\n return Math.sqrt(len2(a));\n}\n\n/** A vector with no length, or no finite one, normalizes to the zero vector\n * rather than to `NaN`. Every other vector keeps its direction, however short. */\nexport function normalize(a: Vec3): Vec3 {\n const l = len(a);\n return l > 0 && l < Infinity ? scale(a, 1 / l) : { x: 0, y: 0, z: 0 };\n}\n\n/** `Vec3` from loose components — the shape `Mat4`'s row math produces. */\nexport function vec3(x: number, y: number, z: number): Vec3 {\n return { x, y, z };\n}\n\n/** The quaternion for no rotation, `[0, 0, 0, 1]`. */\nexport function quatIdentity(): Quat {\n return [0, 0, 0, 1];\n}\n\n/** Rotation by `angle` radians about `axis`, which must be nonzero but need\n * not be unit length. */\nexport function quatFromAxisAngle(axis: Vec3, angle: number): Quat {\n const a = normalize(axis);\n const half = angle / 2;\n const s = Math.sin(half);\n return [a.x * s, a.y * s, a.z * s, Math.cos(half)];\n}\n","/** 4x4 matrices in GL's column-major order: element (row `r`, column `c`) is\n * `m[c * 4 + r]`, which is the layout `gl.uniformMatrix4fv` reads without a\n * transpose and the one three.js `toArray()` emits. */\n\nimport { SINGULAR_RATIO } from '../scalar';\nimport { cross, dot, len, normalize, sub, vec3, type Quat, type Vec3 } from './vec3';\n\n/** 16 numbers, column-major. */\nexport type Mat4 = readonly number[];\n\n/** The identity matrix. */\nexport function identity(): Mat4 {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n/** The product `a · b`: applied to a point, `b` acts first. */\nexport function multiply(a: Mat4, b: Mat4): Mat4 {\n const out = new Array<number>(16);\n for (let c = 0; c < 4; c++) {\n for (let r = 0; r < 4; r++) {\n let sum = 0;\n for (let k = 0; k < 4; k++) sum += a[k * 4 + r] * b[c * 4 + k];\n out[c * 4 + r] = sum;\n }\n }\n return out;\n}\n\n/** `[x, y, z, w]` in whatever space `m` maps into — clip space, when `m` is a view-projection. */\nexport function transformPoint4(\n m: Mat4,\n p: Vec3,\n): readonly [number, number, number, number] {\n const { x, y, z } = p;\n return [\n m[0] * x + m[4] * y + m[8] * z + m[12],\n m[1] * x + m[5] * y + m[9] * z + m[13],\n m[2] * x + m[6] * y + m[10] * z + m[14],\n m[3] * x + m[7] * y + m[11] * z + m[15],\n ];\n}\n\n/** `transformPoint4` divided through by w, however small. A point on the eye\n * plane (w = 0) comes back non-finite. */\nexport function transformPoint(m: Mat4, p: Vec3): Vec3 {\n const [x, y, z, w] = transformPoint4(m, p);\n if (w === 1) return vec3(x, y, z);\n return vec3(x / w, y / w, z / w);\n}\n\n/** Inverse, or null when the matrix is singular, non-finite, or too\n * ill-conditioned to invert meaningfully at its own scale. */\nexport function invert(m: Mat4): Mat4 | null {\n const [\n m00, m01, m02, m03,\n m10, m11, m12, m13,\n m20, m21, m22, m23,\n m30, m31, m32, m33,\n ] = m;\n\n const b00 = m00 * m11 - m01 * m10;\n const b01 = m00 * m12 - m02 * m10;\n const b02 = m00 * m13 - m03 * m10;\n const b03 = m01 * m12 - m02 * m11;\n const b04 = m01 * m13 - m03 * m11;\n const b05 = m02 * m13 - m03 * m12;\n const b06 = m20 * m31 - m21 * m30;\n const b07 = m20 * m32 - m22 * m30;\n const b08 = m20 * m33 - m23 * m30;\n const b09 = m21 * m32 - m22 * m31;\n const b10 = m21 * m33 - m23 * m31;\n const b11 = m22 * m33 - m23 * m32;\n\n const det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n // Hadamard: |det| never exceeds the product of the column lengths, so the\n // ratio is a volume in [0, 1] that no per-column scale can shrink.\n const scale =\n Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02 + m03 * m03) *\n Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12 + m13 * m13) *\n Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22 + m23 * m23) *\n Math.sqrt(m30 * m30 + m31 * m31 + m32 * m32 + m33 * m33);\n // Negated so a non-finite determinant falls out as singular.\n if (!(Math.abs(det) > SINGULAR_RATIO * scale)) return null;\n const d = 1 / det;\n\n return [\n (m11 * b11 - m12 * b10 + m13 * b09) * d,\n (m02 * b10 - m01 * b11 - m03 * b09) * d,\n (m31 * b05 - m32 * b04 + m33 * b03) * d,\n (m22 * b04 - m21 * b05 - m23 * b03) * d,\n (m12 * b08 - m10 * b11 - m13 * b07) * d,\n (m00 * b11 - m02 * b08 + m03 * b07) * d,\n (m32 * b02 - m30 * b05 - m33 * b01) * d,\n (m20 * b05 - m22 * b02 + m23 * b01) * d,\n (m10 * b10 - m11 * b08 + m13 * b06) * d,\n (m01 * b08 - m00 * b10 - m03 * b06) * d,\n (m30 * b04 - m31 * b02 + m33 * b00) * d,\n (m21 * b02 - m20 * b04 - m23 * b00) * d,\n (m11 * b07 - m10 * b09 - m12 * b06) * d,\n (m00 * b09 - m01 * b07 + m02 * b06) * d,\n (m31 * b01 - m30 * b03 - m32 * b00) * d,\n (m20 * b03 - m21 * b01 + m22 * b00) * d,\n ];\n}\n\n/** Translation · rotation · scale: the matrix that scales a point, then\n * rotates it, then moves it by `position`. */\nexport function compose(position: Vec3, rotation: Quat, scaling: Vec3): Mat4 {\n const [x, y, z, w] = rotation;\n const x2 = x + x;\n const y2 = y + y;\n const z2 = z + z;\n const xx = x * x2;\n const xy = x * y2;\n const xz = x * z2;\n const yy = y * y2;\n const yz = y * z2;\n const zz = z * z2;\n const wx = w * x2;\n const wy = w * y2;\n const wz = w * z2;\n const { x: sx, y: sy, z: sz } = scaling;\n\n return [\n (1 - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1 - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1 - (xx + yy)) * sz, 0,\n position.x, position.y, position.z, 1,\n ];\n}\n\n/** A GL-convention projection: vertical field of view `fovY` in radians, the\n * camera looking down −z, and `near`..`far` mapped to clip z −1..1. */\nexport function perspective(fovY: number, aspect: number, near: number, far: number): Mat4 {\n const f = 1 / Math.tan(fovY / 2);\n const range = near - far;\n return [\n f / aspect, 0, 0, 0,\n 0, f, 0, 0,\n 0, 0, (far + near) / range, -1,\n 0, 0, (2 * far * near) / range, 0,\n ];\n}\n\n/** A view from `eye` toward `target`. With the eye on its target, or `up`\n * parallel to the view to within rounding, the view has no orientation and\n * the result is singular. */\nexport function lookAt(eye: Vec3, target: Vec3, up: Vec3): Mat4 {\n const back = normalize(sub(eye, target));\n const side = cross(up, back);\n // |side| is |up| times the sine of the angle between up and the view.\n const right = len(side) > SINGULAR_RATIO * len(up) ? normalize(side) : vec3(0, 0, 0);\n const trueUp = cross(back, right);\n return [\n right.x, trueUp.x, back.x, 0,\n right.y, trueUp.y, back.y, 0,\n right.z, trueUp.z, back.z, 0,\n -dot(right, eye), -dot(trueUp, eye), -dot(back, eye), 1,\n ];\n}\n","/** Rays, axis-aligned boxes, and the intersections picking is built from. */\n\nimport { SINGULAR_RATIO } from '../scalar';\nimport { dot, len, type Vec3 } from './vec3';\nimport { transformPoint, type Mat4 } from './mat4';\n\n/** A ray from `origin` along `direction`, which need not be unit length: the\n * `t` the intersections return is in multiples of it. */\nexport interface Ray {\n origin: Vec3;\n direction: Vec3;\n}\n\n/** An axis-aligned box. `min` is componentwise <= `max`. */\nexport interface Aabb {\n min: Vec3;\n max: Vec3;\n}\n\n/** Distance along the ray to the box, or null. A ray starting inside returns 0. */\nexport function intersectRayAabb(ray: Ray, min: Vec3, max: Vec3): number | null {\n let tMin = Number.NEGATIVE_INFINITY;\n let tMax = Number.POSITIVE_INFINITY;\n\n for (const axis of ['x', 'y', 'z'] as const) {\n const o = ray.origin[axis];\n const d = ray.direction[axis];\n // Any other direction, however short, divides to an honest (possibly infinite) t.\n if (d === 0) {\n if (o < min[axis] || o > max[axis]) return null;\n continue;\n }\n let t1 = (min[axis] - o) / d;\n let t2 = (max[axis] - o) / d;\n if (t1 > t2) [t1, t2] = [t2, t1];\n if (t1 > tMin) tMin = t1;\n if (t2 < tMax) tMax = t2;\n if (tMin > tMax) return null;\n }\n\n if (tMax < 0) return null;\n return tMin < 0 ? 0 : tMin;\n}\n\n/** Plane is `dot(normal, p) === offset`. Null when the ray runs parallel to the\n * plane to within rounding, or points away from it. */\nexport function intersectRayPlane(ray: Ray, normal: Vec3, offset: number): number | null {\n const denom = dot(normal, ray.direction);\n if (!(Math.abs(denom) > SINGULAR_RATIO * len(normal) * len(ray.direction))) return null;\n const t = (offset - dot(normal, ray.origin)) / denom;\n return t < 0 ? null : t;\n}\n\n/**\n * The axis-aligned box enclosing `local` after `m`. All eight corners are\n * transformed and re-bounded, so a rotation widens the result rather than\n * rotating it — an AABB cannot represent an oriented box, and pretending\n * otherwise is how a hit test starts missing its own geometry.\n */\nexport function transformAabb(m: Mat4, local: Aabb): Aabb {\n let min: Vec3 = { x: Infinity, y: Infinity, z: Infinity };\n let max: Vec3 = { x: -Infinity, y: -Infinity, z: -Infinity };\n for (let i = 0; i < 8; i++) {\n const corner: Vec3 = {\n x: i & 1 ? local.max.x : local.min.x,\n y: i & 2 ? local.max.y : local.min.y,\n z: i & 4 ? local.max.z : local.min.z,\n };\n const p = transformPoint(m, corner);\n min = { x: Math.min(min.x, p.x), y: Math.min(min.y, p.y), z: Math.min(min.z, p.z) };\n max = { x: Math.max(max.x, p.x), y: Math.max(max.y, p.y), z: Math.max(max.z, p.z) };\n }\n return { min, max };\n}\n\n/** The box centred on `center` reaching `radius` along every axis. */\nexport function aabbAround(center: Vec3, radius: number): Aabb {\n return {\n min: { x: center.x - radius, y: center.y - radius, z: center.z - radius },\n max: { x: center.x + radius, y: center.y + radius, z: center.z + radius },\n };\n}\n","/**\n * The port-curve rule one dimension up, in `Vec3`. The rule itself lives in\n * `../portCurve`, stated once over components — this wrapper is types and\n * nothing else, so 2D and 3D cannot disagree about what the curve is.\n */\n\nimport {\n PORT_REACH,\n cubicAt as cubicAtN,\n portControls as portControlsN,\n portCurvePoints as portCurvePointsN,\n} from '../portCurve';\nimport type { Vec3 } from './vec3';\n\nexport { PORT_REACH };\n\nconst comps = (v: Vec3): [number, number, number] => [v.x, v.y, v.z];\nconst compsOrNull = (v: Vec3 | null | undefined) => (v == null ? v : comps(v));\nconst fromComps = (p: readonly number[]): Vec3 => ({ x: p[0]!, y: p[1]!, z: p[2]! });\n\n/** `[c1, c2]` for the cubic from `a` to `b`. A null normal falls back to a lerp\n * along the chord; see `../portCurve` for why the two ends differ. */\nexport function portControls(\n a: Vec3,\n b: Vec3,\n outNormal: Vec3 | null | undefined,\n inNormal: Vec3 | null | undefined,\n reach: number = PORT_REACH,\n): [Vec3, Vec3] {\n const [c1, c2] = portControlsN(\n comps(a),\n comps(b),\n compsOrNull(outNormal),\n compsOrNull(inNormal),\n reach,\n );\n return [fromComps(c1), fromComps(c2)];\n}\n\n/** A port curve sampled into `samples` points, excluding its start. */\nexport function portCurvePoints(\n a: Vec3,\n b: Vec3,\n outNormal: Vec3 | null | undefined,\n inNormal: Vec3 | null | undefined,\n samples: number,\n reach: number = PORT_REACH,\n): Vec3[] {\n return portCurvePointsN(\n comps(a),\n comps(b),\n compsOrNull(outNormal),\n compsOrNull(inNormal),\n samples,\n reach,\n ).map(fromComps);\n}\n\n/** A cubic evaluated at `t`. The 2D barrel's `cubicEvalAt`, one dimension up. */\nexport function cubicAt(p0: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, t: number): Vec3 {\n const p = cubicAtN(comps(p0), comps(p1), comps(p2), comps(p3), t);\n return fromComps(p);\n}\n"]}
1
+ {"version":3,"sources":["../../src/3d/vec3.ts","../../src/3d/mat4.ts","../../src/3d/ray3.ts","../../src/3d/portCurve3.ts"],"names":["scale","portControls","portCurvePoints","cubicAt"],"mappings":";;;;;AAmBO,SAAS,GAAA,CAAI,GAAS,CAAA,EAAe;AAC1C,EAAA,OAAO,EAAE,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAE;AACpD;AAGO,SAAS,GAAA,CAAI,GAAS,CAAA,EAAe;AAC1C,EAAA,OAAO,EAAE,CAAA,EAAG,CAAA,CAAE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A,GAAY,CAAC,CAAA,MAAgC,EAAE,GAAG,CAAA,CAAE,CAAC,CAAA,EAAI,CAAA,EAAG,EAAE,CAAC,CAAA,EAAI,CAAA,EAAG,CAAA,CAAE,CAAC,CAAA,EAAG,CAAA;AAI3E,SAASC,cACd,CAAA,EACA,CAAA,EACA,SAAA,EACA,QAAA,EACA,QAAgB,UAAA,EACF;AACd,EAAA,MAAM,CAAC,EAAA,EAAI,EAAE,CAAA,GAAI,YAAA;AAAA,IACf,MAAM,CAAC,CAAA;AAAA,IACP,MAAM,CAAC,CAAA;AAAA,IACP,YAAY,SAAS,CAAA;AAAA,IACrB,YAAY,QAAQ,CAAA;AAAA,IACpB;AAAA,GACF;AACA,EAAA,OAAO,CAAC,SAAA,CAAU,EAAE,CAAA,EAAG,SAAA,CAAU,EAAE,CAAC,CAAA;AACtC;AAGO,SAASC,iBACd,CAAA,EACA,CAAA,EACA,WACA,QAAA,EACA,OAAA,EACA,QAAgB,UAAA,EACR;AACR,EAAA,OAAO,eAAA;AAAA,IACL,MAAM,CAAC,CAAA;AAAA,IACP,MAAM,CAAC,CAAA;AAAA,IACP,YAAY,SAAS,CAAA;AAAA,IACrB,YAAY,QAAQ,CAAA;AAAA,IACpB,OAAA;AAAA,IACA;AAAA,GACF,CAAE,IAAI,SAAS,CAAA;AACjB;AAGO,SAASC,QAAAA,CAAQ,EAAA,EAAU,EAAA,EAAU,EAAA,EAAU,IAAU,CAAA,EAAiB;AAC/E,EAAA,MAAM,CAAA,GAAI,OAAA,CAAS,KAAA,CAAM,EAAE,GAAG,KAAA,CAAM,EAAE,CAAA,EAAG,KAAA,CAAM,EAAE,CAAA,EAAG,KAAA,CAAM,EAAE,GAAG,CAAC,CAAA;AAChE,EAAA,OAAO,UAAU,CAAC,CAAA;AACpB","file":"index.js","sourcesContent":["/** Three-component vectors and unit quaternions. `Vec3`'s fields are readonly:\n * a pose stored in a history snapshot must not be writable through the value\n * handed to a renderer.\n *\n * Named fields rather than a tuple, matching `Vec2` one tier up, so a\n * consumer writing both dimensions says `p.x` in each. `Quat` stays a tuple —\n * it is not a point, and `[x, y, z, w]` is the layout three.js and glMatrix\n * both use. */\n\nexport interface Vec3 {\n readonly x: number;\n readonly y: number;\n readonly z: number;\n}\n\n/** `[x, y, z, w]`, w last — the layout three.js and glMatrix both use. */\nexport type Quat = readonly [number, number, number, number];\n\n/** `a + b`. */\nexport function add(a: Vec3, b: Vec3): Vec3 {\n return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };\n}\n\n/** `a - b`. */\nexport function sub(a: Vec3, b: Vec3): Vec3 {\n return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };\n}\n\n/** `a` multiplied by the scalar `k`. */\nexport function scale(a: Vec3, k: number): Vec3 {\n return { x: a.x * k, y: a.y * k, z: a.z * k };\n}\n\n/** Dot product. */\nexport function dot(a: Vec3, b: Vec3): number {\n return a.x * b.x + a.y * b.y + a.z * b.z;\n}\n\n/** Cross product `a × b`. */\nexport function cross(a: Vec3, b: Vec3): Vec3 {\n return {\n x: a.y * b.z - a.z * b.y,\n y: a.z * b.x - a.x * b.z,\n z: a.x * b.y - a.y * b.x,\n };\n}\n\n/** Squared length. Compare distances with this and skip the square root. */\nexport function len2(a: Vec3): number {\n return dot(a, a);\n}\n\n/** Euclidean length. */\nexport function len(a: Vec3): number {\n return Math.sqrt(len2(a));\n}\n\n/** A vector with no length, or no finite one, normalizes to the zero vector\n * rather than to `NaN`. Every other vector keeps its direction, however short. */\nexport function normalize(a: Vec3): Vec3 {\n const l = len(a);\n return l > 0 && l < Infinity ? scale(a, 1 / l) : { x: 0, y: 0, z: 0 };\n}\n\n/** Euclidean distance between two points. */\nexport function distance(a: Vec3, b: Vec3): number {\n return len(sub(a, b));\n}\n\n/** The point `t` of the way from `a` to `b`; `t` outside [0, 1] extrapolates. */\nexport function lerp(a: Vec3, b: Vec3, t: number): Vec3 {\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t, z: a.z + (b.z - a.z) * t };\n}\n\n/** `Vec3` from loose components — the shape `Mat4`'s row math produces. */\nexport function vec3(x: number, y: number, z: number): Vec3 {\n return { x, y, z };\n}\n\n/** The quaternion for no rotation, `[0, 0, 0, 1]`. */\nexport function quatIdentity(): Quat {\n return [0, 0, 0, 1];\n}\n\n/** Rotation by `angle` radians about `axis`, which must be nonzero but need\n * not be unit length. */\nexport function quatFromAxisAngle(axis: Vec3, angle: number): Quat {\n const a = normalize(axis);\n const half = angle / 2;\n const s = Math.sin(half);\n return [a.x * s, a.y * s, a.z * s, Math.cos(half)];\n}\n","/** 4x4 matrices in GL's column-major order: element (row `r`, column `c`) is\n * `m[c * 4 + r]`, which is the layout `gl.uniformMatrix4fv` reads without a\n * transpose and the one three.js `toArray()` emits. */\n\nimport { SINGULAR_RATIO } from '../scalar';\nimport { cross, dot, len, normalize, sub, vec3, type Quat, type Vec3 } from './vec3';\n\n/** 16 numbers, column-major. */\nexport type Mat4 = readonly number[];\n\n/** The identity matrix. */\nexport function identity(): Mat4 {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n/** The product `a · b`: applied to a point, `b` acts first. */\nexport function multiply(a: Mat4, b: Mat4): Mat4 {\n const out = new Array<number>(16);\n for (let c = 0; c < 4; c++) {\n for (let r = 0; r < 4; r++) {\n let sum = 0;\n for (let k = 0; k < 4; k++) sum += a[k * 4 + r] * b[c * 4 + k];\n out[c * 4 + r] = sum;\n }\n }\n return out;\n}\n\n/** `[x, y, z, w]` in whatever space `m` maps into — clip space, when `m` is a view-projection. */\nexport function transformPoint4(\n m: Mat4,\n p: Vec3,\n): readonly [number, number, number, number] {\n const { x, y, z } = p;\n return [\n m[0] * x + m[4] * y + m[8] * z + m[12],\n m[1] * x + m[5] * y + m[9] * z + m[13],\n m[2] * x + m[6] * y + m[10] * z + m[14],\n m[3] * x + m[7] * y + m[11] * z + m[15],\n ];\n}\n\n/** `transformPoint4` divided through by w, however small. A point on the eye\n * plane (w = 0) comes back non-finite. */\nexport function transformPoint(m: Mat4, p: Vec3): Vec3 {\n const [x, y, z, w] = transformPoint4(m, p);\n if (w === 1) return vec3(x, y, z);\n return vec3(x / w, y / w, z / w);\n}\n\n/** Inverse, or null when the matrix is singular, non-finite, or too\n * ill-conditioned to invert meaningfully at its own scale. */\nexport function invert(m: Mat4): Mat4 | null {\n const [\n m00, m01, m02, m03,\n m10, m11, m12, m13,\n m20, m21, m22, m23,\n m30, m31, m32, m33,\n ] = m;\n\n const b00 = m00 * m11 - m01 * m10;\n const b01 = m00 * m12 - m02 * m10;\n const b02 = m00 * m13 - m03 * m10;\n const b03 = m01 * m12 - m02 * m11;\n const b04 = m01 * m13 - m03 * m11;\n const b05 = m02 * m13 - m03 * m12;\n const b06 = m20 * m31 - m21 * m30;\n const b07 = m20 * m32 - m22 * m30;\n const b08 = m20 * m33 - m23 * m30;\n const b09 = m21 * m32 - m22 * m31;\n const b10 = m21 * m33 - m23 * m31;\n const b11 = m22 * m33 - m23 * m32;\n\n const det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n // Hadamard: |det| never exceeds the product of the column lengths, so the\n // ratio is a volume in [0, 1] that no per-column scale can shrink.\n const scale =\n Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02 + m03 * m03) *\n Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12 + m13 * m13) *\n Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22 + m23 * m23) *\n Math.sqrt(m30 * m30 + m31 * m31 + m32 * m32 + m33 * m33);\n // Negated so a non-finite determinant falls out as singular.\n if (!(Math.abs(det) > SINGULAR_RATIO * scale)) return null;\n const d = 1 / det;\n\n return [\n (m11 * b11 - m12 * b10 + m13 * b09) * d,\n (m02 * b10 - m01 * b11 - m03 * b09) * d,\n (m31 * b05 - m32 * b04 + m33 * b03) * d,\n (m22 * b04 - m21 * b05 - m23 * b03) * d,\n (m12 * b08 - m10 * b11 - m13 * b07) * d,\n (m00 * b11 - m02 * b08 + m03 * b07) * d,\n (m32 * b02 - m30 * b05 - m33 * b01) * d,\n (m20 * b05 - m22 * b02 + m23 * b01) * d,\n (m10 * b10 - m11 * b08 + m13 * b06) * d,\n (m01 * b08 - m00 * b10 - m03 * b06) * d,\n (m30 * b04 - m31 * b02 + m33 * b00) * d,\n (m21 * b02 - m20 * b04 - m23 * b00) * d,\n (m11 * b07 - m10 * b09 - m12 * b06) * d,\n (m00 * b09 - m01 * b07 + m02 * b06) * d,\n (m31 * b01 - m30 * b03 - m32 * b00) * d,\n (m20 * b03 - m21 * b01 + m22 * b00) * d,\n ];\n}\n\n/** Translation · rotation · scale: the matrix that scales a point, then\n * rotates it, then moves it by `position`. */\nexport function compose(position: Vec3, rotation: Quat, scaling: Vec3): Mat4 {\n const [x, y, z, w] = rotation;\n const x2 = x + x;\n const y2 = y + y;\n const z2 = z + z;\n const xx = x * x2;\n const xy = x * y2;\n const xz = x * z2;\n const yy = y * y2;\n const yz = y * z2;\n const zz = z * z2;\n const wx = w * x2;\n const wy = w * y2;\n const wz = w * z2;\n const { x: sx, y: sy, z: sz } = scaling;\n\n return [\n (1 - (yy + zz)) * sx, (xy + wz) * sx, (xz - wy) * sx, 0,\n (xy - wz) * sy, (1 - (xx + zz)) * sy, (yz + wx) * sy, 0,\n (xz + wy) * sz, (yz - wx) * sz, (1 - (xx + yy)) * sz, 0,\n position.x, position.y, position.z, 1,\n ];\n}\n\n/** A GL-convention projection: vertical field of view `fovY` in radians, the\n * camera looking down −z, and `near`..`far` mapped to clip z −1..1. */\nexport function perspective(fovY: number, aspect: number, near: number, far: number): Mat4 {\n const f = 1 / Math.tan(fovY / 2);\n const range = near - far;\n return [\n f / aspect, 0, 0, 0,\n 0, f, 0, 0,\n 0, 0, (far + near) / range, -1,\n 0, 0, (2 * far * near) / range, 0,\n ];\n}\n\n/** A view from `eye` toward `target`. With the eye on its target, or `up`\n * parallel to the view to within rounding, the view has no orientation and\n * the result is singular. */\nexport function lookAt(eye: Vec3, target: Vec3, up: Vec3): Mat4 {\n const back = normalize(sub(eye, target));\n const side = cross(up, back);\n // |side| is |up| times the sine of the angle between up and the view.\n const right = len(side) > SINGULAR_RATIO * len(up) ? normalize(side) : vec3(0, 0, 0);\n const trueUp = cross(back, right);\n return [\n right.x, trueUp.x, back.x, 0,\n right.y, trueUp.y, back.y, 0,\n right.z, trueUp.z, back.z, 0,\n -dot(right, eye), -dot(trueUp, eye), -dot(back, eye), 1,\n ];\n}\n","/** Rays, axis-aligned boxes, and the intersections picking is built from. */\n\nimport { SINGULAR_RATIO } from '../scalar';\nimport { add, dot, len, len2, scale, sub, type Vec3 } from './vec3';\nimport { transformPoint, type Mat4 } from './mat4';\n\n/** A ray from `origin` along `direction`, which need not be unit length: the\n * `t` the intersections return is in multiples of it. */\nexport interface Ray {\n origin: Vec3;\n direction: Vec3;\n}\n\n/** An axis-aligned box. `min` is componentwise <= `max`. */\nexport interface Aabb {\n min: Vec3;\n max: Vec3;\n}\n\n/** Distance along the ray to the box, or null. A ray starting inside returns 0. */\nexport function intersectRayAabb(ray: Ray, min: Vec3, max: Vec3): number | null {\n let tMin = Number.NEGATIVE_INFINITY;\n let tMax = Number.POSITIVE_INFINITY;\n\n for (const axis of ['x', 'y', 'z'] as const) {\n const o = ray.origin[axis];\n const d = ray.direction[axis];\n // Any other direction, however short, divides to an honest (possibly infinite) t.\n if (d === 0) {\n if (o < min[axis] || o > max[axis]) return null;\n continue;\n }\n let t1 = (min[axis] - o) / d;\n let t2 = (max[axis] - o) / d;\n if (t1 > t2) [t1, t2] = [t2, t1];\n if (t1 > tMin) tMin = t1;\n if (t2 < tMax) tMax = t2;\n if (tMin > tMax) return null;\n }\n\n if (tMax < 0) return null;\n return tMin < 0 ? 0 : tMin;\n}\n\n/** Plane is `dot(normal, p) === offset`. Null when the ray runs parallel to the\n * plane to within rounding, or points away from it. */\nexport function intersectRayPlane(ray: Ray, normal: Vec3, offset: number): number | null {\n const denom = dot(normal, ray.direction);\n if (!(Math.abs(denom) > SINGULAR_RATIO * len(normal) * len(ray.direction))) return null;\n const t = (offset - dot(normal, ray.origin)) / denom;\n return t < 0 ? null : t;\n}\n\n/**\n * The axis-aligned box enclosing `local` after `m`. All eight corners are\n * transformed and re-bounded, so a rotation widens the result rather than\n * rotating it — an AABB cannot represent an oriented box, and pretending\n * otherwise is how a hit test starts missing its own geometry.\n */\nexport function transformAabb(m: Mat4, local: Aabb): Aabb {\n let min: Vec3 = { x: Infinity, y: Infinity, z: Infinity };\n let max: Vec3 = { x: -Infinity, y: -Infinity, z: -Infinity };\n for (let i = 0; i < 8; i++) {\n const corner: Vec3 = {\n x: i & 1 ? local.max.x : local.min.x,\n y: i & 2 ? local.max.y : local.min.y,\n z: i & 4 ? local.max.z : local.min.z,\n };\n const p = transformPoint(m, corner);\n min = { x: Math.min(min.x, p.x), y: Math.min(min.y, p.y), z: Math.min(min.z, p.z) };\n max = { x: Math.max(max.x, p.x), y: Math.max(max.y, p.y), z: Math.max(max.z, p.z) };\n }\n return { min, max };\n}\n\n/** The box centred on `center` reaching `radius` along every axis. */\nexport function aabbAround(center: Vec3, radius: number): Aabb {\n return {\n min: { x: center.x - radius, y: center.y - radius, z: center.z - radius },\n max: { x: center.x + radius, y: center.y + radius, z: center.z + radius },\n };\n}\n\n/** The point `t` direction-lengths along the ray. */\nexport function pointOnRay(ray: Ray, t: number): Vec3 {\n return add(ray.origin, scale(ray.direction, t));\n}\n\n/** The smallest box containing every point. No points gives an inverted\n * box, `min` at +Infinity and `max` at -Infinity. */\nexport function aabbOfPoints(points: readonly Vec3[]): Aabb {\n const min = { x: Infinity, y: Infinity, z: Infinity };\n const max = { x: -Infinity, y: -Infinity, z: -Infinity };\n for (const p of points) {\n for (const axis of ['x', 'y', 'z'] as const) {\n if (p[axis] < min[axis]) min[axis] = p[axis];\n if (p[axis] > max[axis]) max[axis] = p[axis];\n }\n }\n return { min, max };\n}\n\n/** The point of the infinite line through `origin` along `direction` nearest\n * `p`. A zero direction makes the line the point `origin`. */\nexport function closestPointOnLine(p: Vec3, origin: Vec3, direction: Vec3): Vec3 {\n const d2 = len2(direction);\n if (!(d2 > 0)) return origin;\n return add(origin, scale(direction, dot(sub(p, origin), direction) / d2));\n}\n\n/** The point of segment `a`–`b` nearest `p`. */\nexport function closestPointOnSegment(p: Vec3, a: Vec3, b: Vec3): Vec3 {\n const ab = sub(b, a);\n const d2 = len2(ab);\n if (!(d2 > 0)) return a;\n const t = Math.min(1, Math.max(0, dot(sub(p, a), ab) / d2));\n return add(a, scale(ab, t));\n}\n\n/**\n * The nearest pair of points between a ray and the infinite line through\n * `origin` along `direction`. `t` is the ray parameter (never negative) and\n * `s` the line's. A line parallel to the ray pairs with the ray's origin.\n */\nexport function closestPointsRayLine(\n ray: Ray,\n origin: Vec3,\n direction: Vec3,\n): { onRay: Vec3; onLine: Vec3; t: number; s: number } {\n const u = ray.direction;\n const v = direction;\n const w = sub(ray.origin, origin);\n const a = len2(u);\n const b = dot(u, v);\n const c = len2(v);\n const d = dot(u, w);\n const e = dot(v, w);\n const denom = a * c - b * b;\n let t = 0;\n if (a > 0 && denom > SINGULAR_RATIO * a * c) t = Math.max(0, (b * e - c * d) / denom);\n const onRay = pointOnRay(ray, t);\n const s = c > 0 ? dot(sub(onRay, origin), v) / c : 0;\n return { onRay, onLine: add(origin, scale(v, s)), t, s };\n}\n","/**\n * The port-curve rule one dimension up, in `Vec3`. The rule itself lives in\n * `../portCurve`, stated once over components — this wrapper is types and\n * nothing else, so 2D and 3D cannot disagree about what the curve is.\n */\n\nimport {\n PORT_REACH,\n cubicAt as cubicAtN,\n portControls as portControlsN,\n portCurvePoints as portCurvePointsN,\n} from '../portCurve';\nimport type { Vec3 } from './vec3';\n\nexport { PORT_REACH };\n\nconst comps = (v: Vec3): [number, number, number] => [v.x, v.y, v.z];\nconst compsOrNull = (v: Vec3 | null | undefined) => (v == null ? v : comps(v));\nconst fromComps = (p: readonly number[]): Vec3 => ({ x: p[0]!, y: p[1]!, z: p[2]! });\n\n/** `[c1, c2]` for the cubic from `a` to `b`. A null normal falls back to a lerp\n * along the chord; see `../portCurve` for why the two ends differ. */\nexport function portControls(\n a: Vec3,\n b: Vec3,\n outNormal: Vec3 | null | undefined,\n inNormal: Vec3 | null | undefined,\n reach: number = PORT_REACH,\n): [Vec3, Vec3] {\n const [c1, c2] = portControlsN(\n comps(a),\n comps(b),\n compsOrNull(outNormal),\n compsOrNull(inNormal),\n reach,\n );\n return [fromComps(c1), fromComps(c2)];\n}\n\n/** A port curve sampled into `samples` points, excluding its start. */\nexport function portCurvePoints(\n a: Vec3,\n b: Vec3,\n outNormal: Vec3 | null | undefined,\n inNormal: Vec3 | null | undefined,\n samples: number,\n reach: number = PORT_REACH,\n): Vec3[] {\n return portCurvePointsN(\n comps(a),\n comps(b),\n compsOrNull(outNormal),\n compsOrNull(inNormal),\n samples,\n reach,\n ).map(fromComps);\n}\n\n/** A cubic evaluated at `t`. The 2D barrel's `cubicEvalAt`, one dimension up. */\nexport function cubicAt(p0: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, t: number): Vec3 {\n const p = cubicAtN(comps(p0), comps(p1), comps(p2), comps(p3), t);\n return fromComps(p);\n}\n"]}
@@ -1,5 +1,4 @@
1
- import { P as PolygonPath, a as Path } from '../path-Bf9KeVxC.js';
2
- import { P as Point } from '../cubicMath-CFXbq6vp.js';
1
+ import { P as PolygonPath, a as Path, b as Point } from '../path-BW8d_2RY.js';
3
2
 
4
3
  /** Union of N paths. Commutative. Returns an empty path if all inputs are empty. */
5
4
  declare function pathUnion(...paths: Path[]): PolygonPath;
@@ -22,14 +21,20 @@ declare function pathDivide(...paths: Path[]): PolygonPath[];
22
21
  declare function pathCrop(...paths: Path[]): PolygonPath[];
23
22
  /**
24
23
  * Fracture N paths along every intersection into the maximal set of
25
- * non-overlapping regions. Returns one piece per region, naming every input
26
- * that covers it. For N=2 these are the three Illustrator "Divide" outputs
27
- * (A−B, B−A, A∩B).
28
- *
29
- * One region per non-empty subset of the inputs, so the 2^N − 1 subset count
30
- * limits this to small N; passing more than ~8 inputs is a misuse.
24
+ * non-overlapping regions. Returns one piece per set of inputs covering some
25
+ * region, naming them. For N=2 these are the three Illustrator "Divide"
26
+ * outputs (A−B, B−A, A∩B). Pieces with fewer sources come first.
31
27
  */
32
28
  declare function pathDividePieces(...paths: Path[]): BooleanPiece[];
29
+ /**
30
+ * The faces the paths cut each other into: {@link pathDividePieces}, with a
31
+ * region that falls apart split into one piece per connected part. A face
32
+ * keeps its holes. Same order, a region's parts left to right.
33
+ *
34
+ * Traces the arrangement of the outlines once, so the cost grows with the
35
+ * edges and their crossings rather than with the subsets of the inputs.
36
+ */
37
+ declare function pathFacePieces(...paths: Path[]): BooleanPiece[];
33
38
  /**
34
39
  * Remove from each path what the paths after it cover (Illustrator "Trim"):
35
40
  * given back to front, every piece is the part of its input left showing.
@@ -73,7 +78,7 @@ interface PathToMultiPolygonOptions {
73
78
  tolerance?: number;
74
79
  }
75
80
  /** Convert a `Path` to a `MultiPolygon` suitable for `polygon-clipping`. */
76
- declare function pathToMultiPolygon(path: Path, opts?: PathToMultiPolygonOptions): MultiPolygon;
81
+ declare function pathToMultiPolygon(given: Path, opts?: PathToMultiPolygonOptions): MultiPolygon;
77
82
  /** Convert a `MultiPolygon` to a polygon path with `fillRule: 'nonzero'`. */
78
83
  declare function multiPolygonToPath(mp: MultiPolygon): PolygonPath;
79
84
 
@@ -137,4 +142,23 @@ declare function splitPathByPolyline(path: Path, cut: readonly Point[], opts?: S
137
142
  */
138
143
  declare function snipPathByPolyline(path: Path, cut: readonly Point[]): Path[] | null;
139
144
 
140
- export { type BooleanPiece, type MultiPolygon, type Pair, type PathToMultiPolygonOptions, type Polygon, type Ring, type SplitBySegmentOptions, multiPolygonToPath, pathCrop, pathCropPieces, pathDivide, pathDividePieces, pathExclude, pathIntersect, pathMerge, pathSubtract, pathToMultiPolygon, pathTrim, pathUnion, snipPathByPolyline, splitPathByPolyline, splitPathBySegment, trianglesToPath };
145
+ /** Options for {@link snipPathsAtCrossings}. */
146
+ interface SnipAtCrossingsOptions {
147
+ /** How closely a cutting path's curves are followed when they are flattened
148
+ * to find where they cross. Default 0.05. */
149
+ flattenTolerance?: number;
150
+ }
151
+ /**
152
+ * Cut the stroke of every path in `paths` wherever another of them crosses
153
+ * it, as {@link snipPathByPolyline} cuts along one polyline: an open subpath
154
+ * becomes open runs between crossings, and a closed one is opened at them.
155
+ * A path is not cut where it crosses itself.
156
+ *
157
+ * Answers one entry per path, in order: its pieces, or `null` when no other
158
+ * path crosses it. The cutting paths' curves are flattened, so a crossing on
159
+ * a curve is found to within `flattenTolerance`; the pieces keep their own
160
+ * segment types.
161
+ */
162
+ declare function snipPathsAtCrossings(paths: readonly Path[], opts?: SnipAtCrossingsOptions): (Path[] | null)[];
163
+
164
+ export { type BooleanPiece, type MultiPolygon, type Pair, type PathToMultiPolygonOptions, type Polygon, type Ring, type SnipAtCrossingsOptions, type SplitBySegmentOptions, multiPolygonToPath, pathCrop, pathCropPieces, pathDivide, pathDividePieces, pathExclude, pathFacePieces, pathIntersect, pathMerge, pathSubtract, pathToMultiPolygon, pathTrim, pathUnion, snipPathByPolyline, snipPathsAtCrossings, splitPathByPolyline, splitPathBySegment, trianglesToPath };