@weasel-js/geom 1.9.4 → 1.10.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.
- package/README.md +132 -16
- package/dist/3d/index.js +1 -1
- package/dist/booleans/index.d.ts +63 -29
- package/dist/booleans/index.js +86 -11
- package/dist/booleans/index.js.map +1 -1
- package/dist/{chunk-N5SYTHMR.js → chunk-755Y4YZS.js} +2 -2
- package/dist/chunk-755Y4YZS.js.map +1 -0
- package/dist/{chunk-NL423YYZ.js → chunk-7WFFCHRL.js} +8 -6
- package/dist/{chunk-NL423YYZ.js.map → chunk-7WFFCHRL.js.map} +1 -1
- package/dist/{chunk-X6GJRIQD.js → chunk-IDXY2NCA.js} +38 -16
- package/dist/chunk-IDXY2NCA.js.map +1 -0
- package/dist/chunk-NJ3IGAKR.js +16 -0
- package/dist/chunk-NJ3IGAKR.js.map +1 -0
- package/dist/{chunk-E4TJRGJD.js → chunk-OXH3NOXC.js} +2 -2
- package/dist/chunk-OXH3NOXC.js.map +1 -0
- package/dist/cubicMath-BW-HJrCE.d.ts +16 -0
- package/dist/curves/index.d.ts +1 -1
- package/dist/curves/index.js +2 -2
- package/dist/index.d.ts +899 -135
- package/dist/index.js +1545 -123
- package/dist/index.js.map +1 -1
- package/dist/{path-D0CoudGM.d.ts → path-ljHxobyu.d.ts} +10 -11
- package/dist/tessellate/index.d.ts +11 -12
- package/dist/tessellate/index.js +22 -5
- package/dist/tessellate/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-E4TJRGJD.js.map +0 -1
- package/dist/chunk-HPVINMOM.js +0 -34
- package/dist/chunk-HPVINMOM.js.map +0 -1
- package/dist/chunk-N5SYTHMR.js.map +0 -1
- package/dist/chunk-X6GJRIQD.js.map +0 -1
- package/dist/cubicMath-CpCvuEl8.d.ts +0 -37
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/box.ts","../src/tessellate/polyline.ts"],"names":[],"mappings":";;;;A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AAS,IAAA;AACjB,UAAA,yBAAA,EAA0B;AAAA,QAC5B;AACA,QAAA;AAAA,MACF;AAAA,MACA;AACE,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,uCAAA,EAA0C,GAAG,CAAA,CAAE,CAAA;AAAA;AACnE,EACF,CAAC,CAAA;AAED,EAAA,IAAI,OAAA,SAAgB,OAAO,CAAA;AAC3B,EAAA,OAAO,GAAA;AACT","file":"chunk-NL423YYZ.js","sourcesContent":["/** Axis-aligned box as [minX, minY, maxX, maxY]. */\nexport type Box = readonly [number, number, number, number];\n\n/** An axis-aligned rectangle in object form. `Box` is the tuple form; this is\n * the one that survives being read by a human. */\nexport interface Rect { x: number; y: number; width: number; height: number }\n\n/** Tight bounds of an interleaved coord stream, or null if empty. */\nexport function boundsOfCoords(coords: ArrayLike<number>): Box | null {\n if (coords.length < 2) return null;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (let i = 0; i + 1 < coords.length; i += 2) {\n const x = coords[i], y = coords[i + 1];\n if (x < minX) minX = x;\n if (y < minY) minY = y;\n if (x > maxX) maxX = x;\n if (y > maxY) maxY = y;\n }\n return [minX, minY, maxX, maxY];\n}\n\n/** Smallest box containing both inputs. */\nexport function unionBox(a: Box, b: Box): Box {\n return [\n Math.min(a[0], b[0]),\n Math.min(a[1], b[1]),\n Math.max(a[2], b[2]),\n Math.max(a[3], b[3]),\n ];\n}\n\n/** Inclusive point-in-box test. */\nexport function boxContainsPoint(b: Box, x: number, y: number): boolean {\n return x >= b[0] && x <= b[2] && y >= b[1] && y <= b[3];\n}\n\n/** Whether `outer` wholly holds `inner`, edges inclusive. Two boxes that merely\n * overlap answer false. */\nexport function boxContainsBox(outer: Box, inner: Box): boolean {\n return inner[0] >= outer[0] && inner[1] >= outer[1] && inner[2] <= outer[2] && inner[3] <= outer[3];\n}\n\n/** Interleaved corner ring for a rect at (x,y,w,h), wound clockwise from the\n * origin corner. The closing edge is implicit — the same unclosed shape\n * `pointInPolygon` takes, and what a repeated first vertex would leave as a\n * zero-length segment for anything that strokes it. */\nexport function rectToContour(x: number, y: number, w: number, h: number): Float64Array {\n return Float64Array.of(x, y, x + w, y, x + w, y + h, x, y + h);\n}\n","import { forEachSegment, PATH_M, PATH_L, PATH_Z, PATH_C, PATH_Q } from '../commands';\nimport { rectToContour } from '../box';\nimport { DEFAULT_FLATTEN_TOLERANCE, flattenCubicWithArcLen, flattenQuadraticWithArcLen } from '../flatten';\nimport type { Path, PolygonPath, RectPath } from '../path';\n\n/** One contour of a path, flattened to straight segments. */\nexport interface Polyline {\n /** Interleaved x,y vertices (length = 2 × point count). */\n points: number[];\n /** Whether the contour was closed (ends with Z, or is a RectPath). */\n closed: boolean;\n /** For each point, the previous anchor index. Anchor-aligned points set A === B. */\n anchorA?: Uint32Array;\n /** For each point, the next anchor index. */\n anchorB?: Uint32Array;\n /** For each point, the arc-length fraction along (A, B). 0 at anchor A; for anchor-aligned, set to 0. */\n anchorT?: Float32Array;\n /** Per-point stroke width, populated by the tessellator when the Stroke\n * carries `vertexWidths`. Undefined means uniform `Stroke.width`. */\n widths?: Float32Array;\n}\n\n/** Options for `extractPolylines`. */\nexport interface ExtractOptions {\n flattenTolerance?: number;\n}\n\n/** Flatten each contour of a path to a straight-segment polyline, carrying the\n * anchor parameterization per point. A rect yields one closed contour. */\nexport function extractPolylines(path: Path, opts: ExtractOptions = {}): Polyline[] {\n if (path.kind === 'rect') return [extractRect(path)];\n return extractPolygon(path, opts);\n}\n\nfunction extractRect(p: RectPath): Polyline {\n const { x, y, width: w, height: h } = p;\n return {\n points: Array.from(rectToContour(x, y, w, h)),\n closed: true,\n anchorA: new Uint32Array([0, 1, 2, 3]),\n anchorB: new Uint32Array([0, 1, 2, 3]),\n anchorT: new Float32Array([0, 0, 0, 0]),\n };\n}\n\nfunction extractPolygon(p: PolygonPath, opts: ExtractOptions): Polyline[] {\n const tolerance = opts.flattenTolerance ?? DEFAULT_FLATTEN_TOLERANCE;\n const { commands, coords } = p;\n const out: Polyline[] = [];\n // Anchors are numbered globally (across all contours) in command-stream order.\n let anchorCounter = 0;\n\n // Builders for the current polyline.\n let pts: number[] | null = null;\n let aA: number[] | null = null;\n let aB: number[] | null = null;\n let aT: number[] | null = null;\n let current: Polyline | null = null;\n\n let prevAnchor = -1;\n // The anchor a subpath opened by a bare drawing command starts from.\n let startAnchor = 0;\n\n const beginContour = (): Polyline => {\n pts = [];\n aA = [];\n aB = [];\n aT = [];\n const next: Polyline = { points: pts, closed: false };\n out.push(next);\n return next;\n };\n\n /**\n * A closed contour's last point repeating its first is redundant — Z already\n * says \"return to the start\" — and it is *harmful*: it leaves a zero-length\n * closing segment, which the stroker discards along with the wrap-around\n * join it should have carried, notching the ribbon at the contour's start.\n *\n * Every font outline serialized by opentype.js is written this way, as is a\n * great deal of hand-written and exported SVG, so this is the common case\n * rather than a defensive edge. Exact equality is the right test: the\n * duplicate is a re-emission of the same number, not an approach to it, and\n * a near-miss is a genuine (if tiny) segment the author asked for.\n */\n const dropDuplicateClosingPoint = (): void => {\n if (!pts || !aA || !aB || !aT) return;\n const n = pts.length / 2;\n if (n < 2) return;\n if (pts[0] !== pts[(n - 1) * 2] || pts[1] !== pts[(n - 1) * 2 + 1]) return;\n pts.length -= 2;\n aA.length -= 1;\n aB.length -= 1;\n aT.length -= 1;\n };\n\n const commit = (target: Polyline): void => {\n if (!pts || !aA || !aB || !aT) return;\n target.anchorA = new Uint32Array(aA);\n target.anchorB = new Uint32Array(aB);\n target.anchorT = new Float32Array(aT);\n };\n\n // Fill anchorA/B/T for each point a curve just appended: interior points\n // interpolate (prevAnchor → target), and the final point is pinned to the\n // target so the draw-time lerp returns anchor B's color exactly.\n const pushCurveAnchors = (segStart: number, arcAccum: number[], total: number, target: number): void => {\n for (let k = 0; k < arcAccum.length; k++) {\n aA!.push(prevAnchor);\n aB!.push(target);\n aT!.push(total > 0 ? arcAccum[k] / total : 0);\n }\n const lastIdx = (segStart + arcAccum.length) - 1;\n aA![lastIdx] = target;\n aB![lastIdx] = target;\n aT![lastIdx] = 0;\n };\n\n forEachSegment(commands, coords, (cmd, coordIdx, prevX, prevY, _i, opensSubpath) => {\n if (opensSubpath) {\n if (current) commit(current);\n current = beginContour();\n pts!.push(prevX, prevY);\n aA!.push(startAnchor);\n aB!.push(startAnchor);\n aT!.push(0);\n prevAnchor = startAnchor;\n }\n switch (cmd) {\n case PATH_M:\n case PATH_L: {\n if (cmd === PATH_M) {\n if (current) commit(current);\n current = beginContour();\n startAnchor = anchorCounter;\n }\n pts!.push(coords[coordIdx], coords[coordIdx + 1]);\n aA!.push(anchorCounter);\n aB!.push(anchorCounter);\n aT!.push(0);\n prevAnchor = anchorCounter;\n anchorCounter++;\n break;\n }\n case PATH_Q: {\n const target = anchorCounter;\n const segStart = pts!.length / 2;\n const arcAccum: number[] = [];\n const total = flattenQuadraticWithArcLen(\n prevX, prevY,\n coords[coordIdx], coords[coordIdx + 1],\n coords[coordIdx + 2], coords[coordIdx + 3],\n tolerance, pts!, arcAccum,\n );\n pushCurveAnchors(segStart, arcAccum, total, target);\n prevAnchor = target;\n anchorCounter++;\n break;\n }\n case PATH_C: {\n const target = anchorCounter;\n const segStart = pts!.length / 2;\n const arcAccum: number[] = [];\n const total = flattenCubicWithArcLen(\n prevX, prevY,\n coords[coordIdx], coords[coordIdx + 1],\n coords[coordIdx + 2], coords[coordIdx + 3],\n coords[coordIdx + 4], coords[coordIdx + 5],\n tolerance, pts!, arcAccum,\n );\n pushCurveAnchors(segStart, arcAccum, total, target);\n prevAnchor = target;\n anchorCounter++;\n break;\n }\n case PATH_Z: {\n if (current) {\n current.closed = true;\n dropDuplicateClosingPoint();\n }\n break;\n }\n default:\n throw new Error(`extractPolylines: unknown command code ${cmd}`);\n }\n });\n\n if (current) commit(current);\n return out;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/box.ts","../src/tessellate/polyline.ts"],"names":[],"mappings":";;;;AAQO,SAAS,eAAe,MAAA,EAAuC;AACpE,EAAA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AA,CAAQ,MAAA,GAAS,IAAA;AACjB,UAAA,yBAAA,EAA0B;AAAA,QAC5B;AACA,QAAA;AAAA,MACF;AAAA,MACA;AACE,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,uCAAA,EAA0C,GAAG,CAAA,CAAE,CAAA;AAAA;AACnE,EACF,CAAC,CAAA;AAED,EAAA,IAAI,OAAA,SAAgB,OAAO,CAAA;AAC3B,EAAA,OAAO,GAAA;AACT","file":"chunk-7WFFCHRL.js","sourcesContent":["/** Axis-aligned box as [minX, minY, maxX, maxY]. */\nexport type Box = readonly [number, number, number, number];\n\n/** An axis-aligned rectangle in object form. `Box` is the tuple form; this is\n * the one that survives being read by a human. */\nexport interface Rect { x: number; y: number; width: number; height: number }\n\n/** Tight bounds of an interleaved coord stream, or null if empty. */\nexport function boundsOfCoords(coords: ArrayLike<number>): Box | null {\n if (coords.length < 2) return null;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (let i = 0; i + 1 < coords.length; i += 2) {\n const x = coords[i], y = coords[i + 1];\n if (x < minX) minX = x;\n if (y < minY) minY = y;\n if (x > maxX) maxX = x;\n if (y > maxY) maxY = y;\n }\n return [minX, minY, maxX, maxY];\n}\n\n/** Smallest box containing both inputs. */\nexport function unionBox(a: Box, b: Box): Box {\n return [\n Math.min(a[0], b[0]),\n Math.min(a[1], b[1]),\n Math.max(a[2], b[2]),\n Math.max(a[3], b[3]),\n ];\n}\n\n/** Inclusive point-in-box test. */\nexport function boxContainsPoint(b: Box, x: number, y: number): boolean {\n return x >= b[0] && x <= b[2] && y >= b[1] && y <= b[3];\n}\n\n/** Whether `outer` wholly holds `inner`, edges inclusive. Two boxes that merely\n * overlap answer false. */\nexport function boxContainsBox(outer: Box, inner: Box): boolean {\n return inner[0] >= outer[0] && inner[1] >= outer[1] && inner[2] <= outer[2] && inner[3] <= outer[3];\n}\n\n/** Interleaved corner ring for a rect at (x,y,w,h), wound clockwise from the\n * origin corner. The closing edge is implicit — the same unclosed shape\n * `pointInPolygon` takes, and what a repeated first vertex would leave as a\n * zero-length segment for anything that strokes it. */\nexport function rectToContour(x: number, y: number, w: number, h: number): Float64Array {\n return Float64Array.of(x, y, x + w, y, x + w, y + h, x, y + h);\n}\n","import { forEachSegment, PATH_M, PATH_L, PATH_Z, PATH_C, PATH_Q } from '../commands';\nimport { rectToContour } from '../box';\nimport { DEFAULT_FLATTEN_TOLERANCE, flattenCubicWithArcLen, flattenQuadraticWithArcLen } from '../flatten';\nimport type { Path, PolygonPath, RectPath } from '../path';\n\n/** One contour of a path, flattened to straight segments. */\nexport interface Polyline {\n /** Interleaved x,y vertices (length = 2 × point count). */\n points: number[];\n /** Whether the contour was closed (ends with Z, or is a RectPath). */\n closed: boolean;\n /** For each point, the previous anchor index. Anchor-aligned points set A === B. */\n anchorA?: Uint32Array;\n /** For each point, the next anchor index. */\n anchorB?: Uint32Array;\n /** For each point, the arc-length fraction along (A, B). 0 at anchor A; for anchor-aligned, set to 0. */\n anchorT?: Float32Array;\n /** Per-point stroke width, populated by the tessellator when the Stroke\n * carries `vertexWidths`. Undefined means uniform `Stroke.width`. */\n widths?: Float32Array;\n}\n\n/** Options for `extractPolylines`. */\nexport interface ExtractOptions {\n flattenTolerance?: number;\n /** Most a curve may turn, in radians, between two flattened vertices.\n * Unbounded when unset. */\n maxTurn?: number;\n}\n\n/** Flatten each contour of a path to a straight-segment polyline, carrying the\n * anchor parameterization per point. A rect yields one closed contour. */\nexport function extractPolylines(path: Path, opts: ExtractOptions = {}): Polyline[] {\n if (path.kind === 'rect') return [extractRect(path)];\n return extractPolygon(path, opts);\n}\n\nfunction extractRect(p: RectPath): Polyline {\n const { x, y, width: w, height: h } = p;\n return {\n points: Array.from(rectToContour(x, y, w, h)),\n closed: true,\n anchorA: new Uint32Array([0, 1, 2, 3]),\n anchorB: new Uint32Array([0, 1, 2, 3]),\n anchorT: new Float32Array([0, 0, 0, 0]),\n };\n}\n\nfunction extractPolygon(p: PolygonPath, opts: ExtractOptions): Polyline[] {\n const tolerance = opts.flattenTolerance ?? DEFAULT_FLATTEN_TOLERANCE;\n const { commands, coords } = p;\n const out: Polyline[] = [];\n // Anchors are numbered globally (across all contours) in command-stream order.\n let anchorCounter = 0;\n\n // Builders for the current polyline.\n let pts: number[] | null = null;\n let aA: number[] | null = null;\n let aB: number[] | null = null;\n let aT: number[] | null = null;\n let current: Polyline | null = null;\n\n let prevAnchor = -1;\n // The anchor a subpath opened by a bare drawing command starts from.\n let startAnchor = 0;\n\n const beginContour = (): Polyline => {\n pts = [];\n aA = [];\n aB = [];\n aT = [];\n const next: Polyline = { points: pts, closed: false };\n out.push(next);\n return next;\n };\n\n /**\n * A closed contour's last point repeating its first leaves a zero-length\n * closing segment, which the stroker discards along with the wrap-around\n * join it should have carried, notching the ribbon at the contour's start.\n * Every font outline serialized by opentype.js is written this way. Exact\n * equality is the right test: the duplicate is a re-emission of the same\n * number, and a near-miss is a genuine (if tiny) segment the author asked for.\n */\n const dropDuplicateClosingPoint = (): void => {\n if (!pts || !aA || !aB || !aT) return;\n const n = pts.length / 2;\n if (n < 2) return;\n if (pts[0] !== pts[(n - 1) * 2] || pts[1] !== pts[(n - 1) * 2 + 1]) return;\n pts.length -= 2;\n aA.length -= 1;\n aB.length -= 1;\n aT.length -= 1;\n };\n\n const commit = (target: Polyline): void => {\n if (!pts || !aA || !aB || !aT) return;\n target.anchorA = new Uint32Array(aA);\n target.anchorB = new Uint32Array(aB);\n target.anchorT = new Float32Array(aT);\n };\n\n // Fill anchorA/B/T for each point a curve just appended: interior points\n // interpolate (prevAnchor → target), and the final point is pinned to the\n // target so the draw-time lerp returns anchor B's color exactly.\n const pushCurveAnchors = (segStart: number, arcAccum: number[], total: number, target: number): void => {\n for (let k = 0; k < arcAccum.length; k++) {\n aA!.push(prevAnchor);\n aB!.push(target);\n aT!.push(total > 0 ? arcAccum[k] / total : 0);\n }\n const lastIdx = (segStart + arcAccum.length) - 1;\n aA![lastIdx] = target;\n aB![lastIdx] = target;\n aT![lastIdx] = 0;\n };\n\n forEachSegment(commands, coords, (cmd, coordIdx, prevX, prevY, _i, opensSubpath) => {\n if (opensSubpath) {\n if (current) commit(current);\n current = beginContour();\n pts!.push(prevX, prevY);\n aA!.push(startAnchor);\n aB!.push(startAnchor);\n aT!.push(0);\n prevAnchor = startAnchor;\n }\n switch (cmd) {\n case PATH_M:\n case PATH_L: {\n if (cmd === PATH_M) {\n if (current) commit(current);\n current = beginContour();\n startAnchor = anchorCounter;\n }\n pts!.push(coords[coordIdx], coords[coordIdx + 1]);\n aA!.push(anchorCounter);\n aB!.push(anchorCounter);\n aT!.push(0);\n prevAnchor = anchorCounter;\n anchorCounter++;\n break;\n }\n case PATH_Q: {\n const target = anchorCounter;\n const segStart = pts!.length / 2;\n const arcAccum: number[] = [];\n const total = flattenQuadraticWithArcLen(\n prevX, prevY,\n coords[coordIdx], coords[coordIdx + 1],\n coords[coordIdx + 2], coords[coordIdx + 3],\n tolerance, pts!, arcAccum, opts.maxTurn,\n );\n pushCurveAnchors(segStart, arcAccum, total, target);\n prevAnchor = target;\n anchorCounter++;\n break;\n }\n case PATH_C: {\n const target = anchorCounter;\n const segStart = pts!.length / 2;\n const arcAccum: number[] = [];\n const total = flattenCubicWithArcLen(\n prevX, prevY,\n coords[coordIdx], coords[coordIdx + 1],\n coords[coordIdx + 2], coords[coordIdx + 3],\n coords[coordIdx + 4], coords[coordIdx + 5],\n tolerance, pts!, arcAccum, opts.maxTurn,\n );\n pushCurveAnchors(segStart, arcAccum, total, target);\n prevAnchor = target;\n anchorCounter++;\n break;\n }\n case PATH_Z: {\n if (current) {\n current.closed = true;\n dropDuplicateClosingPoint();\n }\n break;\n }\n default:\n throw new Error(`extractPolylines: unknown command code ${cmd}`);\n }\n });\n\n if (current) commit(current);\n return out;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sign, len2, dot } from './chunk-
|
|
1
|
+
import { sign, len2, dot } from './chunk-755Y4YZS.js';
|
|
2
2
|
|
|
3
3
|
// src/flatten.ts
|
|
4
4
|
var DEFAULT_FLATTEN_TOLERANCE = 0.5;
|
|
@@ -22,6 +22,14 @@ function distPointToSegment(px, py, ax, ay, bx, by) {
|
|
|
22
22
|
if (along >= 1) return Math.hypot(px - bx, py - by);
|
|
23
23
|
return Math.abs((px - ax) * dy - (py - ay) * dx) / Math.sqrt(len22);
|
|
24
24
|
}
|
|
25
|
+
function controlTurn(x0, y0, x1, y1, x2, y2, x3, y3) {
|
|
26
|
+
return legTurn(x1 - x0, y1 - y0, x2 - x1, y2 - y1) + legTurn(x2 - x1, y2 - y1, x3 - x2, y3 - y2) + (x2 === x1 && y2 === y1 ? legTurn(x1 - x0, y1 - y0, x3 - x2, y3 - y2) : 0);
|
|
27
|
+
}
|
|
28
|
+
function legTurn(ax, ay, bx, by) {
|
|
29
|
+
const la = Math.hypot(ax, ay), lb = Math.hypot(bx, by);
|
|
30
|
+
if (la === 0 || lb === 0) return 0;
|
|
31
|
+
return Math.acos(Math.max(-1, Math.min(1, (ax * bx + ay * by) / (la * lb))));
|
|
32
|
+
}
|
|
25
33
|
function flattenCubic(x0, y0, x1, y1, x2, y2, x3, y3, tolerance, out) {
|
|
26
34
|
if (!finite8(x0, y0, x1, y1, x2, y2, x3, y3)) {
|
|
27
35
|
out.push(x3, y3);
|
|
@@ -64,18 +72,19 @@ function flattenQuadraticRec(x0, y0, x1, y1, x2, y2, tolerance, out, depth) {
|
|
|
64
72
|
flattenQuadraticRec(x0, y0, x01, y01, x012, y012, tolerance, out, depth + 1);
|
|
65
73
|
flattenQuadraticRec(x012, y012, x12, y12, x2, y2, tolerance, out, depth + 1);
|
|
66
74
|
}
|
|
67
|
-
function flattenCubicWithArcLen(x0, y0, x1, y1, x2, y2, x3, y3, tolerance, out, arcOut) {
|
|
75
|
+
function flattenCubicWithArcLen(x0, y0, x1, y1, x2, y2, x3, y3, tolerance, out, arcOut, maxTurn = Infinity) {
|
|
68
76
|
if (!finite8(x0, y0, x1, y1, x2, y2, x3, y3)) {
|
|
69
77
|
out.push(x3, y3);
|
|
70
78
|
arcOut.push(0);
|
|
71
79
|
return 0;
|
|
72
80
|
}
|
|
73
|
-
return flattenCubicArcRec(x0, y0, x1, y1, x2, y2, x3, y3, usableTolerance(tolerance), out, arcOut, 0, 0);
|
|
81
|
+
return flattenCubicArcRec(x0, y0, x1, y1, x2, y2, x3, y3, usableTolerance(tolerance), maxTurn, out, arcOut, 0, 0);
|
|
74
82
|
}
|
|
75
|
-
function flattenCubicArcRec(x0, y0, x1, y1, x2, y2, x3, y3, tolerance, out, arcOut, accum, depth) {
|
|
83
|
+
function flattenCubicArcRec(x0, y0, x1, y1, x2, y2, x3, y3, tolerance, maxTurn, out, arcOut, accum, depth) {
|
|
76
84
|
const d1 = distPointToSegment(x1, y1, x0, y0, x3, y3);
|
|
77
85
|
const d2 = distPointToSegment(x2, y2, x0, y0, x3, y3);
|
|
78
|
-
|
|
86
|
+
const flat = Math.max(d1, d2) <= tolerance && (maxTurn === Infinity || controlTurn(x0, y0, x1, y1, x2, y2, x3, y3) <= maxTurn);
|
|
87
|
+
if (flat || depth >= MAX_FLATTEN_DEPTH) {
|
|
79
88
|
const lastX = out.length >= 2 ? out[out.length - 2] : x0;
|
|
80
89
|
const lastY = out.length >= 2 ? out[out.length - 1] : y0;
|
|
81
90
|
const seg = Math.hypot(x3 - lastX, y3 - lastY);
|
|
@@ -90,21 +99,22 @@ function flattenCubicArcRec(x0, y0, x1, y1, x2, y2, x3, y3, tolerance, out, arcO
|
|
|
90
99
|
const x012 = (x01 + x12) * 0.5, y012 = (y01 + y12) * 0.5;
|
|
91
100
|
const x123 = (x12 + x23) * 0.5, y123 = (y12 + y23) * 0.5;
|
|
92
101
|
const x0123 = (x012 + x123) * 0.5, y0123 = (y012 + y123) * 0.5;
|
|
93
|
-
accum = flattenCubicArcRec(x0, y0, x01, y01, x012, y012, x0123, y0123, tolerance, out, arcOut, accum, depth + 1);
|
|
94
|
-
accum = flattenCubicArcRec(x0123, y0123, x123, y123, x23, y23, x3, y3, tolerance, out, arcOut, accum, depth + 1);
|
|
102
|
+
accum = flattenCubicArcRec(x0, y0, x01, y01, x012, y012, x0123, y0123, tolerance, maxTurn, out, arcOut, accum, depth + 1);
|
|
103
|
+
accum = flattenCubicArcRec(x0123, y0123, x123, y123, x23, y23, x3, y3, tolerance, maxTurn, out, arcOut, accum, depth + 1);
|
|
95
104
|
return accum;
|
|
96
105
|
}
|
|
97
|
-
function flattenQuadraticWithArcLen(x0, y0, x1, y1, x2, y2, tolerance, out, arcOut) {
|
|
106
|
+
function flattenQuadraticWithArcLen(x0, y0, x1, y1, x2, y2, tolerance, out, arcOut, maxTurn = Infinity) {
|
|
98
107
|
if (!finite6(x0, y0, x1, y1, x2, y2)) {
|
|
99
108
|
out.push(x2, y2);
|
|
100
109
|
arcOut.push(0);
|
|
101
110
|
return 0;
|
|
102
111
|
}
|
|
103
|
-
return flattenQuadraticArcRec(x0, y0, x1, y1, x2, y2, usableTolerance(tolerance), out, arcOut, 0, 0);
|
|
112
|
+
return flattenQuadraticArcRec(x0, y0, x1, y1, x2, y2, usableTolerance(tolerance), maxTurn, out, arcOut, 0, 0);
|
|
104
113
|
}
|
|
105
|
-
function flattenQuadraticArcRec(x0, y0, x1, y1, x2, y2, tolerance, out, arcOut, accum, depth) {
|
|
114
|
+
function flattenQuadraticArcRec(x0, y0, x1, y1, x2, y2, tolerance, maxTurn, out, arcOut, accum, depth) {
|
|
106
115
|
const d = distPointToSegment(x1, y1, x0, y0, x2, y2);
|
|
107
|
-
|
|
116
|
+
const flat = d <= tolerance && (maxTurn === Infinity || controlTurn(x0, y0, x1, y1, x2, y2, x2, y2) <= maxTurn);
|
|
117
|
+
if (flat || depth >= MAX_FLATTEN_DEPTH) {
|
|
108
118
|
const lastX = out.length >= 2 ? out[out.length - 2] : x0;
|
|
109
119
|
const lastY = out.length >= 2 ? out[out.length - 1] : y0;
|
|
110
120
|
const seg = Math.hypot(x2 - lastX, y2 - lastY);
|
|
@@ -116,8 +126,8 @@ function flattenQuadraticArcRec(x0, y0, x1, y1, x2, y2, tolerance, out, arcOut,
|
|
|
116
126
|
const x01 = (x0 + x1) * 0.5, y01 = (y0 + y1) * 0.5;
|
|
117
127
|
const x12 = (x1 + x2) * 0.5, y12 = (y1 + y2) * 0.5;
|
|
118
128
|
const x012 = (x01 + x12) * 0.5, y012 = (y01 + y12) * 0.5;
|
|
119
|
-
accum = flattenQuadraticArcRec(x0, y0, x01, y01, x012, y012, tolerance, out, arcOut, accum, depth + 1);
|
|
120
|
-
accum = flattenQuadraticArcRec(x012, y012, x12, y12, x2, y2, tolerance, out, arcOut, accum, depth + 1);
|
|
129
|
+
accum = flattenQuadraticArcRec(x0, y0, x01, y01, x012, y012, tolerance, maxTurn, out, arcOut, accum, depth + 1);
|
|
130
|
+
accum = flattenQuadraticArcRec(x012, y012, x12, y12, x2, y2, tolerance, maxTurn, out, arcOut, accum, depth + 1);
|
|
121
131
|
return accum;
|
|
122
132
|
}
|
|
123
133
|
|
|
@@ -150,6 +160,18 @@ function pointSegmentDist2(px, py, ax, ay, bx, by) {
|
|
|
150
160
|
return len2(dx, dy);
|
|
151
161
|
}
|
|
152
162
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
163
|
+
// src/openFill.ts
|
|
164
|
+
var fallback = "close";
|
|
165
|
+
function setDefaultOpenFill(rule) {
|
|
166
|
+
fallback = rule;
|
|
167
|
+
}
|
|
168
|
+
function defaultOpenFill() {
|
|
169
|
+
return fallback;
|
|
170
|
+
}
|
|
171
|
+
function fillsOpenSubpaths(path) {
|
|
172
|
+
return (path.openFill ?? fallback) === "close";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export { DEFAULT_FLATTEN_TOLERANCE, defaultOpenFill, fillsOpenSubpaths, flattenCubic, flattenCubicWithArcLen, flattenQuadratic, flattenQuadraticWithArcLen, pointInPolygon, pointSegmentDist2, segmentsCross, setDefaultOpenFill };
|
|
176
|
+
//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,EAAA,CAAA;AACnD,EAAA,OAAO,IAAA,CAAK,IAAI,EAAE,CAAA;AACpB;;;ACxDA,IAAI,QAAA,GAAyB,OAAA;AAItB,SAAS,mBAAmB,IAAA,EAA0B;AAC3D,EAAA,QAAA,GAAW,IAAA;AACb;AAGO,SAAS,eAAA,GAAgC;AAC9C,EAAA,OAAO,QAAA;AACT;AAIO,SAAS,kBAAkB,IAAA,EAA4B;AAC5D,EAAA,OAAA,CAAQ,IAAA,CAAK,YAAY,QAAA,MAAc,OAAA;AACzC","file":"chunk-IDXY2NCA.js","sourcesContent":["/**\n * Bezier flattening — subdivide cubic and quadratic segments into polyline\n * approximations within a flatness tolerance.\n *\n * The flatness metric is the maximum distance from any control point to the\n * chord between endpoints.\n *\n * Tolerance is in world units. 0.5 is a sensible default for screen-rate\n * rendering at 1× zoom; consumers that zoom in heavily should pass a\n * tighter tolerance.\n */\n\nexport const DEFAULT_FLATTEN_TOLERANCE = 0.5;\n\n/** Floor for a non-positive or NaN tolerance. Without it the flatness test can\n * never be satisfied and the subdivision recurses until the stack blows. */\nconst MIN_FLATTEN_TOLERANCE = 1e-6;\n\n/** Subdivision ceiling. The tolerance floor bounds the common runaway; this\n * bounds the other one, coordinates large enough that reaching 1e-6 takes\n * hundreds of levels. Error falls roughly 4x per level, so 16 is far beyond\n * any tolerance a caller can mean. */\nconst MAX_FLATTEN_DEPTH = 16;\n\nfunction usableTolerance(tolerance: number): number {\n return tolerance > 0 ? tolerance : MIN_FLATTEN_TOLERANCE;\n}\n\nfunction finite6(a: number, b: number, c: number, d: number, e: number, f: number): boolean {\n return Number.isFinite(a) && Number.isFinite(b) && Number.isFinite(c)\n && Number.isFinite(d) && Number.isFinite(e) && Number.isFinite(f);\n}\n\nfunction finite8(\n a: number, b: number, c: number, d: number,\n e: number, f: number, g: number, h: number,\n): boolean {\n return finite6(a, b, c, d, e, f) && Number.isFinite(g) && Number.isFinite(h);\n}\n\n/**\n * Distance from point P to segment AB. To the segment, not the line through\n * it: a control point on that line but past an end still pulls the curve out\n * beyond the chord, and measures zero against the line.\n */\nfunction distPointToSegment(px: number, py: number, ax: number, ay: number, bx: number, by: number): number {\n const dx = bx - ax;\n const dy = by - ay;\n const len2 = dx * dx + dy * dy;\n const along = len2 === 0 ? 0 : ((px - ax) * dx + (py - ay) * dy) / len2;\n if (along <= 0) return Math.hypot(px - ax, py - ay);\n if (along >= 1) return Math.hypot(px - bx, py - by);\n return Math.abs((px - ax) * dy - (py - ay) * dx) / Math.sqrt(len2);\n}\n\n/** Total turn of a control polygon, in radians, skipping zero-length legs. It\n * bounds the turn of the curve it controls, so it bounds the corner a chord\n * standing in for that curve can leave. */\nfunction controlTurn(\n x0: number, y0: number, x1: number, y1: number,\n x2: number, y2: number, x3: number, y3: number,\n): number {\n return legTurn(x1 - x0, y1 - y0, x2 - x1, y2 - y1)\n + legTurn(x2 - x1, y2 - y1, x3 - x2, y3 - y2)\n + (x2 === x1 && y2 === y1 ? legTurn(x1 - x0, y1 - y0, x3 - x2, y3 - y2) : 0);\n}\n\n/** Angle between two legs; zero when either has no length. */\nfunction legTurn(ax: number, ay: number, bx: number, by: number): number {\n const la = Math.hypot(ax, ay), lb = Math.hypot(bx, by);\n if (la === 0 || lb === 0) return 0;\n return Math.acos(Math.max(-1, Math.min(1, (ax * bx + ay * by) / (la * lb))));\n}\n\n/**\n * Recursively subdivide a cubic bezier (P0..P3) and append `lineTo`-style\n * vertices to `out` (interleaved x,y). The starting endpoint is *not*\n * appended — callers usually emitted it as the segment's previous vertex.\n */\nexport function flattenCubic(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n x3: number, y3: number,\n tolerance: number,\n out: number[],\n): void {\n if (!finite8(x0, y0, x1, y1, x2, y2, x3, y3)) {\n out.push(x3, y3);\n return;\n }\n flattenCubicRec(x0, y0, x1, y1, x2, y2, x3, y3, usableTolerance(tolerance), out, 0);\n}\n\nfunction flattenCubicRec(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n x3: number, y3: number,\n tolerance: number,\n out: number[],\n depth: number,\n): void {\n const d1 = distPointToSegment(x1, y1, x0, y0, x3, y3);\n const d2 = distPointToSegment(x2, y2, x0, y0, x3, y3);\n if (Math.max(d1, d2) <= tolerance || depth >= MAX_FLATTEN_DEPTH) {\n out.push(x3, y3);\n return;\n }\n // De Casteljau split at t=0.5\n const x01 = (x0 + x1) * 0.5, y01 = (y0 + y1) * 0.5;\n const x12 = (x1 + x2) * 0.5, y12 = (y1 + y2) * 0.5;\n const x23 = (x2 + x3) * 0.5, y23 = (y2 + y3) * 0.5;\n const x012 = (x01 + x12) * 0.5, y012 = (y01 + y12) * 0.5;\n const x123 = (x12 + x23) * 0.5, y123 = (y12 + y23) * 0.5;\n const x0123 = (x012 + x123) * 0.5, y0123 = (y012 + y123) * 0.5;\n flattenCubicRec(x0, y0, x01, y01, x012, y012, x0123, y0123, tolerance, out, depth + 1);\n flattenCubicRec(x0123, y0123, x123, y123, x23, y23, x3, y3, tolerance, out, depth + 1);\n}\n\n/** Recursively subdivide a quadratic bezier (P0, P1, P2). */\nexport function flattenQuadratic(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n tolerance: number,\n out: number[],\n): void {\n if (!finite6(x0, y0, x1, y1, x2, y2)) {\n out.push(x2, y2);\n return;\n }\n flattenQuadraticRec(x0, y0, x1, y1, x2, y2, usableTolerance(tolerance), out, 0);\n}\n\nfunction flattenQuadraticRec(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n tolerance: number,\n out: number[],\n depth: number,\n): void {\n const d = distPointToSegment(x1, y1, x0, y0, x2, y2);\n if (d <= tolerance || depth >= MAX_FLATTEN_DEPTH) {\n out.push(x2, y2);\n return;\n }\n const x01 = (x0 + x1) * 0.5, y01 = (y0 + y1) * 0.5;\n const x12 = (x1 + x2) * 0.5, y12 = (y1 + y2) * 0.5;\n const x012 = (x01 + x12) * 0.5, y012 = (y01 + y12) * 0.5;\n flattenQuadraticRec(x0, y0, x01, y01, x012, y012, tolerance, out, depth + 1);\n flattenQuadraticRec(x012, y012, x12, y12, x2, y2, tolerance, out, depth + 1);\n}\n\n/**\n * Like `flattenCubic` but also appends to `arcOut`, for each new flattened\n * point, its *cumulative distance from the segment start* — not a normalized\n * fraction. The caller divides each by the segment's total flattened arc\n * length to yield t ∈ (0, 1]. `maxTurn`, in radians, also bounds how far each\n * piece's control polygon may turn.\n */\nexport function flattenCubicWithArcLen(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n x3: number, y3: number,\n tolerance: number,\n out: number[],\n arcOut: number[],\n maxTurn = Infinity,\n): number {\n if (!finite8(x0, y0, x1, y1, x2, y2, x3, y3)) {\n out.push(x3, y3);\n arcOut.push(0);\n return 0;\n }\n return flattenCubicArcRec(x0, y0, x1, y1, x2, y2, x3, y3, usableTolerance(tolerance), maxTurn, out, arcOut, 0, 0);\n}\n\nfunction flattenCubicArcRec(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n x3: number, y3: number,\n tolerance: number,\n maxTurn: number,\n out: number[],\n arcOut: number[],\n accum: number,\n depth: number,\n): number {\n const d1 = distPointToSegment(x1, y1, x0, y0, x3, y3);\n const d2 = distPointToSegment(x2, y2, x0, y0, x3, y3);\n const flat = Math.max(d1, d2) <= tolerance\n && (maxTurn === Infinity || controlTurn(x0, y0, x1, y1, x2, y2, x3, y3) <= maxTurn);\n if (flat || depth >= MAX_FLATTEN_DEPTH) {\n const lastX = out.length >= 2 ? out[out.length - 2] : x0;\n const lastY = out.length >= 2 ? out[out.length - 1] : y0;\n const seg = Math.hypot(x3 - lastX, y3 - lastY);\n accum += seg;\n out.push(x3, y3);\n arcOut.push(accum);\n return accum;\n }\n const x01 = (x0 + x1) * 0.5, y01 = (y0 + y1) * 0.5;\n const x12 = (x1 + x2) * 0.5, y12 = (y1 + y2) * 0.5;\n const x23 = (x2 + x3) * 0.5, y23 = (y2 + y3) * 0.5;\n const x012 = (x01 + x12) * 0.5, y012 = (y01 + y12) * 0.5;\n const x123 = (x12 + x23) * 0.5, y123 = (y12 + y23) * 0.5;\n const x0123 = (x012 + x123) * 0.5, y0123 = (y012 + y123) * 0.5;\n accum = flattenCubicArcRec(x0, y0, x01, y01, x012, y012, x0123, y0123, tolerance, maxTurn, out, arcOut, accum, depth + 1);\n accum = flattenCubicArcRec(x0123, y0123, x123, y123, x23, y23, x3, y3, tolerance, maxTurn, out, arcOut, accum, depth + 1);\n return accum;\n}\n\n/** Flatten a quadratic bezier into line segments within `tolerance`, appending\n * points to `out` and their cumulative arc lengths to `arcOut`. The arc\n * lengths are what lets per-anchor color and dash phase be interpolated\n * evenly along the curve rather than per segment. */\nexport function flattenQuadraticWithArcLen(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n tolerance: number,\n out: number[],\n arcOut: number[],\n maxTurn = Infinity,\n): number {\n if (!finite6(x0, y0, x1, y1, x2, y2)) {\n out.push(x2, y2);\n arcOut.push(0);\n return 0;\n }\n return flattenQuadraticArcRec(x0, y0, x1, y1, x2, y2, usableTolerance(tolerance), maxTurn, out, arcOut, 0, 0);\n}\n\nfunction flattenQuadraticArcRec(\n x0: number, y0: number,\n x1: number, y1: number,\n x2: number, y2: number,\n tolerance: number,\n maxTurn: number,\n out: number[],\n arcOut: number[],\n accum: number,\n depth: number,\n): number {\n const d = distPointToSegment(x1, y1, x0, y0, x2, y2);\n const flat = d <= tolerance\n && (maxTurn === Infinity || controlTurn(x0, y0, x1, y1, x2, y2, x2, y2) <= maxTurn);\n if (flat || depth >= MAX_FLATTEN_DEPTH) {\n const lastX = out.length >= 2 ? out[out.length - 2] : x0;\n const lastY = out.length >= 2 ? out[out.length - 1] : y0;\n const seg = Math.hypot(x2 - lastX, y2 - lastY);\n accum += seg;\n out.push(x2, y2);\n arcOut.push(accum);\n return accum;\n }\n const x01 = (x0 + x1) * 0.5, y01 = (y0 + y1) * 0.5;\n const x12 = (x1 + x2) * 0.5, y12 = (y1 + y2) * 0.5;\n const x012 = (x01 + x12) * 0.5, y012 = (y01 + y12) * 0.5;\n accum = flattenQuadraticArcRec(x0, y0, x01, y01, x012, y012, tolerance, maxTurn, out, arcOut, accum, depth + 1);\n accum = flattenQuadraticArcRec(x012, y012, x12, y12, x2, y2, tolerance, maxTurn, out, arcOut, accum, depth + 1);\n return accum;\n}\n\n","import { sign, dot, len2 } from './scalar';\n\n/**\n * Even-odd ray-cast point-in-polygon over an interleaved, unclosed contour\n * [x0,y0,x1,y1,…]. The closing edge (last→first) is implicit.\n *\n * `start`/`end` are vertex indices, not float offsets, and bound one contour\n * inside a buffer holding several.\n */\nexport function pointInPolygon(\n coords: ArrayLike<number>,\n px: number,\n py: number,\n start = 0,\n end = coords.length >> 1,\n): boolean {\n if (end - start < 3) return false;\n let inside = false;\n for (let i = start, j = end - 1; i < end; j = i++) {\n const xi = coords[i * 2], yi = coords[i * 2 + 1];\n const xj = coords[j * 2], yj = coords[j * 2 + 1];\n const crosses =\n (yi > py) !== (yj > py) &&\n px < ((xj - xi) * (py - yi)) / (yj - yi) + xi;\n if (crosses) inside = !inside;\n }\n return inside;\n}\n\n/**\n * True if segments (ax,ay)-(bx,by) and (cx,cy)-(dx,dy) intersect at a single\n * point. An endpoint landing on the other segment counts (a T-junction and a\n * shared endpoint both answer true) — hit-testing wants a grazing edge to\n * register. Collinear overlap answers false: there is no single crossing\n * point, so the sign test both segments rely on is zero on all four sides.\n */\nexport function segmentsCross(\n ax: number, ay: number, bx: number, by: number,\n cx: number, cy: number, dx: number, dy: number,\n): boolean {\n const d1 = sign((dx - cx) * (ay - cy) - (dy - cy) * (ax - cx));\n const d2 = sign((dx - cx) * (by - cy) - (dy - cy) * (bx - cx));\n const d3 = sign((bx - ax) * (cy - ay) - (by - ay) * (cx - ax));\n const d4 = sign((bx - ax) * (dy - ay) - (by - ay) * (dx - ax));\n return d1 !== d2 && d3 !== d4;\n}\n\n/** Squared distance from (px,py) to segment (ax,ay)-(bx,by), endpoint-clamped. */\nexport function pointSegmentDist2(\n px: number, py: number, ax: number, ay: number, bx: number, by: number,\n): number {\n const vx = bx - ax, vy = by - ay;\n const wx = px - ax, wy = py - ay;\n const vv = len2(vx, vy);\n let t = vv === 0 ? 0 : dot(wx, wy, vx, vy) / vv;\n t = t < 0 ? 0 : t > 1 ? 1 : t;\n const dx = px - (ax + t * vx), dy = py - (ay + t * vy);\n return len2(dx, dy);\n}\n","import type { PathOpenFill, PolygonPath } from './path';\n\nlet fallback: PathOpenFill = 'close';\n\n/** Set whether a fill closes an open subpath, for every path that names no\n * `openFill` of its own. Starts at `'close'`. */\nexport function setDefaultOpenFill(rule: PathOpenFill): void {\n fallback = rule;\n}\n\n/** The rule a path with no `openFill` of its own follows. */\nexport function defaultOpenFill(): PathOpenFill {\n return fallback;\n}\n\n/** Whether `path`'s open subpaths fill, each closed by a straight edge back to\n * its start. What painting, area, and the filled-region hit tests all ask. */\nexport function fillsOpenSubpaths(path: PolygonPath): boolean {\n return (path.openFill ?? fallback) === 'close';\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cubicEvalAt, splitCubicAt } from './chunk-URQMDR6Q.js';
|
|
2
|
+
|
|
3
|
+
// src/paths/cubicMath.ts
|
|
4
|
+
function cubicPointAt(p0, p1, p2, p3, t) {
|
|
5
|
+
const [x, y] = cubicEvalAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);
|
|
6
|
+
return { x, y };
|
|
7
|
+
}
|
|
8
|
+
function splitCubicAtT(p0, p1, p2, p3, t) {
|
|
9
|
+
const [l, r] = splitCubicAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);
|
|
10
|
+
const quad = (c) => [{ x: c[0], y: c[1] }, { x: c[2], y: c[3] }, { x: c[4], y: c[5] }, { x: c[6], y: c[7] }];
|
|
11
|
+
return { left: quad(l), right: quad(r) };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { cubicPointAt, split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,CAAA;AACzF,EAAA,OAAO,EAAE,MAAM,IAAA,CAAK,CAAC,GAAG,KAAA,EAAO,IAAA,CAAK,CAAC,CAAA,EAAE;AACzC","file":"chunk-NJ3IGAKR.js","sourcesContent":["import { cubicEvalAt, splitCubicAt, type CubicCoords } from '../curve';\n\n/** A 2D point, the shape the point-taking path helpers read and return. */\nexport interface Point { x: number; y: number; }\n\n/** Point on the cubic Bezier (p0, p1, p2, p3) at parameter t. The point-shaped\n * face of geom's `cubicEvalAt`. */\nexport function cubicPointAt(p0: Point, p1: Point, p2: Point, p3: Point, t: number): Point {\n const [x, y] = cubicEvalAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);\n return { x, y };\n}\n\n/** De Casteljau subdivision of a cubic at parameter t. The point-shaped face\n * of geom's `splitCubicAt`; `left[3]` and `right[0]` are the point at t. */\nexport function splitCubicAtT(\n p0: Point, p1: Point, p2: Point, p3: Point,\n t: number,\n): { left: [Point, Point, Point, Point]; right: [Point, Point, Point, Point] } {\n const [l, r] = splitCubicAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);\n const quad = (c: CubicCoords): [Point, Point, Point, Point] =>\n [{ x: c[0], y: c[1] }, { x: c[2], y: c[3] }, { x: c[4], y: c[5] }, { x: c[6], y: c[7] }];\n return { left: quad(l), right: quad(r) };\n}\n"]}
|
|
@@ -58,5 +58,5 @@ function forEachSegment(commands, coords, visit) {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export { PATH_C, PATH_CMD_LENGTHS, PATH_COMMANDS, PATH_L, PATH_M, PATH_Q, PATH_Z, forEachSegment, pathCommandCoordCount };
|
|
61
|
-
//# sourceMappingURL=chunk-
|
|
62
|
-
//# sourceMappingURL=chunk-
|
|
61
|
+
//# sourceMappingURL=chunk-OXH3NOXC.js.map
|
|
62
|
+
//# sourceMappingURL=chunk-OXH3NOXC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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,GAAO,KAAA;AACX,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,QAAA,CAAS,QAAQ,CAAA,EAAA,EAAK;AACxC,IAAA,MAAM,GAAA,GAAM,SAAS,CAAC,CAAA;AACtB,IAAA,MAAM,KAAA,GAAQ,CAAC,IAAA,IAAQ,GAAA,KAAQ,UAAU,GAAA,KAAQ,MAAA;AACjD,IAAA,IAAI,KAAA,EAAO;AAAE,MAAA,MAAA,GAAS,EAAA;AAAI,MAAA,MAAA,GAAS,EAAA;AAAA,IAAI;AACvC,IAAA,IAAA,GAAO,GAAA,KAAQ,MAAA;AACf,IAAA,IAAI,KAAA,CAAM,KAAK,EAAA,EAAI,EAAA,EAAI,IAAI,CAAA,EAAG,KAAK,MAAM,KAAA,EAAO;AAChD,IAAA,MAAM,GAAA,GAAM,sBAAsB,GAAG,CAAA;AACrC,IAAA,IAAI,QAAQ,MAAA,EAAW,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,GAAG,CAAA,CAAE,CAAA;AACpF,IAAA,IAAI,MAAM,CAAA,EAAG;AACX,MAAA,EAAA,GAAK,MAAA,CAAO,EAAA,GAAK,GAAA,GAAM,CAAC,CAAA;AACxB,MAAA,EAAA,GAAK,MAAA,CAAO,EAAA,GAAK,GAAA,GAAM,CAAC,CAAA;AACxB,MAAA,EAAA,IAAM,GAAA;AACN,MAAA,IAAI,QAAQ,MAAA,EAAQ;AAAE,QAAA,MAAA,GAAS,EAAA;AAAI,QAAA,MAAA,GAAS,EAAA;AAAA,MAAI;AAAA,IAClD,CAAA,MAAA,IAAW,QAAQ,MAAA,EAAQ;AACzB,MAAA,EAAA,GAAK,MAAA;AAAQ,MAAA,EAAA,GAAK,MAAA;AAAA,IACpB;AAAA,EACF;AACF","file":"chunk-OXH3NOXC.js","sourcesContent":["/**\n * SVG-style command-stream encoding — the kit's single declaration of the path\n * opcodes.\n *\n * The codes index a `Uint8Array` command stream whose coords live in a\n * parallel float array, so a code declared anywhere but `PATH_COMMANDS` makes\n * every walker that doesn't know it misread the coord stream from that command\n * on — silently, for every path.\n */\n\n/** Opcode table: command code and the float coords it consumes. */\nexport const PATH_COMMANDS = {\n /** moveTo — opens a new subpath. */\n M: { code: 0, coords: 2 },\n /** Straight segment from the pen to the next coord pair. */\n L: { code: 1, coords: 2 },\n /** Cubic bezier: two control points then the endpoint. */\n C: { code: 2, coords: 6 },\n /** Quadratic bezier: one control point then the endpoint. */\n Q: { code: 3, coords: 4 },\n /** Close the current subpath back to its start. Consumes no coords and\n * leaves the pen where it is. */\n Z: { code: 4, coords: 0 },\n} as const;\n\n/** Mnemonic of a declared command (`'M' | 'L' | …`). */\nexport type PathCommandName = keyof typeof PATH_COMMANDS;\n/** Numeric code of a declared command. */\nexport type PathCommandCode = (typeof PATH_COMMANDS)[PathCommandName]['code'];\n\n/** Command code of `M` (moveTo). */\nexport const PATH_M = PATH_COMMANDS.M.code;\n/** Command code of `L` (lineTo). */\nexport const PATH_L = PATH_COMMANDS.L.code;\n/** Command code of `C` (cubic bezier). */\nexport const PATH_C = PATH_COMMANDS.C.code;\n/** Command code of `Q` (quadratic bezier). */\nexport const PATH_Q = PATH_COMMANDS.Q.code;\n/** Command code of `Z` (close subpath). */\nexport const PATH_Z = PATH_COMMANDS.Z.code;\n\n/** Float coords consumed by each command, indexed by command code. */\nexport const PATH_CMD_LENGTHS: readonly number[] = buildCmdLengths();\n\nfunction buildCmdLengths(): number[] {\n const lengths: number[] = [];\n for (const { code, coords } of Object.values(PATH_COMMANDS)) lengths[code] = coords;\n return lengths;\n}\n\n/** Float coords consumed by the command with this code. */\nexport function pathCommandCoordCount(cmd: number): number {\n return PATH_CMD_LENGTHS[cmd];\n}\n\n/**\n * Visit each command with its coord offset and the pen position BEFORE the\n * command consumes its coords (the segment start). The callback stops the\n * walk by returning `false`. `Z` returns the pen to the subpath's opening `M`.\n *\n * A command following a `Z` without an intervening `M` opens a new subpath at\n * the pen, as does a drawing command no `M` precedes at all. The visitor is\n * told with `opensSubpath`, and has to start its contour at `(penX, penY)`\n * then: there is no `M` to do it.\n *\n * A code `PATH_COMMANDS` does not declare throws once the visitor has seen it.\n */\nexport function forEachSegment(\n commands: ArrayLike<number>,\n coords: ArrayLike<number>,\n visit: (\n cmd: number,\n coordIndex: number,\n penX: number,\n penY: number,\n commandIndex: number,\n opensSubpath: boolean,\n ) => void | boolean,\n): void {\n let ci = 0;\n let px = 0, py = 0;\n let startX = 0, startY = 0;\n let open = false;\n for (let i = 0; i < commands.length; i++) {\n const cmd = commands[i];\n const opens = !open && cmd !== PATH_M && cmd !== PATH_Z;\n if (opens) { startX = px; startY = py; }\n open = cmd !== PATH_Z;\n if (visit(cmd, ci, px, py, i, opens) === false) return;\n const len = pathCommandCoordCount(cmd);\n if (len === undefined) throw new Error(`forEachSegment: unknown command code ${cmd}`);\n if (len > 0) {\n px = coords[ci + len - 2];\n py = coords[ci + len - 1];\n ci += len;\n if (cmd === PATH_M) { startX = px; startY = py; }\n } else if (cmd === PATH_Z) {\n px = startX; py = startY;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A 2D point, the shape the point-taking path helpers read and return. */
|
|
2
|
+
interface Point {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
/** Point on the cubic Bezier (p0, p1, p2, p3) at parameter t. The point-shaped
|
|
7
|
+
* face of geom's `cubicEvalAt`. */
|
|
8
|
+
declare function cubicPointAt(p0: Point, p1: Point, p2: Point, p3: Point, t: number): Point;
|
|
9
|
+
/** De Casteljau subdivision of a cubic at parameter t. The point-shaped face
|
|
10
|
+
* of geom's `splitCubicAt`; `left[3]` and `right[0]` are the point at t. */
|
|
11
|
+
declare function splitCubicAtT(p0: Point, p1: Point, p2: Point, p3: Point, t: number): {
|
|
12
|
+
left: [Point, Point, Point, Point];
|
|
13
|
+
right: [Point, Point, Point, Point];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { type Point as P, cubicPointAt as c, splitCubicAtT as s };
|
package/dist/curves/index.d.ts
CHANGED
package/dist/curves/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { cubicPointAt } from '../chunk-
|
|
1
|
+
import { cubicPointAt } from '../chunk-NJ3IGAKR.js';
|
|
2
2
|
import '../chunk-URQMDR6Q.js';
|
|
3
|
-
import { PATH_M, PATH_C, PATH_L, PATH_Q } from '../chunk-
|
|
3
|
+
import { PATH_M, PATH_C, PATH_L, PATH_Q } from '../chunk-OXH3NOXC.js';
|
|
4
4
|
|
|
5
5
|
// src/curves/anchorHandles.ts
|
|
6
6
|
var DEFAULT_HANDLE_FRACTION = 1 / 3;
|