@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.
Files changed (95) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/README.md +117 -10
  3. package/dist/_brand.d.ts +14 -0
  4. package/dist/_brand.d.ts.map +1 -0
  5. package/dist/_brand.js +2 -0
  6. package/dist/_brand.js.map +1 -0
  7. package/dist/_coverage-contour2.d.ts +55 -0
  8. package/dist/_coverage-contour2.d.ts.map +1 -0
  9. package/dist/_coverage-contour2.js +2068 -0
  10. package/dist/_coverage-contour2.js.map +1 -0
  11. package/dist/_grid-offsets2.d.ts +15 -0
  12. package/dist/_grid-offsets2.d.ts.map +1 -0
  13. package/dist/_grid-offsets2.js +53 -0
  14. package/dist/_grid-offsets2.js.map +1 -0
  15. package/dist/_nearest-site-propagation2.d.ts +80 -0
  16. package/dist/_nearest-site-propagation2.d.ts.map +1 -0
  17. package/dist/_nearest-site-propagation2.js +707 -0
  18. package/dist/_nearest-site-propagation2.js.map +1 -0
  19. package/dist/breadth-first-grid2.d.ts +65 -0
  20. package/dist/breadth-first-grid2.d.ts.map +1 -0
  21. package/dist/breadth-first-grid2.js +116 -0
  22. package/dist/breadth-first-grid2.js.map +1 -0
  23. package/dist/flood-fill2.d.ts +39 -0
  24. package/dist/flood-fill2.d.ts.map +1 -0
  25. package/dist/flood-fill2.js +76 -0
  26. package/dist/flood-fill2.js.map +1 -0
  27. package/dist/grid-neighbors2.d.ts +45 -0
  28. package/dist/grid-neighbors2.d.ts.map +1 -0
  29. package/dist/grid-neighbors2.js +45 -0
  30. package/dist/grid-neighbors2.js.map +1 -0
  31. package/dist/grid-pack-dfs.d.ts.map +1 -1
  32. package/dist/grid-pack-dfs.js +4 -2
  33. package/dist/grid-pack-dfs.js.map +1 -1
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +6 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/infinite-grid2.js.map +1 -1
  39. package/dist/max-rects-pack.d.ts +90 -0
  40. package/dist/max-rects-pack.d.ts.map +1 -0
  41. package/dist/max-rects-pack.js +310 -0
  42. package/dist/max-rects-pack.js.map +1 -0
  43. package/dist/rasterize-line2.d.ts +33 -0
  44. package/dist/rasterize-line2.d.ts.map +1 -0
  45. package/dist/rasterize-line2.js +103 -0
  46. package/dist/rasterize-line2.js.map +1 -0
  47. package/dist/shelf-allocator.d.ts +7 -1
  48. package/dist/shelf-allocator.d.ts.map +1 -1
  49. package/dist/shelf-allocator.js +32 -32
  50. package/dist/shelf-allocator.js.map +1 -1
  51. package/dist/signed-distance-from-coverage2.d.ts +63 -21
  52. package/dist/signed-distance-from-coverage2.d.ts.map +1 -1
  53. package/dist/signed-distance-from-coverage2.js +327 -99
  54. package/dist/signed-distance-from-coverage2.js.map +1 -1
  55. package/dist/squared-distance-transform2.d.ts +9 -4
  56. package/dist/squared-distance-transform2.d.ts.map +1 -1
  57. package/dist/squared-distance-transform2.js +9 -4
  58. package/dist/squared-distance-transform2.js.map +1 -1
  59. package/dist/tile/_tile-matrix.d.ts +33 -0
  60. package/dist/tile/_tile-matrix.d.ts.map +1 -0
  61. package/dist/tile/_tile-matrix.js +186 -0
  62. package/dist/tile/_tile-matrix.js.map +1 -0
  63. package/dist/tile/index.d.ts +8 -0
  64. package/dist/tile/index.d.ts.map +1 -0
  65. package/dist/tile/index.js +8 -0
  66. package/dist/tile/index.js.map +1 -0
  67. package/dist/tile/quadkey.d.ts +30 -0
  68. package/dist/tile/quadkey.d.ts.map +1 -0
  69. package/dist/tile/quadkey.js +91 -0
  70. package/dist/tile/quadkey.js.map +1 -0
  71. package/dist/tile/tile-address.d.ts +91 -0
  72. package/dist/tile/tile-address.d.ts.map +1 -0
  73. package/dist/tile/tile-address.js +228 -0
  74. package/dist/tile/tile-address.js.map +1 -0
  75. package/dist/tile/tile-index.d.ts +26 -0
  76. package/dist/tile/tile-index.d.ts.map +1 -0
  77. package/dist/tile/tile-index.js +2 -0
  78. package/dist/tile/tile-index.js.map +1 -0
  79. package/dist/tile/tile-level.d.ts +24 -0
  80. package/dist/tile/tile-level.d.ts.map +1 -0
  81. package/dist/tile/tile-level.js +53 -0
  82. package/dist/tile/tile-level.js.map +1 -0
  83. package/dist/tile/tile-matrix-set-json.d.ts +67 -0
  84. package/dist/tile/tile-matrix-set-json.d.ts.map +1 -0
  85. package/dist/tile/tile-matrix-set-json.js +247 -0
  86. package/dist/tile/tile-matrix-set-json.js.map +1 -0
  87. package/dist/tile/tile-matrix-set.d.ts +174 -0
  88. package/dist/tile/tile-matrix-set.d.ts.map +1 -0
  89. package/dist/tile/tile-matrix-set.js +244 -0
  90. package/dist/tile/tile-matrix-set.js.map +1 -0
  91. package/dist/tile/tile-range.d.ts +57 -0
  92. package/dist/tile/tile-range.d.ts.map +1 -0
  93. package/dist/tile/tile-range.js +140 -0
  94. package/dist/tile/tile-range.js.map +1 -0
  95. package/package.json +10 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,154 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5c203e7: Grid algorithms over a `width × height` grid in row-major order, cells reached
8
+ through `(col, row)` callbacks:
9
+
10
+ - `gridNeighbors2(col, row, width, height, connectivity, visit)` visits the
11
+ neighbours on the grid; `GridConnectivity2` is `4`, `8`, or one of the four
12
+ hexagonal offset layouts (`"hex-odd-r"`, `"hex-even-r"`, `"hex-odd-q"`,
13
+ `"hex-even-q"`).
14
+ - `floodFill2(out, width, height, col, row, inside, connectivity?)` marks the
15
+ connected region in a `Uint8Array` mask and returns how many cells it filled;
16
+ marked cells are neither tested nor entered.
17
+ - `breadthFirstGrid2(width, height, col, row, passable, connectivity?)` returns
18
+ the fewest steps to every cell and each cell's predecessor
19
+ (`GridBreadthFirst2`), and `gridPath2(search, col, row)` the path as cell
20
+ indices.
21
+ - `rasterizeLine2(fromCol, fromRow, toCol, toRow, visit)` is Bresenham's line,
22
+ the same cells whichever end it is drawn from.
23
+ - `maxRectsPack(bins, items, { heuristic, allowRotation })` packs rectangles
24
+ into bins with MaxRects' global best fit and five heuristics, returning each
25
+ item's placement (or `undefined`), each bin's occupancy and the fill ratio.
26
+ - 5c203e7: Tile pyramids: the tile matrix sets of OGC 17-083r4 (TMS 2.0) in any CRS, and
27
+ the tile queries over them. Depends on `@ac-kit/math-integer`.
28
+
29
+ - `tileMatrixSetCreate(spec)` makes a frozen `TileMatrixSet`: tile matrices
30
+ with their scale denominator, cell size, corner of origin (`"topLeft"` or
31
+ `"bottomLeft"`), point of origin, tile and matrix sizes and variable matrix
32
+ widths (coalesced rows), sorted coarsest first so a tile's `level` indexes
33
+ them; `tileMatrixSetLevelOf` finds a matrix by identifier. Coordinates are in
34
+ plane order `[x, y]`, x along the columns, whatever the CRS axis order.
35
+ - `tileMatrixSetFromJson(json, options?)` and `tileMatrixSetToJson(set)` read
36
+ and write the JSON encoding, swapping latitude-first coordinates by the axis
37
+ order of the option, `orderedAxes` or a well-known CRS (`RangeError` when it
38
+ cannot be known, `TypeError` for wrong JSON types).
39
+ - `tileAt`, `tileBounds`, `tileParent`, `tileChildren` and
40
+ `tileNeighbours(set, tile, visit, { wrap })` address tiles: half-open in index
41
+ space with the matrix's far edges closed, a coalesced tile spanning its group
42
+ and named by its first column, neighbours across coalesced rows.
43
+ - `tilesCoveringBox(set, level, box, { wrap, epsilon })` gives the tile ranges
44
+ a box overlaps (two across the antimeridian with `wrap`, edges snapped within
45
+ `TILE_EPSILON`), and `tileRangeForEach` and `tileRangeCount` enumerate and
46
+ count a `TileRange` in O(tiles).
47
+ - `tileLevelForResolution(set, cellSize, { rounding })` picks the nearest,
48
+ finer or coarser level; `tileRowFlip` and `tileMatrixSetWithCornerOfOrigin`
49
+ convert between the XYZ and TMS numberings; `tileQuadkey` and
50
+ `tileFromQuadkey` read and write Bing Maps quadkeys up to level 53;
51
+ `tileMatrixCoalescence` and `tileMatrixBounds` describe one matrix.
52
+ - A level, column or row outside the set throws `RangeError`; `NaN` in gives
53
+ `NaN` out. The queries allocate nothing but `tilesCoveringBox`'s ranges.
54
+
55
+ ### Patch Changes
56
+
57
+ - 5c203e7: Sped up `signedDistanceFromCoverage2` (~1.9× faster on 256 × 64 labels, down to
58
+ 1.07× the binary two-pass transform) by fusing the Sobel edge and residual
59
+ reads, iterating only contour site cells, storing splatted squared distances in
60
+ 32-bit floats in place, and adding half-plane and axis-aligned fast paths for
61
+ corner fitting and segment splatting while preserving exact-corner accuracy and
62
+ 0 B allocation with a caller scratch.
63
+ - Updated dependencies [5c203e7]
64
+ - Updated dependencies [5c203e7]
65
+ - Updated dependencies [5c203e7]
66
+ - Updated dependencies [5c203e7]
67
+ - Updated dependencies [5c203e7]
68
+ - Updated dependencies [5c203e7]
69
+ - Updated dependencies [5c203e7]
70
+ - Updated dependencies [5c203e7]
71
+ - Updated dependencies [5c203e7]
72
+ - Updated dependencies [5c203e7]
73
+ - Updated dependencies [5c203e7]
74
+ - Updated dependencies [5c203e7]
75
+ - Updated dependencies [5c203e7]
76
+ - Updated dependencies [5c203e7]
77
+ - Updated dependencies [5c203e7]
78
+ - Updated dependencies [5c203e7]
79
+ - Updated dependencies [5c203e7]
80
+ - Updated dependencies [5c203e7]
81
+ - @ac-kit/algo@0.7.0
82
+ - @ac-kit/core@0.14.0
83
+ - @ac-kit/math-geometry@0.5.0
84
+ - @ac-kit/math-integer@0.4.0
85
+ - @ac-kit/math-linear@0.5.0
86
+
87
+ ## 0.4.0
88
+
89
+ ### Minor Changes
90
+
91
+ - 0b4fe43: `signedDistanceFromCoverage2(out, coverage, width, height, range, scratch?)`
92
+ measures every texel's distance to the contour located inside each edge texel
93
+ from the coverage, merged into straight runs with corners where two runs meet at
94
+ an angle (Gustavson and Strand's antialiased Euclidean distance transform). The
95
+ field is within 0.1 texel of the analytic distance, up to 5 texels from the
96
+ edge, on discs of radius 4 and more (6 before) and on polygons whose sides are
97
+ at least 8 texels long and whose corners are at least 20° (coverage sampled
98
+ 16 × 16 per texel, rounded to bytes); a stripe thinner than a texel along a
99
+ row, a column or a diagonal of texel centres, of ink or a gap, keeps its
100
+ centreline half its width deep, within 0.02 texel. A feature thinner than a
101
+ texel that crosses texels off their centres can be up to half a texel off. A
102
+ texel's side is decided before its magnitude is capped, by the corner or stripe
103
+ that places it where its coverage alone would not. Magnitudes are capped at the
104
+ largest 32-bit float not above `range`, so the field never passes `range` and
105
+ stays finite for any finite `range`. It runs in time linear in the edge texels,
106
+ then the lesser of O(edge texels · range²) and O(width · height). With a
107
+ `scratch` of at least `8 · width · height` entries it allocates nothing, at any
108
+ range. Two of `out`, `coverage` and `scratch` sharing bytes within the entries
109
+ the call uses throw a `RangeError` before anything is written, shadowed
110
+ `byteOffset`, `byteLength` or `buffer` properties included.
111
+
112
+ ### Patch Changes
113
+
114
+ - 0b4fe43: Instance state that was held in `#` private fields is now held in
115
+ TypeScript-private properties (named with a trailing `_`). They are no longer
116
+ hidden at runtime: they appear as own properties (`Object.keys`,
117
+ `JSON.stringify`, `structuredClone`, deep equality), and the declarations list
118
+ them as `private`. Public members are unchanged.
119
+ - Updated dependencies [0b4fe43]
120
+ - Updated dependencies [0b4fe43]
121
+ - Updated dependencies [0b4fe43]
122
+ - Updated dependencies [0b4fe43]
123
+ - Updated dependencies [0b4fe43]
124
+ - Updated dependencies [0b4fe43]
125
+ - Updated dependencies [0b4fe43]
126
+ - Updated dependencies [0b4fe43]
127
+ - Updated dependencies [0b4fe43]
128
+ - Updated dependencies [0b4fe43]
129
+ - Updated dependencies [0b4fe43]
130
+ - Updated dependencies [0b4fe43]
131
+ - Updated dependencies [0b4fe43]
132
+ - Updated dependencies [0b4fe43]
133
+ - Updated dependencies [0b4fe43]
134
+ - Updated dependencies [0b4fe43]
135
+ - Updated dependencies [0b4fe43]
136
+ - Updated dependencies [0b4fe43]
137
+ - Updated dependencies [0b4fe43]
138
+ - Updated dependencies [0b4fe43]
139
+ - Updated dependencies [0b4fe43]
140
+ - Updated dependencies [0b4fe43]
141
+ - Updated dependencies [0b4fe43]
142
+ - Updated dependencies [0b4fe43]
143
+ - Updated dependencies [0b4fe43]
144
+ - Updated dependencies [0b4fe43]
145
+ - Updated dependencies [0b4fe43]
146
+ - Updated dependencies [0b4fe43]
147
+ - @ac-kit/algo@0.6.0
148
+ - @ac-kit/core@0.13.0
149
+ - @ac-kit/math-geometry@0.4.0
150
+ - @ac-kit/math-linear@0.4.0
151
+
3
152
  ## 0.3.0
4
153
 
5
154
  ### Minor Changes
package/README.md CHANGED
@@ -19,7 +19,7 @@ grid.getCell({ row: 1, col: 2 }); // "widget"
19
19
  ## Scope
20
20
 
21
21
  Geometry where positions are integers and cells are the unit of measurement —
22
- tile maps, bin packing, layout solvers, cellular automata.
22
+ tile maps, bin packing, layout solvers, cellular automata, tile pyramids.
23
23
 
24
24
  Continuous geometry lives in `@ac-kit/math-geometry`; the conversion functions
25
25
  between the two are here.
@@ -35,8 +35,8 @@ between the two are here.
35
35
 
36
36
  Plus `GridCoord2`, `GridSize2`, `GridRect2`, the conversions to and from
37
37
  continuous space (`vec2FromGridCoord2`, `box2FromGridRect2`,
38
- `gridRect2FromBox2`, …), and the tiling algorithms `findFrontierTilings` and
39
- `dfsPackGrid2`.
38
+ `gridRect2FromBox2`, …), the tiling algorithms `findFrontierTilings` and
39
+ `dfsPackGrid2`, and the OGC tile matrix sets of [tile pyramids](#tile-matrix-sets).
40
40
 
41
41
  ## Atlases and distance fields
42
42
 
@@ -59,10 +59,29 @@ atlas.occupancy; // 0
59
59
  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
+ `maxRectsPack(bins, items, { heuristic, allowRotation })` is the offline
63
+ packer: given every rectangle up front, it places them with MaxRects (Jylänki's
64
+ global best fit, five scoring heuristics, quarter turns on request) into the
65
+ bins in order, and reports each bin's occupancy and the overall fill ratio.
66
+
67
+ ```ts
68
+ import { maxRectsPack } from "@ac-kit/math-grid";
69
+
70
+ const { placements, fillRatio } = maxRectsPack(
71
+ [{ width: 256, height: 256 }],
72
+ [
73
+ { width: 128, height: 64 },
74
+ { width: 64, height: 200 },
75
+ ],
76
+ { heuristic: "best-short-side-fit", allowRotation: true },
77
+ );
78
+ placements[0]; // { bin: 0, x, y, rotated } — undefined for an item that fit no bin
79
+ ```
80
+
62
81
  `squaredDistanceTransform2` turns a grid of seeds (0 at a feature, `Infinity`
63
- far from any, a squared sub-texel distance for a coverage-estimated edge cell)
64
- into exact squared distances, in place, in O(width · height): the core of a
65
- signed-distance-field glyph. Pass a `scratch` of at least
82
+ far from any, or any other non-negative cost) into the exact squared distance
83
+ to the nearest feature, cost included, in place, in O(width · height).
84
+ Features are cell centres. Pass a `scratch` of at least
66
85
  `3 · max(width, height) + 1` entries to avoid any allocation.
67
86
 
68
87
  ```ts
@@ -75,10 +94,23 @@ squaredDistanceTransform2(grid, 5, 3); // 5 2 1 2 5 / 4 1 0 1 4 / 5 2 1 2 5
75
94
 
76
95
  `signedDistanceFromCoverage2` turns antialiased coverage bytes (0 outside, 255
77
96
  inside) into a signed distance field in texels, negative inside, capped at a
78
- `range`, within a tenth of a texel on discs — where seeding the transform above
79
- from coverage is half a texel off. It keeps sub-texel edges by locating the
80
- contour in each edge texel from the coverage gradient. O(edge texels · range²),
81
- no allocation.
97
+ `range`: the sub-texel contour, located in each edge texel from the coverage,
98
+ is merged into straight runs, with a corner where two runs meet at an angle,
99
+ and every texel within `range` measures its distance to it (Gustavson &
100
+ Strand's antialiased Euclidean distance transform; vector propagation for a
101
+ long range). Within a tenth of a texel of the analytic distance, up to 5
102
+ texels from the edge, on discs of radius 4 and more and on polygons whose sides
103
+ are at least 8 texels long and whose corners are at least 20° (coverage sampled
104
+ 16 × 16 per texel, rounded to bytes), and within 0.02 texel on stripes 0.1 to
105
+ 0.8 texel wide along a row, a column or a diagonal of texel centres, whose
106
+ centreline lies half their width deep; seeding the transform above from
107
+ coverage is half a texel off. A feature thinner than a texel that crosses
108
+ texels off their centres can still be up to half a texel off: one texel's
109
+ coverage cannot tell where in it the feature lies. The field is 32-bit floats,
110
+ capped at the largest one not above `range`, so it stays finite whatever the
111
+ range, and a texel's side is decided before the cap. Pass a `scratch` of
112
+ `8 · width · height` entries to avoid any allocation: the call then allocates
113
+ nothing, whatever the range.
82
114
 
83
115
  ```ts
84
116
  import { signedDistanceFromCoverage2 } from "@ac-kit/math-grid";
@@ -121,6 +153,81 @@ nearest(origin, cells, gridCoord2DistanceManhattan); // { row: 0, col: 5 }
121
153
  nearest(origin, cells, gridCoord2DistanceChebyshev); // { row: 3, col: 3 }
122
154
  ```
123
155
 
156
+ ## Neighbours, fills, searches and lines
157
+
158
+ These take a grid as its size, `width` columns by `height` rows, and read or
159
+ write cells in row-major order (`index = row · width + col`); the caller's
160
+ cells stay wherever they are, reached through callbacks of `(col, row)`.
161
+
162
+ | Function | What it does |
163
+ | ------------------------------------------------------------ | ---------------------------------------------------------------------------- |
164
+ | `gridNeighbors2(col, row, width, height, connectivity, visit)` | The neighbours on the grid: `4`, `8`, or six on a hexagonal grid (`"hex-odd-r"`, `"hex-even-r"`, `"hex-odd-q"`, `"hex-even-q"`) |
165
+ | `floodFill2(out, width, height, col, row, inside, connectivity?)` | Marks the region connected to a cell in a `Uint8Array` mask; marked cells bound later fills |
166
+ | `breadthFirstGrid2(width, height, col, row, passable, connectivity?)` | Fewest steps from a cell to every cell, with each cell's predecessor |
167
+ | `gridPath2(search, col, row)` | The shortest path that search found, as cell indices |
168
+ | `rasterizeLine2(fromCol, fromRow, toCol, toRow, visit)` | Bresenham's line, the same cells in both directions |
169
+
170
+ ```ts
171
+ import { breadthFirstGrid2, gridPath2 } from "@ac-kit/math-grid";
172
+
173
+ // A 3 × 3 grid with a wall in the top two cells of the middle column.
174
+ const search = breadthFirstGrid2(3, 3, 0, 0, (col, row) => !(col === 1 && row < 2));
175
+ gridPath2(search, 2, 0); // Int32Array [0, 3, 6, 7, 8, 5, 2] — down, across, up
176
+ ```
177
+
178
+ ## Tile matrix sets
179
+
180
+ The tile pyramids of web maps and image servers, as OGC 17-083r4 (_Two
181
+ Dimensional Tile Matrix Set_ 2.0) models them, in any CRS: a
182
+ `TileMatrixSet` is a list of tile matrices, each a grid of `matrixWidth ×
183
+ matrixHeight` tiles of `tileWidth × tileHeight` cells of `cellSize` CRS units,
184
+ numbered from a corner of origin (`"topLeft"`, the "XYZ" numbering, or
185
+ `"bottomLeft"`, the "TMS" one), with rows of coalesced tiles near the poles
186
+ where a set has variable matrix widths. `tileMatrixSetCreate(spec)` validates a
187
+ set and sorts its matrices coarsest first, so a tile's `level` is an index into
188
+ them; `tileMatrixSetFromJson` and `tileMatrixSetToJson` read and write the
189
+ standard's JSON encoding. WebMercatorQuad and WorldCRS84Quad themselves are in
190
+ `@ac-kit/math-map-projection`.
191
+
192
+ Coordinates are in plane order, `[x, y]` with x along the columns, whatever
193
+ order the CRS gives its axes: the JSON readers swap EPSG:4326's latitude-first
194
+ points, taking the order from `orderedAxes` or a well-known CRS.
195
+
196
+ | Function | Gives |
197
+ | ------------------------------------------- | ------------------------------------------------------------------------------------ |
198
+ | `tileAt(out, set, level, point)` | The tile holding a point; `NaN` outside the matrix |
199
+ | `tileBounds(out, set, tile)` | Its extent, `[minX, minY, maxX, maxY]` (OGC Annex I) |
200
+ | `tileParent`, `tileChildren` | The coarser tile holding its centre; the range of finer tiles inside it |
201
+ | `tileNeighbours(set, tile, visit, options)` | Every tile touching it, across coalesced rows, wrapping columns on request |
202
+ | `tilesCoveringBox(set, level, box, options)` | The ranges of tiles a box overlaps, split at the antimeridian with `wrap` |
203
+ | `tileRangeForEach`, `tileRangeCount` | The tiles of a range, each coalesced tile once, in O(tiles) |
204
+ | `tileLevelForResolution(set, cellSize)` | The level of the nearest, finer or coarser cell size |
205
+ | `tileRowFlip`, `tileMatrixSetWithCornerOfOrigin` | The XYZ ↔ TMS row flip, for one row or a whole set |
206
+ | `tileQuadkey`, `tileFromQuadkey` | Bing Maps quadkeys, to level 53, over `@ac-kit/math-integer`'s `interleaveBits2` |
207
+
208
+ Tiles are half-open in index space, so a point on an edge belongs to the tile
209
+ of higher index, except on the far edges of a matrix, which belong to its last
210
+ tiles; `tileAt` and `tileBounds` compute every edge the same way, so a tile's
211
+ corner of origin gives that tile back. Box queries snap edges within
212
+ `TILE_EPSILON` (`1e-6` tile, the standard's tolerance for rounded cell sizes).
213
+ A level, column or row outside the set throws `RangeError`; `NaN` in gives
214
+ `NaN` out. The queries allocate nothing but `tilesCoveringBox`'s ranges.
215
+
216
+ ```ts
217
+ import {
218
+ tileAt,
219
+ tileMatrixSetFromJson,
220
+ tileNeighbours,
221
+ } from "@ac-kit/math-grid";
222
+ import { vec2Of } from "@ac-kit/math-linear";
223
+
224
+ const set = tileMatrixSetFromJson(await (await fetch(url)).json());
225
+ const tile = tileAt({ level: 0, col: 0, row: 0 }, set, 3, vec2Of(2.35, 48.85));
226
+ tileNeighbours(set, tile, (col, row) => load(tile.level, col, row), {
227
+ wrap: true,
228
+ });
229
+ ```
230
+
124
231
  ## Choosing a storage strategy
125
232
 
126
233
  The four grid types exist because the access pattern, not the abstraction,
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The brand of every value type of the math packages: a property with a string
3
+ * key that is stable across versions, so two installed copies of a package (two
4
+ * dependents pinning different minors) stay assignable to each other, which a
5
+ * per-package `unique symbol` would not allow.
6
+ *
7
+ * Declared identically and internally in each package, never imported across
8
+ * packages: the structure is the identity. The key is reserved, and the brand
9
+ * costs nothing at run time.
10
+ */
11
+ export type Brand_<Name extends string> = {
12
+ readonly "~acKitMathType": Name;
13
+ };
14
+ //# sourceMappingURL=_brand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_brand.d.ts","sourceRoot":"","sources":["../src/_brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,MAAM,CAAC,IAAI,SAAS,MAAM,IAAI;IACzC,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC;CAChC,CAAC"}
package/dist/_brand.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=_brand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_brand.js","sourceRoot":"","sources":["../src/_brand.ts"],"names":[],"mappings":""}
@@ -0,0 +1,55 @@
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, and its straight-edge
20
+ * residual over the 3 × 3 neighbourhood into `residuals[cell]`. Interior texels
21
+ * reuse the nine coverage samples already loaded for the Sobel gradient.
22
+ */
23
+ export declare function locateEdgeAndResidual_(sites: Float64Array, at: number, coverage: Uint8Array, value: number, x: number, y: number, width: number, height: number, residuals: Float32Array, cell: number): void;
24
+ /**
25
+ * Writes the straight edge of antialiased texel `(x, y)`, of coverage `value`,
26
+ * at `sites[at]` in the `COVERAGE_STRIDE_` layout.
27
+ */
28
+ export declare function locateEdge_(sites: Float64Array, at: number, coverage: Uint8Array, value: number, x: number, y: number, width: number, height: number): void;
29
+ /**
30
+ * Writes into `residuals[cell]` how far the coverage of the texels around
31
+ * antialiased texel `(x, y)`, as a fraction of a texel, strays from what its
32
+ * straight edge (at `sites[at]`) predicts; `NaN` for a texel without one (a
33
+ * zero gradient).
34
+ */
35
+ export declare function edgeResidual_(sites: Float64Array, at: number, coverage: Uint8Array, x: number, y: number, width: number, height: number, residuals: Float32Array, cell: number): void;
36
+ /**
37
+ * Merges the straight pieces of contour of a coverage grid into runs, one
38
+ * segment site each, and places a corner where two runs meet at an angle (see
39
+ * the module notes). `scratch` holds each site cell's label in `[0, count)`
40
+ * (`UNASSIGNED_` on entry; afterwards its run's holder for a run's piece, its
41
+ * own cell for a corner's holder, the holder for a cell that took a corner,
42
+ * else negative), free room in `[count, 2 · count)`, and the site geometry from
43
+ * `2 · count`; `residuals` the straight-edge residual of each antialiased
44
+ * texel. Returns how many corners there are, their holders listed from
45
+ * `scratch[count]`.
46
+ */
47
+ export declare function findContour_(scratch: Float64Array, residuals: Float32Array, coverage: Uint8Array, width: number, height: number, siteCells: Int32Array, siteCount: number): number;
48
+ /**
49
+ * Whether cell `cell` holds contour: an antialiased texel, or a full or empty
50
+ * texel with an opposite neighbour to the right or below.
51
+ */
52
+ export declare function isSiteCell_(coverage: Uint8Array, cell: number, width: number, count: number): boolean;
53
+ /** Whether the site of cell `cell` is a corner. */
54
+ export declare function isCorner_(scratch: Float64Array, base: number, cell: number): boolean;
55
+ //# 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;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,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,EACd,SAAS,EAAE,YAAY,EACvB,IAAI,EAAE,MAAM,GACV,IAAI,CAqON;AA8BD;;;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,EACd,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,MAAM,GACf,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;AAgoBD,mDAAmD;AACnD,wBAAgB,SAAS,CACxB,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV,OAAO,CAOT"}