@ac-kit/math-grid 0.3.0 → 0.5.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 +149 -0
- package/README.md +117 -10
- package/dist/_brand.d.ts +14 -0
- package/dist/_brand.d.ts.map +1 -0
- package/dist/_brand.js +2 -0
- package/dist/_brand.js.map +1 -0
- package/dist/_coverage-contour2.d.ts +55 -0
- package/dist/_coverage-contour2.d.ts.map +1 -0
- package/dist/_coverage-contour2.js +2068 -0
- package/dist/_coverage-contour2.js.map +1 -0
- package/dist/_grid-offsets2.d.ts +15 -0
- package/dist/_grid-offsets2.d.ts.map +1 -0
- package/dist/_grid-offsets2.js +53 -0
- package/dist/_grid-offsets2.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 +707 -0
- package/dist/_nearest-site-propagation2.js.map +1 -0
- package/dist/breadth-first-grid2.d.ts +65 -0
- package/dist/breadth-first-grid2.d.ts.map +1 -0
- package/dist/breadth-first-grid2.js +116 -0
- package/dist/breadth-first-grid2.js.map +1 -0
- package/dist/flood-fill2.d.ts +39 -0
- package/dist/flood-fill2.d.ts.map +1 -0
- package/dist/flood-fill2.js +76 -0
- package/dist/flood-fill2.js.map +1 -0
- package/dist/grid-neighbors2.d.ts +45 -0
- package/dist/grid-neighbors2.d.ts.map +1 -0
- package/dist/grid-neighbors2.js +45 -0
- package/dist/grid-neighbors2.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/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/infinite-grid2.js.map +1 -1
- package/dist/max-rects-pack.d.ts +90 -0
- package/dist/max-rects-pack.d.ts.map +1 -0
- package/dist/max-rects-pack.js +310 -0
- package/dist/max-rects-pack.js.map +1 -0
- package/dist/rasterize-line2.d.ts +33 -0
- package/dist/rasterize-line2.d.ts.map +1 -0
- package/dist/rasterize-line2.js +103 -0
- package/dist/rasterize-line2.js.map +1 -0
- 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 +327 -99
- 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/dist/tile/_tile-matrix.d.ts +33 -0
- package/dist/tile/_tile-matrix.d.ts.map +1 -0
- package/dist/tile/_tile-matrix.js +186 -0
- package/dist/tile/_tile-matrix.js.map +1 -0
- package/dist/tile/index.d.ts +8 -0
- package/dist/tile/index.d.ts.map +1 -0
- package/dist/tile/index.js +8 -0
- package/dist/tile/index.js.map +1 -0
- package/dist/tile/quadkey.d.ts +30 -0
- package/dist/tile/quadkey.d.ts.map +1 -0
- package/dist/tile/quadkey.js +91 -0
- package/dist/tile/quadkey.js.map +1 -0
- package/dist/tile/tile-address.d.ts +91 -0
- package/dist/tile/tile-address.d.ts.map +1 -0
- package/dist/tile/tile-address.js +228 -0
- package/dist/tile/tile-address.js.map +1 -0
- package/dist/tile/tile-index.d.ts +26 -0
- package/dist/tile/tile-index.d.ts.map +1 -0
- package/dist/tile/tile-index.js +2 -0
- package/dist/tile/tile-index.js.map +1 -0
- package/dist/tile/tile-level.d.ts +24 -0
- package/dist/tile/tile-level.d.ts.map +1 -0
- package/dist/tile/tile-level.js +53 -0
- package/dist/tile/tile-level.js.map +1 -0
- package/dist/tile/tile-matrix-set-json.d.ts +67 -0
- package/dist/tile/tile-matrix-set-json.d.ts.map +1 -0
- package/dist/tile/tile-matrix-set-json.js +247 -0
- package/dist/tile/tile-matrix-set-json.js.map +1 -0
- package/dist/tile/tile-matrix-set.d.ts +174 -0
- package/dist/tile/tile-matrix-set.d.ts.map +1 -0
- package/dist/tile/tile-matrix-set.js +244 -0
- package/dist/tile/tile-matrix-set.js.map +1 -0
- package/dist/tile/tile-range.d.ts +57 -0
- package/dist/tile/tile-range.d.ts.map +1 -0
- package/dist/tile/tile-range.js +140 -0
- package/dist/tile/tile-range.js.map +1 -0
- package/package.json +10 -8
package/dist/shelf-allocator.js
CHANGED
|
@@ -24,13 +24,13 @@ function assertDimension(name, value) {
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export class ShelfAllocator {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
width_;
|
|
28
|
+
height_;
|
|
29
|
+
shelves_ = [];
|
|
30
|
+
entries_ = new Map();
|
|
31
|
+
nextId_ = 0;
|
|
32
|
+
nextY_ = 0;
|
|
33
|
+
usedArea_ = 0;
|
|
34
34
|
/**
|
|
35
35
|
* @throws {RangeError} When `width` or `height` is not a positive integer, or
|
|
36
36
|
* when `width · height` is not a safe integer.
|
|
@@ -41,12 +41,12 @@ export class ShelfAllocator {
|
|
|
41
41
|
if (!Number.isSafeInteger(width * height)) {
|
|
42
42
|
throw new RangeError(`area ${width}×${height} exceeds the safe integer range`);
|
|
43
43
|
}
|
|
44
|
-
this
|
|
45
|
-
this
|
|
44
|
+
this.width_ = width;
|
|
45
|
+
this.height_ = height;
|
|
46
46
|
}
|
|
47
47
|
/** The area given to live allocations over the total area, in `[0, 1]`. */
|
|
48
48
|
get occupancy() {
|
|
49
|
-
return this
|
|
49
|
+
return this.usedArea_ / (this.width_ * this.height_);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* The top-left of a free area and its id, or `undefined` when none fits.
|
|
@@ -58,12 +58,12 @@ export class ShelfAllocator {
|
|
|
58
58
|
allocate(width, height) {
|
|
59
59
|
assertDimension("width", width);
|
|
60
60
|
assertDimension("height", height);
|
|
61
|
-
if (width > this
|
|
61
|
+
if (width > this.width_ || height > this.height_) {
|
|
62
62
|
return undefined;
|
|
63
63
|
}
|
|
64
64
|
let best;
|
|
65
65
|
let bestSpan = -1;
|
|
66
|
-
for (const shelf of this
|
|
66
|
+
for (const shelf of this.shelves_) {
|
|
67
67
|
if (shelf.height < height ||
|
|
68
68
|
(best !== undefined && shelf.height >= best.height)) {
|
|
69
69
|
continue;
|
|
@@ -75,20 +75,20 @@ export class ShelfAllocator {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
if (best === undefined) {
|
|
78
|
-
if (this
|
|
78
|
+
if (this.height_ - this.nextY_ < height) {
|
|
79
79
|
return undefined;
|
|
80
80
|
}
|
|
81
81
|
best = {
|
|
82
|
-
y: this
|
|
82
|
+
y: this.nextY_,
|
|
83
83
|
height,
|
|
84
|
-
free: [{ start: 0, length: this
|
|
84
|
+
free: [{ start: 0, length: this.width_ }],
|
|
85
85
|
live: 0,
|
|
86
86
|
};
|
|
87
87
|
bestSpan = 0;
|
|
88
|
-
this
|
|
89
|
-
this
|
|
88
|
+
this.shelves_.push(best);
|
|
89
|
+
this.nextY_ += height;
|
|
90
90
|
}
|
|
91
|
-
const id = this
|
|
91
|
+
const id = this.nextId_++;
|
|
92
92
|
const span = best.free[bestSpan];
|
|
93
93
|
const x = span.start;
|
|
94
94
|
if (span.length === width) {
|
|
@@ -99,8 +99,8 @@ export class ShelfAllocator {
|
|
|
99
99
|
span.length -= width;
|
|
100
100
|
}
|
|
101
101
|
best.live += 1;
|
|
102
|
-
this
|
|
103
|
-
this
|
|
102
|
+
this.entries_.set(id, { shelf: best, x, width, height });
|
|
103
|
+
this.usedArea_ += width * height;
|
|
104
104
|
return { x, y: best.y, id };
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
@@ -112,12 +112,12 @@ export class ShelfAllocator {
|
|
|
112
112
|
* released or was cleared.
|
|
113
113
|
*/
|
|
114
114
|
release(id) {
|
|
115
|
-
const entry = this
|
|
115
|
+
const entry = this.entries_.get(id);
|
|
116
116
|
if (entry === undefined) {
|
|
117
117
|
throw new RangeError(`unknown or already released id ${id}`);
|
|
118
118
|
}
|
|
119
|
-
this
|
|
120
|
-
this
|
|
119
|
+
this.entries_.delete(id);
|
|
120
|
+
this.usedArea_ -= entry.width * entry.height;
|
|
121
121
|
const shelf = entry.shelf;
|
|
122
122
|
shelf.live -= 1;
|
|
123
123
|
if (shelf.live > 0) {
|
|
@@ -141,12 +141,12 @@ export class ShelfAllocator {
|
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
shelf.free.length = 0;
|
|
144
|
-
shelf.free.push({ start: 0, length: this
|
|
145
|
-
let last = this
|
|
144
|
+
shelf.free.push({ start: 0, length: this.width_ });
|
|
145
|
+
let last = this.shelves_.at(-1);
|
|
146
146
|
while (last !== undefined && last.live === 0) {
|
|
147
|
-
this
|
|
148
|
-
this
|
|
149
|
-
last = this
|
|
147
|
+
this.shelves_.pop();
|
|
148
|
+
this.nextY_ = last.y;
|
|
149
|
+
last = this.shelves_.at(-1);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
@@ -154,10 +154,10 @@ export class ShelfAllocator {
|
|
|
154
154
|
* entries.
|
|
155
155
|
*/
|
|
156
156
|
clear() {
|
|
157
|
-
this
|
|
158
|
-
this
|
|
159
|
-
this
|
|
160
|
-
this
|
|
157
|
+
this.shelves_.length = 0;
|
|
158
|
+
this.entries_.clear();
|
|
159
|
+
this.nextY_ = 0;
|
|
160
|
+
this.usedArea_ = 0;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
//# sourceMappingURL=shelf-allocator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shelf-allocator.js","sourceRoot":"","sources":["../src/shelf-allocator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA4B7C,SAAS,eAAe,CAAC,IAAY,EAAE,KAAa;IACnD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,UAAU,CACnB,GAAG,IAAI,oCAAoC,aAAa,CAAC,KAAK,CAAC,EAAE,CACjE,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,cAAc;
|
|
1
|
+
{"version":3,"file":"shelf-allocator.js","sourceRoot":"","sources":["../src/shelf-allocator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA4B7C,SAAS,eAAe,CAAC,IAAY,EAAE,KAAa;IACnD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,UAAU,CACnB,GAAG,IAAI,oCAAoC,aAAa,CAAC,KAAK,CAAC,EAAE,CACjE,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,cAAc;IACT,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,QAAQ,GAAY,EAAE,CAAC;IACvB,QAAQ,GAAG,IAAI,GAAG,EAAiB,CAAC;IAC7C,OAAO,GAAG,CAAC,CAAC;IACZ,MAAM,GAAG,CAAC,CAAC;IACX,SAAS,GAAG,CAAC,CAAC;IAEtB;;;OAGG;IACH,YAAY,KAAa,EAAE,MAAc;QACxC,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAChC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,GAA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res at `(x, y)`.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
7
|
+
* Gustavson & Strand's antialiased Euclidean distance transform (2011, _Pattern
|
|
8
|
+
* Recognition Letters_ 32(2)), seeded with sub-texel contour pieces and
|
|
9
|
+
* extended to straight runs and corners. Each edge texel (coverage strictly
|
|
10
|
+
* between 0 and 255) locates the contour inside it: the normal is the Sobel
|
|
11
|
+
* gradient of the coverage, and the offset from the texel centre inverts the
|
|
12
|
+
* exact area coverage of a straight edge through a unit square at that angle,
|
|
13
|
+
* so the field keeps sub-texel edges instead of snapping to a threshold. Binary
|
|
14
|
+
* transitions (a full texel beside an empty one, as hand-drawn masks have) put
|
|
15
|
+
* the contour midway. The pieces whose 3 × 3 coverage is one straight edge
|
|
16
|
+
* merge into straight runs, each one segment along the line fitted through
|
|
17
|
+
* them; where two runs end next to each other at an angle, the lines cross at a
|
|
18
|
+
* corner's vertex, which the coverage around it then places along the bisector
|
|
19
|
+
* (a sharp tip's crossing is ill-conditioned), the runs end there, and the
|
|
20
|
+
* texels around the vertex that the corner explains take it, so that no piece
|
|
21
|
+
* overshoots it. Every texel then learns its nearest piece of contour, measured
|
|
22
|
+
* to its segments rather than to a point, which would overestimate by up to a
|
|
23
|
+
* quarter texel between samples: from the pieces themselves, each measuring the
|
|
24
|
+
* texels within `range` of it, when that is cheaper (few edge texels, short
|
|
25
|
+
* range); else from its neighbours in two raster sweeps (vector propagation),
|
|
26
|
+
* then along the contour to a nearer piece, which leaves up to about 0.05 texel
|
|
27
|
+
* where pieces of the contour compete (its medial axis). A texel whose 3 × 3
|
|
28
|
+
* coverage is symmetric about it (no gradient) holds no straight edge: when a
|
|
29
|
+
* stripe thinner than a texel through its centre explains that coverage (a
|
|
30
|
+
* hairline, or a thin gap), the stripe's two edges are its contour, so that the
|
|
31
|
+
* stripe's centreline lies half its width inside (or outside, for a gap); else
|
|
32
|
+
* the coverage determines nothing and the contour is taken at its centre. The
|
|
33
|
+
* side of every texel is decided before its magnitude is capped: by its
|
|
34
|
+
* coverage (inside when at least 128), unless a corner it holds or is nearest
|
|
35
|
+
* to, or a stripe it holds, places its centre on the other side. Texels farther
|
|
36
|
+
* than `range` from any contour saturate at the cap.
|
|
17
37
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
38
|
+
* The field is stored as 32-bit floats: magnitudes are capped at the largest
|
|
39
|
+
* 32-bit float not above `range` (`3.4028234663852886e38` for a larger
|
|
40
|
+
* `range`), so the field never exceeds `range` and never overflows to an
|
|
41
|
+
* infinity; below the smallest 32-bit float (`2⁻¹⁴⁹`) only the sign of zero is
|
|
42
|
+
* left.
|
|
22
43
|
*
|
|
23
|
-
*
|
|
44
|
+
* Within 0.1 texel of the analytic distance, up to 5 texels from the edge, on
|
|
45
|
+
* coverage sampled 16 × 16 per texel and rounded to bytes, for discs of radius
|
|
46
|
+
* 4 and more and polygons whose sides are at least 8 texels long and whose
|
|
47
|
+
* corners are at least 20°, convex or concave; and within 0.02 texel, on
|
|
48
|
+
* exact-area coverage rounded to bytes, for stripes from 0.1 to 0.8 texel wide,
|
|
49
|
+
* of ink or a gap, along a row, a column or a diagonal of texel centres.
|
|
50
|
+
* Smaller polygons and sharper tips leave their corners to the straight pieces,
|
|
51
|
+
* up to half a texel off near the vertex; a feature thinner than a texel that
|
|
52
|
+
* crosses texels off their centres (a hairline at another angle) can be up to
|
|
53
|
+
* half a texel off, as one texel's coverage cannot tell where in it such a
|
|
54
|
+
* feature lies.
|
|
55
|
+
*
|
|
56
|
+
* O(width · height) time: a pass over the grid, the runs grown once from the
|
|
57
|
+
* pieces, a corner tried only where two runs end next to each other, then the
|
|
58
|
+
* lesser of O(pieces · range²) and two sweeps that measure only the texels
|
|
59
|
+
* within `range + 2` of the contour. `8 · width · height` doubles of working
|
|
60
|
+
* memory, none allocated when `scratch` is given. Unlike TinySDF's seeding of
|
|
61
|
+
* {@link squaredDistanceTransform2} (a squared sub-texel offset added at the
|
|
62
|
+
* edge texel, half a texel off near the edge), the distance is measured to the
|
|
63
|
+
* contour itself.
|
|
24
64
|
*
|
|
25
65
|
* @example
|
|
26
66
|
* const coverage = new Uint8Array([0, 0, 128, 255, 255]);
|
|
@@ -30,13 +70,15 @@
|
|
|
30
70
|
* @param out - At least `width · height` entries; overwritten.
|
|
31
71
|
* @param coverage - `width · height` bytes, 0 outside to 255 inside.
|
|
32
72
|
* @param range - The most distance kept, in texels, positive and finite.
|
|
73
|
+
* @param scratch - At least `8 · width · height` entries of working memory,
|
|
74
|
+
* overwritten; allocated when omitted.
|
|
33
75
|
* @returns `out`.
|
|
34
76
|
* @throws {RangeError} When a size is not a positive integer, `range` is not
|
|
35
|
-
* positive and finite, `coverage` or `
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
77
|
+
* positive and finite, `coverage`, `out` or `scratch` is too short, or two of
|
|
78
|
+
* `out`, `coverage` and `scratch` share bytes within the entries the call
|
|
79
|
+
* uses (checked before anything is written). Views over a `SharedArrayBuffer`
|
|
80
|
+
* and over any other shared buffer, a clone of it included, are taken to
|
|
81
|
+
* share memory.
|
|
40
82
|
*/
|
|
41
|
-
export declare function signedDistanceFromCoverage2(out: Float32Array, coverage: Uint8Array, width: number, height: number, range: number): Float32Array;
|
|
83
|
+
export declare function signedDistanceFromCoverage2(out: Float32Array, coverage: Uint8Array, width: number, height: number, range: number, scratch?: Float64Array): Float32Array;
|
|
42
84
|
//# sourceMappingURL=signed-distance-from-coverage2.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signed-distance-from-coverage2.d.ts","sourceRoot":"","sources":["../src/signed-distance-from-coverage2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signed-distance-from-coverage2.d.ts","sourceRoot":"","sources":["../src/signed-distance-from-coverage2.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AACH,wBAAgB,2BAA2B,CAC1C,GAAG,EAAE,YAAY,EACjB,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,YAAY,GACpB,YAAY,CAgMd"}
|