@weasel-js/geom 1.15.2 → 1.16.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.
@@ -0,0 +1,212 @@
1
+ // src/paths/segmentLength.ts
2
+ var GL_X = [
3
+ -0.9602898564975363,
4
+ -0.7966664774136267,
5
+ -0.525532409916329,
6
+ -0.1834346424956498,
7
+ 0.1834346424956498,
8
+ 0.525532409916329,
9
+ 0.7966664774136267,
10
+ 0.9602898564975363
11
+ ];
12
+ var GL_W = [
13
+ 0.1012285362903763,
14
+ 0.2223810344533745,
15
+ 0.3137066458778873,
16
+ 0.362683783378362,
17
+ 0.362683783378362,
18
+ 0.3137066458778873,
19
+ 0.2223810344533745,
20
+ 0.1012285362903763
21
+ ];
22
+ var G4_X = [-0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526];
23
+ var G4_W = [0.3478548451374538, 0.6521451548625461, 0.6521451548625461, 0.3478548451374538];
24
+ var PANEL_AGREE = 1e-9;
25
+ var DIP_PANELS = 1;
26
+ var EDGE_NEAR = 0.05;
27
+ var SETTLE = 1e-13;
28
+ function speed(c, dim, t) {
29
+ const n = c.length / dim - 1;
30
+ const u = 1 - t;
31
+ let sum = 0;
32
+ for (let k = 0; k < dim; k++) {
33
+ const d0 = c[dim + k] - c[k];
34
+ const v = n === 1 ? d0 : n === 2 ? 2 * (u * d0 + t * (c[2 * dim + k] - c[dim + k])) : 3 * (u * u * d0 + 2 * u * t * (c[2 * dim + k] - c[dim + k]) + t * t * (c[3 * dim + k] - c[2 * dim + k]));
35
+ sum += v * v;
36
+ }
37
+ return Math.sqrt(sum);
38
+ }
39
+ function rule(c, dim, a, b, xs, ws) {
40
+ const mid = (a + b) / 2, half = (b - a) / 2;
41
+ let sum = 0;
42
+ for (let i = 0; i < xs.length; i++) sum += ws[i] * speed(c, dim, mid + xs[i] * half);
43
+ return sum * half;
44
+ }
45
+ function refined(c, dim, a, b, whole, tol, depth) {
46
+ const m = (a + b) / 2;
47
+ const l = rule(c, dim, a, m, GL_X, GL_W), r = rule(c, dim, m, b, GL_X, GL_W);
48
+ if (depth >= 20 || !(Math.abs(l + r - whole) > tol)) return l + r;
49
+ return refined(c, dim, a, m, l, tol, depth + 1) + refined(c, dim, m, b, r, tol, depth + 1);
50
+ }
51
+ function hullLength(c, dim) {
52
+ let sum = 0;
53
+ for (let i = dim; i < c.length; i += dim) {
54
+ let d2 = 0;
55
+ for (let k = 0; k < dim; k++) d2 += (c[i + k] - c[i - dim + k]) ** 2;
56
+ sum += Math.sqrt(d2);
57
+ }
58
+ return sum;
59
+ }
60
+ function finite(c) {
61
+ for (let i = 0; i < c.length; i++) if (!Number.isFinite(c[i])) return false;
62
+ return true;
63
+ }
64
+ function derivativeRoots(c, dim, a, b) {
65
+ const n = c.length / dim - 1;
66
+ const out = [];
67
+ const keep = (t) => {
68
+ if (t > a && t < b) out.push(t);
69
+ };
70
+ for (let k = 0; k < dim; k++) {
71
+ const d0 = c[dim + k] - c[k];
72
+ const d1 = c[2 * dim + k] - c[dim + k];
73
+ if (n === 2) {
74
+ if (d0 !== d1) keep(d0 / (d0 - d1));
75
+ continue;
76
+ }
77
+ const d2 = c[3 * dim + k] - c[2 * dim + k];
78
+ const A = d0 - 2 * d1 + d2, B = 2 * (d1 - d0), C = d0;
79
+ if (Math.abs(A) <= 1e-12 * (Math.abs(B) + Math.abs(C))) {
80
+ if (B !== 0) keep(-C / B);
81
+ continue;
82
+ }
83
+ const disc = B * B - 4 * A * C;
84
+ if (disc < 0) continue;
85
+ const q = -(B + Math.sign(B || 1) * Math.sqrt(disc)) / 2;
86
+ keep(q / A);
87
+ if (q !== 0) keep(C / q);
88
+ }
89
+ out.sort((x, y) => x - y);
90
+ return out.filter((t, i) => i === 0 || t !== out[i - 1]);
91
+ }
92
+ function panelLength(c, dim, p0, p1, size, beside) {
93
+ if (!(p1 > p0)) return 0;
94
+ const g8 = rule(c, dim, p0, p1, GL_X, GL_W);
95
+ const settled = !beside && !(Math.abs(g8 - rule(c, dim, p0, p1, G4_X, G4_W)) > PANEL_AGREE * size);
96
+ return settled ? g8 : refined(c, dim, p0, p1, g8, SETTLE * size, 0);
97
+ }
98
+ function segmentLength(coords, dim, a = 0, b = 1) {
99
+ if (!finite(coords)) return NaN;
100
+ if (coords.length === 2 * dim) return speed(coords, dim, 0) * (b - a);
101
+ const size = hullLength(coords, dim);
102
+ return lengthOver(coords, dim, a, b, size, speedDips(coords, dim));
103
+ }
104
+ function bend(c, dim, t) {
105
+ const n = c.length / dim - 1;
106
+ let sum = 0;
107
+ for (let k = 0; k < dim; k++) {
108
+ const e0 = c[2 * dim + k] - 2 * c[dim + k] + c[k];
109
+ const v = n === 2 ? 2 * e0 : 6 * ((1 - t) * e0 + t * (c[3 * dim + k] - 2 * c[2 * dim + k] + c[dim + k]));
110
+ sum += v * v;
111
+ }
112
+ return Math.sqrt(sum);
113
+ }
114
+ function speedDips(c, dim) {
115
+ return derivativeRoots(c, dim, 0, 1).map((t) => {
116
+ const b = bend(c, dim, t);
117
+ return { t, width: b > 0 ? speed(c, dim, t) / b : Infinity };
118
+ });
119
+ }
120
+ function dipsFor(dips, h) {
121
+ const out = [];
122
+ for (const d of dips) if (d.width < DIP_PANELS * h) out.push(d.t);
123
+ return out;
124
+ }
125
+ function lengthOver(c, dim, a, b, size, dips, panels = 8) {
126
+ const h = (b - a) / panels;
127
+ const last = panels - 1;
128
+ let sum = 0;
129
+ const roots = dipsFor(dips, h);
130
+ if (roots.length === 0) {
131
+ for (let k = 0; k < panels; k++) sum += panelLength(c, dim, a + k * h, k === last ? b : a + (k + 1) * h, size, false);
132
+ return sum;
133
+ }
134
+ const near = (t) => roots.some((r2) => Math.abs(r2 - t) <= EDGE_NEAR * h);
135
+ let r = 0;
136
+ while (r < roots.length && roots[r] <= a) r++;
137
+ for (let k = 0; k < panels; k++) {
138
+ const p0 = a + k * h, p1 = k === last ? b : p0 + h;
139
+ let from = p0;
140
+ while (r < roots.length && roots[r] < p1) {
141
+ sum += panelLength(c, dim, from, roots[r], size, true);
142
+ from = roots[r++];
143
+ }
144
+ sum += panelLength(c, dim, from, p1, size, near(from) || near(p1));
145
+ }
146
+ return sum;
147
+ }
148
+ function segmentTAtLength(coords, dim, length, total = segmentLength(coords, dim)) {
149
+ if (length <= 0 || !(total > 0) || !Number.isFinite(total)) return 0;
150
+ if (length >= total) return 1;
151
+ if (coords.length === 2 * dim) return length / total;
152
+ const size = hullLength(coords, dim);
153
+ const dips = speedDips(coords, dim);
154
+ let lo = 0, hi = 1, t = length / total;
155
+ for (let i = 0; i < 30; i++) {
156
+ const err = lengthOver(coords, dim, 0, t, size, dips) - length;
157
+ if (Math.abs(err) < 1e-10 * total) break;
158
+ if (err > 0) hi = t;
159
+ else lo = t;
160
+ const v = speed(coords, dim, t);
161
+ let next = v > 0 ? t - err / v : NaN;
162
+ if (!(next > lo && next < hi)) next = (lo + hi) / 2;
163
+ t = next;
164
+ }
165
+ return t;
166
+ }
167
+ var STEPS = 16;
168
+ function arcLookup(coords, dim) {
169
+ const size = hullLength(coords, dim);
170
+ const dips = finite(coords) ? speedDips(coords, dim) : [];
171
+ const s = new Float64Array(STEPS + 1);
172
+ for (let k = 0; k < STEPS; k++) s[k + 1] = s[k] + lengthOver(coords, dim, k / STEPS, (k + 1) / STEPS, size, dips, 1);
173
+ return { s, size, dips };
174
+ }
175
+ function lookupLength(coords, dim, lk, t) {
176
+ const f = Math.min(Math.max(t, 0), 1);
177
+ const k = Math.min(Math.floor(f * STEPS), STEPS - 1);
178
+ return lk.s[k] + lengthOver(coords, dim, k / STEPS, f, lk.size, lk.dips, 1);
179
+ }
180
+ function lookupT(coords, dim, lk, length) {
181
+ const { s } = lk;
182
+ const total = s[STEPS];
183
+ if (length <= 0 || !(total > 0) || !Number.isFinite(total)) return 0;
184
+ if (length >= total) return 1;
185
+ let k = 0;
186
+ let hi = STEPS - 1;
187
+ while (k < hi) {
188
+ const mid = k + hi + 1 >> 1;
189
+ if (s[mid] <= length) k = mid;
190
+ else hi = mid - 1;
191
+ }
192
+ const a = k / STEPS;
193
+ let lo = a, top = (k + 1) / STEPS;
194
+ const step = s[k + 1] - s[k];
195
+ let t = step > 0 ? a + (length - s[k]) / step / STEPS : a;
196
+ for (let i = 0; i < 30; i++) {
197
+ const err = s[k] + lengthOver(coords, dim, a, t, lk.size, lk.dips, 1) - length;
198
+ if (Math.abs(err) < 1e-10 * total) break;
199
+ if (err > 0) top = t;
200
+ else lo = t;
201
+ const v = speed(coords, dim, t);
202
+ let next = v > 0 ? t - err / v : NaN;
203
+ if (!(next > lo && next < top)) next = (lo + top) / 2;
204
+ t = next;
205
+ }
206
+ return t;
207
+ }
208
+ var flatPoints = (pts) => pts.flatMap((p) => [p.x, p.y]);
209
+
210
+ export { arcLookup, flatPoints, lookupLength, lookupT, segmentLength, segmentTAtLength };
211
+ //# sourceMappingURL=chunk-IOD2NFHQ.js.map
212
+ //# sourceMappingURL=chunk-IOD2NFHQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/paths/segmentLength.ts"],"names":["r"],"mappings":";AAEA,IAAM,IAAA,GAAO;AAAA,EAAC,mBAAA;AAAA,EAAqB,mBAAA;AAAA,EAAqB,kBAAA;AAAA,EAAqB,mBAAA;AAAA,EAC3E,kBAAA;AAAA,EAAoB,iBAAA;AAAA,EAAoB,kBAAA;AAAA,EAAoB;AAAkB,CAAA;AAChF,IAAM,IAAA,GAAO;AAAA,EAAC,kBAAA;AAAA,EAAoB,kBAAA;AAAA,EAAoB,kBAAA;AAAA,EAAoB,iBAAA;AAAA,EACxE,iBAAA;AAAA,EAAoB,kBAAA;AAAA,EAAoB,kBAAA;AAAA,EAAoB;AAAkB,CAAA;AAEhF,IAAM,IAAA,GAAO,CAAC,mBAAA,EAAqB,mBAAA,EAAqB,oBAAoB,kBAAkB,CAAA;AAC9F,IAAM,IAAA,GAAO,CAAC,kBAAA,EAAoB,kBAAA,EAAoB,oBAAoB,kBAAkB,CAAA;AA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C,CAAA,CAAE,CAAA,EAAG,CAAA,CAAE,CAAC,CAAC","file":"chunk-IOD2NFHQ.js","sourcesContent":["/** Measuring one Bézier segment by arc length, and finding where a run of it ends. */\n\nconst GL_X = [-0.9602898564975363, -0.7966664774136267, -0.5255324099163290, -0.1834346424956498,\n 0.1834346424956498, 0.5255324099163290, 0.7966664774136267, 0.9602898564975363];\nconst GL_W = [0.1012285362903763, 0.2223810344533745, 0.3137066458778873, 0.3626837833783620,\n 0.3626837833783620, 0.3137066458778873, 0.2223810344533745, 0.1012285362903763];\n\nconst G4_X = [-0.8611363115940526, -0.3399810435848563, 0.3399810435848563, 0.8611363115940526];\nconst G4_W = [0.3478548451374538, 0.6521451548625461, 0.6521451548625461, 0.3478548451374538];\n\n/** How far the eight-point rule may sit from the four-point one on a panel, as a share of the\n * segment's size, before the panel is refined. */\nconst PANEL_AGREE = 1e-9;\n/** A derivative root is a cusp or a dip in speed when the dip is narrower than this many panel\n * widths: its speed over the curvature of its path there, `|B′| / |B″|`, a width in `t`. */\nconst DIP_PANELS = 1;\n/** A dip this share of a panel from its edge marks the panel across the edge too: its shoulder\n * sits in the gap before the edge's nearest Gauss node. */\nconst EDGE_NEAR = 0.05;\n/** How closely a refined panel's halves must agree, as a share of the segment's size. */\nconst SETTLE = 1e-13;\n\n/** The speed of the segment at `t`: the length of its derivative. */\nfunction speed(c: ArrayLike<number>, dim: number, t: number): number {\n const n = c.length / dim - 1;\n const u = 1 - t;\n let sum = 0;\n for (let k = 0; k < dim; k++) {\n const d0 = c[dim + k] - c[k];\n const v = n === 1 ? d0\n : n === 2 ? 2 * (u * d0 + t * (c[2 * dim + k] - c[dim + k]))\n : 3 * (u * u * d0 + 2 * u * t * (c[2 * dim + k] - c[dim + k]) + t * t * (c[3 * dim + k] - c[2 * dim + k]));\n sum += v * v;\n }\n return Math.sqrt(sum);\n}\n\nfunction rule(c: ArrayLike<number>, dim: number, a: number, b: number, xs: readonly number[], ws: readonly number[]): number {\n const mid = (a + b) / 2, half = (b - a) / 2;\n let sum = 0;\n for (let i = 0; i < xs.length; i++) sum += ws[i] * speed(c, dim, mid + xs[i] * half);\n return sum * half;\n}\n\n/** `whole`, the eight-point length over `a..b`, refined by halves until they agree within `tol`.\n * A difference that is not a number counts as settled. */\nfunction refined(c: ArrayLike<number>, dim: number, a: number, b: number, whole: number, tol: number, depth: number): number {\n const m = (a + b) / 2;\n const l = rule(c, dim, a, m, GL_X, GL_W), r = rule(c, dim, m, b, GL_X, GL_W);\n if (depth >= 20 || !(Math.abs(l + r - whole) > tol)) return l + r;\n return refined(c, dim, a, m, l, tol, depth + 1) + refined(c, dim, m, b, r, tol, depth + 1);\n}\n\n/** The length of the control polygon: the segment's own size, which tolerances scale by. */\nfunction hullLength(c: ArrayLike<number>, dim: number): number {\n let sum = 0;\n for (let i = dim; i < c.length; i += dim) {\n let d2 = 0;\n for (let k = 0; k < dim; k++) d2 += (c[i + k] - c[i - dim + k]) ** 2;\n sum += Math.sqrt(d2);\n }\n return sum;\n}\n\nfunction finite(c: ArrayLike<number>): boolean {\n for (let i = 0; i < c.length; i++) if (!Number.isFinite(c[i])) return false;\n return true;\n}\n\n/** Where a component of the segment's derivative is zero, strictly inside `a..b`, ascending:\n * the only places a cusp or a dip in speed can sit, which an error estimate can step over. */\nfunction derivativeRoots(c: ArrayLike<number>, dim: number, a: number, b: number): number[] {\n const n = c.length / dim - 1;\n const out: number[] = [];\n const keep = (t: number) => { if (t > a && t < b) out.push(t); };\n for (let k = 0; k < dim; k++) {\n const d0 = c[dim + k] - c[k];\n const d1 = c[2 * dim + k] - c[dim + k];\n if (n === 2) {\n if (d0 !== d1) keep(d0 / (d0 - d1));\n continue;\n }\n // Bernstein (d0, d1, d2) as A t² + B t + C.\n const d2 = c[3 * dim + k] - c[2 * dim + k];\n const A = d0 - 2 * d1 + d2, B = 2 * (d1 - d0), C = d0;\n if (Math.abs(A) <= 1e-12 * (Math.abs(B) + Math.abs(C))) {\n if (B !== 0) keep(-C / B);\n continue;\n }\n const disc = B * B - 4 * A * C;\n if (disc < 0) continue;\n // The stable pair: one root from the sum that cannot cancel, the other from the product.\n const q = -(B + Math.sign(B || 1) * Math.sqrt(disc)) / 2;\n keep(q / A);\n if (q !== 0) keep(C / q);\n }\n out.sort((x, y) => x - y);\n return out.filter((t, i) => i === 0 || t !== out[i - 1]);\n}\n\n/** The eight-point length over `p0..p1`, refined when it sits beside a slow root or its\n * four-point rule disagrees. */\nfunction panelLength(c: ArrayLike<number>, dim: number, p0: number, p1: number, size: number, beside: boolean): number {\n if (!(p1 > p0)) return 0;\n const g8 = rule(c, dim, p0, p1, GL_X, GL_W);\n const settled = !beside && !(Math.abs(g8 - rule(c, dim, p0, p1, G4_X, G4_W)) > PANEL_AGREE * size);\n return settled ? g8 : refined(c, dim, p0, p1, g8, SETTLE * size, 0);\n}\n\n/**\n * Length of a Bézier segment between parameters `a` and `b`, by Gauss–Legendre\n * over eight panels, split where a component of its derivative is zero and\n * the speed dips there within a panel's width. The panels beside such a root\n * are halved until they settle, and so is any other where the eight- and\n * four-point rules disagree. `coords` holds its control\n * points flat, `dim` components each: two points for a line, three for a\n * quadratic, four for a cubic. NaN when a coordinate is not finite.\n */\nexport function segmentLength(coords: ArrayLike<number>, dim: 2 | 3, a = 0, b = 1): number {\n if (!finite(coords)) return NaN;\n if (coords.length === 2 * dim) return speed(coords, dim, 0) * (b - a);\n const size = hullLength(coords, dim);\n return lengthOver(coords, dim, a, b, size, speedDips(coords, dim));\n}\n\n/** The length of the segment's second derivative at `t`. */\nfunction bend(c: ArrayLike<number>, dim: number, t: number): number {\n const n = c.length / dim - 1;\n let sum = 0;\n for (let k = 0; k < dim; k++) {\n const e0 = c[2 * dim + k] - 2 * c[dim + k] + c[k];\n const v = n === 2 ? 2 * e0 : 6 * ((1 - t) * e0 + t * (c[3 * dim + k] - 2 * c[2 * dim + k] + c[dim + k]));\n sum += v * v;\n }\n return Math.sqrt(sum);\n}\n\n/** A derivative root inside 0..1, and how wide its dip in speed is, in `t`. */\ninterface Dip { t: number; width: number }\n\n/** @internal The derivative roots inside 0..1, each with the width of its dip. */\nexport function speedDips(c: ArrayLike<number>, dim: number): Dip[] {\n return derivativeRoots(c, dim, 0, 1).map((t) => {\n const b = bend(c, dim, t);\n return { t, width: b > 0 ? speed(c, dim, t) / b : Infinity };\n });\n}\n\n/** @internal The dips a panel `h` wide cannot be trusted to see: narrower than {@link DIP_PANELS} panels. */\nexport function dipsFor(dips: readonly Dip[], h: number): number[] {\n const out: number[] = [];\n for (const d of dips) if (d.width < DIP_PANELS * h) out.push(d.t);\n return out;\n}\n\n/** {@link segmentLength} over `a..b` in `panels` panels, given the segment's size and its dips. */\nfunction lengthOver(\n c: ArrayLike<number>, dim: number, a: number, b: number, size: number, dips: readonly Dip[], panels = 8,\n): number {\n const h = (b - a) / panels;\n const last = panels - 1;\n let sum = 0;\n const roots = dipsFor(dips, h);\n if (roots.length === 0) {\n for (let k = 0; k < panels; k++) sum += panelLength(c, dim, a + k * h, k === last ? b : a + (k + 1) * h, size, false);\n return sum;\n }\n const near = (t: number): boolean => roots.some((r) => Math.abs(r - t) <= EDGE_NEAR * h);\n let r = 0;\n while (r < roots.length && roots[r] <= a) r++;\n for (let k = 0; k < panels; k++) {\n const p0 = a + k * h, p1 = k === last ? b : p0 + h;\n let from = p0;\n // A dip splits its panel, and every piece that touches one, or comes near, is refined.\n while (r < roots.length && roots[r] < p1) {\n sum += panelLength(c, dim, from, roots[r], size, true);\n from = roots[r++];\n }\n sum += panelLength(c, dim, from, p1, size, near(from) || near(p1));\n }\n return sum;\n}\n\n/**\n * The parameter at which the segment {@link segmentLength} reads has run\n * `length` from its start, clamped to 0..1: Newton steps on the arc length,\n * held inside a shrinking bracket. `total` is its whole length, when the\n * caller has it; it is trusted, not checked, and a wrong one misplaces the\n * clamp and the first guess. 0 when a coordinate is not finite, as for a\n * segment of no length.\n */\nexport function segmentTAtLength(\n coords: ArrayLike<number>, dim: 2 | 3, length: number, total = segmentLength(coords, dim),\n): number {\n if (length <= 0 || !(total > 0) || !Number.isFinite(total)) return 0;\n if (length >= total) return 1;\n if (coords.length === 2 * dim) return length / total;\n const size = hullLength(coords, dim);\n const dips = speedDips(coords, dim);\n let lo = 0, hi = 1, t = length / total;\n for (let i = 0; i < 30; i++) {\n const err = lengthOver(coords, dim, 0, t, size, dips) - length;\n if (Math.abs(err) < 1e-10 * total) break;\n if (err > 0) hi = t; else lo = t;\n const v = speed(coords, dim, t);\n let next = v > 0 ? t - err / v : NaN;\n if (!(next > lo && next < hi)) next = (lo + hi) / 2;\n t = next;\n }\n return t;\n}\n\nconst STEPS = 16;\n\n/** A curved segment's exact arc length at evenly spaced parameters: what repeated length queries on one segment start from. */\nexport interface ArcLookup {\n /** The length from the start to parameter `k / 16`, `k` = 0..16. */\n readonly s: Float64Array;\n readonly size: number;\n readonly dips: readonly Dip[];\n}\n\n/** @internal The {@link ArcLookup} of curved segment `coords`, each step measured as one panel of {@link segmentLength}'s rule. */\nexport function arcLookup(coords: ArrayLike<number>, dim: 2 | 3): ArcLookup {\n const size = hullLength(coords, dim);\n const dips = finite(coords) ? speedDips(coords, dim) : [];\n const s = new Float64Array(STEPS + 1);\n for (let k = 0; k < STEPS; k++) s[k + 1] = s[k] + lengthOver(coords, dim, k / STEPS, (k + 1) / STEPS, size, dips, 1);\n return { s, size, dips };\n}\n\n/** @internal The length from the start of `coords` to parameter `t`, read from its lookup `lk`. */\nexport function lookupLength(coords: ArrayLike<number>, dim: 2 | 3, lk: ArcLookup, t: number): number {\n const f = Math.min(Math.max(t, 0), 1);\n const k = Math.min(Math.floor(f * STEPS), STEPS - 1);\n return lk.s[k] + lengthOver(coords, dim, k / STEPS, f, lk.size, lk.dips, 1);\n}\n\n/**\n * @internal {@link segmentTAtLength} from a lookup: the step holding `length`\n * gives the first guess and the bracket, and Newton steps on one panel's\n * length finish it, so a query costs a few panels rather than a whole-segment solve.\n */\nexport function lookupT(coords: ArrayLike<number>, dim: 2 | 3, lk: ArcLookup, length: number): number {\n const { s } = lk;\n const total = s[STEPS];\n if (length <= 0 || !(total > 0) || !Number.isFinite(total)) return 0;\n if (length >= total) return 1;\n let k = 0;\n let hi = STEPS - 1;\n while (k < hi) {\n const mid = (k + hi + 1) >> 1;\n if (s[mid] <= length) k = mid;\n else hi = mid - 1;\n }\n const a = k / STEPS;\n let lo = a, top = (k + 1) / STEPS;\n const step = s[k + 1] - s[k];\n let t = step > 0 ? a + ((length - s[k]) / step) / STEPS : a;\n for (let i = 0; i < 30; i++) {\n const err = s[k] + lengthOver(coords, dim, a, t, lk.size, lk.dips, 1) - length;\n if (Math.abs(err) < 1e-10 * total) break;\n if (err > 0) top = t; else lo = t;\n const v = speed(coords, dim, t);\n let next = v > 0 ? t - err / v : NaN;\n if (!(next > lo && next < top)) next = (lo + top) / 2;\n t = next;\n }\n return t;\n}\n\n/** `pts` as the flat 2D coords {@link segmentLength} reads. */\nexport const flatPoints = (pts: readonly { x: number; y: number }[]): number[] => pts.flatMap((p) => [p.x, p.y]);\n"]}
@@ -1,4 +1,4 @@
1
- import { cornerCuts, decodeContours, ringSignedArea, fillsOpenSubpaths, resolveCorners, segmentsCross, pointInPolygon } from './chunk-GA5R5KWD.js';
1
+ import { cornerCuts, decodeContours, ringSignedArea, fillsOpenSubpaths, resolveCorners, segmentsCross, pointInPolygon } from './chunk-TBS4NHGQ.js';
2
2
  import { withoutCorners, compactCorners, worldCoords, PATH_M, PATH_L, PATH_Q, PATH_C, PATH_Z, originFor, coordsFrom, forEachSegment, pathCommandCoordCount, PathBuilder, distance, splitQuadraticAt, splitCubicAt, nearestOnLine, nearestOnCubic, lerpPoint } from './chunk-346XYYMX.js';
3
3
  import { EPS } from './chunk-DNX24KBT.js';
4
4
 
@@ -677,5 +677,5 @@ function writePath(subpaths, fillRule) {
677
677
  }
678
678
 
679
679
  export { CORNER_RESTORE_TOLERANCE, anchorRange, assembleRegions, carryCorners, contoursIntersect, cornerTraces, derivSeg, endSide, evalSeg, extentOf, intersectSegments, keepCorners, negligibleArea, orientBoundaries, parseContours, parseSubpaths, regionArea, restoreCorners, reverseContour, sampleContour, sideCoeffs, signChanges, signedArea, subSeg, toPath, windingAt, writePath };
680
- //# sourceMappingURL=chunk-OQP5M5VD.js.map
681
- //# sourceMappingURL=chunk-OQP5M5VD.js.map
680
+ //# sourceMappingURL=chunk-OBPXEPUH.js.map
681
+ //# sourceMappingURL=chunk-OBPXEPUH.js.map