@flighthq/path 0.1.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/containsPathPoint.d.ts +13 -0
- package/dist/containsPathPoint.d.ts.map +1 -0
- package/dist/containsPathPoint.js +194 -0
- package/dist/containsPathPoint.js.map +1 -0
- package/dist/copyPath.d.ts +4 -0
- package/dist/copyPath.d.ts.map +1 -0
- package/dist/copyPath.js +28 -0
- package/dist/copyPath.js.map +1 -0
- package/dist/dashPath.d.ts +3 -0
- package/dist/dashPath.d.ts.map +1 -0
- package/dist/dashPath.js +105 -0
- package/dist/dashPath.js.map +1 -0
- package/dist/fitPathCurves.d.ts +3 -0
- package/dist/fitPathCurves.d.ts.map +1 -0
- package/dist/fitPathCurves.js +222 -0
- package/dist/fitPathCurves.js.map +1 -0
- package/dist/flattenPath.d.ts +3 -0
- package/dist/flattenPath.d.ts.map +1 -0
- package/dist/flattenPath.js +145 -0
- package/dist/flattenPath.js.map +1 -0
- package/dist/forEachPathSegment.d.ts +3 -0
- package/dist/forEachPathSegment.d.ts.map +1 -0
- package/dist/forEachPathSegment.js +66 -0
- package/dist/forEachPathSegment.js.map +1 -0
- package/dist/getPathBounds.d.ts +3 -0
- package/dist/getPathBounds.d.ts.map +1 -0
- package/dist/getPathBounds.js +167 -0
- package/dist/getPathBounds.js.map +1 -0
- package/dist/getPathContourLengths.d.ts +3 -0
- package/dist/getPathContourLengths.d.ts.map +1 -0
- package/dist/getPathContourLengths.js +21 -0
- package/dist/getPathContourLengths.js.map +1 -0
- package/dist/getPathLength.d.ts +3 -0
- package/dist/getPathLength.d.ts.map +1 -0
- package/dist/getPathLength.js +23 -0
- package/dist/getPathLength.js.map +1 -0
- package/dist/getPathNearestPoint.d.ts +3 -0
- package/dist/getPathNearestPoint.d.ts.map +1 -0
- package/dist/getPathNearestPoint.js +47 -0
- package/dist/getPathNearestPoint.js.map +1 -0
- package/dist/getPathPointAtDistance.d.ts +5 -0
- package/dist/getPathPointAtDistance.d.ts.map +1 -0
- package/dist/getPathPointAtDistance.js +100 -0
- package/dist/getPathPointAtDistance.js.map +1 -0
- package/dist/getPathSegmentAtParameter.d.ts +8 -0
- package/dist/getPathSegmentAtParameter.d.ts.map +1 -0
- package/dist/getPathSegmentAtParameter.js +163 -0
- package/dist/getPathSegmentAtParameter.js.map +1 -0
- package/dist/getPathSignedArea.d.ts +4 -0
- package/dist/getPathSignedArea.d.ts.map +1 -0
- package/dist/getPathSignedArea.js +43 -0
- package/dist/getPathSignedArea.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/offsetPath.d.ts +3 -0
- package/dist/offsetPath.d.ts.map +1 -0
- package/dist/offsetPath.js +146 -0
- package/dist/offsetPath.js.map +1 -0
- package/dist/path.d.ts +17 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +293 -0
- package/dist/path.js.map +1 -0
- package/dist/pathMeshPool.d.ts +6 -0
- package/dist/pathMeshPool.d.ts.map +1 -0
- package/dist/pathMeshPool.js +58 -0
- package/dist/pathMeshPool.js.map +1 -0
- package/dist/reversePath.d.ts +3 -0
- package/dist/reversePath.d.ts.map +1 -0
- package/dist/reversePath.js +95 -0
- package/dist/reversePath.js.map +1 -0
- package/dist/simplifyPath.d.ts +3 -0
- package/dist/simplifyPath.d.ts.map +1 -0
- package/dist/simplifyPath.js +78 -0
- package/dist/simplifyPath.js.map +1 -0
- package/dist/strokePath.d.ts +4 -0
- package/dist/strokePath.d.ts.map +1 -0
- package/dist/strokePath.js +458 -0
- package/dist/strokePath.js.map +1 -0
- package/dist/tessellatePath.d.ts +3 -0
- package/dist/tessellatePath.d.ts.map +1 -0
- package/dist/tessellatePath.js +107 -0
- package/dist/tessellatePath.js.map +1 -0
- package/dist/tessellatePathTyped.d.ts +3 -0
- package/dist/tessellatePathTyped.d.ts.map +1 -0
- package/dist/tessellatePathTyped.js +12 -0
- package/dist/tessellatePathTyped.js.map +1 -0
- package/dist/transformPath.d.ts +4 -0
- package/dist/transformPath.d.ts.map +1 -0
- package/dist/transformPath.js +62 -0
- package/dist/transformPath.js.map +1 -0
- package/package.json +37 -0
- package/src/containsPathPoint.test.ts +125 -0
- package/src/copyPath.test.ts +56 -0
- package/src/dashPath.test.ts +76 -0
- package/src/fitPathCurves.test.ts +65 -0
- package/src/flattenPath.test.ts +87 -0
- package/src/forEachPathSegment.test.ts +82 -0
- package/src/getPathBounds.test.ts +84 -0
- package/src/getPathContourLengths.test.ts +51 -0
- package/src/getPathLength.test.ts +33 -0
- package/src/getPathNearestPoint.test.ts +64 -0
- package/src/getPathPointAtDistance.test.ts +94 -0
- package/src/getPathSegmentAtParameter.test.ts +178 -0
- package/src/getPathSignedArea.test.ts +45 -0
- package/src/offsetPath.test.ts +78 -0
- package/src/path.test.ts +376 -0
- package/src/pathMeshPool.test.ts +78 -0
- package/src/reversePath.test.ts +51 -0
- package/src/simplifyPath.test.ts +69 -0
- package/src/strokePath.test.ts +150 -0
- package/src/tessellatePath.test.ts +62 -0
- package/src/tessellatePathTyped.test.ts +26 -0
- package/src/transformPath.test.ts +79 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { flattenPath } from './flattenPath';
|
|
2
|
+
// Evaluates the point on the path at `distance` arc-length units from the start, writing it into
|
|
3
|
+
// `out`. Returns `true` if the distance is within the path's total length; `false` if the path is
|
|
4
|
+
// empty, in which case `out` is left unchanged.
|
|
5
|
+
//
|
|
6
|
+
// When `distance` exceeds the total path length, the result clamps to the final endpoint.
|
|
7
|
+
// When `distance` is negative, it clamps to the first endpoint.
|
|
8
|
+
//
|
|
9
|
+
// Curves are adaptively flattened to `tolerance` before measurement.
|
|
10
|
+
export function getPathPointAtDistance(path, distance, out, tolerance = 0.25) {
|
|
11
|
+
const contours = flattenPath(path, tolerance);
|
|
12
|
+
return samplePathPoint(contours, distance, out);
|
|
13
|
+
}
|
|
14
|
+
// Evaluates both the point and the unit tangent at `distance`, writing results into `pointOut` and
|
|
15
|
+
// `tangentOut`. More efficient than calling both functions separately (one flatten pass).
|
|
16
|
+
export function getPathPositionAtDistance(path, distance, pointOut, tangentOut, tolerance = 0.25) {
|
|
17
|
+
const contours = flattenPath(path, tolerance);
|
|
18
|
+
const hasPoint = samplePathPoint(contours, distance, pointOut);
|
|
19
|
+
samplePathTangent(contours, distance, tangentOut);
|
|
20
|
+
return hasPoint;
|
|
21
|
+
}
|
|
22
|
+
// Evaluates the unit tangent direction of the path at `distance` arc-length units from the start,
|
|
23
|
+
// writing the result into `out`. Returns `true` on success, `false` for an empty path.
|
|
24
|
+
// The tangent is the normalized direction of the segment at `distance`. For degenerate zero-length
|
|
25
|
+
// segments the previous non-degenerate direction is reused; if none exists, (1, 0) is used.
|
|
26
|
+
export function getPathTangentAtDistance(path, distance, out, tolerance = 0.25) {
|
|
27
|
+
const contours = flattenPath(path, tolerance);
|
|
28
|
+
return samplePathTangent(contours, distance, out);
|
|
29
|
+
}
|
|
30
|
+
// Shared arc-length walk: finds the point at `distance` across all contours.
|
|
31
|
+
function samplePathPoint(contours, distance, out) {
|
|
32
|
+
if (contours.length === 0)
|
|
33
|
+
return false;
|
|
34
|
+
let remaining = distance;
|
|
35
|
+
for (let ci = 0; ci < contours.length; ci++) {
|
|
36
|
+
const contour = contours[ci];
|
|
37
|
+
if (contour.length < 2)
|
|
38
|
+
continue;
|
|
39
|
+
// Clamp to start of first contour.
|
|
40
|
+
if (remaining <= 0) {
|
|
41
|
+
out.x = contour[0];
|
|
42
|
+
out.y = contour[1];
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
for (let i = 2; i < contour.length; i += 2) {
|
|
46
|
+
const dx = contour[i] - contour[i - 2];
|
|
47
|
+
const dy = contour[i + 1] - contour[i - 1];
|
|
48
|
+
const segLen = Math.sqrt(dx * dx + dy * dy);
|
|
49
|
+
if (remaining <= segLen) {
|
|
50
|
+
// Interpolate along this segment.
|
|
51
|
+
const t = segLen > 0 ? remaining / segLen : 0;
|
|
52
|
+
out.x = contour[i - 2] + t * dx;
|
|
53
|
+
out.y = contour[i - 1] + t * dy;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
remaining -= segLen;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Clamped to the last endpoint.
|
|
60
|
+
const last = contours[contours.length - 1];
|
|
61
|
+
out.x = last[last.length - 2];
|
|
62
|
+
out.y = last[last.length - 1];
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
// Shared arc-length walk: finds the unit tangent at `distance` across all contours.
|
|
66
|
+
function samplePathTangent(contours, distance, out) {
|
|
67
|
+
if (contours.length === 0) {
|
|
68
|
+
out.x = 1;
|
|
69
|
+
out.y = 0;
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
let remaining = distance;
|
|
73
|
+
let lastTx = 1;
|
|
74
|
+
let lastTy = 0;
|
|
75
|
+
for (let ci = 0; ci < contours.length; ci++) {
|
|
76
|
+
const contour = contours[ci];
|
|
77
|
+
if (contour.length < 4)
|
|
78
|
+
continue;
|
|
79
|
+
for (let i = 2; i < contour.length; i += 2) {
|
|
80
|
+
const dx = contour[i] - contour[i - 2];
|
|
81
|
+
const dy = contour[i + 1] - contour[i - 1];
|
|
82
|
+
const segLen = Math.sqrt(dx * dx + dy * dy);
|
|
83
|
+
if (segLen > 0) {
|
|
84
|
+
const invLen = 1 / segLen;
|
|
85
|
+
lastTx = dx * invLen;
|
|
86
|
+
lastTy = dy * invLen;
|
|
87
|
+
}
|
|
88
|
+
if (remaining <= segLen) {
|
|
89
|
+
out.x = lastTx;
|
|
90
|
+
out.y = lastTy;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
remaining -= segLen;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
out.x = lastTx;
|
|
97
|
+
out.y = lastTy;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=getPathPointAtDistance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPathPointAtDistance.js","sourceRoot":"","sources":["../src/getPathPointAtDistance.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,iGAAiG;AACjG,kGAAkG;AAClG,gDAAgD;AAChD,EAAE;AACF,0FAA0F;AAC1F,gEAAgE;AAChE,EAAE;AACF,qEAAqE;AACrE,MAAM,UAAU,sBAAsB,CACpC,IAAoB,EACpB,QAAgB,EAChB,GAAgB,EAChB,SAAS,GAAG,IAAI;IAEhB,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9C,OAAO,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,mGAAmG;AACnG,0FAA0F;AAC1F,MAAM,UAAU,yBAAyB,CACvC,IAAoB,EACpB,QAAgB,EAChB,QAAqB,EACrB,UAAuB,EACvB,SAAS,GAAG,IAAI;IAEhB,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9C,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/D,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAClD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,kGAAkG;AAClG,uFAAuF;AACvF,mGAAmG;AACnG,4FAA4F;AAC5F,MAAM,UAAU,wBAAwB,CACtC,IAAoB,EACpB,QAAgB,EAChB,GAAgB,EAChB,SAAS,GAAG,IAAI;IAEhB,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9C,OAAO,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;AACpD,CAA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M,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACvC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;YAC5C,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;gBACf,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC;gBAC1B,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;gBACrB,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;YACvB,CAAC;YACD,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;gBACxB,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;gBACf,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;gBACf,OAAO,IAAI,CAAC;YACd,CAAC;YACD,SAAS,IAAI,MAAM,CAAC;QACtB,CAAC;IACH,CAAC;IACD,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;IACf,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;IACf,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Path, Vector2Like } from '@flighthq/types';
|
|
2
|
+
export declare function getCubicBezierPoint(x0: number, y0: number, c1x: number, c1y: number, c2x: number, c2y: number, x1: number, y1: number, t: number, out: Vector2Like): Vector2Like;
|
|
3
|
+
export declare function getCubicBezierTangent(x0: number, y0: number, c1x: number, c1y: number, c2x: number, c2y: number, x1: number, y1: number, t: number, out: Vector2Like): Vector2Like;
|
|
4
|
+
export declare function getPathSegmentPointAtParameter(path: Readonly<Path>, segmentIndex: number, t: number, out: Vector2Like): boolean;
|
|
5
|
+
export declare function getPathSegmentTangentAtParameter(path: Readonly<Path>, segmentIndex: number, t: number, out: Vector2Like): boolean;
|
|
6
|
+
export declare function getQuadraticBezierPoint(x0: number, y0: number, cx: number, cy: number, x1: number, y1: number, t: number, out: Vector2Like): Vector2Like;
|
|
7
|
+
export declare function getQuadraticBezierTangent(x0: number, y0: number, cx: number, cy: number, x1: number, y1: number, t: number, out: Vector2Like): Vector2Like;
|
|
8
|
+
//# sourceMappingURL=getPathSegmentAtParameter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPathSegmentAtParameter.d.ts","sourceRoot":"","sources":["../src/getPathSegmentAtParameter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKzD,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,GACf,WAAW,CASb;AAKD,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,GACf,WAAW,CAOb;AASD,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EACpB,YAAY,EAAE,MAAM,EACpB,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,GACf,OAAO,CAET;AAKD,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EACpB,YAAY,EAAE,MAAM,EACpB,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,GACf,OAAO,CAET;AAID,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,GACf,WAAW,CAKb;AAKD,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,CAAC,EAAE,MAAM,EACT,GAAG,EAAE,WAAW,GACf,WAAW,CAKb"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { PathCommand } from '@flighthq/types';
|
|
2
|
+
// Returns the point at parameter `t` (0..1) on a cubic bezier
|
|
3
|
+
// P0 → C1 → C2 → P1 using de Casteljau. Writes into `out`.
|
|
4
|
+
export function getCubicBezierPoint(x0, y0, c1x, c1y, c2x, c2y, x1, y1, t, out) {
|
|
5
|
+
const u = 1 - t;
|
|
6
|
+
const u2 = u * u;
|
|
7
|
+
const u3 = u2 * u;
|
|
8
|
+
const t2 = t * t;
|
|
9
|
+
const t3 = t2 * t;
|
|
10
|
+
out.x = u3 * x0 + 3 * u2 * t * c1x + 3 * u * t2 * c2x + t3 * x1;
|
|
11
|
+
out.y = u3 * y0 + 3 * u2 * t * c1y + 3 * u * t2 * c2y + t3 * y1;
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
// Returns the tangent direction at parameter `t` on a cubic bezier (first derivative).
|
|
15
|
+
// B'(t) = 3*(1-t)^2*(C1-P0) + 6*(1-t)*t*(C2-C1) + 3*t^2*(P1-C2).
|
|
16
|
+
// Writes into `out`.
|
|
17
|
+
export function getCubicBezierTangent(x0, y0, c1x, c1y, c2x, c2y, x1, y1, t, out) {
|
|
18
|
+
const u = 1 - t;
|
|
19
|
+
const u2 = u * u;
|
|
20
|
+
const t2 = t * t;
|
|
21
|
+
out.x = 3 * (u2 * (c1x - x0) + 2 * u * t * (c2x - c1x) + t2 * (x1 - c2x));
|
|
22
|
+
out.y = 3 * (u2 * (c1y - y0) + 2 * u * t * (c2y - c1y) + t2 * (y1 - c2y));
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
// Evaluates the point at parameter `t` on the n-th segment of `path` (0-indexed, counting
|
|
26
|
+
// segments in path-walk order: MOVE_TO does not count as a segment; LINE_TO, CURVE_TO,
|
|
27
|
+
// CUBIC_CURVE_TO each count as one). Writes into `out`. Returns `true` on success; `false` if
|
|
28
|
+
// `segmentIndex` is out of range.
|
|
29
|
+
//
|
|
30
|
+
// Parameter t=0 is the segment start; t=1 is the segment end. For a LINE_TO the interpolation
|
|
31
|
+
// is linear; for CURVE_TO quadratic; for CUBIC_CURVE_TO cubic.
|
|
32
|
+
export function getPathSegmentPointAtParameter(path, segmentIndex, t, out) {
|
|
33
|
+
return walkPathSegment(path, segmentIndex, t, out, false);
|
|
34
|
+
}
|
|
35
|
+
// Evaluates the tangent direction at parameter `t` on the n-th segment of `path`. The returned
|
|
36
|
+
// vector is the first derivative — callers that need a unit tangent should normalize it.
|
|
37
|
+
// Returns `true` on success; `false` if `segmentIndex` is out of range.
|
|
38
|
+
export function getPathSegmentTangentAtParameter(path, segmentIndex, t, out) {
|
|
39
|
+
return walkPathSegment(path, segmentIndex, t, out, true);
|
|
40
|
+
}
|
|
41
|
+
// Returns the point at parameter `t` (0..1) on a quadratic bezier defined by (x0,y0) → (cx,cy) → (x1,y1).
|
|
42
|
+
// Writes the result into `out` and returns `out`.
|
|
43
|
+
export function getQuadraticBezierPoint(x0, y0, cx, cy, x1, y1, t, out) {
|
|
44
|
+
const u = 1 - t;
|
|
45
|
+
out.x = u * u * x0 + 2 * u * t * cx + t * t * x1;
|
|
46
|
+
out.y = u * u * y0 + 2 * u * t * cy + t * t * y1;
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
// Returns the tangent direction (not necessarily unit length) at parameter `t` on a quadratic bezier.
|
|
50
|
+
// The tangent is the first derivative: B'(t) = 2*(1-t)*(C-P0) + 2*t*(P1-C).
|
|
51
|
+
// Writes the result into `out` and returns `out`.
|
|
52
|
+
export function getQuadraticBezierTangent(x0, y0, cx, cy, x1, y1, t, out) {
|
|
53
|
+
const u = 1 - t;
|
|
54
|
+
out.x = 2 * (u * (cx - x0) + t * (x1 - cx));
|
|
55
|
+
out.y = 2 * (u * (cy - y0) + t * (y1 - cy));
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
// Shared walker: iterates the segment stream and evaluates either the point or the tangent at t
|
|
59
|
+
// on the requested segment.
|
|
60
|
+
function walkPathSegment(path, segmentIndex, t, out, wantTangent) {
|
|
61
|
+
const commands = path.commands;
|
|
62
|
+
const data = path.data;
|
|
63
|
+
let currentSegment = 0;
|
|
64
|
+
let x = 0;
|
|
65
|
+
let y = 0;
|
|
66
|
+
let di = 0;
|
|
67
|
+
for (let ci = 0; ci < commands.length; ci++) {
|
|
68
|
+
const command = commands[ci];
|
|
69
|
+
if (command === PathCommand.MOVE_TO) {
|
|
70
|
+
x = data[di];
|
|
71
|
+
y = data[di + 1];
|
|
72
|
+
di += 2;
|
|
73
|
+
}
|
|
74
|
+
else if (command === PathCommand.WIDE_MOVE_TO) {
|
|
75
|
+
x = data[di + 2];
|
|
76
|
+
y = data[di + 3];
|
|
77
|
+
di += 4;
|
|
78
|
+
}
|
|
79
|
+
else if (command === PathCommand.LINE_TO) {
|
|
80
|
+
const x1 = data[di];
|
|
81
|
+
const y1 = data[di + 1];
|
|
82
|
+
di += 2;
|
|
83
|
+
if (currentSegment === segmentIndex) {
|
|
84
|
+
if (wantTangent) {
|
|
85
|
+
out.x = x1 - x;
|
|
86
|
+
out.y = y1 - y;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
out.x = x + t * (x1 - x);
|
|
90
|
+
out.y = y + t * (y1 - y);
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
x = x1;
|
|
95
|
+
y = y1;
|
|
96
|
+
currentSegment++;
|
|
97
|
+
}
|
|
98
|
+
else if (command === PathCommand.WIDE_LINE_TO) {
|
|
99
|
+
const x1 = data[di + 2];
|
|
100
|
+
const y1 = data[di + 3];
|
|
101
|
+
di += 4;
|
|
102
|
+
if (currentSegment === segmentIndex) {
|
|
103
|
+
if (wantTangent) {
|
|
104
|
+
out.x = x1 - x;
|
|
105
|
+
out.y = y1 - y;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
out.x = x + t * (x1 - x);
|
|
109
|
+
out.y = y + t * (y1 - y);
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
x = x1;
|
|
114
|
+
y = y1;
|
|
115
|
+
currentSegment++;
|
|
116
|
+
}
|
|
117
|
+
else if (command === PathCommand.CURVE_TO) {
|
|
118
|
+
const cx = data[di];
|
|
119
|
+
const cy = data[di + 1];
|
|
120
|
+
const x1 = data[di + 2];
|
|
121
|
+
const y1 = data[di + 3];
|
|
122
|
+
di += 4;
|
|
123
|
+
if (currentSegment === segmentIndex) {
|
|
124
|
+
if (wantTangent) {
|
|
125
|
+
getQuadraticBezierTangent(x, y, cx, cy, x1, y1, t, out);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
getQuadraticBezierPoint(x, y, cx, cy, x1, y1, t, out);
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
x = x1;
|
|
133
|
+
y = y1;
|
|
134
|
+
currentSegment++;
|
|
135
|
+
}
|
|
136
|
+
else if (command === PathCommand.CUBIC_CURVE_TO) {
|
|
137
|
+
const c1x = data[di];
|
|
138
|
+
const c1y = data[di + 1];
|
|
139
|
+
const c2x = data[di + 2];
|
|
140
|
+
const c2y = data[di + 3];
|
|
141
|
+
const x1 = data[di + 4];
|
|
142
|
+
const y1 = data[di + 5];
|
|
143
|
+
di += 6;
|
|
144
|
+
if (currentSegment === segmentIndex) {
|
|
145
|
+
if (wantTangent) {
|
|
146
|
+
getCubicBezierTangent(x, y, c1x, c1y, c2x, c2y, x1, y1, t, out);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
getCubicBezierPoint(x, y, c1x, c1y, c2x, c2y, x1, y1, t, out);
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
x = x1;
|
|
154
|
+
y = y1;
|
|
155
|
+
currentSegment++;
|
|
156
|
+
}
|
|
157
|
+
else if (command === PathCommand.CLOSE) {
|
|
158
|
+
// CLOSE is not a parametric segment.
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=getPathSegmentAtParameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPathSegmentAtParameter.js","sourceRoot":"","sources":["../src/getPathSegmentAtParameter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,8DAA8D;AAC9D,2DAA2D;AAC3D,MAAM,UAAU,mBAAmB,CACjC,EAAU,EACV,EAAU,EACV,GAAW,EACX,GAAW,EACX,GAAW,EACX,GAAW,EACX,EAAU,EACV,EAAU,EACV,CAAS,EACT,GAAgB;IAEhB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,GAAG,CAAC,CAAC,GAAG,EA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C;YACzB,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YACzB,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YACzB,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YACxB,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;YACxB,EAAE,IAAI,CAAC,CAAC;YACR,IAAI,cAAc,KAAK,YAAY,EAAE,CAAC;gBACpC,IAAI,WAAW,EAAE,CAAC;oBAChB,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;gBAClE,CAAC;qBAAM,CAAC;oBACN,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;gBAChE,CAAC;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YACD,CAAC,GAAG,EAAE,CAAC;YACP,CAAC,GAAG,EAAE,CAAC;YACP,cAAc,EAAE,CAAC;QACnB,CAAC;aAAM,IAAI,OAAO,KAAK,WAAW,CAAC,KAAK,EAAE,CAAC;YACzC,qCAAqC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Path } from '@flighthq/types';
|
|
2
|
+
export declare function getPathContourOrientation(path: Readonly<Path>, tolerance?: number): 'ccw' | 'cw' | 'degenerate';
|
|
3
|
+
export declare function getPathSignedArea(path: Readonly<Path>, tolerance?: number): number;
|
|
4
|
+
//# sourceMappingURL=getPathSignedArea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPathSignedArea.d.ts","sourceRoot":"","sources":["../src/getPathSignedArea.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAM5C,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,SAAO,GAAG,KAAK,GAAG,IAAI,GAAG,YAAY,CAO7G;AAQD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,SAAO,GAAG,MAAM,CAOhF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { flattenPath } from './flattenPath';
|
|
2
|
+
// Returns the orientation of the path's primary (first) contour: 'ccw', 'cw', or 'degenerate'
|
|
3
|
+
// (for zero-area paths such as a point or a straight line).
|
|
4
|
+
export function getPathContourOrientation(path, tolerance = 0.25) {
|
|
5
|
+
const contours = flattenPath(path, tolerance);
|
|
6
|
+
if (contours.length === 0)
|
|
7
|
+
return 'degenerate';
|
|
8
|
+
const area = shoelaceArea(contours[0]);
|
|
9
|
+
if (area > 0)
|
|
10
|
+
return 'ccw';
|
|
11
|
+
if (area < 0)
|
|
12
|
+
return 'cw';
|
|
13
|
+
return 'degenerate';
|
|
14
|
+
}
|
|
15
|
+
// Returns the signed area of the path (summed across all contours) by applying the shoelace formula
|
|
16
|
+
// to the flattened contours. Positive values indicate CCW winding (in a y-up coordinate system);
|
|
17
|
+
// negative values indicate CW winding (in y-down screen space). An empty path returns 0.
|
|
18
|
+
//
|
|
19
|
+
// The result is the algebraic (signed) area: contours that wind in opposite directions subtract
|
|
20
|
+
// from each other, which is the standard interpretation for evenOdd and nonZero fills with holes.
|
|
21
|
+
export function getPathSignedArea(path, tolerance = 0.25) {
|
|
22
|
+
const contours = flattenPath(path, tolerance);
|
|
23
|
+
let total = 0;
|
|
24
|
+
for (let ci = 0; ci < contours.length; ci++) {
|
|
25
|
+
total += shoelaceArea(contours[ci]);
|
|
26
|
+
}
|
|
27
|
+
return total;
|
|
28
|
+
}
|
|
29
|
+
// Shoelace (Gauss) formula for the signed area of a polygon given as a flat [x0,y0,x1,y1,...]
|
|
30
|
+
// coordinate array. Returns half the signed cross-product sum: positive = CCW (y-up), negative = CW.
|
|
31
|
+
function shoelaceArea(contour) {
|
|
32
|
+
const n = contour.length >> 1;
|
|
33
|
+
if (n < 3)
|
|
34
|
+
return 0;
|
|
35
|
+
let area = 0;
|
|
36
|
+
for (let i = 0; i < n; i++) {
|
|
37
|
+
const j = (i + 1) % n;
|
|
38
|
+
area += contour[i * 2] * contour[j * 2 + 1];
|
|
39
|
+
area -= contour[j * 2] * contour[i * 2 + 1];
|
|
40
|
+
}
|
|
41
|
+
return area / 2;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=getPathSignedArea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPathSignedArea.js","sourceRoot":"","sources":["../src/getPathSignedArea.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,8FAA8F;AAC9F,4DAA4D;AAC5D,MAAM,UAAU,yBAAyB,CAAC,IAAoB,EAAE,SAAS,GAAG,IAAI;IAC9E,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,YAAY,CAAC;IAC/C,MAAM,IAAI,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACvC,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC3B,IAAI,IAAI,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1B,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,oGAAoG;AACpG,iGAAiG;AACjG,yFAAyF;AACzF,EAAE;AACF,gGAAgG;AAChG,kGAAkG;AAClG,MAAM,UAAU,iBAAiB,CAAC,IAAoB,EAAE,SAAS,GAAG,IAAI;IACtE,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;QAC5C,KAAK,IAAI,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,8FAA8F;AAC9F,qGAAqG;AACrG,SAAS,YAAY,CAAC,OAA2B;IAC/C,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IACpB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5C,IAAI,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from './containsPathPoint';
|
|
2
|
+
export * from './copyPath';
|
|
3
|
+
export * from './dashPath';
|
|
4
|
+
export * from './fitPathCurves';
|
|
5
|
+
export * from './flattenPath';
|
|
6
|
+
export * from './forEachPathSegment';
|
|
7
|
+
export * from './getPathBounds';
|
|
8
|
+
export * from './getPathContourLengths';
|
|
9
|
+
export * from './getPathLength';
|
|
10
|
+
export * from './getPathNearestPoint';
|
|
11
|
+
export * from './getPathPointAtDistance';
|
|
12
|
+
export * from './getPathSegmentAtParameter';
|
|
13
|
+
export * from './getPathSignedArea';
|
|
14
|
+
export * from './offsetPath';
|
|
15
|
+
export * from './path';
|
|
16
|
+
export * from './pathMeshPool';
|
|
17
|
+
export * from './reversePath';
|
|
18
|
+
export * from './simplifyPath';
|
|
19
|
+
export * from './strokePath';
|
|
20
|
+
export * from './tessellatePath';
|
|
21
|
+
export * from './tessellatePathTyped';
|
|
22
|
+
export * from './transformPath';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from './containsPathPoint';
|
|
2
|
+
export * from './copyPath';
|
|
3
|
+
export * from './dashPath';
|
|
4
|
+
export * from './fitPathCurves';
|
|
5
|
+
export * from './flattenPath';
|
|
6
|
+
export * from './forEachPathSegment';
|
|
7
|
+
export * from './getPathBounds';
|
|
8
|
+
export * from './getPathContourLengths';
|
|
9
|
+
export * from './getPathLength';
|
|
10
|
+
export * from './getPathNearestPoint';
|
|
11
|
+
export * from './getPathPointAtDistance';
|
|
12
|
+
export * from './getPathSegmentAtParameter';
|
|
13
|
+
export * from './getPathSignedArea';
|
|
14
|
+
export * from './offsetPath';
|
|
15
|
+
export * from './path';
|
|
16
|
+
export * from './pathMeshPool';
|
|
17
|
+
export * from './reversePath';
|
|
18
|
+
export * from './simplifyPath';
|
|
19
|
+
export * from './strokePath';
|
|
20
|
+
export * from './tessellatePath';
|
|
21
|
+
export * from './tessellatePathTyped';
|
|
22
|
+
export * from './transformPath';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"offsetPath.d.ts","sourceRoot":"","sources":["../src/offsetPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAS5C,wBAAgB,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,SAAO,GAAG,IAAI,CActG"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { PathCommand } from '@flighthq/types';
|
|
2
|
+
import { flattenPath } from './flattenPath';
|
|
3
|
+
// Offsets each contour of `source` by `distance` path units (positive = outset, negative =
|
|
4
|
+
// inset). The result is a polyline approximation of the parallel curve, written into `out`.
|
|
5
|
+
// Curves are first flattened to `tolerance`, then each segment is shifted along its outward
|
|
6
|
+
// normal by `distance`. Closed contours detect winding to ensure positive = outward. Alias-safe.
|
|
7
|
+
export function offsetPath(source, distance, out, tolerance = 0.25) {
|
|
8
|
+
const contours = flattenPath(source, tolerance);
|
|
9
|
+
out.commands.length = 0;
|
|
10
|
+
out.data.length = 0;
|
|
11
|
+
out.winding = source.winding;
|
|
12
|
+
if (distance === 0) {
|
|
13
|
+
copyFlatContours(contours, out);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
for (const contour of contours) {
|
|
17
|
+
offsetContour(contour, distance, out);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function offsetContour(pts, distance, out) {
|
|
21
|
+
const n = pts.length >> 1;
|
|
22
|
+
if (n < 2)
|
|
23
|
+
return;
|
|
24
|
+
const closed = n >= 3 && pts[0] === pts[(n - 1) * 2] && pts[1] === pts[(n - 1) * 2 + 1];
|
|
25
|
+
const segCount = closed ? n - 1 : n - 1;
|
|
26
|
+
// For closed contours, determine winding so positive distance always outsets.
|
|
27
|
+
// Shoelace area > 0 → CCW (y-up) → left normals point outward.
|
|
28
|
+
// Shoelace area < 0 → CW (y-up, i.e. standard screen CW) → left normals point inward → negate.
|
|
29
|
+
let d = distance;
|
|
30
|
+
if (closed) {
|
|
31
|
+
const area = shoelace(pts, closed ? n - 1 : n);
|
|
32
|
+
if (area > 0)
|
|
33
|
+
d = -d;
|
|
34
|
+
}
|
|
35
|
+
const normals = new Float64Array(segCount * 2);
|
|
36
|
+
for (let i = 0; i < segCount; i++) {
|
|
37
|
+
const dx = pts[(i + 1) * 2] - pts[i * 2];
|
|
38
|
+
const dy = pts[(i + 1) * 2 + 1] - pts[i * 2 + 1];
|
|
39
|
+
const len = Math.sqrt(dx * dx + dy * dy);
|
|
40
|
+
if (len > 0) {
|
|
41
|
+
normals[i * 2] = -dy / len;
|
|
42
|
+
normals[i * 2 + 1] = dx / len;
|
|
43
|
+
}
|
|
44
|
+
else if (i > 0) {
|
|
45
|
+
normals[i * 2] = normals[(i - 1) * 2];
|
|
46
|
+
normals[i * 2 + 1] = normals[(i - 1) * 2 + 1];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
normals[i * 2] = 0;
|
|
50
|
+
normals[i * 2 + 1] = 1;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const result = [];
|
|
54
|
+
if (closed) {
|
|
55
|
+
addOffsetJoin(pts, 0, normals, segCount - 1, 0, d, result);
|
|
56
|
+
for (let i = 1; i < segCount; i++) {
|
|
57
|
+
addOffsetJoin(pts, i, normals, i - 1, i, d, result);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
result.push(pts[0] + normals[0] * d, pts[1] + normals[1] * d);
|
|
62
|
+
for (let i = 1; i < n - 1; i++) {
|
|
63
|
+
addOffsetJoin(pts, i, normals, i - 1, i, d, result);
|
|
64
|
+
}
|
|
65
|
+
result.push(pts[(n - 1) * 2] + normals[(segCount - 1) * 2] * d, pts[(n - 1) * 2 + 1] + normals[(segCount - 1) * 2 + 1] * d);
|
|
66
|
+
}
|
|
67
|
+
if (result.length < 4)
|
|
68
|
+
return;
|
|
69
|
+
out.commands.push(PathCommand.MOVE_TO);
|
|
70
|
+
out.data.push(result[0], result[1]);
|
|
71
|
+
for (let i = 2; i < result.length; i += 2) {
|
|
72
|
+
out.commands.push(PathCommand.LINE_TO);
|
|
73
|
+
out.data.push(result[i], result[i + 1]);
|
|
74
|
+
}
|
|
75
|
+
if (closed)
|
|
76
|
+
out.commands.push(PathCommand.CLOSE);
|
|
77
|
+
}
|
|
78
|
+
function addOffsetJoin(pts, ptIdx, normals, seg0, seg1, distance, result) {
|
|
79
|
+
const px = pts[ptIdx * 2];
|
|
80
|
+
const py = pts[ptIdx * 2 + 1];
|
|
81
|
+
const n0x = normals[seg0 * 2];
|
|
82
|
+
const n0y = normals[seg0 * 2 + 1];
|
|
83
|
+
const n1x = normals[seg1 * 2];
|
|
84
|
+
const n1y = normals[seg1 * 2 + 1];
|
|
85
|
+
const cross = n0x * n1y - n0y * n1x;
|
|
86
|
+
if (Math.abs(cross) < 1e-8) {
|
|
87
|
+
result.push(px + n0x * distance, py + n0y * distance);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Segment directions: perpendicular to normal, (ny, -nx).
|
|
91
|
+
const d0x = n0y;
|
|
92
|
+
const d0y = -n0x;
|
|
93
|
+
const ox0 = px + n0x * distance;
|
|
94
|
+
const oy0 = py + n0y * distance;
|
|
95
|
+
const ox1 = px + n1x * distance;
|
|
96
|
+
const oy1 = py + n1y * distance;
|
|
97
|
+
// Intersect: ox0 + s*d0 = ox1 + t*d1
|
|
98
|
+
const dpx = ox1 - ox0;
|
|
99
|
+
const dpy = oy1 - oy0;
|
|
100
|
+
const d1x = n1y;
|
|
101
|
+
const d1y = -n1x;
|
|
102
|
+
const det = d0x * d1y - d0y * d1x;
|
|
103
|
+
if (Math.abs(det) < 1e-12) {
|
|
104
|
+
result.push(px + n0x * distance, py + n0y * distance);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const s = (dpx * d1y - dpy * d1x) / det;
|
|
108
|
+
const mx = ox0 + s * d0x;
|
|
109
|
+
const my = oy0 + s * d0y;
|
|
110
|
+
const miterDistSq = (mx - px) * (mx - px) + (my - py) * (my - py);
|
|
111
|
+
const absDist = Math.abs(distance);
|
|
112
|
+
const limitSq = absDist * 4 * (absDist * 4);
|
|
113
|
+
if (miterDistSq <= limitSq) {
|
|
114
|
+
result.push(mx, my);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
result.push(ox0, oy0, ox1, oy1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function copyFlatContours(contours, out) {
|
|
121
|
+
for (const contour of contours) {
|
|
122
|
+
const n = contour.length >> 1;
|
|
123
|
+
if (n < 2)
|
|
124
|
+
continue;
|
|
125
|
+
const closed = n >= 3 && contour[0] === contour[(n - 1) * 2] && contour[1] === contour[(n - 1) * 2 + 1];
|
|
126
|
+
out.commands.push(PathCommand.MOVE_TO);
|
|
127
|
+
out.data.push(contour[0], contour[1]);
|
|
128
|
+
const last = closed ? n - 1 : n;
|
|
129
|
+
for (let i = 1; i < last; i++) {
|
|
130
|
+
out.commands.push(PathCommand.LINE_TO);
|
|
131
|
+
out.data.push(contour[i * 2], contour[i * 2 + 1]);
|
|
132
|
+
}
|
|
133
|
+
if (closed)
|
|
134
|
+
out.commands.push(PathCommand.CLOSE);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function shoelace(pts, n) {
|
|
138
|
+
let area = 0;
|
|
139
|
+
for (let i = 0; i < n; i++) {
|
|
140
|
+
const j = (i + 1) % n;
|
|
141
|
+
area += pts[i * 2] * pts[j * 2 + 1];
|
|
142
|
+
area -= pts[j * 2] * pts[i * 2 + 1];
|
|
143
|
+
}
|
|
144
|
+
return area / 2;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=offsetPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACpC,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,GAAG,CAAC,CAAC;AAClB,CAAC"}
|
package/dist/path.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Path, PathWinding } from '@flighthq/types';
|
|
2
|
+
export declare function appendPathArc(path: Path, cx: number, cy: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean, connectToCurrent?: boolean): void;
|
|
3
|
+
export declare function appendPathArcTo(path: Path, radiusX: number, radiusY: number, xAxisRotation: number, largeArc: boolean, sweep: boolean, endX: number, endY: number): void;
|
|
4
|
+
export declare function appendPathCircle(path: Path, cx: number, cy: number, radius: number): void;
|
|
5
|
+
export declare function appendPathClose(path: Path): void;
|
|
6
|
+
export declare function appendPathCubicCurveTo(path: Path, control1X: number, control1Y: number, control2X: number, control2Y: number, anchorX: number, anchorY: number): void;
|
|
7
|
+
export declare function appendPathCurveTo(path: Path, controlX: number, controlY: number, anchorX: number, anchorY: number): void;
|
|
8
|
+
export declare function appendPathEllipse(path: Path, cx: number, cy: number, radiusX: number, radiusY: number): void;
|
|
9
|
+
export declare function appendPathLineTo(path: Path, x: number, y: number): void;
|
|
10
|
+
export declare function appendPathMoveTo(path: Path, x: number, y: number): void;
|
|
11
|
+
export declare function appendPathPolygon(path: Path, points: Readonly<number[]>): void;
|
|
12
|
+
export declare function appendPathPolyline(path: Path, points: Readonly<number[]>): void;
|
|
13
|
+
export declare function appendPathRectangle(path: Path, x: number, y: number, width: number, height: number): void;
|
|
14
|
+
export declare function appendPathRoundRectangle(path: Path, x: number, y: number, width: number, height: number, radius: number | [number, number, number, number]): void;
|
|
15
|
+
export declare function createPath(winding?: PathWinding): Path;
|
|
16
|
+
export declare function getPathLastPoint(path: Readonly<Path>): [number, number] | null;
|
|
17
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AASzD,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,aAAa,UAAQ,EACrB,gBAAgB,UAAQ,GACvB,IAAI,CAiBN;AAWD,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACX,IAAI,CA8DN;AAKD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAEzF;AAID,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAEhD;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,IAAI,CAGN;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,IAAI,CAGN;AAK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