svg-path-commander 2.3.5 → 2.4.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/AGENTS.md +141 -10
- package/CHANGELOG.md +236 -0
- package/CLAUDE.md +1 -0
- package/README.md +156 -24
- package/dist/index.d.ts +475 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3505 -671
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/util.d.ts +322 -33
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +3301 -649
- package/dist/util.js.map +1 -1
- package/llms.txt +100 -0
- package/package.json +5 -3
package/AGENTS.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Project Overview
|
|
4
4
|
|
|
5
|
-
SVGPathCommander v2.
|
|
5
|
+
SVGPathCommander v2.4.0 — TypeScript library for manipulating SVG `<path>` `d` attributes. Works in browser and Node.js.
|
|
6
6
|
|
|
7
7
|
## Commands
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ vpr test:ui # Run tests with UI and --watch option
|
|
|
14
14
|
vpr test:watch # Run tests with --watch option
|
|
15
15
|
vpr test -- class.test.ts # Run a single test file
|
|
16
16
|
vpr test -- -t "Test name" # Run a single test by name
|
|
17
|
-
vpr bench # Benchmark vs svgpath (
|
|
17
|
+
vpr bench # Benchmark vs svgpath (prints the table; --write updates the README)
|
|
18
18
|
vpr lint # oxlint src + tsc --noEmit
|
|
19
19
|
vpr lint:ts # oxlint src
|
|
20
20
|
vpr fix:ts # oxlint src --fix
|
|
@@ -25,6 +25,10 @@ vpr check:ts # tsc --noEmit (type check only)
|
|
|
25
25
|
|
|
26
26
|
Always run `vpr lint` and `vpr test` after making changes.
|
|
27
27
|
|
|
28
|
+
The benchmark harness measures with `performance.now()` and reports the median and the best of 30
|
|
29
|
+
runs; it only rewrites the README when `--write` is passed, so a plain `vpr bench` leaves the
|
|
30
|
+
working tree clean.
|
|
31
|
+
|
|
28
32
|
Deno equivalents (via `deno.json`):
|
|
29
33
|
|
|
30
34
|
```bash
|
|
@@ -53,7 +57,7 @@ Keep the `paths` filters of all three workflows in sync when adding a file that
|
|
|
53
57
|
- **Test:** Vitest 5 in **browser mode** (Playwright + Chromium, headless) + Istanbul coverage (`test/class.test.ts`, `test/static.test.ts`)
|
|
54
58
|
- **Lint/Format:** Vite+ (oxlint / oxfmt via `vp lint src` and `vp fmt src`) — not Deno; `deno lint` / `deno fmt` still gate the JSR publish
|
|
55
59
|
- **JSR:** `deno.json` publishes as `@thednp/svg-path-commander` — `deno check src`, `deno lint src` and `deno publish --dry-run --allow-dirty` must all pass
|
|
56
|
-
- **Dependency:** `@thednp/dommatrix` `^3.1.
|
|
60
|
+
- **Dependency:** `@thednp/dommatrix` `^3.1.4` (DOMMatrix shim)
|
|
57
61
|
|
|
58
62
|
## Source Structure (`src/`)
|
|
59
63
|
|
|
@@ -63,7 +67,9 @@ Keep the `paths` filters of all three workflows in sync when adding a file that
|
|
|
63
67
|
| `main.ts` | SVGPathCommander class (core, chainable instance methods) |
|
|
64
68
|
| `types.ts` | TypeScript type definitions (PathCommand, PathSegment, PathArray, etc.) |
|
|
65
69
|
| `interface.ts` | Interfaces (Options, TransformObject, PathBBox, shape attrs) |
|
|
66
|
-
| `util.ts` | Re-export of
|
|
70
|
+
| `util.ts` | Re-export of every standalone tool (tree-shakeable entry) |
|
|
71
|
+
| `morph.ts` | Internal barrel for the morphing tools |
|
|
72
|
+
| `intersect.ts` | Internal barrel for the intersection tools |
|
|
67
73
|
| `convert/` | Path format conversion (absolute, relative, curve, string) |
|
|
68
74
|
| `parser/` | SVG path string tokenizer/scanner |
|
|
69
75
|
| `process/` | Manipulation algorithms (normalize, optimize, reverse, transform, etc.) |
|
|
@@ -72,6 +78,92 @@ Keep the `paths` filters of all three workflows in sync when adding a file that
|
|
|
72
78
|
| `util/` | Query helpers (bbox, length, point-at-length, intersection, etc.) |
|
|
73
79
|
| `options/` | Default configuration |
|
|
74
80
|
|
|
81
|
+
The library ships two entry points:
|
|
82
|
+
|
|
83
|
+
| Entry point | Source | Holds |
|
|
84
|
+
| ------------------------- | -------------- | ----------------------------------------------- |
|
|
85
|
+
| `svg-path-commander` | `src/index.ts` | the class, its static methods and all the types |
|
|
86
|
+
| `svg-path-commander/util` | `src/util.ts` | every standalone tool |
|
|
87
|
+
|
|
88
|
+
The utility entry includes the morphing and intersection tools through the internal `src/morph.ts` and
|
|
89
|
+
`src/intersect.ts` barrels. The class holds every engine as a static field (`static equalize = equalize;`),
|
|
90
|
+
so the main entry always includes those implementations. A bundler drops the unused standalone exports
|
|
91
|
+
from the utility entry. The package and JSR exports maps must expose the same two entry points.
|
|
92
|
+
|
|
93
|
+
The curve-preserving simplification lives in `process/` and is built from five modules:
|
|
94
|
+
|
|
95
|
+
| Module | Purpose |
|
|
96
|
+
| --------------------------- | -------------------------------------------------------------------- |
|
|
97
|
+
| `process/simplifyPath.ts` | The public API — normalizes, splits and rebuilds the simplified path |
|
|
98
|
+
| `process/samplePath.ts` | Samples a normalized path along its own parameterization |
|
|
99
|
+
| `process/douglasPeucker.ts` | The Douglas-Peucker core — the indexes of the points to keep |
|
|
100
|
+
| `process/fitCubic.ts` | Adaptive Schneider cubic fitting for the sampled curve runs |
|
|
101
|
+
| `process/splitSubPaths.ts` | Splits an already normalized path into its sub-paths |
|
|
102
|
+
|
|
103
|
+
Only `simplifyPath` is public — it is re-exported from `src/util.ts`. The internal
|
|
104
|
+
`splitSubPaths` helper is shared with the resampler: it operates on an already normalized path and
|
|
105
|
+
does not parse or absolutize it again. It is distinct from the public `splitPath`, whose contract is
|
|
106
|
+
to parse a path of any command form and return absolute path arrays.
|
|
107
|
+
|
|
108
|
+
The path offsetting lives in `process/` and is built from three modules:
|
|
109
|
+
|
|
110
|
+
| Module | Purpose |
|
|
111
|
+
| ------------------------ | ----------------------------------------------------------------------- |
|
|
112
|
+
| `process/offsetPath.ts` | The public API — measures the path, offsets it and assembles the result |
|
|
113
|
+
| `process/offsetNodes.ts` | Samples the segments of a sub-path into points with their tangent |
|
|
114
|
+
| `process/offsetJoin.ts` | The join and the cap geometry — the miter, the bevel and the round arc |
|
|
115
|
+
|
|
116
|
+
Only `offsetPath` is public — it is re-exported from `src/util.ts`. The offset reuses the frame of
|
|
117
|
+
`util/segmentFrame.ts`, so the normal of a sample is the normal `getPropertiesAtLength()` returns.
|
|
118
|
+
The offset is not cleaned up: an offset distance larger than the local radius of curvature produces
|
|
119
|
+
a self-crossing curve, and the removal of the self-intersections needs a polygon clipping pass.
|
|
120
|
+
|
|
121
|
+
The hit test of a filled shape lives in `util/` and is built from three modules:
|
|
122
|
+
|
|
123
|
+
| Module | Purpose |
|
|
124
|
+
| ------------------------ | ----------------------------------------------------------------------------- |
|
|
125
|
+
| `util/isPointInPath.ts` | The public API — validates the options, flattens the path and tests the point |
|
|
126
|
+
| `process/flattenPath.ts` | Flattens a curve path into one polygon per sub-path, within a tolerance |
|
|
127
|
+
| `math/pointInPolygon.ts` | The crossings, the winding number and the boundary test of a polygon |
|
|
128
|
+
|
|
129
|
+
Only `isPointInPath` is public — it is re-exported from `src/util.ts`. The `nonzero` and the
|
|
130
|
+
`evenodd` fill rules of the SVG `fill-rule` attribute are both supported, and a point on the
|
|
131
|
+
boundary of a shape is inside of it, the way the browser answers it with `isPointInFill()`. The
|
|
132
|
+
answer is checked against the browser in `test/static.test.ts`, with a fixed set of points and
|
|
133
|
+
with a seeded sweep of the points, so the two answers cannot drift apart.
|
|
134
|
+
|
|
135
|
+
The morphing toolkit lives in `morph/` and is built from four modules:
|
|
136
|
+
|
|
137
|
+
| Module | Purpose |
|
|
138
|
+
| --------------------------- | ---------------------------------------------------------------------------- |
|
|
139
|
+
| `morph/equalize.ts` | The public facade — routes single and multi sub-path pairs to the right tool |
|
|
140
|
+
| `morph/equalizePaths.ts` | Splits the paths into sub-paths, matches them and equalizes every pair |
|
|
141
|
+
| `morph/equalizeSegments.ts` | Equalizes a single sub-path pair, with the `segment` or `arcLength` strategy |
|
|
142
|
+
| `morph/resamplePath.ts` | Resamples every sub-path to a given number of points, spread over its length |
|
|
143
|
+
|
|
144
|
+
`equalize` and `resamplePath` are public — they are re-exported through `src/morph.ts` and
|
|
145
|
+
`src/util.ts`, next to the `equalizeSegments` and `equalizePaths` they build on. The public resampler
|
|
146
|
+
uses the shared `splitSubPaths` helper: every sub-path is resampled on its own, `count` is the number
|
|
147
|
+
of points of each sub-path, and the result never connects two sub-paths. The public result type is
|
|
148
|
+
`PathArray`, because a multi-subpath result holds more than one `M` command.
|
|
149
|
+
|
|
150
|
+
Two modules in `util/` are the backbone of the length machinery and are shared by every query:
|
|
151
|
+
|
|
152
|
+
| Module | Purpose |
|
|
153
|
+
| ------------------------- | ---------------------------------------------------------------------------- |
|
|
154
|
+
| `util/measureSegments.ts` | One pass that measures every segment and the length accumulated before it |
|
|
155
|
+
| `util/pathLengthTable.ts` | The measured path as a searchable table (lengths + start points + endpoints) |
|
|
156
|
+
|
|
157
|
+
A third one answers the frame of the path at a given length:
|
|
158
|
+
|
|
159
|
+
| Module | Purpose |
|
|
160
|
+
| ---------------------- | ----------------------------------------------------------------------- |
|
|
161
|
+
| `util/segmentFrame.ts` | The point, the unit tangent, the unit normal and the angle of a segment |
|
|
162
|
+
|
|
163
|
+
All three are internal — they are not re-exported from `src/util.ts`, and a new public export has
|
|
164
|
+
to be added to `src/util.ts` **and** to the `exports` map in `deno.json` (the JSR package has its
|
|
165
|
+
own map).
|
|
166
|
+
|
|
75
167
|
## Code Conventions
|
|
76
168
|
|
|
77
169
|
### Imports
|
|
@@ -111,6 +203,25 @@ Keep the `paths` filters of all three workflows in sync when adding a file that
|
|
|
111
203
|
- Validate inputs early, fail fast with clear messages
|
|
112
204
|
- Static methods return safe defaults for empty/invalid input (e.g., `getPathBBox('')`)
|
|
113
205
|
|
|
206
|
+
### Empty and Malformed Input
|
|
207
|
+
|
|
208
|
+
The contract is fixed — do not change it without a changelog entry:
|
|
209
|
+
|
|
210
|
+
| Input | Answer |
|
|
211
|
+
| ----------------------------------- | --------------------------------------------------------- |
|
|
212
|
+
| empty path | zeroed bbox / `{x:0,y:0}` / `false` / `undefined` segment |
|
|
213
|
+
| empty path, `getPropertiesAtLength` | a synthetic `["M", 0, 0]` segment, `index: 0` |
|
|
214
|
+
| empty path, `getPropertiesAtPoint` | `{ closest: {x:0,y:0}, distance: Infinity }` |
|
|
215
|
+
| negative distance | the same early return as a distance of `0` |
|
|
216
|
+
| malformed segment (`[[]]`) | `TypeError: invalid path segment at index N` |
|
|
217
|
+
| a path that does not begin with `M` | `TypeError: path data must begin with a moveto command` |
|
|
218
|
+
|
|
219
|
+
A leading relative moveto is the one exception to the last row — it is a pair of absolute
|
|
220
|
+
coordinates, so the parser rewrites it as an absolute one.
|
|
221
|
+
|
|
222
|
+
Static methods never modify the data they are given — `roundPath`, `matchPaths` and `transformPath`
|
|
223
|
+
all work on copies, and the transform origin is copied before it is written to.
|
|
224
|
+
|
|
114
225
|
### Class Design
|
|
115
226
|
|
|
116
227
|
- Instance methods are chainable — always `return this`
|
|
@@ -121,10 +232,11 @@ Keep the `paths` filters of all three workflows in sync when adding a file that
|
|
|
121
232
|
### Testing
|
|
122
233
|
|
|
123
234
|
- Tests run with Vitest + Istanbul coverage via `vpr test`
|
|
124
|
-
- Test files: `test/class.test.ts` (instance API), `test/static.test.ts` (static methods)
|
|
235
|
+
- Test files: `test/class.test.ts` (instance API), `test/static.test.ts` (static methods),
|
|
236
|
+
`test/getPropertiesAtLength.parity.test.ts` (the parity of the length lookup)
|
|
125
237
|
- Fixtures in `test/fixtures/`
|
|
126
238
|
- Use `expect().to.deep.equal()` for object comparison, `expect().to.equal()` for primitives
|
|
127
|
-
- Coverage provider: Istanbul
|
|
239
|
+
- Coverage provider: Istanbul — the suite has to stay at 100 %
|
|
128
240
|
|
|
129
241
|
## Build Outputs
|
|
130
242
|
|
|
@@ -132,9 +244,27 @@ Keep the `paths` filters of all three workflows in sync when adding a file that
|
|
|
132
244
|
| ------------------- | -------------------------------------------------------- |
|
|
133
245
|
| `dist/index.min.js` | UMD bundle (minified, browser-ready, includes dommatrix) |
|
|
134
246
|
| `dist/index.js` | ESM bundle (tree-shakeable, neutral platform) |
|
|
135
|
-
| `dist/util.js` |
|
|
247
|
+
| `dist/util.js` | Every standalone tool (tree-shakeable) |
|
|
136
248
|
| `dist/index.d.ts` | Type declarations |
|
|
137
249
|
|
|
250
|
+
The main and utility entry points are built on their own, so a bundle never depends on a chunk of
|
|
251
|
+
another one.
|
|
252
|
+
|
|
253
|
+
## Releases
|
|
254
|
+
|
|
255
|
+
- The version lives in `package.json` and is mirrored into `deno.json` — `node scripts/update-deno.js`
|
|
256
|
+
syncs it (the script rewrites `deno.json` with `JSON.stringify`, so run `deno fmt deno.json` after
|
|
257
|
+
it to keep the formatting).
|
|
258
|
+
- Every release needs a `CHANGELOG.md` entry; the entry lists the _behaviour_, not the commits.
|
|
259
|
+
- `dist/` and `docs/` are committed build artifacts — rebuild them (`vpr build`) with the release
|
|
260
|
+
commit, never separately.
|
|
261
|
+
- Publishing happens from the GitHub Release workflow (`publish.yml`); the npm publish runs with
|
|
262
|
+
`--ignore-scripts` so the committed sources are what ships, and the JSR publish runs
|
|
263
|
+
`deno publish --allow-dirty` against the same sources.
|
|
264
|
+
- `prepublishOnly` (`vp up --latest && vpr up:deno && ...`) is a **dependency bump**, not a release
|
|
265
|
+
step — it moves the Vitest pins off the version Vite+ bundles. Keep the `catalog:` pins aligned
|
|
266
|
+
with `vp toolchain vitest` instead.
|
|
267
|
+
|
|
138
268
|
<!--VITE PLUS START-->
|
|
139
269
|
|
|
140
270
|
# Using Vite+, the Unified Toolchain for the Web
|
|
@@ -168,13 +298,14 @@ release. Add a tool name to select part of the graph. For example, run
|
|
|
168
298
|
<!--VITE PLUS END-->
|
|
169
299
|
|
|
170
300
|
## Workflow notes
|
|
301
|
+
|
|
171
302
|
- **Harness folders**: dev repro/harness scaffolding (debugging the Vite plugin,
|
|
172
303
|
a compiler, or the browser) goes in `TMP/`; fixtures imported by vitest suites
|
|
173
|
-
go in `
|
|
304
|
+
go in `test/fixtures/` — **never** in the root or in OS temp dirs. Root-level
|
|
174
305
|
harness files break `tsdown`/`vitest` path resolution, and temp dirs outside
|
|
175
306
|
the project get swept by OS cleaners and leave stale `node_modules`/`.vite`
|
|
176
|
-
state that corrupts the next run. (`
|
|
177
|
-
`vp lint` + `tsc` like the rest of `
|
|
307
|
+
state that corrupts the next run. (`test/fixtures/` is covered by
|
|
308
|
+
`vp lint` + `tsc` like the rest of `test/` — keep fixtures valid;
|
|
178
309
|
intentionally-broken inputs don't belong there.)
|
|
179
310
|
- **Never delete files**: do not `rm` source/test files. If a file must be
|
|
180
311
|
removed from the tree, **rename it to `<name>-bak.<ext>`** (e.g. `foo.ts` →
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,241 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.4.0] - 2026-11-23
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- The parser rejects a path that does not begin with a moveto command — `parsePathString()` relabelled the first segment of every path as an `M`, whatever it was, without touching its parameter list, so `"h10"` became `[["M",10]]` and `"C1 2 3 4 5 6"` became `[["M",1,2,3,4,5,6]]`; the damage downstream was silent and numeric (`getPathBBox("h10")` answered a box with a `NaN` height, `getTotalLength("A5 5 0 0 1 10 10")` answered zero for an arc that is 15.7 units long). The rewrite was written for one case — the leading relative moveto of PR #49, which is a pair of absolute coordinates — and it was over-generalised to every first command. The leading `m` is rewritten and every other first command is rejected with a `TypeError`, for a path string and for a path array alike, so the parser agrees with `isValidPath()` and with the SVG spec, where a path that does not begin with a moveto is in error:
|
|
8
|
+
```js
|
|
9
|
+
SVGPathCommander.parsePathString("m10 10");
|
|
10
|
+
// => [["M", 10, 10]] — the leading relative moveto is a pair of absolute coordinates
|
|
11
|
+
SVGPathCommander.parsePathString("L10 10");
|
|
12
|
+
// => TypeError: SVGPathCommanderError: path data must begin with a moveto command
|
|
13
|
+
```
|
|
14
|
+
- `segmentToCubic()` returns a `PathSegment` — the function declared that it returns an `MSegment` or a `CSegment`, but it returns every other segment unchanged: the smooth cubic, the smooth quadratic, the horizontal and the vertical lineto fall through to the last line of the function. The declaration was a lie that the cast at that line told the type system to believe.
|
|
15
|
+
- `resamplePath()` returns a `PathArray` — a multi-subpath result holds one `M` command for every source sub-path, so the narrower `MorphPathArray` type could not describe the result. The single-subpath helper keeps its morph-specific type.
|
|
16
|
+
- `equalize()` and `equalizePaths()` return `PathArray` tuples — a multi-subpath result holds one `M` command for every matched contour, so the narrower `MorphPathArray` type could not describe the result. `equalizeSegments()` keeps its morph-specific type because it only accepts single-subpath paths.
|
|
17
|
+
- `fixPath()` returns the fixed path instead of `void` — the helper documents that it removes an unnecessary closing segment, but `parsePathString()` clones an array input, so the old in-place splice never reached the caller's array and the return value was `undefined`. The helper now returns a fixed copy and leaves the source path unchanged; `equalizeSegments()` consumes that copy, so the redundant `Z` is actually removed before equalization.
|
|
18
|
+
- The morphing tools preserve input closure by default instead of leaving the result open — every closed contour now retains its `Z` command, open paths stay open, and a closed/open pair is closed on both sides to keep the commands compatible. Pass `close: false` to restore the previous open-result behavior.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `offsetPath()` — the offsetting of a path along its normals: the path is sampled along its length, every sample is shifted along the normal of the path, and the result is a path of straight lines. The `side` option is literal — the left side is the left normal of the direction of travel, the same normal `getPropertiesAtLength()` returns — and the `both` side is the outline of the stroke, the band between the two sides of the path:
|
|
23
|
+
```js
|
|
24
|
+
SVGPathCommander.offsetPath("M0 0L100 0", 10);
|
|
25
|
+
// => [["M", 0, 10], ["L", 100, 10]]
|
|
26
|
+
SVGPathCommander.offsetPath("M0 0L100 0", 10, { side: "both" });
|
|
27
|
+
// => [["M", 0, 10], ["L", 100, 10], ["L", 100, -10], ["L", 0, -10], ["Z"]]
|
|
28
|
+
```
|
|
29
|
+
- The offset accepts the `join` option (`"miter"`, the default, `"bevel"` or `"round"`), the `miterLimit` option (the ratio of the miter length to the offset distance, `4` by default), the `cap` option (`"butt"`, the default, `"square"` or `"round"`), the `steps` option (the number of the intervals a curve is sampled with, `16` by default) and the `precision` option (the number of the decimals of the result, `4` by default). The defaults are the initial values of the SVG presentation attributes.
|
|
30
|
+
- `SVGPathCommander#offset(distance, options)` — the instance method of the offset, the counterpart of `simplify()`:
|
|
31
|
+
```js
|
|
32
|
+
new SVGPathCommander("M0 0L100 0").offset(10).toString();
|
|
33
|
+
// => "M0 10L100 10"
|
|
34
|
+
```
|
|
35
|
+
- `joinPath()` — the joining of two paths into a single path with two sub-paths:
|
|
36
|
+
```js
|
|
37
|
+
SVGPathCommander.joinPath("M0 0L100 0", "M0 100L100 100");
|
|
38
|
+
// => [["M", 0, 0], ["L", 100, 0], ["M", 0, 100], ["L", 100, 100]]
|
|
39
|
+
```
|
|
40
|
+
- `reverseSubPath()` — the reversing of one sub-path of a path, the other sub-paths are left untouched:
|
|
41
|
+
```js
|
|
42
|
+
SVGPathCommander.reverseSubPath("M0 0L100 0ZM0 100L100 100", 1);
|
|
43
|
+
// => [["M", 0, 0], ["L", 100, 0], ["Z"], ["M", 100, 100], ["L", 0, 100]]
|
|
44
|
+
```
|
|
45
|
+
- `SVGPathCommander#join(path)` and `SVGPathCommander#reverseSubPath(index)` — the instance methods of the two, chainable like the rest of the class API
|
|
46
|
+
- `isPointInPath()` — the hit test of a filled shape: the path is flattened into polygons and the point is tested against them with the `nonzero` or the `evenodd` fill rule, the two rules of the SVG `fill-rule` attribute:
|
|
47
|
+
```js
|
|
48
|
+
SVGPathCommander.isPointInPath("M0 0L100 0L100 100L0 100Z", { x: 50, y: 50 });
|
|
49
|
+
// => true
|
|
50
|
+
SVGPathCommander.isPointInPath(
|
|
51
|
+
"M0 0L100 0L100 100L0 100ZM25 25L75 25L75 75L25 75Z",
|
|
52
|
+
{ x: 50, y: 50 },
|
|
53
|
+
{
|
|
54
|
+
fillRule: "evenodd",
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
// => false — the inner square is a hole with the evenodd rule
|
|
58
|
+
```
|
|
59
|
+
A point on the boundary of the shape is inside of it, the way the browser answers it with `isPointInFill()`, and the curves of the path are approximated with chords, so the answer can differ from the exact geometry for the points that are within the `tolerance` (0.1 by default) of the boundary of a curve.
|
|
60
|
+
- `SVGPathCommander#isPointInPath(point, options)` — the instance method of the hit test, the counterpart of `isPointInStroke()`
|
|
61
|
+
- `isPointInStroke()` accepts the `width` option — the tool answered whether a point is _on_ the path, which is the path itself and not the band a stroke paints around it, so the hit test of a stroked shape was impossible. With a width the stroke is the band around the path: the point is in the stroke when it is at most half the width away from the path. The ends of an open path are treated as if the stroke had round caps:
|
|
62
|
+
```js
|
|
63
|
+
SVGPathCommander.isPointInStroke("M0 0L100 0", { x: 50, y: 5 });
|
|
64
|
+
// => false — the point is not on the path
|
|
65
|
+
SVGPathCommander.isPointInStroke("M0 0L100 0", { x: 50, y: 5 }, { width: 10 });
|
|
66
|
+
// => true — the point is inside the stroke
|
|
67
|
+
```
|
|
68
|
+
The answer without a width is the same as before, so the change is additive.
|
|
69
|
+
|
|
70
|
+
### Fixed
|
|
71
|
+
|
|
72
|
+
- `equalize()` preserves the input closure by default — closed contours keep their `Z` command through both strategies, including every contour of a multi-subpath result, so the final morph frame no longer acquires a spurious open-path join. Open inputs stay open, a closed/open pair is closed on both sides to keep the commands compatible, and `close: false` remains the explicit opt-out
|
|
73
|
+
- Multi-subpath morphing matches outer contours only to outer contours and holes only to holes — an unmatched contour collapses at its own centroid instead of taking the opposite fill role, so target holes no longer disappear in the intermediate frames
|
|
74
|
+
- Morph rotation scores every corresponding coordinate, including Bézier control points, instead of scoring only the endpoints — the arc-length strategy no longer chooses a rotation with matching vertices but twisted curve handles
|
|
75
|
+
- `getPathBBox()` and `arcTools.getArcBBox()` answer the bounds of an arc correctly — the bounds were computed from the end point of the arc and the extrema of the ellipse, so the **start point of the arc was dropped** and the box of an arc did not contain the arc:
|
|
76
|
+
```js
|
|
77
|
+
SVGPathCommander.arcTools.getArcBBox(0, 0, 50, 50, 0, 0, 1, 50, 50);
|
|
78
|
+
// => [50, 50, 50, 50] — the start point (0, 0) was gone
|
|
79
|
+
```
|
|
80
|
+
An extremum of the ellipse is on the arc when its angle is in the swept interval, and that was decided with two probe points inside the arc, so an extremum **between the probes and the end of the arc** was missed as well:
|
|
81
|
+
```js
|
|
82
|
+
SVGPathCommander.getPathBBox("M-40 -20A10 10 30 0 0 -30 -40");
|
|
83
|
+
// => x2: -30 — the rightmost point of the arc is at -23.82
|
|
84
|
+
```
|
|
85
|
+
The bounds are the two end points and the extrema the sweep covers now. A degenerate arc — the same start and end point, which the spec omits — answers the box of its single point instead of the box of the ellipse, and an arc with a zero radius answers the box of the straight line to its end point, like the length does.
|
|
86
|
+
- The arc queries answer numbers for arcs whose ends are diametrically opposite — the cosine of the angle between the two ends of a diameter can land a hair outside of the `[-1-1]` range, and `acos()` of a value under `-1` is `NaN`, so the sweep of the arc was `NaN` and so were the length, the point at a length and the frame at a length:
|
|
87
|
+
```js
|
|
88
|
+
SVGPathCommander.getTotalLength("M-40 -20A10 10 30 0 0 -30 -40");
|
|
89
|
+
// => NaN
|
|
90
|
+
```
|
|
91
|
+
- `getRectanglePath()` builds the rounded corners of a rectangle with **elliptical arcs**, like the spec of the `<rect>` element — the corners were smooth cubic segments, and the reflected control point of a smooth cubic follows a line command, so it collapsed to the current point and the corner was a cusp: the length of the rectangle was 0.22 % too long and its area was 0.12 % too big
|
|
92
|
+
- `getRectanglePath()` follows the auto rules of the radius of the corners — a missing `rx` takes the value of `ry` and a missing `ry` takes the value of `rx`, so a `<rect ry="10">` is a rounded rectangle now; an explicit zero still disables the rounding and a radius bigger than half of the size of the rectangle is clamped to it
|
|
93
|
+
- `isMultiPath()` answers `false` for an empty or a malformed path array instead of throwing — `isPathArray()` rejects an empty array, so the predicate fell through to its `TypeError` and `equalize("", "")` and `equalizePaths("", "")` failed with "expected string or PathArray" for an input that is a path; a malformed segment is now answered `false` too, as the 2.3.6 entry of `isPathArray()` promised, and only a value that is not a path at all throws
|
|
94
|
+
- `getPropertiesAtPoint()`, `getClosestPoint()` and `isPointInStroke()` now find the closest point on the closing segment of a closed sub-path of a **multi-subpath** path — the coarse scan of the path samples the start of a closed sub-path twice, once at the start of the sub-path and once at the end of its closing segment, and it kept the first of the two equally close samples, so the refinement walked away from the closing segment and the point was reported at the distance of the start of the sub-path:
|
|
95
|
+
```js
|
|
96
|
+
SVGPathCommander.getPropertiesAtPoint("M0 0L100 0L100 100L0 100ZM50 50L150 50", { x: 0, y: 1 });
|
|
97
|
+
// => { closest: { x: 0, y: 1 }, distance: 0, segment: { segment: ["Z"], … } }
|
|
98
|
+
```
|
|
99
|
+
The scan now collects the local minima of the distance and the search refines around every one of them, so a path that passes near the point more than once is searched at every one of those places. A path that runs at a constant distance from the point — a circle around it — has no minimum, and the noise of the samples is not read as one.
|
|
100
|
+
- `getPropertiesAtPoint()`, `getClosestPoint()` and `isPointInStroke()` now find the closest point on the closing segment of a closed path — the search starts at the beginning of the path and walks towards the end, so it could not walk over the end of a path that ends where it starts, and a point on the closing segment was reported at the distance of the start of the path:
|
|
101
|
+
```js
|
|
102
|
+
SVGPathCommander.getPropertiesAtPoint("M0 0L100 0L100 100L0 100Z", { x: 0, y: 1 });
|
|
103
|
+
// => { closest: { x: 0, y: 1 }, distance: 0, segment: { segment: ["Z"], … } }
|
|
104
|
+
```
|
|
105
|
+
The length table of the path knows whether the path is a loop now, and the search walks over the end of a loop the way it walks over the end of a segment.
|
|
106
|
+
- `resamplePath()` resamples every sub-path on its own instead of flattening a multi-subpath path into one continuous polyline — the old implementation ignored the break between two sub-paths, so the result connected the body of an icon to its eyes and destroyed the shape. The `count` option is the number of points of every sub-path now, and the result keeps one `M` command for every source sub-path:
|
|
107
|
+
```js
|
|
108
|
+
SVGPathCommander.resamplePath("M0 0L10 0M20 0L30 0", 2);
|
|
109
|
+
// => [["M", 0, 0], ["L", 10, 0], ["M", 20, 0], ["L", 30, 0]]
|
|
110
|
+
```
|
|
111
|
+
- The `arcLength` strategy no longer bulges across the joints of the source path — the resampler fitted one cubic to a span that could cross several source segments, so the fitted curve departed from the source by as much as 0.456 units on the demo shapes. Each span is now the exact de Casteljau sub-curve of the source, and every source segment boundary is an arc-length knot, so the corners and the shape of the source are preserved.
|
|
112
|
+
- The `arcLength` strategy keeps every sub-path separate and complete — the number of points is chosen for each sub-path, the source segment boundaries are kept whenever the requested count allows it, and an explicitly under-sampled sub-path uses the documented best-effort fallback instead of dropping geometry.
|
|
113
|
+
- Multi-subpath morphing no longer drops an outer contour or a hole — outer contours only match outer contours and holes only match holes. The paths are reversed as whole paths, so the outer/hole relationships are preserved, and an unmatched contour receives a placeholder at its own centroid instead of taking the opposite fill role. All 42 ordered pairs of the demo shapes now keep their geometry and topology with both the `segment` and the `arcLength` strategy.
|
|
114
|
+
- `getPropertiesAtPoint()`, `getClosestPoint()` and `isPointInStroke()` no longer report a materially wrong distance on a very long path — the refinement precision had a relative floor, so a narrow curve feature could be missed on a path of millions of units. The refinement is now capped at an absolute precision of `1e-6` length units.
|
|
115
|
+
- The exact straight-segment projection no longer replaces a nearer result with a slightly farther tie, and a zero-length moveto point is considered as a point projection. The returned segment metadata now belongs to the same measured segment as the reported closest point, including at moveto and closing-segment boundaries.
|
|
116
|
+
- `getPropertiesAtPoint()`, `getClosestPoint()` and `isPointInStroke()` no longer miss the closest point of a path shorter than the old 8-unit scan step — the coarse scan is scaled with the length of the path, the end of the path is sampled explicitly, and a straight segment is answered with the exact projection of the query point:
|
|
117
|
+
```js
|
|
118
|
+
SVGPathCommander.getPropertiesAtPoint("M7.759 2.722L12.968 3.144L5.288 5.065", {
|
|
119
|
+
x: 1.083779092102759,
|
|
120
|
+
y: 3.890545689621021,
|
|
121
|
+
}).closest;
|
|
122
|
+
// => { x: 5.288, y: 5.065 }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Performance
|
|
126
|
+
|
|
127
|
+
- `parsePathString()` is **1.8x** faster on a 4 000 segment path (1.75 ms -> 0.95 ms) — the parser looked the number of the parameters of a command up in an object, by the lowercased command, for every segment it scanned; the lookup is now by character code, and the command is not lowercased twice per segment. The parser answers the same paths and the same errors.
|
|
128
|
+
- `normalizePath()` is **1.8x** faster on a 4 000 segment path (0.37 ms -> 0.21 ms) — the normalized segment was built with three arrays (a copy of the values, a map over them and a concatenation), and the map was computed for every segment, including the ones that never used it; the segment is now built in one pass. `optimizePath()` and `reversePath()` normalize a path too and get faster with it.
|
|
129
|
+
- `optimizePath()` is **2.3x** faster on a 4 000 segment path (4.1 ms -> 1.8 ms) — the rounded segment was built with three arrays (a copy, a map and a concatenation) and the absolute and the relative form of a segment were compared by building their strings; the rounded segment is now built in one pass and the length of the string of a segment is computed without building it. The optimizer answers the same paths.
|
|
130
|
+
- `getPropertiesAtPoint()`, `getClosestPoint()` and `isPointInStroke()` measure the path **once** — the search built a length table from a normalized copy of the path and then asked `getPropertiesAtLength()` for the segment at the answer, which measured the path a second time; the length table is now built from the shared measure pass, so the normalization and the second measurement are gone: **1.5x** faster on a 4 000 segment path (3.3 ms -> 2.2 ms), with the same answers — the two implementations agree on every path of a 1 000 case random corpus
|
|
131
|
+
- The length queries are much faster — `getTotalLength()` is **4x** faster on a path of 4 000 lines (1.3 ms -> 0.3 ms) and **2.3x** faster on a path of 4 000 curves (3.5 ms -> 1.5 ms), and `getPropertiesAtLength()` is **2.7x** faster on the lines (0.9 ms -> 0.3 ms) and **2.3x** faster on the curves (3.7 ms -> 1.6 ms). The measure pass copied every absolute segment, sliced the end point of every segment into a throw-away array and read the parameters of a segment with an array destructuring, which allocates an iterator for every segment; the parameters are read directly now and the copy is gone. The length of a line is computed without the two point arrays it needed, and the quadrature of the length of a curve computes the speed of the curve without a point per sample. The answers are the same: a differential harness over 2 000 random paths answers the same lengths, the same points and the same frames, bit for bit
|
|
132
|
+
- The closest point search builds one set of measures instead of two — the length table held a copy of every measure of the path, with the geometry of the measure in it; the table holds the measures of the path now, so a search of a 4 000 segment path is **1.5x** faster (1.7 ms -> 1.2 ms)
|
|
133
|
+
|
|
134
|
+
### Changed
|
|
135
|
+
|
|
136
|
+
- The demo in `docs/` covers the features of 2.4.0 — the process page has the simplification, the offsetting, the join, the reverse of a single sub-path, the hit test of the filled shape and of the stroke, and the frame at a length, and the morphing page has the resampling and the `equalize()` facade with its strategy and its point count
|
|
137
|
+
- The simplification tolerance of the demo is a percentage of the source shape's diagonal and the absolute tolerance is printed with the result — the old fixed value of `1` unit was about 6 % of a 16-unit icon and could destroy a small shape. The library API keeps its absolute tolerance in units
|
|
138
|
+
- `splitPath()`, `simplifyPath()` and `getPropertiesAtLength()` no longer add an implicit moveto to a path that does not begin with one — the parser rejects such a path now, so the three of them have nothing left to paper over
|
|
139
|
+
- `transformPath()` no longer keeps a leading relative moveto relative — the parser rewrites it as an absolute one, which is the same pair of coordinates
|
|
140
|
+
- The `svg-path-commander/util` entry holds every standalone tool, including the morphing and intersection engines; the package and JSR exports maps expose only the main entry and the utility entry
|
|
141
|
+
- Rebuilt `dist` and `docs` bundles
|
|
142
|
+
|
|
143
|
+
### Known limitations
|
|
144
|
+
|
|
145
|
+
- The offset of a path is not cleaned up: an offset distance larger than the local radius of curvature of the path produces a self-crossing curve, and an inner offset that overlaps itself is not trimmed. The removal of the self-intersections needs a polygon clipping pass, and it is not part of this release.
|
|
146
|
+
- A multi-subpath morph fallback that pairs an outer contour with a hole keeps their opposite winding, so that pair can interpolate with a twist. Matched contours are never reversed independently because reversing a hole on its own would change the fill topology of the path; the paths are reversed as whole paths instead.
|
|
147
|
+
|
|
148
|
+
## [2.3.6] - 2026-11-20
|
|
149
|
+
|
|
150
|
+
### Added
|
|
151
|
+
|
|
152
|
+
- `getPropertiesAtLength()` returns the frame of the path at the given length — the `point` at that length, the unit `tangent` vector, the unit `normal` vector (the left normal of the tangent) and the `angle` of the tangent in degrees; the result is the union of the segment metadata and the frame, so the existing destructuring of `{ segment, index, length, lengthAtSegment }` keeps working
|
|
153
|
+
- `SVGPathCommander#getPropertiesAtLength(length)` — the instance method of the frame, the counterpart of `getPointAtLength()`:
|
|
154
|
+
```js
|
|
155
|
+
new SVGPathCommander("M0 0L100 0").getPropertiesAtLength(50);
|
|
156
|
+
// => { segment: ["L", 100, 0], index: 1, length: 100, lengthAtSegment: 0,
|
|
157
|
+
// point: { x: 50, y: 0 }, tangent: { x: 1, y: 0 },
|
|
158
|
+
// normal: { x: 0, y: 1 }, angle: 0 }
|
|
159
|
+
```
|
|
160
|
+
- `simplifyPath()` — the curve-preserving simplification of a path: straight-line runs are reduced with Douglas-Peucker and curve runs are fitted with adaptive Schneider cubic Béziers. Arcs and original curves are retained whenever fitting would not reduce the segment count, and every source sub-path and closure is preserved:
|
|
161
|
+
```js
|
|
162
|
+
SVGPathCommander.simplifyPath("M0 0L10 0L20 0L30 0", 1);
|
|
163
|
+
// => [["M", 0, 0], ["L", 30, 0]]
|
|
164
|
+
```
|
|
165
|
+
- `SVGPathCommander#simplify(tolerance)` — the instance method of the simplification, the counterpart of `normalize()`:
|
|
166
|
+
```js
|
|
167
|
+
new SVGPathCommander("M0 0L10 0L20 0L30 0").simplify(1).toString();
|
|
168
|
+
// => "M0 0L30 0"
|
|
169
|
+
```
|
|
170
|
+
- `equalize()` — the recommended entry point for morphing two paths: it picks the right strategy for the paths, aligns their points and normalizes their winding, so the two paths hold the same number of segments of the same type:
|
|
171
|
+
```js
|
|
172
|
+
const [eq1, eq2] = SVGPathCommander.equalize("M0 0L100 0L50 100Z", "M0 0L100 0L100 100L0 100Z", {
|
|
173
|
+
strategy: "arcLength",
|
|
174
|
+
});
|
|
175
|
+
// eq1.length === eq2.length === 6 — ready for morphing
|
|
176
|
+
```
|
|
177
|
+
- `resamplePath()` — the resampling of a path to a given number of points, distributed along its length: the source segment boundaries and corners are points of the result too when the requested count allows it, so the shape of the path keeps its vertices:
|
|
178
|
+
```js
|
|
179
|
+
SVGPathCommander.resamplePath("M0 0L100 0L100 100", 3);
|
|
180
|
+
// => [["M", 0, 0], ["L", 100, 0], ["L", 100, 100]]
|
|
181
|
+
```
|
|
182
|
+
- `equalizeSegments()` and `equalizePaths()` accept the `strategy` option — `segment` (the default) splits the segments of the paths, so the points of the result are the points of the paths, while `arcLength` distributes the result points along the path length and keeps the source segment boundaries and corners when the requested count allows it
|
|
183
|
+
- `equalizeSegments()` and `equalizePaths()` accept the `align` option — the points of the second path are rotated onto the points of the first one by default, `align: false` keeps them where they are
|
|
184
|
+
- `equalizeSegments()` and `equalizePaths()` accept `reverse: "auto"` — the path that is reversed is the one that leaves the two paths closest to each other, instead of always the second one
|
|
185
|
+
- `equalizeSegments()` and `equalizePaths()` accept the `mode: "line"` option — the result of the equalization is a polyline, even when the paths hold curves
|
|
186
|
+
|
|
187
|
+
### Fixed
|
|
188
|
+
|
|
189
|
+
- `samplePolygon()` no longer throws on a quadratic segment — the winding of a path with a `Q` segment could not be read, so the equalization of such a path failed with `path command "Q" is not supported`
|
|
190
|
+
- `getPointAtLength()` no longer jumps to the end of a zero radius arc — the SVG spec treats a zero radius as a straight line to the end point, and the length of such an arc was already measured that way, but the point lookup returned the end point for every distance along it
|
|
191
|
+
- `reversePath()` no longer corrupts the geometry of a `T` segment — a reversed `T` was emitted as the `T` shorthand whenever the original predecessor was not a `Q`/`T`, but in the reversed path the predecessor of a segment is its original _successor_, so when that successor was a `Q` the shorthand reflected the `Q`'s control point instead of the `T`'s own control point and silently changed the curve; e.g. `M0 0L10 0T20 20Q30 30 40 40` was off by up to 21 units — the shorthand is now kept wherever it is provably safe and falls back to an explicit `Q` otherwise
|
|
192
|
+
- `arcToCubic()` no longer produces `NaN` control points for a zero radius arc — the SVG spec treats a zero radius as a straight line to the end point, which is what the conversion produces now
|
|
193
|
+
- `getArcLength()` measures a zero radius arc as the straight line to its end point, the same as `getPointAtArcLength()` already did
|
|
194
|
+
- `arcToCubic()` uses the absolute value of a negative radius, as the spec says — the converted curve used to be a different shape than the arc it came from, and the length of `pathToCurve(arc)` was 7.4 % off the length of the arc itself
|
|
195
|
+
- `getPathSplits()` no longer hangs when the target cannot be reached — a target below the segment count, a fractional target and a non-finite target all made the adjustment loop wrap around forever (the hang was live: `getPathSplits([['M',0,0],['L',10,0],['L',20,0]], 2)` never returned); the target is now clamped to the segment count, fractional targets are floored and non-finite targets are rejected with a `TypeError`
|
|
196
|
+
- `equalizeSegments()` and `equalizePaths()` no longer mutate the module level defaults — the options of the first call were written into the defaults object, so every later call without options inherited them (`mode: "curve"` leaked, and so did `reverse: false`, which `equalizePaths()` passes for every matched subpath pair and which permanently disabled the winding normalisation of every later `equalizeSegments()` call — two paths with an opposite winding were then morphed without being aligned)
|
|
197
|
+
- Empty input has a defined contract everywhere — `getPathBBox([])` returns a zeroed bounding box, `getPointAtLength([], 10)` returns `{ x: 0, y: 0 }`, `isClosedPath([])` returns `false`, `getPropertiesAtPoint([])` returns `{ closest: { x: 0, y: 0 }, distance: Infinity }`, `getSegmentOfPoint([])` returns `undefined`, `isPointInStroke([])` returns `false`, `getClosestPoint([])` returns `{ x: 0, y: 0 }`, `getPropertiesAtLength([])` returns a synthetic `["M", 0, 0]` segment and `isValidPath(" ")` returns `false`; `getPathBBox()` was the worst of them — the guard tested the truthiness of the _input_, so an empty array (which is truthy) slipped through and the result was `{ x: Infinity, y: Infinity, x2: -Infinity, cx: NaN }`
|
|
198
|
+
- `getPropertiesAtLength()` no longer returns `undefined` for a negative distance (which made `getSegmentAtLength(path, -5)` throw) — a negative distance takes the same early return as a distance of zero
|
|
199
|
+
- A malformed segment (`[[]]`, `[[1, 2, 3]]`) now throws a descriptive `TypeError` naming the offending index, instead of "Cannot read properties of undefined" from deep inside the iterator
|
|
200
|
+
- `roundPath()` no longer modifies the caller's array — it returned the caller's own array with the segments replaced in place
|
|
201
|
+
- `transformPath()` no longer writes the default origin into the caller's transform object, where it was the _same array_ as `SVGPathCommander.options.origin` — a caller who mutated the origin they passed in corrupted the library's global default for the rest of the process
|
|
202
|
+
- `getSVGMatrix()` falls back to the default origin instead of throwing "origin is not iterable"
|
|
203
|
+
- `splitLineToCount()` splits a line into equal lengths — the breakpoints were computed from the _original_ start point, so a 90 unit line split in three became 30, 15 and 45 units long; this is the point distribution `equalizeSegments()` is built on, so an edge split in ten used to bunch its points at the start instead of spreading them evenly
|
|
204
|
+
- `matchPaths()` no longer destroys the caller's arrays — it sorted them in place and emptied them with `shift()`
|
|
205
|
+
- `splitPath()` no longer drops the segments before the first `M` and always returns absolute segments, as its docstring promises
|
|
206
|
+
- `isPathArray()` — and with it `isMultiPath()`, `isAbsoluteArray()` and `isRelativeArray()` — answers `false` for a malformed segment instead of throwing
|
|
207
|
+
- `projection2d()` no longer returns `Infinity` or `NaN` when the relative position has no `z` — the guard `Math.abs(originZ) / Math.abs(relativePositionZ) || 1` returns `Infinity` for a zero denominator, and `Infinity` is truthy, so the fallback never applied
|
|
208
|
+
- `classifyPaths()` no longer inverts outer and inner paths — the classification was purely `signedArea > 0 ? outer : inner`, but in the SVG coordinate system (y pointing down) the usual outer contour has a _negative_ signed area, so a square and its hole both came back as holes; a path is now an inner path when another path of the same set contains it, which does not depend on the winding at all
|
|
209
|
+
- The parser accepts a leading zero again (`M09 09`) — the SVG path grammar defines a number as a digit sequence and every browser accepts it; the rejection came from a borrowed Esprima rule that belongs to the JavaScript numeric literal grammar
|
|
210
|
+
- The parser rejects a number it cannot represent (`M1e999 0`) with a descriptive `TypeError`, instead of parsing it into an infinite coordinate that propagated into every length, bounding box and transformation
|
|
211
|
+
- `pathToAbsolute()` absolutizes a leading relative moveto — the SVG spec says "If a relative moveto (m) appears as the first element of the path, then it is treated as a pair of absolute coordinates", but `absolutizeSegment()` returned the first segment untouched
|
|
212
|
+
- `getPolyPath()` drops an incomplete point pair instead of producing a segment with an `undefined` coordinate
|
|
213
|
+
- `getSegmentAtLength(path, Infinity)` clamps to the last segment like every other out of range distance, instead of returning the first one
|
|
214
|
+
- An explicit `origin: [x, y, 0]` is no longer overwritten by the instance origin — `originZ || cz` treated a zero as missing
|
|
215
|
+
- A non numeric transform value is ignored instead of being stored as `NaN` — `typeof Number(v) === "number"` is true for every value
|
|
216
|
+
|
|
217
|
+
### Performance
|
|
218
|
+
|
|
219
|
+
- `getPropertiesAtLength()` no longer measures the path O(n²) times — it truncated the path and called `getTotalLength()` on the truncated copy once per segment; it now reads the shared measure table and picks the segment with one scan: **16.7x** faster at 200 segments and **514x** at 4 000 (1 105 ms -> 2.15 ms)
|
|
220
|
+
- `getPropertiesAtPoint()` and `getPointAtLength()` are served from a length table — every sample of the closest point search walked the whole path from the start, so the search was quadratic: **21.5x** faster at 50 segments and **489x** at 1 600 (615 ms -> 1.26 ms)
|
|
221
|
+
- `getPropertiesAtPoint()` no longer normalizes the path again for every sample of its search — **2.7x - 3.1x** faster
|
|
222
|
+
- `getRotatedPath()` no longer materialises a copy of the path for every possible start segment — at 4 000 segments the search needed 145 MB of heap for the copies alone and 933 ms; it now needs 2 MB and 3 ms
|
|
223
|
+
- `getDrawDirection()` converts the path to a curve once instead of twice — **1.78x** faster on a 6 000 segment path (12.80 ms -> 7.19 ms)
|
|
224
|
+
- The parser no longer builds a 25 element array for every character it reads — **5.47x** faster (20.55 ms -> 3.75 ms per 1 000 000 calls)
|
|
225
|
+
|
|
226
|
+
### Changed
|
|
227
|
+
|
|
228
|
+
- The `mode` option of `equalizeSegments()` accepts `"line"` — the option was documented but not implemented: a `"line"` mode fell through to the curve branch, so the result of the equalization always held cubic segments
|
|
229
|
+
- The frame of `getPropertiesAtLength()` shares one `t` ratio between the point and the tangent — the point and the frame are computed from the very same spot on the curve, which is **1.9x - 3.7x** faster than looking both up separately
|
|
230
|
+
- The Douglas-Peucker simplification splits a range at its worst point _and_ in its middle when the worst point sits at the edge of the range — a split at the edge alone makes the recursion as deep as the range is long, which was quadratic on a path that alternates between two sides of a line: a 4 000 curve path went from **1 090 ms** to **17 ms**, and the result keeps the same shape within the tolerance
|
|
231
|
+
- `getTotalLength()` and `getPathSplits()` now share one length measurement pass — `measureSegments()` yields the length of every segment together with the length accumulated before it, so the two can no longer disagree and `getPathSplits()` no longer computes every segment length twice; the pass handles every command the way `getTotalLength()` does, where the old `getPathSplits()` measured `H`, `V` and `Z` segments as cubics and produced `NaN` for them
|
|
232
|
+
- `equalizeSegments("", "")` returns `[[], []]` instead of `[[], null]` — an empty path has no rotation, and the morph facade no longer reports a `null` one
|
|
233
|
+
- The benchmark harness (`scripts/bench.js`) measures with `performance.now()` instead of `new Date().getTime()` (1 ms resolution, on operations that take single-digit milliseconds), runs 30 times after 5 warmups and reports the **median** and the **best** of the runs in separate columns; it only rewrites the README when `--write` is passed, so `vpr bench` no longer leaves the working tree dirty
|
|
234
|
+
- `interHelper` imports `distanceEpsilon` directly instead of through the barrel, which removes the import cycle between the intersection engine and `src/util.ts`
|
|
235
|
+
- Nine `@example` blocks were corrected to match what the code returns (`getPathArea`, `getTotalLength`, `pathToCurve`, `toCurve`, `normalize`, `reversePath`, `optimizePath`, `transformPath`)
|
|
236
|
+
- Updated dev dependencies: `vite-plus` `1.7.0`, `vitest` / `@vitest/*` `5.1.0`, `vite` -> `@voidzero-dev/vite-plus-core` `8.3.8000`
|
|
237
|
+
- Rebuilt `dist` and `docs` bundles
|
|
238
|
+
|
|
3
239
|
## [2.3.5] - 2026-11-16
|
|
4
240
|
|
|
5
241
|
### Fixed
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
AGENTS.md
|