@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.
- package/dist/3d/index.d.ts +13 -1
- package/dist/3d/index.js +11 -1
- package/dist/3d/index.js.map +1 -1
- package/dist/booleans/index.js +3 -2
- package/dist/booleans/index.js.map +1 -1
- package/dist/{chunk-IDSKOHA4.js → chunk-5W425HJA.js} +81 -15
- package/dist/chunk-5W425HJA.js.map +1 -0
- package/dist/chunk-FOXMA54X.js +266 -0
- package/dist/chunk-FOXMA54X.js.map +1 -0
- package/dist/chunk-IOD2NFHQ.js +212 -0
- package/dist/chunk-IOD2NFHQ.js.map +1 -0
- package/dist/{chunk-OQP5M5VD.js → chunk-OBPXEPUH.js} +3 -3
- package/dist/{chunk-OQP5M5VD.js.map → chunk-OBPXEPUH.js.map} +1 -1
- package/dist/chunk-QSVZO7QZ.js +40 -0
- package/dist/chunk-QSVZO7QZ.js.map +1 -0
- package/dist/{chunk-GA5R5KWD.js → chunk-TBS4NHGQ.js} +13 -30
- package/dist/chunk-TBS4NHGQ.js.map +1 -0
- package/dist/{chunk-MIKP4V2C.js → chunk-VJG5ZWCR.js} +3 -3
- package/dist/{chunk-MIKP4V2C.js.map → chunk-VJG5ZWCR.js.map} +1 -1
- package/dist/{chunk-STYO7J4Y.js → chunk-ZV24QZ6X.js} +3 -3
- package/dist/{chunk-STYO7J4Y.js.map → chunk-ZV24QZ6X.js.map} +1 -1
- package/dist/index.d.ts +86 -11
- package/dist/index.js +267 -128
- package/dist/index.js.map +1 -1
- package/dist/lengthTable-Cv3W6lsH.d.ts +64 -0
- package/dist/tessellate/index.d.ts +23 -1
- package/dist/tessellate/index.js +29 -15
- package/dist/tessellate/index.js.map +1 -1
- package/dist/warp/index.js +4 -3
- package/dist/warp/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-GA5R5KWD.js.map +0 -1
- package/dist/chunk-IDSKOHA4.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** One subpath of a path in pen order: points joined by straight segments, or by curves where `controls` gives them. */
|
|
2
|
+
interface LengthRun {
|
|
3
|
+
/** `dim` components per point. A closed run does not repeat its first point. */
|
|
4
|
+
points: ArrayLike<number>;
|
|
5
|
+
/** Whether a closing edge runs from the last point back to the first. */
|
|
6
|
+
closed: boolean;
|
|
7
|
+
/** Per point, the anchor before it, the anchor after it, and the arc-length
|
|
8
|
+
* fraction between them, as `Polyline` carries them. Absent, every point is
|
|
9
|
+
* an anchor, numbered on from the previous run's. */
|
|
10
|
+
anchorA?: ArrayLike<number>;
|
|
11
|
+
anchorB?: ArrayLike<number>;
|
|
12
|
+
anchorT?: ArrayLike<number>;
|
|
13
|
+
/** A closed run's last anchor when it sat on the first point and was dropped, as `Polyline` carries it. */
|
|
14
|
+
closeAnchor?: number;
|
|
15
|
+
/** Per segment, from point `i` to the next (a closed run's closing edge last), the control
|
|
16
|
+
* points of the curve between them, `dim` components each; empty, null or absent where
|
|
17
|
+
* the segment is straight. A curved segment is measured by its exact arc length. */
|
|
18
|
+
controls?: readonly (ArrayLike<number> | null | undefined)[];
|
|
19
|
+
}
|
|
20
|
+
/** A stretch of a path between two pen-order lengths, `from` before `to`. */
|
|
21
|
+
interface LengthSpan {
|
|
22
|
+
from: number;
|
|
23
|
+
to: number;
|
|
24
|
+
}
|
|
25
|
+
/** A path's arc length in pen order: subpaths in order, the lift between them covering no distance. */
|
|
26
|
+
interface LengthTable {
|
|
27
|
+
readonly dim: 2 | 3;
|
|
28
|
+
readonly runs: readonly LengthRun[];
|
|
29
|
+
/** Pen-order length, closing edges included. */
|
|
30
|
+
readonly total: number;
|
|
31
|
+
/** Where each run starts, `runs.length + 1` entries; the last is `total`. */
|
|
32
|
+
readonly runStart: Float64Array;
|
|
33
|
+
/** The anchor range: per subpath, the segments between its anchors, a closed one's closing edge included. */
|
|
34
|
+
readonly segments: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The length table of `runs`, in `dim` components per point. `anchorSources`
|
|
38
|
+
* (from `resolveCornersWithSources`) maps the anchors of a corner-expanded path
|
|
39
|
+
* back to the authored ones, so anchor queries answer in authored numbering:
|
|
40
|
+
* an anchor rounded into an arc sits at the arc's midpoint.
|
|
41
|
+
*/
|
|
42
|
+
declare function lengthTable(runs: readonly LengthRun[], dim: 2 | 3, anchorSources?: Uint32Array | null): LengthTable;
|
|
43
|
+
/** The pen-order length at authored anchor position `anchor`; `3.5` is halfway
|
|
44
|
+
* along the segment from anchor 3 by length. Clamps to the path. */
|
|
45
|
+
declare function lengthAtAnchor(t: LengthTable, anchor: number): number;
|
|
46
|
+
/** The authored anchor position at pen length `s`: the inverse of
|
|
47
|
+
* {@link lengthAtAnchor}. Where a pen lift puts two anchors at one length,
|
|
48
|
+
* the later. Clamps to the path. */
|
|
49
|
+
declare function anchorAtLength(t: LengthTable, s: number): number;
|
|
50
|
+
/** The pen-order length at the start of subpath `subpath`; a fractional part
|
|
51
|
+
* goes that share of the way along it by length. Clamps to the path. */
|
|
52
|
+
declare function lengthAtSubpath(t: LengthTable, subpath: number): number;
|
|
53
|
+
/** The pen-order length at fraction `f` of the anchor range: each segment an
|
|
54
|
+
* equal share, a pen lift none. Clamps to the path. */
|
|
55
|
+
declare function lengthAtSegmentFraction(t: LengthTable, f: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* The anchor a closed run's closing edge ends at when that anchor was dropped
|
|
58
|
+
* as a duplicate of the first point: `closeAnchor`, else the anchor the last
|
|
59
|
+
* point is heading toward. `undefined` when none was dropped, so the edge
|
|
60
|
+
* ends at the run's first anchor. `dim` is the run's components per point.
|
|
61
|
+
*/
|
|
62
|
+
declare function closingAnchor(run: LengthRun, dim?: 2 | 3): number | undefined;
|
|
63
|
+
|
|
64
|
+
export { type LengthTable as L, type LengthSpan as a, type LengthRun as b, anchorAtLength as c, closingAnchor as d, lengthAtSegmentFraction as e, lengthAtSubpath as f, lengthTable as g, lengthAtAnchor as l };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { a as Path } from '../path-t80OoJnM.js';
|
|
2
|
+
import { b as LengthRun } from '../lengthTable-Cv3W6lsH.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* A tessellated representation of a Path, ready to upload to GL.
|
|
@@ -62,6 +63,9 @@ interface Polyline {
|
|
|
62
63
|
anchorB?: Uint32Array;
|
|
63
64
|
/** For each point, the arc-length fraction along (A, B). 0 at anchor A; for anchor-aligned, set to 0. */
|
|
64
65
|
anchorT?: Float32Array;
|
|
66
|
+
/** A closed contour's last anchor when it repeated the first point and was
|
|
67
|
+
* dropped for that; the closing edge ends at it. */
|
|
68
|
+
closeAnchor?: number;
|
|
65
69
|
/** Per-point stroke width, populated by the tessellator when the Stroke
|
|
66
70
|
* carries `vertexWidths`. Undefined means uniform `Stroke.width`. */
|
|
67
71
|
widths?: Float32Array;
|
|
@@ -102,6 +106,24 @@ declare function extractPolylines(path: Path, opts?: ExtractOptions): Polyline[]
|
|
|
102
106
|
*/
|
|
103
107
|
declare function trimPolyline(pl: Polyline, startInset: number, endInset: number): Polyline | null;
|
|
104
108
|
|
|
109
|
+
/** A curve position found on one flattening of its run. */
|
|
110
|
+
interface PolylinePlace {
|
|
111
|
+
/** How far from the polyline's first point it sits, along the polyline: the polyline's own measure. */
|
|
112
|
+
length: number;
|
|
113
|
+
/** The point itself, on the curve rather than on the chord beside it. */
|
|
114
|
+
x: number;
|
|
115
|
+
y: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Where curve position (`segment`, `t`) falls on `pl`, a flattening of `run`.
|
|
119
|
+
* Segment `k` runs from `pl`'s `k`-th anchor-aligned point to the next, a
|
|
120
|
+
* closed `pl`'s closing edge last, as `pathLengthTable` counts them; `run`
|
|
121
|
+
* gives each curve's control points, and without one every segment is
|
|
122
|
+
* straight. The ends come from `pl`, so a run of the same shape carried
|
|
123
|
+
* elsewhere (a rect shifted by alignment) places onto it too.
|
|
124
|
+
*/
|
|
125
|
+
declare function polylineAtCurve(pl: Polyline, segment: number, t: number, run?: LengthRun): PolylinePlace;
|
|
126
|
+
|
|
105
127
|
/**
|
|
106
128
|
* The anchor parameters `(A, B, t)` of a point a fraction `frac` of the way
|
|
107
129
|
* from one polyline point to the next: `t` interpolated when both lie between
|
|
@@ -109,4 +131,4 @@ declare function trimPolyline(pl: Polyline, startInset: number, endInset: number
|
|
|
109
131
|
*/
|
|
110
132
|
declare function anchorParamsBetween(a0: number, b0: number, t0: number, a1: number, b1: number, t1: number, frac: number): [number, number, number];
|
|
111
133
|
|
|
112
|
-
export { type ExtractOptions, MAX_EVENODD_RESOLVE_WORK, type Mesh, type Polyline, type TessellateOptions, anchorParamsBetween, extractPolylines, tessellate, trimPolyline };
|
|
134
|
+
export { type ExtractOptions, MAX_EVENODD_RESOLVE_WORK, type Mesh, type Polyline, type PolylinePlace, type TessellateOptions, anchorParamsBetween, extractPolylines, polylineAtCurve, tessellate, trimPolyline };
|
package/dist/tessellate/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export { extractPolylines } from '../chunk-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { extractPolylines, polylineAtCurve } from '../chunk-5W425HJA.js';
|
|
2
|
+
import '../chunk-QSVZO7QZ.js';
|
|
3
|
+
export { MAX_EVENODD_RESOLVE_WORK, tessellate } from '../chunk-VJG5ZWCR.js';
|
|
4
|
+
import '../chunk-TBS4NHGQ.js';
|
|
5
|
+
import '../chunk-IOD2NFHQ.js';
|
|
4
6
|
import '../chunk-346XYYMX.js';
|
|
5
7
|
import '../chunk-DNX24KBT.js';
|
|
6
8
|
|
|
@@ -26,6 +28,11 @@ function sampleAt(pl, cum, A, B, T, W, O, dist, vertexFollows) {
|
|
|
26
28
|
const o = O ? O[i - 1] + (O[i] - O[i - 1]) * f : 0;
|
|
27
29
|
return { x: px + (qx - px) * f, y: py + (qy - py) * f, a, b, t, w, o, next: i };
|
|
28
30
|
}
|
|
31
|
+
var ROUNDING = 4 * 2 ** -23;
|
|
32
|
+
function nearVertex(pl, s, i) {
|
|
33
|
+
const x = pl.points[i * 2], y = pl.points[i * 2 + 1];
|
|
34
|
+
return Math.hypot(s.x - x, s.y - y) <= ROUNDING * Math.max(1, Math.abs(x), Math.abs(y));
|
|
35
|
+
}
|
|
29
36
|
function trimPolyline(pl, startInset, endInset) {
|
|
30
37
|
const from = Math.max(0, startInset);
|
|
31
38
|
const to = Math.max(0, endInset);
|
|
@@ -50,12 +57,24 @@ function trimPolyline(pl, startInset, endInset) {
|
|
|
50
57
|
if (cutB - cutA <= EPS) return null;
|
|
51
58
|
const head = sampleAt(pl, cum, A, B, T, W, O, cutA, true);
|
|
52
59
|
const tail = sampleAt(pl, cum, A, B, T, W, O, cutB, false);
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
60
|
+
const interior = tail.next - head.next;
|
|
61
|
+
const headOnVertex = interior > 0 && nearVertex(pl, head, head.next);
|
|
62
|
+
const tailOnVertex = interior > 0 && nearVertex(pl, tail, tail.next - 1) && interior + (headOnVertex ? 0 : 1) >= 2;
|
|
63
|
+
const points = [];
|
|
64
|
+
const aOut = [];
|
|
65
|
+
const bOut = [];
|
|
66
|
+
const tOut = [];
|
|
67
|
+
const wOut = W ? [] : void 0;
|
|
68
|
+
const oOut = O ? [] : void 0;
|
|
69
|
+
const push = (s) => {
|
|
70
|
+
points.push(s.x, s.y);
|
|
71
|
+
aOut.push(s.a);
|
|
72
|
+
bOut.push(s.b);
|
|
73
|
+
tOut.push(s.t);
|
|
74
|
+
if (wOut) wOut.push(s.w);
|
|
75
|
+
if (oOut) oOut.push(s.o);
|
|
76
|
+
};
|
|
77
|
+
if (!headOnVertex) push(head);
|
|
59
78
|
for (let i = head.next; i < tail.next; i++) {
|
|
60
79
|
points.push(pl.points[i * 2], pl.points[i * 2 + 1]);
|
|
61
80
|
aOut.push(A[i]);
|
|
@@ -64,12 +83,7 @@ function trimPolyline(pl, startInset, endInset) {
|
|
|
64
83
|
if (wOut) wOut.push(W[i]);
|
|
65
84
|
if (oOut) oOut.push(O[i]);
|
|
66
85
|
}
|
|
67
|
-
|
|
68
|
-
aOut.push(tail.a);
|
|
69
|
-
bOut.push(tail.b);
|
|
70
|
-
tOut.push(tail.t);
|
|
71
|
-
if (wOut) wOut.push(tail.w);
|
|
72
|
-
if (oOut) oOut.push(tail.o);
|
|
86
|
+
if (!tailOnVertex) push(tail);
|
|
73
87
|
return {
|
|
74
88
|
points,
|
|
75
89
|
closed: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tessellate/anchorParams.ts","../../src/tessellate/trim.ts"],"names":[],"mappings":";;;;;;;AAKO,SAAS,oBACd,EAAA,EAAY,EAAA,EAAY,IACxB,EAAA,EAAY,EAAA,EAAY,IACxB,IAAA,EAC0B;AAC1B,EAAA,IAAI,EAAA,KAAO,EAAA,IAAM,EAAA,KAAO,EAAA,EAAI,OAAO,CAAC,EAAA,EAAI,EAAA,EAAI,EAAA,GAAA,CAAM,EAAA,GAAK,EAAA,IAAM,IAAI,CAAA;AACjE,EAAA,OAAO,IAAA,GAAO,GAAA,GAAM,CAAC,EAAA,EAAI,EAAA,EAAI,EAAE,CAAA,GAAI,CAAC,EAAA,EAAI,EAAA,EAAI,EAAE,CAAA;AAChD;;;ACAA,IAAM,GAAA,GAAM,IAAA;AAWZ,SAAS,QAAA,CACP,IAAc,GAAA,EACd,CAAA,EAAgB,GAAgB,CAAA,EAAiB,CAAA,EAA6B,CAAA,EAC9E,IAAA,EAGA,aAAA,EACQ;AACR,EAAA,MAAM,IAAI,GAAA,CAAI,MAAA;AACd,EAAA,IAAI,CAAA,GAAI,CAAA;AACR,EAAA,OAAO,CAAA,GAAI,CAAA,GAAI,CAAA,KAAM,aAAA,GAAgB,GAAA,CAAI,CAAC,CAAA,IAAK,IAAA,GAAO,GAAA,C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AAA;AAAA,IACA,MAAA,EAAQ,KAAA;AAAA,IACR,OAAA,EAAS,IAAI,WAAA,CAAY,IAAI,CAAA;AAAA,IAC7B,OAAA,EAAS,IAAI,WAAA,CAAY,IAAI,CAAA;AAAA,IAC7B,OAAA,EAAS,IAAI,YAAA,CAAa,IAAI,CAAA;AAAA,IAC9B,GAAI,OAAO,EAAE,MAAA,EAAQ,IAAI,YAAA,CAAa,IAAI,CAAA,EAAE,GAAI,EAAC;AAAA,IACjD,GAAI,OAAO,EAAE,OAAA,EAAS,IAAI,YAAA,CAAa,IAAI,CAAA,EAAE,GAAI;AAAC,GACpD;AACF","file":"index.js","sourcesContent":["/**\n * The anchor parameters `(A, B, t)` of a point a fraction `frac` of the way\n * from one polyline point to the next: `t` interpolated when both lie between\n * the same two anchors, otherwise the nearer point's own.\n */\nexport function anchorParamsBetween(\n a0: number, b0: number, t0: number,\n a1: number, b1: number, t1: number,\n frac: number,\n): [number, number, number] {\n if (a0 === a1 && b0 === b1) return [a0, b0, t0 + (t1 - t0) * frac];\n return frac < 0.5 ? [a0, b0, t0] : [a1, b1, t1];\n}\n","/**\n * Shortening a flattened subpath so a filled marker is not speared by its own\n * line. SVG has no equivalent — it paints the marker over a full-length\n * stroke — so this is the one place our rendering deliberately differs.\n *\n * Runs before dash splitting, so a dash pattern fits the visible line rather\n * than running off under the head.\n */\n\nimport { anchorParamsBetween } from './anchorParams';\nimport type { Polyline } from './polyline';\n\nconst EPS = 1e-9;\n\ninterface Sample {\n x: number; y: number;\n a: number; b: number; t: number;\n w: number;\n o: number;\n /** Index of the first original point at or after this sample. */\n next: number;\n}\n\nfunction sampleAt(\n pl: Polyline, cum: Float64Array,\n A: Uint32Array, B: Uint32Array, T: Float32Array, W: Float32Array | undefined, O: Float32Array | undefined,\n dist: number,\n /** For a cut landing exactly on a vertex: whether the vertex belongs to the\n * run after the sample (a head) or before it (a tail), so it is kept once. */\n vertexFollows: boolean,\n): Sample {\n const n = cum.length;\n let i = 1;\n while (i < n - 1 && (vertexFollows ? cum[i] <= dist : cum[i] < dist)) i++;\n const segStart = cum[i - 1];\n const segLen = cum[i] - segStart;\n const f = segLen > EPS ? (dist - segStart) / segLen : 0;\n\n const px = pl.points[(i - 1) * 2], py = pl.points[(i - 1) * 2 + 1];\n const qx = pl.points[i * 2], qy = pl.points[i * 2 + 1];\n\n const [a, b, t] = anchorParamsBetween(A[i - 1], B[i - 1], T[i - 1], A[i], B[i], T[i], f);\n\n const w = W ? W[i - 1] + (W[i] - W[i - 1]) * f : 0;\n const o = O ? O[i - 1] + (O[i] - O[i - 1]) * f : 0;\n return { x: px + (qx - px) * f, y: py + (qy - py) * f, a, b, t, w, o, next: i };\n}\n\n/**\n * Shorten `pl` by `startInset` from its first point and `endInset` from its\n * last, both in the same world units as the points.\n *\n * Returns `pl` itself when there is nothing to do (both insets zero, or the\n * subpath is closed and so has no free ends), and `null` when the insets\n * consume the whole run — a caller should then draw no ribbon at all.\n */\nexport function trimPolyline(\n pl: Polyline,\n startInset: number,\n endInset: number,\n): Polyline | null {\n const from = Math.max(0, startInset);\n const to = Math.max(0, endInset);\n if (from <= 0 && to <= 0) return pl;\n if (pl.closed) return pl;\n\n const n = pl.points.length / 2;\n if (n < 2) return null;\n\n const A = pl.anchorA ?? new Uint32Array(n);\n const B = pl.anchorB ?? new Uint32Array(n);\n const T = pl.anchorT ?? new Float32Array(n);\n const W = pl.widths;\n const O = pl.offsets;\n\n const cum = new Float64Array(n);\n for (let i = 1; i < n; i++) {\n const dx = pl.points[i * 2] - pl.points[(i - 1) * 2];\n const dy = pl.points[i * 2 + 1] - pl.points[(i - 1) * 2 + 1];\n cum[i] = cum[i - 1] + Math.hypot(dx, dy);\n }\n const total = cum[n - 1];\n const cutA = from;\n const cutB = total - to;\n if (cutB - cutA <= EPS) return null;\n\n const head = sampleAt(pl, cum, A, B, T, W, O, cutA, true);\n const tail = sampleAt(pl, cum, A, B, T, W, O, cutB, false);\n\n const points: number[] = [head.x, head.y];\n const aOut: number[] = [head.a];\n const bOut: number[] = [head.b];\n const tOut: number[] = [head.t];\n const wOut: number[] | undefined = W ? [head.w] : undefined;\n const oOut: number[] | undefined = O ? [head.o] : undefined;\n\n for (let i = head.next; i < tail.next; i++) {\n points.push(pl.points[i * 2], pl.points[i * 2 + 1]);\n aOut.push(A[i]); bOut.push(B[i]); tOut.push(T[i]);\n if (wOut) wOut.push(W![i]);\n if (oOut) oOut.push(O![i]);\n }\n\n points.push(tail.x, tail.y);\n aOut.push(tail.a); bOut.push(tail.b); tOut.push(tail.t);\n if (wOut) wOut.push(tail.w);\n if (oOut) oOut.push(tail.o);\n\n return {\n points,\n closed: false,\n anchorA: new Uint32Array(aOut),\n anchorB: new Uint32Array(bOut),\n anchorT: new Float32Array(tOut),\n ...(wOut ? { widths: new Float32Array(wOut) } : {}),\n ...(oOut ? { offsets: new Float32Array(oOut) } : {}),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/tessellate/anchorParams.ts","../../src/tessellate/trim.ts"],"names":[],"mappings":";;;;;;;;;AAKO,SAAS,oBACd,EAAA,EAAY,EAAA,EAAY,IACxB,EAAA,EAAY,EAAA,EAAY,IACxB,IAAA,EAC0B;AAC1B,EAAA,IAAI,EAAA,KAAO,EAAA,IAAM,EAAA,KAAO,EAAA,EAAI,OAAO,CAAC,EAAA,EAAI,EAAA,EAAI,EAAA,GAAA,CAAM,EAAA,GAAK,EAAA,IAAM,IAAI,CAAA;AACjE,EAAA,OAAO,IAAA,GAAO,GAAA,GAAM,CAAC,EAAA,EAAI,EAAA,EAAI,EAAE,CAAA,GAAI,CAAC,EAAA,EAAI,EAAA,EAAI,EAAE,CAAA;AAChD;;;ACAA,IAAM,GAAA,GAAM,IAAA;AAWZ,SAAS,QAAA,CACP,IAAc,GAAA,EACd,CAAA,EAAgB,GAAgB,CAAA,EAAiB,CAAA,EAA6B,CAAA,EAC9E,IAAA,EAGA,aAAA,EACQ;AACR,EAAA,MAAM,IAAI,GAAA,CAAI,MAAA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E,MAAA,EAAQ,IAAI,YAAA,CAAa,IAAI,CAAA,EAAE,GAAI,EAAC;AAAA,IACjD,GAAI,OAAO,EAAE,OAAA,EAAS,IAAI,YAAA,CAAa,IAAI,CAAA,EAAE,GAAI;AAAC,GACpD;AACF","file":"index.js","sourcesContent":["/**\n * The anchor parameters `(A, B, t)` of a point a fraction `frac` of the way\n * from one polyline point to the next: `t` interpolated when both lie between\n * the same two anchors, otherwise the nearer point's own.\n */\nexport function anchorParamsBetween(\n a0: number, b0: number, t0: number,\n a1: number, b1: number, t1: number,\n frac: number,\n): [number, number, number] {\n if (a0 === a1 && b0 === b1) return [a0, b0, t0 + (t1 - t0) * frac];\n return frac < 0.5 ? [a0, b0, t0] : [a1, b1, t1];\n}\n","/**\n * Shortening a flattened subpath so a filled marker is not speared by its own\n * line. SVG has no equivalent — it paints the marker over a full-length\n * stroke — so this is the one place our rendering deliberately differs.\n *\n * Runs before dash splitting, so a dash pattern fits the visible line rather\n * than running off under the head.\n */\n\nimport { anchorParamsBetween } from './anchorParams';\nimport type { Polyline } from './polyline';\n\nconst EPS = 1e-9;\n\ninterface Sample {\n x: number; y: number;\n a: number; b: number; t: number;\n w: number;\n o: number;\n /** Index of the first original point at or after this sample. */\n next: number;\n}\n\nfunction sampleAt(\n pl: Polyline, cum: Float64Array,\n A: Uint32Array, B: Uint32Array, T: Float32Array, W: Float32Array | undefined, O: Float32Array | undefined,\n dist: number,\n /** For a cut landing exactly on a vertex: whether the vertex belongs to the\n * run after the sample (a head) or before it (a tail), so it is kept once. */\n vertexFollows: boolean,\n): Sample {\n const n = cum.length;\n let i = 1;\n while (i < n - 1 && (vertexFollows ? cum[i] <= dist : cum[i] < dist)) i++;\n const segStart = cum[i - 1];\n const segLen = cum[i] - segStart;\n const f = segLen > EPS ? (dist - segStart) / segLen : 0;\n\n const px = pl.points[(i - 1) * 2], py = pl.points[(i - 1) * 2 + 1];\n const qx = pl.points[i * 2], qy = pl.points[i * 2 + 1];\n\n const [a, b, t] = anchorParamsBetween(A[i - 1], B[i - 1], T[i - 1], A[i], B[i], T[i], f);\n\n const w = W ? W[i - 1] + (W[i] - W[i - 1]) * f : 0;\n const o = O ? O[i - 1] + (O[i] - O[i - 1]) * f : 0;\n return { x: px + (qx - px) * f, y: py + (qy - py) * f, a, b, t, w, o, next: i };\n}\n\n/** Float32 rounding at a coordinate's magnitude, with headroom: what points stored as\n * `Float32Array` and lengths summed in doubles can disagree by. */\nconst ROUNDING = 4 * 2 ** -23;\n\nfunction nearVertex(pl: Polyline, s: Sample, i: number): boolean {\n const x = pl.points[i * 2], y = pl.points[i * 2 + 1];\n return Math.hypot(s.x - x, s.y - y) <= ROUNDING * Math.max(1, Math.abs(x), Math.abs(y));\n}\n\n/**\n * Shorten `pl` by `startInset` from its first point and `endInset` from its\n * last, both in the same world units as the points.\n *\n * Returns `pl` itself when there is nothing to do (both insets zero, or the\n * subpath is closed and so has no free ends), and `null` when the insets\n * consume the whole run — a caller should then draw no ribbon at all.\n */\nexport function trimPolyline(\n pl: Polyline,\n startInset: number,\n endInset: number,\n): Polyline | null {\n const from = Math.max(0, startInset);\n const to = Math.max(0, endInset);\n if (from <= 0 && to <= 0) return pl;\n if (pl.closed) return pl;\n\n const n = pl.points.length / 2;\n if (n < 2) return null;\n\n const A = pl.anchorA ?? new Uint32Array(n);\n const B = pl.anchorB ?? new Uint32Array(n);\n const T = pl.anchorT ?? new Float32Array(n);\n const W = pl.widths;\n const O = pl.offsets;\n\n const cum = new Float64Array(n);\n for (let i = 1; i < n; i++) {\n const dx = pl.points[i * 2] - pl.points[(i - 1) * 2];\n const dy = pl.points[i * 2 + 1] - pl.points[(i - 1) * 2 + 1];\n cum[i] = cum[i - 1] + Math.hypot(dx, dy);\n }\n const total = cum[n - 1];\n const cutA = from;\n const cutB = total - to;\n if (cutB - cutA <= EPS) return null;\n\n const head = sampleAt(pl, cum, A, B, T, W, O, cutA, true);\n const tail = sampleAt(pl, cum, A, B, T, W, O, cutB, false);\n // A cut within float rounding of a kept vertex is that vertex: the sliver\n // between them has a direction made of noise, which skews a cap or a head.\n const interior = tail.next - head.next;\n const headOnVertex = interior > 0 && nearVertex(pl, head, head.next);\n const tailOnVertex = interior > 0 && nearVertex(pl, tail, tail.next - 1) && interior + (headOnVertex ? 0 : 1) >= 2;\n\n const points: number[] = [];\n const aOut: number[] = [];\n const bOut: number[] = [];\n const tOut: number[] = [];\n const wOut: number[] | undefined = W ? [] : undefined;\n const oOut: number[] | undefined = O ? [] : undefined;\n const push = (s: Sample) => {\n points.push(s.x, s.y);\n aOut.push(s.a); bOut.push(s.b); tOut.push(s.t);\n if (wOut) wOut.push(s.w);\n if (oOut) oOut.push(s.o);\n };\n\n if (!headOnVertex) push(head);\n for (let i = head.next; i < tail.next; i++) {\n points.push(pl.points[i * 2], pl.points[i * 2 + 1]);\n aOut.push(A[i]); bOut.push(B[i]); tOut.push(T[i]);\n if (wOut) wOut.push(W![i]);\n if (oOut) oOut.push(O![i]);\n }\n if (!tailOnVertex) push(tail);\n\n return {\n points,\n closed: false,\n anchorA: new Uint32Array(aOut),\n anchorB: new Uint32Array(bOut),\n anchorT: new Float32Array(tOut),\n ...(wOut ? { widths: new Float32Array(wOut) } : {}),\n ...(oOut ? { offsets: new Float32Array(oOut) } : {}),\n };\n}\n"]}
|
package/dist/warp/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { boundsOfPath, keepCorner, fitPointRun } from '../chunk-
|
|
1
|
+
import { boundsOfPath, keepCorner, fitPointRun } from '../chunk-ZV24QZ6X.js';
|
|
2
2
|
import { pathToAnchors, anchorsToPath } from '../chunk-HTT5AQIU.js';
|
|
3
|
-
import { nestRings, flattenPolygon, resolveCrossings } from '../chunk-
|
|
4
|
-
import { pointInPolygon } from '../chunk-
|
|
3
|
+
import { nestRings, flattenPolygon, resolveCrossings } from '../chunk-VJG5ZWCR.js';
|
|
4
|
+
import { pointInPolygon } from '../chunk-TBS4NHGQ.js';
|
|
5
|
+
import '../chunk-IOD2NFHQ.js';
|
|
5
6
|
import { cubicPointAt, addOrigin, nearestOnLine, pointSegmentDist } from '../chunk-346XYYMX.js';
|
|
6
7
|
import '../chunk-DNX24KBT.js';
|
|
7
8
|
import earcut from 'earcut';
|