@mailwoman/spatial 9.1.0 → 9.3.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 (161) hide show
  1. package/{bbox.ts → lib/bbox.ts} +54 -3
  2. package/lib/coordinate-bounds.ts +52 -0
  3. package/{coordinate-formats.ts → lib/coordinate-formats.ts} +16 -3
  4. package/lib/distance.ts +165 -0
  5. package/{feature.ts → lib/feature.ts} +1 -1
  6. package/{geometries → lib/geometries}/collection.ts +4 -4
  7. package/lib/geometries/index.ts +13 -0
  8. package/{geometries → lib/geometries}/line-string.ts +2 -2
  9. package/{geometries → lib/geometries}/point.ts +9 -9
  10. package/{geometries → lib/geometries}/polygon.ts +93 -89
  11. package/lib/geometries/ring-blob.ts +521 -0
  12. package/{google → lib/google}/index.ts +1 -1
  13. package/{h3 → lib/h3}/cell.ts +83 -1
  14. package/lib/h3/coverage.ts +45 -0
  15. package/{h3 → lib/h3}/index.ts +5 -3
  16. package/lib/h3/interior-cells.ts +138 -0
  17. package/lib/h3/polygon-cells.ts +462 -0
  18. package/lib/index.ts +21 -0
  19. package/{objects.ts → lib/objects.ts} +1 -1
  20. package/lib/open-location-code.ts +168 -0
  21. package/{osgb36.ts → lib/osgb36.ts} +2 -2
  22. package/{polyline.ts → lib/polyline.ts} +1 -1
  23. package/lib/position.ts +216 -0
  24. package/lib/projection-transform.ts +115 -0
  25. package/{regions → lib/regions}/codes.ts +1 -1
  26. package/{regions → lib/regions}/index.ts +2 -2
  27. package/lib/tools/ogr-stream.ts +99 -0
  28. package/lib/tools/ogr.ts +201 -0
  29. package/{sdk → lib}/well-known-text.ts +2 -1
  30. package/out/bbox.d.ts +23 -2
  31. package/out/bbox.d.ts.map +1 -1
  32. package/out/bbox.js +33 -2
  33. package/out/bbox.js.map +1 -1
  34. package/out/coordinate-bounds.d.ts +41 -0
  35. package/out/coordinate-bounds.d.ts.map +1 -0
  36. package/out/coordinate-bounds.js +45 -0
  37. package/out/coordinate-bounds.js.map +1 -0
  38. package/out/coordinate-formats.d.ts +8 -0
  39. package/out/coordinate-formats.d.ts.map +1 -1
  40. package/out/coordinate-formats.js +14 -3
  41. package/out/coordinate-formats.js.map +1 -1
  42. package/out/distance.d.ts +84 -0
  43. package/out/distance.d.ts.map +1 -0
  44. package/out/distance.js +132 -0
  45. package/out/distance.js.map +1 -0
  46. package/out/feature.d.ts +1 -1
  47. package/out/feature.d.ts.map +1 -1
  48. package/out/feature.js.map +1 -1
  49. package/out/geometries/collection.d.ts +4 -4
  50. package/out/geometries/collection.d.ts.map +1 -1
  51. package/out/geometries/collection.js.map +1 -1
  52. package/out/geometries/index.d.ts +5 -4
  53. package/out/geometries/index.d.ts.map +1 -1
  54. package/out/geometries/index.js +5 -4
  55. package/out/geometries/index.js.map +1 -1
  56. package/out/geometries/line-string.d.ts +2 -2
  57. package/out/geometries/line-string.d.ts.map +1 -1
  58. package/out/geometries/line-string.js.map +1 -1
  59. package/out/geometries/point.d.ts +9 -9
  60. package/out/geometries/point.d.ts.map +1 -1
  61. package/out/geometries/point.js +9 -9
  62. package/out/geometries/point.js.map +1 -1
  63. package/out/geometries/polygon.d.ts +60 -56
  64. package/out/geometries/polygon.d.ts.map +1 -1
  65. package/out/geometries/polygon.js +66 -63
  66. package/out/geometries/polygon.js.map +1 -1
  67. package/out/geometries/ring-blob.d.ts +183 -0
  68. package/out/geometries/ring-blob.d.ts.map +1 -0
  69. package/out/geometries/ring-blob.js +376 -0
  70. package/out/geometries/ring-blob.js.map +1 -0
  71. package/out/google/index.d.ts +1 -1
  72. package/out/google/index.d.ts.map +1 -1
  73. package/out/google/index.js +1 -1
  74. package/out/google/index.js.map +1 -1
  75. package/out/google/place-id.d.ts.map +1 -1
  76. package/out/google/place-id.js.map +1 -1
  77. package/out/h3/cell.d.ts +32 -0
  78. package/out/h3/cell.d.ts.map +1 -1
  79. package/out/h3/cell.js +68 -1
  80. package/out/h3/cell.js.map +1 -1
  81. package/out/h3/coverage.d.ts +32 -0
  82. package/out/h3/coverage.d.ts.map +1 -0
  83. package/out/h3/coverage.js +27 -0
  84. package/out/h3/coverage.js.map +1 -0
  85. package/out/h3/index.d.ts +5 -3
  86. package/out/h3/index.d.ts.map +1 -1
  87. package/out/h3/index.js +5 -3
  88. package/out/h3/index.js.map +1 -1
  89. package/out/h3/interior-cells.d.ts +54 -0
  90. package/out/h3/interior-cells.d.ts.map +1 -0
  91. package/out/h3/interior-cells.js +111 -0
  92. package/out/h3/interior-cells.js.map +1 -0
  93. package/out/h3/polygon-cells.d.ts +182 -0
  94. package/out/h3/polygon-cells.d.ts.map +1 -0
  95. package/out/h3/polygon-cells.js +339 -0
  96. package/out/h3/polygon-cells.js.map +1 -0
  97. package/out/index.d.ts +15 -12
  98. package/out/index.d.ts.map +1 -1
  99. package/out/index.js +15 -12
  100. package/out/index.js.map +1 -1
  101. package/out/objects.d.ts +1 -1
  102. package/out/objects.d.ts.map +1 -1
  103. package/out/objects.js +1 -1
  104. package/out/objects.js.map +1 -1
  105. package/out/open-location-code.d.ts +48 -0
  106. package/out/open-location-code.d.ts.map +1 -0
  107. package/out/open-location-code.js +137 -0
  108. package/out/open-location-code.js.map +1 -0
  109. package/out/osgb36.d.ts +2 -2
  110. package/out/osgb36.d.ts.map +1 -1
  111. package/out/osgb36.js +1 -1
  112. package/out/osgb36.js.map +1 -1
  113. package/out/polyline.d.ts.map +1 -1
  114. package/out/polyline.js +1 -1
  115. package/out/polyline.js.map +1 -1
  116. package/out/position.d.ts +4 -61
  117. package/out/position.d.ts.map +1 -1
  118. package/out/position.js +14 -126
  119. package/out/position.js.map +1 -1
  120. package/out/projection-transform.d.ts +67 -0
  121. package/out/projection-transform.d.ts.map +1 -0
  122. package/out/projection-transform.js +48 -0
  123. package/out/projection-transform.js.map +1 -0
  124. package/out/projection.d.ts.map +1 -1
  125. package/out/projection.js.map +1 -1
  126. package/out/regions/codes.d.ts.map +1 -1
  127. package/out/regions/codes.js.map +1 -1
  128. package/out/regions/index.d.ts +2 -2
  129. package/out/regions/index.d.ts.map +1 -1
  130. package/out/regions/index.js +2 -2
  131. package/out/regions/index.js.map +1 -1
  132. package/out/regions/names.d.ts.map +1 -1
  133. package/out/regions/names.js.map +1 -1
  134. package/out/tools/ogr-stream.d.ts +34 -0
  135. package/out/tools/ogr-stream.d.ts.map +1 -0
  136. package/out/tools/ogr-stream.js +74 -0
  137. package/out/tools/ogr-stream.js.map +1 -0
  138. package/out/tools/ogr.d.ts +87 -0
  139. package/out/tools/ogr.d.ts.map +1 -0
  140. package/out/tools/ogr.js +84 -0
  141. package/out/tools/ogr.js.map +1 -0
  142. package/out/tsconfig.test.tsbuildinfo +1 -1
  143. package/out/{sdk/well-known-text.d.ts → well-known-text.d.ts} +1 -1
  144. package/out/well-known-text.d.ts.map +1 -0
  145. package/out/well-known-text.js.map +1 -0
  146. package/package.json +143 -14
  147. package/geometries/index.ts +0 -12
  148. package/index.ts +0 -18
  149. package/out/sdk/index.d.ts +0 -7
  150. package/out/sdk/index.d.ts.map +0 -1
  151. package/out/sdk/index.js +0 -7
  152. package/out/sdk/index.js.map +0 -1
  153. package/out/sdk/well-known-text.d.ts.map +0 -1
  154. package/out/sdk/well-known-text.js.map +0 -1
  155. package/out/tsconfig.tsbuildinfo +0 -1
  156. package/position.ts +0 -345
  157. package/sdk/index.ts +0 -7
  158. /package/{google → lib/google}/place-id.ts +0 -0
  159. /package/{projection.ts → lib/projection.ts} +0 -0
  160. /package/{regions → lib/regions}/names.ts +0 -0
  161. /package/out/{sdk/well-known-text.js → well-known-text.js} +0 -0
@@ -3,7 +3,6 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  */
6
- import { ResourceError } from "@mailwoman/core/errors";
7
6
  /**
8
7
  * Predicate for checking if a GeoJSON object is a `Polygon` geometry.
9
8
  */
@@ -15,6 +14,8 @@ export function isPolygonLiteral(input) {
15
14
  /**
16
15
  * Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
17
16
  */
17
+ // The parameter admits BOTH paths because distinguishing them is the function's job: defaulted to
18
+ // `SolidPolygonPath`, it cannot be asked about a polygon with holes without the caller asserting past the signature.
18
19
  export function isSolidPolygonPath(input) {
19
20
  return input.coordinates.length === 1;
20
21
  }
@@ -62,79 +63,81 @@ export function pointInMultiPolygon(lon, lat, polygons) {
62
63
  return polygons.some((rings) => pointInPolygon(lon, lat, rings));
63
64
  }
64
65
  /**
65
- * Predicate for checking if a GeoJSON object is a `MultiPolygon` geometry.
66
+ * A geometry's polygons in the `MultiPolygon` coordinate shape, whichever areal type it arrived as — `null` when the
67
+ * geometry is not areal (a Point or a LineString bounds no area).
68
+ *
69
+ * The one place a `Polygon` is lifted to `[rings]`; a caller that must refuse a non-areal geometry does so on the
70
+ * `null`, with its own message.
66
71
  */
72
+ export function arealPolygons(geometry) {
73
+ if (!geometry)
74
+ return null;
75
+ if (geometry.type === "Polygon")
76
+ return [geometry.coordinates];
77
+ if (geometry.type === "MultiPolygon")
78
+ return geometry.coordinates;
79
+ return null;
80
+ }
67
81
  /**
68
- * Given a polygon geometry, return an OSM filter string.
82
+ * The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
83
+ * writing for itself.
69
84
  *
70
- * This is useful when working with the Overpass API.
85
+ * @param subject Names the feature in the refusal, e.g. `feature 41209`.
86
+ * @param context Names the calling ingest, so a build log says which layer stopped.
87
+ * @throws {Error} When the geometry is neither a `Polygon` nor a `MultiPolygon`.
71
88
  */
72
- export function polygonToOSMFilter(input) {
73
- if (!isPolygonLiteral(input))
74
- return "";
75
- const [exteriorRing] = input.coordinates;
76
- const filter = exteriorRing.map(([lon, lat]) => `${lat} ${lon}`).join(" ");
77
- return `poly:'${filter}'`;
89
+ export function requireArealPolygons(geometry, subject, context) {
90
+ const polygons = arealPolygons(geometry);
91
+ if (polygons)
92
+ return polygons;
93
+ throw new Error(`${context}: ${subject} is a ${geometry.type}, expected Polygon or MultiPolygon`);
78
94
  }
79
95
  /**
80
- * Tags returned by the Overpass API for a node.
96
+ * Does an areal GeoJSON geometry contain the point?
97
+ *
98
+ * The three-valued return is the point of the function. `null` means the geometry is NOT AREAL — a Point or a
99
+ * LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
100
+ * geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
101
+ * containment pass instead of falling through to the approximate path.
81
102
  *
82
- * @category OSM
103
+ * `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
104
+ * HAND if this one changes — it is the one copy no import can reach.
83
105
  */
84
- export const OSMNodeTag = {
85
- HouseNumber: "addr:housenumber",
86
- PostCode: "addr:postcode",
87
- Street: "addr:street",
88
- State: "addr:state",
89
- City: "addr:city",
90
- Website: "website",
91
- Email: "email",
92
- Phone: "phone",
93
- Shop: "shop",
94
- Brand: "brand",
95
- Cuisine: "cuisine",
96
- Name: "name",
97
- Healthcare: "healthcare",
98
- Office: "office",
99
- Amenity: "amenity",
100
- };
106
+ export function geometryContains(geometry, lon, lat) {
107
+ const polygons = arealPolygons(geometry);
108
+ if (!polygons)
109
+ return null;
110
+ return polygons.some((rings) => pointInPolygon(lon, lat, rings));
111
+ }
101
112
  /**
102
- * OSM node tags that disqualify a node from being treated as residential — a node carrying one of these is
103
- * infrastructure or commercial, whatever else it claims.
113
+ * An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise — the exterior
114
+ * winding.
115
+ *
116
+ * SHARED BECAUSE THE WINDING IS A CONVENTION AND A SECOND COPY IS A SECOND PLACE FOR IT TO DRIFT. Three layer builders
117
+ * hand-build rectangles for their fixture rungs, and each pairs this with {@link reversedRing} to make a hole. A copy
118
+ * whose hole is wound the same way as its exterior produces a fixture that passes every structural check and tests
119
+ * nothing about hole handling — which is the exact failure the area cross-check exists to catch in production data.
104
120
  */
105
- export const ForbiddenResidentialOSMNodeTags = new Set([
106
- OSMNodeTag.Shop,
107
- OSMNodeTag.Brand,
108
- OSMNodeTag.Cuisine,
109
- OSMNodeTag.Office,
110
- OSMNodeTag.Healthcare,
111
- ]);
121
+ export function rectangleRing(minLon, minLat, maxLon, maxLat) {
122
+ return [
123
+ [minLon, minLat],
124
+ [maxLon, minLat],
125
+ [maxLon, maxLat],
126
+ [minLon, maxLat],
127
+ [minLon, minLat],
128
+ ];
129
+ }
112
130
  /**
113
- * Given an OSM element, attempts to infer if the result is a residential address.
131
+ * The same rectangle wound the other way — a hole, under the GeoJSON convention.
114
132
  */
115
- export function isResidentialElement(element) {
116
- for (const key in element.tags) {
117
- if (ForbiddenResidentialOSMNodeTags.has(key))
118
- return false;
119
- }
120
- if (element.tags[OSMNodeTag.Amenity] === "restaurant")
121
- return false;
122
- return true;
123
- }
124
- export function fetchOSMElementViaOverpassAPI(input) {
125
- const filter = polygonToOSMFilter(input);
126
- const url = new URL("http://overpass-api.de/api/interpreter");
127
- url.searchParams.set("data", `[out:json];(node['addr:housenumber'](${filter}););out body;>;out skel qt;`);
128
- return fetch(url)
129
- .then((response) => {
130
- if (!response.ok)
131
- throw ResourceError.from(response.status, response.statusText, "osm", "overpass-api", "fetch");
132
- return response;
133
- })
134
- .then((response) => response.json())
135
- .then((body) => body.elements)
136
- .catch((error) => {
137
- throw ResourceError.wrap(error, "osm", "overpass-api", "fetch");
138
- });
133
+ export function reversedRing(minLon, minLat, maxLon, maxLat) {
134
+ return [
135
+ [minLon, minLat],
136
+ [minLon, maxLat],
137
+ [maxLon, maxLat],
138
+ [maxLon, minLat],
139
+ [minLon, minLat],
140
+ ];
139
141
  }
142
+ //#endregion
140
143
  //# sourceMappingURL=polygon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"polygon.js","sourceRoot":"","sources":["../../geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAqGtD;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAsC,KAAc;IACnF,IAAI,OAAO,KAAK,KAAK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AAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;KAChB,CAAA;AACF,CAAC;AAED,YAAY"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * @copyright Sister Software
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * The ring blob — how a polygon layer stores one authority feature's UNSIMPLIFIED coordinates, and the
7
+ * point test that reads it without materializing them.
8
+ *
9
+ * THE GEOMETRY IS THE TRUTH TABLE. An H3 index above it answers a cell that lies wholly inside one
10
+ * feature; a cell a boundary crosses falls through to a ray cast against the few features the index
11
+ * already named. A rooftop answer at a boundary — which is where the answer usually matters most — has
12
+ * no other source, so the rings are stored at the resolution the authority published them and never
13
+ * simplified.
14
+ *
15
+ * THE LAYOUT PUTS THE COORDINATES ON AN 8-BYTE BOUNDARY, so the reader takes a `Float64Array` view over
16
+ * them instead of a `DataView.getFloat64` per ordinate. Header is `u32 version`, `u32 ringCount`, then
17
+ * one `(u32 pointCount, u32 polygonIndex)` pair per ring — `8 + 8 × ringCount` bytes, a multiple of
18
+ * eight by construction. Coordinates follow as `[lon, lat]` pairs, ring by ring.
19
+ *
20
+ * `polygonIndex` IS required AND CANNOT BE INFERRED. A source feature is a MultiPolygon, so its
21
+ * rings belong to several polygons and "the first ring is the exterior" is true only per polygon. The
22
+ * point test is orientation-free and nesting-free (even-odd across a polygon's own rings, the rule
23
+ * {@link pointInPolygon} uses), but it still has to know which rings share a polygon: an island sitting
24
+ * inside another polygon's hole is inside the layer and would cancel to "outside" if every ring were
25
+ * pooled into one list.
26
+ *
27
+ * SHARED BY EVERY POLYGON LAYER RATHER THAN COPIED INTO EACH. `@mailwoman/flood` and `@mailwoman/soil`
28
+ * both store an authority's rings this way, and a second copy of the alignment arithmetic or of the
29
+ * signed-area reading would be a second thing to get right — both failure modes are silent, since a
30
+ * mis-read blob answers a containment question wrongly and a hole-blind area reading answers "inside"
31
+ * for every point in a hole.
32
+ */
33
+ import type { MultiPolygonRings } from "#geometries/polygon";
34
+ /**
35
+ * Format version stamped into every blob. A reader that meets a different number throws rather than reinterpreting
36
+ * bytes it does not know the shape of.
37
+ */
38
+ export declare const RING_BLOB_VERSION = 1;
39
+ /**
40
+ * One decoded feature: `[exteriorRing, ...holes]` per polygon, each ring a flat `[lon, lat, lon, lat, …]` run.
41
+ */
42
+ export interface DecodedRings {
43
+ /**
44
+ * `polygons[p][r]` is a flat coordinate run for ring `r` of polygon `p`.
45
+ */
46
+ polygons: number[][][];
47
+ }
48
+ /**
49
+ * Pack a GeoJSON `MultiPolygon`/`Polygon` coordinate tree into the stored blob.
50
+ *
51
+ * @throws {RangeError} When the geometry carries no ring, or a ring carries fewer than four positions (a linear ring is
52
+ * closed, so three is the minimum distinct-vertex count plus the repeat).
53
+ */
54
+ export declare function encodeRings(polygons: MultiPolygonRings): Uint8Array;
55
+ /**
56
+ * Is the point inside the stored geometry?
57
+ *
58
+ * Even-odd within each polygon's own ring list, inside-any-polygon across them — the orientation-free rule
59
+ * {@linkcode pointInPolygon} states, applied without allocating the ring arrays. Reading a hole as an exterior ring is
60
+ * what this rule survives: a point inside a hole crosses two rings and comes out even, whichever way either ring
61
+ * winds.
62
+ */
63
+ export declare function pointInEncodedRings(blob: Uint8Array, lon: number, lat: number): boolean;
64
+ /**
65
+ * Unpack the blob back into per-polygon flat coordinate runs — for tests, for a debug render, and for the round-trip
66
+ * check a build's fixtures assert.
67
+ */
68
+ export declare function decodeRings(blob: Uint8Array): DecodedRings;
69
+ /**
70
+ * Signed spherical area of one linear ring, in square metres. **CLOCKWISE is positive**, counter-clockwise negative.
71
+ *
72
+ * The sign is the whole point: an orientation-respecting sum over a polygon's rings subtracts its holes, while a sum of
73
+ * absolute values adds them. Comparing the two against the source's own area figure is what tells a builder whether it
74
+ * has read the holes at all — the failure mode is silent, because a hole read as an exterior ring produces a perfectly
75
+ * well-formed polygon that simply covers more ground than the authority mapped.
76
+ *
77
+ * WHICH WINDING IS POSITIVE IS A CONTRACT, NOT A DETAIL, because a builder whose source encodes hole roles by
78
+ * ORIENTATION reads roles off this sign. It is the opposite of the standard planar shoelace: this sum runs `(lonᵢ −
79
+ * lonⱼ)` against the shoelace's `(xⱼ − xᵢ)`, so a ring `@mailwoman/spatial`'s own {@link rectangleRing} builds
80
+ * counter-clockwise answers NEGATIVE here. `@mailwoman/zoning` is the caller that depends on it, and
81
+ * `packages/zoning/test/unit/ring-roles.test.ts` pins the sign directly.
82
+ */
83
+ export declare function ringSignedAreaM2(ring: ReadonlyArray<readonly number[]>): number;
84
+ /**
85
+ * Both readings of one feature's area, in square metres: `nested` respects ring orientation (holes subtract) and
86
+ * `allExterior` does not (holes add).
87
+ *
88
+ * A source whose holes are correctly nested makes `nested` match the authority's own figure and `allExterior` exceed
89
+ * it. The gap between them is the area a hole-blind reader would answer "inside" for.
90
+ */
91
+ export declare function ringAreaReadings(polygons: MultiPolygonRings): {
92
+ nested: number;
93
+ allExterior: number;
94
+ };
95
+ /**
96
+ * A rectangle in CRS84 degrees.
97
+ */
98
+ export interface DegreeExtent {
99
+ minLon: number;
100
+ minLat: number;
101
+ maxLon: number;
102
+ maxLat: number;
103
+ }
104
+ /**
105
+ * Refuse a feature whose reprojected vertices fall outside the publisher's own declared extent.
106
+ *
107
+ * THE CHECK A PROJECTION CHECK CANNOT MAKE. A swapped coordinate order survives an authority-code comparison — both
108
+ * axes are still numbers in a plausible range — and a source read in its own metres as if they were degrees produces
109
+ * perfectly well-formed coordinates in the wrong ocean. Both show up here on the first feature, before a whole layer is
110
+ * written to the wrong side of the planet.
111
+ *
112
+ * SHARED BY EVERY POLYGON INGEST, because it is rectangle arithmetic over the ring types and knows nothing about any
113
+ * product. `marginDegrees` is the caller's, because a declared extent is itself a rounded published value and how
114
+ * tightly a source hugs its own is a fact about that source.
115
+ *
116
+ * @param context Names the calling ingest in the refusal, so a build log says which layer stopped.
117
+ * @throws {RangeError} On the first vertex outside the extent.
118
+ */
119
+ export declare function assertRingsInsideExtent(polygons: MultiPolygonRings, label: string, extent: DegreeExtent, marginDegrees: number, context?: string): void;
120
+ /**
121
+ * One stored polygon's bounding box and geometry, as every polygon layer's truth table stores them.
122
+ */
123
+ export interface EncodedArea {
124
+ min_lat: number;
125
+ min_lon: number;
126
+ max_lat: number;
127
+ max_lon: number;
128
+ rings: Uint8Array;
129
+ }
130
+ /**
131
+ * A point INSIDE one stored polygon, for a verification sampler.
132
+ *
133
+ * The bounding-box centre is tried first; where it is not inside — a crescent, a band hugging a river, a polygon with a
134
+ * hole through its middle — a small deterministic grid over the box is scanned. A polygon no grid point lands inside is
135
+ * refused (`undefined`) rather than approximated, because a sample point that is not actually inside the polygon turns
136
+ * an agreement check into a check on the sampler.
137
+ *
138
+ * SHARED BY EVERY POLYGON LAYER'S VERIFY, because it is bounding-box arithmetic over the ring blob and knows nothing
139
+ * about any product. `gridSteps` is the one thing that differs between them: a layer whose polygons are narrow strips
140
+ * needs a finer grid than one whose polygons are compact, and the value is part of a layer's sampling receipt — two
141
+ * runs of the same layer must draw the same points, so it is a caller's choice rather than a shared default nobody
142
+ * owns.
143
+ *
144
+ * @param gridSteps Grid divisions per axis. Only `steps − 1` interior lines are tested, so 7 gives a 6 × 6 grid.
145
+ */
146
+ export declare function interiorPointOfEncodedRings(area: EncodedArea, gridSteps?: number): {
147
+ latitude: number;
148
+ longitude: number;
149
+ } | undefined;
150
+ /**
151
+ * Whether a stored polygon's precomputed bounding box contains the point — the ray cast's prefilter, so the blob is
152
+ * only pulled off disk for a polygon that could contain the point.
153
+ */
154
+ export declare function bboxContains(bounds: Pick<EncodedArea, "min_lat" | "min_lon" | "max_lat" | "max_lon">, longitude: number, latitude: number): boolean;
155
+ /**
156
+ * A reproducible sample of interior points drawn by a deterministic STRIDE over a key list — the shape every polygon
157
+ * layer's verification sampler shares.
158
+ *
159
+ * The keys are chosen before any geometry is read: selecting them alone is an index-only walk over the primary key, and
160
+ * the rows they name are then fetched by key. The draw is deterministic rather than random, so a re-run compares the
161
+ * same points and a disagreement can be looked at rather than re-rolled.
162
+ *
163
+ * @param options.gridSteps The interior-point search depth, per {@link interiorPointOfEncodedRings} — part of a layer's
164
+ * sampling receipt, so it is a caller's choice rather than a shared default nobody owns.
165
+ */
166
+ export declare function strideSampleInteriorPoints<Area extends EncodedArea, Point>(keys: readonly string[], count: number, options: {
167
+ fetch: (key: string) => Area | undefined;
168
+ gridSteps: number;
169
+ toPoint: (area: Area, interior: {
170
+ latitude: number;
171
+ longitude: number;
172
+ }) => Point;
173
+ }): Point[];
174
+ /**
175
+ * The bounding rectangle of one feature's rings, in degrees — a ray cast's prefilter, precomputed.
176
+ */
177
+ export declare function ringsBoundingBox(polygons: MultiPolygonRings): {
178
+ minLat: number;
179
+ minLon: number;
180
+ maxLat: number;
181
+ maxLon: number;
182
+ };
183
+ //# sourceMappingURL=ring-blob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ring-blob.d.ts","sourceRoot":"","sources":["../../lib/geometries/ring-blob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAkBlC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,iBAAiB,GAAG,UAAU,CA8CnE;AAuDD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CA2BvF;AAuBD;;;GAGG;AACH,wBAAgB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