@weasel-js/geom 1.10.1 → 1.11.1

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 +9 -1
  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 +18 -11
  6. package/dist/booleans/index.js +432 -352
  7. package/dist/booleans/index.js.map +1 -1
  8. package/dist/chunk-4Y67BZL5.js +573 -0
  9. package/dist/chunk-4Y67BZL5.js.map +1 -0
  10. package/dist/chunk-6FGQML7D.js +152 -0
  11. package/dist/chunk-6FGQML7D.js.map +1 -0
  12. package/dist/{chunk-7WFFCHRL.js → chunk-7F66PQCJ.js} +6 -37
  13. package/dist/chunk-7F66PQCJ.js.map +1 -0
  14. package/dist/chunk-B53BERKG.js +386 -0
  15. package/dist/chunk-B53BERKG.js.map +1 -0
  16. package/dist/chunk-CE7IY7TB.js +104 -0
  17. package/dist/chunk-CE7IY7TB.js.map +1 -0
  18. package/dist/chunk-EAKE3N7W.js +804 -0
  19. package/dist/chunk-EAKE3N7W.js.map +1 -0
  20. package/dist/chunk-LRVPK7HI.js +491 -0
  21. package/dist/chunk-LRVPK7HI.js.map +1 -0
  22. package/dist/chunk-Q66NA2FU.js +174 -0
  23. package/dist/chunk-Q66NA2FU.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 +1511 -283
  31. package/dist/index.js +5755 -2674
  32. package/dist/index.js.map +1 -1
  33. package/dist/nd/index.d.ts +92 -27
  34. package/dist/nd/index.js +297 -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 +15 -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 +254 -0
  42. package/dist/warp/index.js +1448 -0
  43. package/dist/warp/index.js.map +1 -0
  44. package/package.json +5 -1
  45. package/dist/chunk-7WFFCHRL.js.map +0 -1
  46. package/dist/chunk-IDXY2NCA.js +0 -177
  47. package/dist/chunk-IDXY2NCA.js.map +0 -1
  48. package/dist/chunk-NJ3IGAKR.js +0 -16
  49. package/dist/chunk-NJ3IGAKR.js.map +0 -1
  50. package/dist/chunk-OXH3NOXC.js +0 -62
  51. package/dist/chunk-OXH3NOXC.js.map +0 -1
  52. package/dist/chunk-URQMDR6Q.js +0 -80
  53. package/dist/chunk-URQMDR6Q.js.map +0 -1
  54. package/dist/cubicMath-BW-HJrCE.d.ts +0 -16
  55. package/dist/path-ljHxobyu.d.ts +0 -44
@@ -0,0 +1,254 @@
1
+ import { b as Point, P as PolygonPath } from '../path-BW8d_2RY.js';
2
+
3
+ /**
4
+ * Maps from the unit square onto a quadrilateral: what a box becomes when its
5
+ * four corners are dragged apart independently.
6
+ */
7
+
8
+ /** Four corners, in the order the unit square's land on them: (0,0), (1,0),
9
+ * (1,1), (0,1) — a box's top-left, top-right, bottom-right, bottom-left. */
10
+ type Quad = readonly [Point, Point, Point, Point];
11
+ /** A map from unit-square coordinates to the plane. */
12
+ type UvMap = (u: number, v: number) => Point;
13
+ /**
14
+ * The bilinear map onto `q`: each corner weighted by its share of the square.
15
+ * Lines of constant `u` or `v` stay straight; any other line bends.
16
+ */
17
+ declare function bilinearQuad(q: Quad): UvMap;
18
+ /**
19
+ * The projective map taking the unit square onto `q`, as `[a, b, c, d, e, f,
20
+ * g, h]`: `x = (a·u + b·v + c) / w` and `y = (d·u + e·v + f) / w`, where
21
+ * `w = g·u + h·v + 1`. Null when `q` is not strictly convex, since no
22
+ * projective map then sends the square's inside onto the quad's.
23
+ */
24
+ declare function squareToQuadHomography(q: Quad): readonly number[] | null;
25
+ /**
26
+ * The projective map onto `q`: straight lines stay straight, and the box's far
27
+ * side foreshortens the way a plane seen at an angle does. Null where
28
+ * {@link squareToQuadHomography} is.
29
+ */
30
+ declare function projectiveQuad(q: Quad): UvMap | null;
31
+
32
+ /**
33
+ * Maps from the unit square through a grid of control points: an envelope
34
+ * mesh. The grid's points are interpolated, so a grid laid evenly over a box
35
+ * maps the box onto itself.
36
+ */
37
+
38
+ /** A grid of `rows` × `cols` patches: `(rows + 1) × (cols + 1)` points, row by
39
+ * row from the top. */
40
+ interface MeshGrid {
41
+ rows: number;
42
+ cols: number;
43
+ points: readonly Point[];
44
+ }
45
+ /** An even grid of `rows` × `cols` patches over the box. */
46
+ declare function meshGridOver(box: {
47
+ x: number;
48
+ y: number;
49
+ width: number;
50
+ height: number;
51
+ }, rows: number, cols: number): MeshGrid;
52
+ /** A grid of `rows` × `cols` patches whose points are where `map` sends an
53
+ * even grid over the unit square — a mesh resampled at a new resolution. */
54
+ declare function meshGridFrom(map: UvMap, rows: number, cols: number): MeshGrid;
55
+ /**
56
+ * The smooth surface through every grid point: a Catmull-Rom spline along each
57
+ * row, and another down the columns through those. Bending one point bends its
58
+ * neighborhood smoothly, across patch edges included.
59
+ */
60
+ declare function bicubicMesh(grid: MeshGrid): UvMap;
61
+ /**
62
+ * One Coons patch per grid cell: the cell's four edges are the splines through
63
+ * the grid lines, and its inside is blended from those edges alone. Edges
64
+ * match the bicubic surface; the inside follows them more literally, without
65
+ * the bicubic surface's pull from points beyond the cell.
66
+ */
67
+ declare function coonsMesh(grid: MeshGrid): UvMap;
68
+
69
+ /** A triangle mesh at rest: interleaved `x, y` vertices and vertex-index triples. */
70
+ interface ArapMesh {
71
+ vertices: Float64Array;
72
+ triangles: Uint32Array;
73
+ }
74
+ /**
75
+ * A stage of a solve: `similarity` is the first linear step, `rigid` the
76
+ * second, `local-global` each round after them, and `injective` each round
77
+ * of the pass that runs when those leave a triangle turned over. That pass's
78
+ * last step is the result: its pins set exactly, or the local/global result
79
+ * again when the pins cannot be set without a fold.
80
+ */
81
+ type ArapStage = 'similarity' | 'rigid' | 'local-global' | 'injective';
82
+ /** A solve's state after one stage: every vertex's position, interleaved `x, y`. */
83
+ interface ArapStep {
84
+ stage: ArapStage;
85
+ /** Which round of its stage, from 1. */
86
+ round: number;
87
+ vertices: Float64Array;
88
+ }
89
+ /** Options for {@link ArapSolver.solve}. */
90
+ interface ArapSolveOptions {
91
+ /** The most local/global rounds to run after the two linear steps; 0
92
+ * returns their result alone. Rounds stop early once the mesh settles.
93
+ * Default {@link ARAP_ROUNDS}. */
94
+ iterations?: number;
95
+ /** The most rounds of the injective pass; 0 skips it. Default
96
+ * {@link ARAP_INJECTIVE_ROUNDS}. */
97
+ injectiveIterations?: number;
98
+ /** Called with the state after each stage, in order; the last call carries
99
+ * the result. A step's `vertices` is the caller's to keep. */
100
+ trace?: (step: ArapStep) => void;
101
+ }
102
+ /** A factored deformation; `solve` takes each pinned vertex's target, as
103
+ * interleaved `x, y` in pin order, and returns every vertex's position. */
104
+ interface ArapSolver {
105
+ solve(targets: ArrayLike<number>, opts?: ArapSolveOptions): Float64Array;
106
+ }
107
+ /** The default most local/global rounds per solve. */
108
+ declare const ARAP_ROUNDS = 5;
109
+ /** The default most injective rounds per solve. */
110
+ declare const ARAP_INJECTIVE_ROUNDS = 100;
111
+ /**
112
+ * Factor the deformation of `mesh` with vertices `pinned` held. A piece of
113
+ * the mesh holding two pins or more deforms as rigidly as they allow; one
114
+ * holding a single pin moves with it; one holding none moves rigidly with the
115
+ * pins as a whole.
116
+ */
117
+ declare function createArapSolver(mesh: ArapMesh, pinned: readonly number[]): ArapSolver;
118
+
119
+ /** A puppet's mesh, and the vertex standing for each pin. */
120
+ interface PuppetMesh extends ArapMesh {
121
+ pinVertex: Int32Array;
122
+ }
123
+ /** Options for {@link puppetMesh}. */
124
+ interface PuppetMeshOptions {
125
+ /** Roughly how many vertices to spread over the region. Default 400. */
126
+ vertices?: number;
127
+ }
128
+ /**
129
+ * The mesh a puppet with pins at `pins` deforms over `path`'s fill. A pin
130
+ * inside the fill gets a vertex where it is; one on the outline, or off the
131
+ * shape, gets the nearest point of the outline. Pins on one spot share a vertex.
132
+ */
133
+ declare function puppetMesh(path: PolygonPath, pins: readonly Point[], opts?: PuppetMeshOptions): PuppetMesh;
134
+
135
+ /**
136
+ * Puppet deformation: pins placed on a shape and dragged, with everything
137
+ * between them moved as rigidly as the pins allow. The shape's fill is
138
+ * triangulated (`puppetMesh`) and deformed as-rigid-as-possible (`arap`), so
139
+ * the pull of a pin travels through the shape: two limbs that nearly touch
140
+ * share no triangle and move apart. A point is carried by a smooth
141
+ * (Clough–Tocher) interpolation of the deformed mesh, so a bend has no kink
142
+ * where two triangles meet.
143
+ */
144
+
145
+ /** A pin: where it was placed on the unwarped shape, and where it is now. */
146
+ interface PuppetPin {
147
+ from: Point;
148
+ to: Point;
149
+ }
150
+ /**
151
+ * The map `pins` make of `source`'s fill: smooth across the deformed mesh,
152
+ * through every pin, and carried on past the outline for a point off the
153
+ * shape. The mesh and its solve are set up once per source and pin set, so
154
+ * moving pins only re-solves. No pins, or none moved, is the identity, and
155
+ * one pin moves the whole shape with it.
156
+ */
157
+ declare function puppetMap(source: PolygonPath, pins: readonly PuppetPin[]): (p: Point) => Point;
158
+ /**
159
+ * The mesh `puppetMap` deforms for `pins` and where its vertices land, solved
160
+ * with `opts` — its `trace` reports every stage of the solve, and its round
161
+ * caps bound it. With the default options the vertices are the ones
162
+ * `puppetMap` places points by. Null with no pins, or when none landed on the
163
+ * mesh (then `puppetMap` moves the shape with the first pin).
164
+ */
165
+ declare function puppetSolve(source: PolygonPath, pins: readonly PuppetPin[], opts?: ArapSolveOptions): {
166
+ mesh: PuppetMesh;
167
+ vertices: Float64Array;
168
+ } | null;
169
+ /**
170
+ * The point `map` sends to `target`, found by stepping from `guess` by the
171
+ * miss until it is within `tolerance` — for a map that stays close to rigid,
172
+ * as a puppet's does, a few steps suffice. Returns the best point found.
173
+ */
174
+ declare function unwarpPoint(map: (p: Point) => Point, target: Point, guess?: Point, tolerance?: number): Point;
175
+
176
+ /** Options for {@link warpPath}. */
177
+ interface WarpPathOptions {
178
+ /** How far, in output units, the refitted curves may stray from the warped
179
+ * original. Default 0.5. */
180
+ tolerance?: number;
181
+ }
182
+ /**
183
+ * `path` carried through `map`, point by point, and refitted as cubics within
184
+ * `tolerance` of the warped curve. Every anchor stays an anchor, at the point
185
+ * it maps to, so the result edits like the original; a segment the map keeps
186
+ * straight stays a straight segment, and one it bends gains anchors only where
187
+ * one cubic cannot follow it. Fill rules carry over.
188
+ */
189
+ declare function warpPath(path: PolygonPath, map: (p: Point) => Point, opts?: WarpPathOptions): PolygonPath;
190
+
191
+ /**
192
+ * A warp as data: what a shape was warped by, held beside the shape so the
193
+ * warp can be edited again later. Each kind names its controls in the same
194
+ * space as the path it warps.
195
+ */
196
+
197
+ /** An axis-aligned box: the area a distort or an envelope was laid over. */
198
+ interface WarpBox {
199
+ x: number;
200
+ y: number;
201
+ width: number;
202
+ height: number;
203
+ }
204
+ /** How a distort maps its box onto its corners. `free` is bilinear, and bends
205
+ * straight lines; `perspective` is projective, and keeps them straight. */
206
+ type DistortMode = 'free' | 'perspective';
207
+ /** How an envelope interpolates its mesh. See `bicubicMesh` and `coonsMesh`. */
208
+ type EnvelopeMapping = 'bicubic' | 'coons';
209
+ /** The box's four corners, each dragged on its own. */
210
+ interface DistortWarp {
211
+ kind: 'distort';
212
+ mode: DistortMode;
213
+ box: WarpBox;
214
+ /** Where the box's top-left, top-right, bottom-right and bottom-left went. */
215
+ corners: Quad;
216
+ }
217
+ /** A grid of control points laid over the box. */
218
+ interface EnvelopeWarp {
219
+ kind: 'envelope';
220
+ mapping: EnvelopeMapping;
221
+ box: WarpBox;
222
+ mesh: MeshGrid;
223
+ }
224
+ /** Pins on the shape, each dragged on its own. */
225
+ interface PuppetWarp {
226
+ kind: 'puppet';
227
+ pins: readonly PuppetPin[];
228
+ }
229
+ /** Any of the warps a path can hold. */
230
+ type PathWarp = DistortWarp | EnvelopeWarp | PuppetWarp;
231
+ /** A distort over `box` that leaves it where it is. */
232
+ declare function distortOver(box: WarpBox, mode?: DistortMode): DistortWarp;
233
+ /** An envelope of `rows` × `cols` patches over `box` that leaves it where it is. */
234
+ declare function envelopeOver(box: WarpBox, rows: number, cols: number, mapping?: EnvelopeMapping): EnvelopeWarp;
235
+ /** `warp` with a mesh of `rows` × `cols` patches, placed where the current
236
+ * mesh carries an even grid, so the shape changes as little as a coarser or
237
+ * finer grid allows. */
238
+ declare function resizeEnvelope(warp: EnvelopeWarp, rows: number, cols: number): EnvelopeWarp;
239
+ /**
240
+ * Where `warp`, laid over `source`, sends each point of the plane. A
241
+ * perspective distort whose corners no longer make a convex quad has no
242
+ * projective map, and falls back to the bilinear one until they do. Only a
243
+ * puppet reads `source`: its pins pull through the shape's fill.
244
+ */
245
+ declare function pathWarpMap(warp: PathWarp, source: PolygonPath): (p: Point) => Point;
246
+ /** `source` warped by `warp`, refitted within `tolerance` (`warpPath`). */
247
+ declare function applyPathWarp(source: PolygonPath, warp: PathWarp, tolerance?: number): PolygonPath;
248
+ /** The points a user drags to change `warp`: a distort's corners, an
249
+ * envelope's mesh points, a puppet's pins where they are now. */
250
+ declare function warpControls(warp: PathWarp): readonly Point[];
251
+ /** `warp` with control `index` (as {@link warpControls} counts them) at `to`. */
252
+ declare function moveWarpControl(warp: PathWarp, index: number, to: Point): PathWarp;
253
+
254
+ export { ARAP_INJECTIVE_ROUNDS, ARAP_ROUNDS, type ArapMesh, type ArapSolveOptions, type ArapSolver, type ArapStage, type ArapStep, type DistortMode, type DistortWarp, type EnvelopeMapping, type EnvelopeWarp, type MeshGrid, type PathWarp, type PuppetMesh, type PuppetMeshOptions, type PuppetPin, type PuppetWarp, type Quad, type UvMap, type WarpBox, type WarpPathOptions, applyPathWarp, bicubicMesh, bilinearQuad, coonsMesh, createArapSolver, distortOver, envelopeOver, meshGridFrom, meshGridOver, moveWarpControl, pathWarpMap, projectiveQuad, puppetMap, puppetMesh, puppetSolve, resizeEnvelope, squareToQuadHomography, unwarpPoint, warpControls, warpPath };