@ac-kit/math-grid 0.3.0 → 0.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/CHANGELOG.md +65 -0
- package/README.md +20 -7
- package/dist/_coverage-contour2.d.ts +48 -0
- package/dist/_coverage-contour2.d.ts.map +1 -0
- package/dist/_coverage-contour2.js +1670 -0
- package/dist/_coverage-contour2.js.map +1 -0
- package/dist/_nearest-site-propagation2.d.ts +80 -0
- package/dist/_nearest-site-propagation2.d.ts.map +1 -0
- package/dist/_nearest-site-propagation2.js +551 -0
- package/dist/_nearest-site-propagation2.js.map +1 -0
- package/dist/grid-pack-dfs.d.ts.map +1 -1
- package/dist/grid-pack-dfs.js +4 -2
- package/dist/grid-pack-dfs.js.map +1 -1
- package/dist/infinite-grid2.js.map +1 -1
- package/dist/shelf-allocator.d.ts +7 -1
- package/dist/shelf-allocator.d.ts.map +1 -1
- package/dist/shelf-allocator.js +32 -32
- package/dist/shelf-allocator.js.map +1 -1
- package/dist/signed-distance-from-coverage2.d.ts +63 -21
- package/dist/signed-distance-from-coverage2.d.ts.map +1 -1
- package/dist/signed-distance-from-coverage2.js +238 -98
- package/dist/signed-distance-from-coverage2.js.map +1 -1
- package/dist/squared-distance-transform2.d.ts +9 -4
- package/dist/squared-distance-transform2.d.ts.map +1 -1
- package/dist/squared-distance-transform2.js +9 -4
- package/dist/squared-distance-transform2.js.map +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0b4fe43: `signedDistanceFromCoverage2(out, coverage, width, height, range, scratch?)`
|
|
8
|
+
measures every texel's distance to the contour located inside each edge texel
|
|
9
|
+
from the coverage, merged into straight runs with corners where two runs meet at
|
|
10
|
+
an angle (Gustavson and Strand's antialiased Euclidean distance transform). The
|
|
11
|
+
field is within 0.1 texel of the analytic distance, up to 5 texels from the
|
|
12
|
+
edge, on discs of radius 4 and more (6 before) and on polygons whose sides are
|
|
13
|
+
at least 8 texels long and whose corners are at least 20° (coverage sampled
|
|
14
|
+
16 × 16 per texel, rounded to bytes); a stripe thinner than a texel along a
|
|
15
|
+
row, a column or a diagonal of texel centres, of ink or a gap, keeps its
|
|
16
|
+
centreline half its width deep, within 0.02 texel. A feature thinner than a
|
|
17
|
+
texel that crosses texels off their centres can be up to half a texel off. A
|
|
18
|
+
texel's side is decided before its magnitude is capped, by the corner or stripe
|
|
19
|
+
that places it where its coverage alone would not. Magnitudes are capped at the
|
|
20
|
+
largest 32-bit float not above `range`, so the field never passes `range` and
|
|
21
|
+
stays finite for any finite `range`. It runs in time linear in the edge texels,
|
|
22
|
+
then the lesser of O(edge texels · range²) and O(width · height). With a
|
|
23
|
+
`scratch` of at least `8 · width · height` entries it allocates nothing, at any
|
|
24
|
+
range. Two of `out`, `coverage` and `scratch` sharing bytes within the entries
|
|
25
|
+
the call uses throw a `RangeError` before anything is written, shadowed
|
|
26
|
+
`byteOffset`, `byteLength` or `buffer` properties included.
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 0b4fe43: Instance state that was held in `#` private fields is now held in
|
|
31
|
+
TypeScript-private properties (named with a trailing `_`). They are no longer
|
|
32
|
+
hidden at runtime: they appear as own properties (`Object.keys`,
|
|
33
|
+
`JSON.stringify`, `structuredClone`, deep equality), and the declarations list
|
|
34
|
+
them as `private`. Public members are unchanged.
|
|
35
|
+
- Updated dependencies [0b4fe43]
|
|
36
|
+
- Updated dependencies [0b4fe43]
|
|
37
|
+
- Updated dependencies [0b4fe43]
|
|
38
|
+
- Updated dependencies [0b4fe43]
|
|
39
|
+
- Updated dependencies [0b4fe43]
|
|
40
|
+
- Updated dependencies [0b4fe43]
|
|
41
|
+
- Updated dependencies [0b4fe43]
|
|
42
|
+
- Updated dependencies [0b4fe43]
|
|
43
|
+
- Updated dependencies [0b4fe43]
|
|
44
|
+
- Updated dependencies [0b4fe43]
|
|
45
|
+
- Updated dependencies [0b4fe43]
|
|
46
|
+
- Updated dependencies [0b4fe43]
|
|
47
|
+
- Updated dependencies [0b4fe43]
|
|
48
|
+
- Updated dependencies [0b4fe43]
|
|
49
|
+
- Updated dependencies [0b4fe43]
|
|
50
|
+
- Updated dependencies [0b4fe43]
|
|
51
|
+
- Updated dependencies [0b4fe43]
|
|
52
|
+
- Updated dependencies [0b4fe43]
|
|
53
|
+
- Updated dependencies [0b4fe43]
|
|
54
|
+
- Updated dependencies [0b4fe43]
|
|
55
|
+
- Updated dependencies [0b4fe43]
|
|
56
|
+
- Updated dependencies [0b4fe43]
|
|
57
|
+
- Updated dependencies [0b4fe43]
|
|
58
|
+
- Updated dependencies [0b4fe43]
|
|
59
|
+
- Updated dependencies [0b4fe43]
|
|
60
|
+
- Updated dependencies [0b4fe43]
|
|
61
|
+
- Updated dependencies [0b4fe43]
|
|
62
|
+
- Updated dependencies [0b4fe43]
|
|
63
|
+
- @ac-kit/algo@0.6.0
|
|
64
|
+
- @ac-kit/core@0.13.0
|
|
65
|
+
- @ac-kit/math-geometry@0.4.0
|
|
66
|
+
- @ac-kit/math-linear@0.4.0
|
|
67
|
+
|
|
3
68
|
## 0.3.0
|
|
4
69
|
|
|
5
70
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -60,9 +60,9 @@ A released rectangle's space is reused once every rectangle of its shelf is
|
|
|
60
60
|
released; until then it is not.
|
|
61
61
|
|
|
62
62
|
`squaredDistanceTransform2` turns a grid of seeds (0 at a feature, `Infinity`
|
|
63
|
-
far from any,
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
far from any, or any other non-negative cost) into the exact squared distance
|
|
64
|
+
to the nearest feature, cost included, in place, in O(width · height).
|
|
65
|
+
Features are cell centres. Pass a `scratch` of at least
|
|
66
66
|
`3 · max(width, height) + 1` entries to avoid any allocation.
|
|
67
67
|
|
|
68
68
|
```ts
|
|
@@ -75,10 +75,23 @@ squaredDistanceTransform2(grid, 5, 3); // 5 2 1 2 5 / 4 1 0 1 4 / 5 2 1 2 5
|
|
|
75
75
|
|
|
76
76
|
`signedDistanceFromCoverage2` turns antialiased coverage bytes (0 outside, 255
|
|
77
77
|
inside) into a signed distance field in texels, negative inside, capped at a
|
|
78
|
-
`range
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
`range`: the sub-texel contour, located in each edge texel from the coverage,
|
|
79
|
+
is merged into straight runs, with a corner where two runs meet at an angle,
|
|
80
|
+
and every texel within `range` measures its distance to it (Gustavson &
|
|
81
|
+
Strand's antialiased Euclidean distance transform; vector propagation for a
|
|
82
|
+
long range). Within a tenth of a texel of the analytic distance, up to 5
|
|
83
|
+
texels from the edge, on discs of radius 4 and more and on polygons whose sides
|
|
84
|
+
are at least 8 texels long and whose corners are at least 20° (coverage sampled
|
|
85
|
+
16 × 16 per texel, rounded to bytes), and within 0.02 texel on stripes 0.1 to
|
|
86
|
+
0.8 texel wide along a row, a column or a diagonal of texel centres, whose
|
|
87
|
+
centreline lies half their width deep; seeding the transform above from
|
|
88
|
+
coverage is half a texel off. A feature thinner than a texel that crosses
|
|
89
|
+
texels off their centres can still be up to half a texel off: one texel's
|
|
90
|
+
coverage cannot tell where in it the feature lies. The field is 32-bit floats,
|
|
91
|
+
capped at the largest one not above `range`, so it stays finite whatever the
|
|
92
|
+
range, and a texel's side is decided before the cap. Pass a `scratch` of
|
|
93
|
+
`8 · width · height` entries to avoid any allocation: the call then allocates
|
|
94
|
+
nothing, whatever the range.
|
|
82
95
|
|
|
83
96
|
```ts
|
|
84
97
|
import { signedDistanceFromCoverage2 } from "@ac-kit/math-grid";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contour of an antialiased coverage grid, as sites (see
|
|
3
|
+
* {@link COVERAGE_STRIDE_}): each edge texel's straight edge, merged into one
|
|
4
|
+
* segment per straight run of them, and a corner where two runs meet.
|
|
5
|
+
*
|
|
6
|
+
* Cost is linear in the edge texels: the runs grow once from their pieces, and
|
|
7
|
+
* a corner is only tried where two runs end next to each other, so a texel on a
|
|
8
|
+
* straight edge (most of them) costs its piece and one membership test.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The largest coverage error, as a fraction of a texel, of a straight edge's
|
|
12
|
+
* prediction over the 3 × 3 texels around an edge texel for its texel to count
|
|
13
|
+
* as straight: above the curvature of a disc of radius 6, below what a corner
|
|
14
|
+
* inside the window leaves.
|
|
15
|
+
*/
|
|
16
|
+
export declare const STRAIGHT_RESIDUAL_ = 0.1;
|
|
17
|
+
/**
|
|
18
|
+
* Writes the straight edge of antialiased texel `(x, y)`, of coverage `value`,
|
|
19
|
+
* at `sites[at]` in the `COVERAGE_STRIDE_` layout.
|
|
20
|
+
*/
|
|
21
|
+
export declare function locateEdge_(sites: Float64Array, at: number, coverage: Uint8Array, value: number, x: number, y: number, width: number, height: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Writes into `residuals[cell]` how far the coverage of the texels around
|
|
24
|
+
* antialiased texel `(x, y)`, as a fraction of a texel, strays from what its
|
|
25
|
+
* straight edge (at `sites[at]`) predicts; `NaN` for a texel without one (a
|
|
26
|
+
* zero gradient).
|
|
27
|
+
*/
|
|
28
|
+
export declare function edgeResidual_(sites: Float64Array, at: number, coverage: Uint8Array, x: number, y: number, width: number, height: number, residuals: Float32Array, cell: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Merges the straight pieces of contour of a coverage grid into runs, one
|
|
31
|
+
* segment site each, and places a corner where two runs meet at an angle (see
|
|
32
|
+
* the module notes). `scratch` holds each site cell's label in `[0, count)`
|
|
33
|
+
* (`UNASSIGNED_` on entry; afterwards its run's holder for a run's piece, its
|
|
34
|
+
* own cell for a corner's holder, the holder for a cell that took a corner,
|
|
35
|
+
* else negative), free room in `[count, 2 · count)`, and the site geometry from
|
|
36
|
+
* `2 · count`; `residuals` the straight-edge residual of each antialiased
|
|
37
|
+
* texel. Returns how many corners there are, their holders listed from
|
|
38
|
+
* `scratch[count]`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function findContour_(scratch: Float64Array, residuals: Float32Array, coverage: Uint8Array, width: number, height: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Whether cell `cell` holds contour: an antialiased texel, or a full or empty
|
|
43
|
+
* texel with an opposite neighbour to the right or below.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isSiteCell_(coverage: Uint8Array, cell: number, width: number, count: number): boolean;
|
|
46
|
+
/** Whether the site of cell `cell` is a corner. */
|
|
47
|
+
export declare function isCorner_(scratch: Float64Array, base: number, cell: number): boolean;
|
|
48
|
+
//# sourceMappingURL=_coverage-contour2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_coverage-contour2.d.ts","sourceRoot":"","sources":["../src/_coverage-contour2.ts"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAuEtC;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,YAAY,EACnB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,MAAM,EACb,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACZ,IAAI,CAoFN;AAwQD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,YAAY,EACnB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,UAAU,EACpB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,MAAM,GACV,IAAI,CA8BN;AAcD;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC3B,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,YAAY,EACvB,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACZ,MAAM,CAWR;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,QAAQ,EAAE,UAAU,EACpB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACX,OAAO,CAUT;AA0kBD,mDAAmD;AACnD,wBAAgB,SAAS,CACxB,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV,OAAO,CAOT"}
|