@mailwoman/spatial 10.0.0 → 10.1.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 (145) hide show
  1. package/README.md +2 -2
  2. package/lib/bbox.ts +41 -34
  3. package/lib/coordinate/bounds.ts +2 -2
  4. package/lib/coordinate/formats.ts +10 -27
  5. package/lib/distance.ts +53 -27
  6. package/lib/feature.ts +2 -2
  7. package/lib/geometries/point.ts +41 -33
  8. package/lib/geometries/polygon.ts +24 -128
  9. package/lib/geometries/ring-blob.ts +33 -130
  10. package/lib/google/place-id.ts +4 -2
  11. package/lib/h3/cell.ts +21 -76
  12. package/lib/h3/coverage.ts +11 -7
  13. package/lib/h3/interior-cells.ts +13 -34
  14. package/lib/h3/polygon-cells.ts +59 -165
  15. package/lib/{h3/index.ts → h3.ts} +1 -1
  16. package/lib/index.ts +5 -5
  17. package/lib/objects.ts +6 -6
  18. package/lib/open-location-code.ts +11 -42
  19. package/lib/osgb36.ts +28 -187
  20. package/lib/polyline.ts +5 -3
  21. package/lib/position.ts +18 -2
  22. package/lib/projection/transform.ts +39 -40
  23. package/lib/{projection/index.ts → projection.ts} +1 -1
  24. package/lib/well-known-text.ts +8 -8
  25. package/out/bbox.d.ts +17 -14
  26. package/out/bbox.d.ts.map +1 -1
  27. package/out/bbox.js +32 -23
  28. package/out/bbox.js.map +1 -1
  29. package/out/coordinate/bounds.d.ts +2 -2
  30. package/out/coordinate/bounds.js +2 -2
  31. package/out/coordinate/formats.d.ts +8 -11
  32. package/out/coordinate/formats.d.ts.map +1 -1
  33. package/out/coordinate/formats.js +10 -27
  34. package/out/coordinate/formats.js.map +1 -1
  35. package/out/distance.d.ts +48 -25
  36. package/out/distance.d.ts.map +1 -1
  37. package/out/distance.js +53 -27
  38. package/out/distance.js.map +1 -1
  39. package/out/feature.d.ts +2 -2
  40. package/out/feature.d.ts.map +1 -1
  41. package/out/geometries/point.d.ts +30 -22
  42. package/out/geometries/point.d.ts.map +1 -1
  43. package/out/geometries/point.js +35 -29
  44. package/out/geometries/point.js.map +1 -1
  45. package/out/geometries/polygon.d.ts +23 -122
  46. package/out/geometries/polygon.d.ts.map +1 -1
  47. package/out/geometries/polygon.js +13 -41
  48. package/out/geometries/polygon.js.map +1 -1
  49. package/out/geometries/ring-blob.d.ts +23 -109
  50. package/out/geometries/ring-blob.d.ts.map +1 -1
  51. package/out/geometries/ring-blob.js +29 -115
  52. package/out/geometries/ring-blob.js.map +1 -1
  53. package/out/{geometries/index.js → geometries.d.ts} +1 -1
  54. package/out/geometries.d.ts.map +1 -0
  55. package/out/{geometries/index.d.ts → geometries.js} +1 -1
  56. package/out/geometries.js.map +1 -0
  57. package/out/google/place-id.d.ts +4 -2
  58. package/out/google/place-id.d.ts.map +1 -1
  59. package/out/google/place-id.js.map +1 -1
  60. package/out/{google/index.d.ts → google.d.ts} +1 -1
  61. package/out/google.d.ts.map +1 -0
  62. package/out/{google/index.js → google.js} +1 -1
  63. package/out/google.js.map +1 -0
  64. package/out/h3/cell.d.ts +19 -73
  65. package/out/h3/cell.d.ts.map +1 -1
  66. package/out/h3/cell.js +20 -63
  67. package/out/h3/cell.js.map +1 -1
  68. package/out/h3/coverage.d.ts +11 -7
  69. package/out/h3/coverage.d.ts.map +1 -1
  70. package/out/h3/coverage.js +11 -7
  71. package/out/h3/coverage.js.map +1 -1
  72. package/out/h3/interior-cells.d.ts +9 -28
  73. package/out/h3/interior-cells.d.ts.map +1 -1
  74. package/out/h3/interior-cells.js +13 -32
  75. package/out/h3/interior-cells.js.map +1 -1
  76. package/out/h3/polygon-cells.d.ts +28 -120
  77. package/out/h3/polygon-cells.d.ts.map +1 -1
  78. package/out/h3/polygon-cells.js +48 -146
  79. package/out/h3/polygon-cells.js.map +1 -1
  80. package/out/{h3/index.d.ts → h3.d.ts} +2 -2
  81. package/out/h3.d.ts.map +1 -0
  82. package/out/{h3/index.js → h3.js} +2 -2
  83. package/out/h3.js.map +1 -0
  84. package/out/index.d.ts +5 -5
  85. package/out/index.d.ts.map +1 -1
  86. package/out/index.js +5 -5
  87. package/out/index.js.map +1 -1
  88. package/out/objects.d.ts +6 -6
  89. package/out/open-location-code.d.ts +11 -22
  90. package/out/open-location-code.d.ts.map +1 -1
  91. package/out/open-location-code.js +9 -40
  92. package/out/open-location-code.js.map +1 -1
  93. package/out/osgb36.d.ts +21 -97
  94. package/out/osgb36.d.ts.map +1 -1
  95. package/out/osgb36.js +12 -165
  96. package/out/osgb36.js.map +1 -1
  97. package/out/polyline.d.ts +5 -3
  98. package/out/polyline.d.ts.map +1 -1
  99. package/out/polyline.js +5 -3
  100. package/out/polyline.js.map +1 -1
  101. package/out/position.d.ts +16 -2
  102. package/out/position.d.ts.map +1 -1
  103. package/out/position.js.map +1 -1
  104. package/out/projection/transform.d.ts +30 -27
  105. package/out/projection/transform.d.ts.map +1 -1
  106. package/out/projection/transform.js +14 -16
  107. package/out/projection/transform.js.map +1 -1
  108. package/out/{projection/index.d.ts → projection.d.ts} +2 -2
  109. package/out/projection.d.ts.map +1 -0
  110. package/out/{projection/index.js → projection.js} +2 -2
  111. package/out/projection.js.map +1 -0
  112. package/out/{regions/index.js → regions.d.ts} +1 -1
  113. package/out/regions.d.ts.map +1 -0
  114. package/out/{regions/index.d.ts → regions.js} +1 -1
  115. package/out/regions.js.map +1 -0
  116. package/out/tools/ogr/stream.d.ts +21 -11
  117. package/out/tools/ogr/stream.d.ts.map +1 -1
  118. package/out/tools/ogr/stream.js +16 -9
  119. package/out/tools/ogr/stream.js.map +1 -1
  120. package/out/tools/{ogr/index.d.ts → ogr.d.ts} +14 -11
  121. package/out/tools/ogr.d.ts.map +1 -0
  122. package/out/tools/{ogr/index.js → ogr.js} +18 -14
  123. package/out/tools/ogr.js.map +1 -0
  124. package/out/tools/tsconfig.tsbuildinfo +1 -0
  125. package/out/tsconfig.test.tsbuildinfo +1 -1
  126. package/out/well-known-text.d.ts +8 -8
  127. package/out/well-known-text.js +7 -7
  128. package/package.json +35 -127
  129. package/{lib/tools → tools}/ogr/stream.ts +25 -14
  130. package/{lib/tools/ogr/index.ts → tools/ogr.ts} +25 -19
  131. package/out/geometries/index.d.ts.map +0 -1
  132. package/out/geometries/index.js.map +0 -1
  133. package/out/google/index.d.ts.map +0 -1
  134. package/out/google/index.js.map +0 -1
  135. package/out/h3/index.d.ts.map +0 -1
  136. package/out/h3/index.js.map +0 -1
  137. package/out/projection/index.d.ts.map +0 -1
  138. package/out/projection/index.js.map +0 -1
  139. package/out/regions/index.d.ts.map +0 -1
  140. package/out/regions/index.js.map +0 -1
  141. package/out/tools/ogr/index.d.ts.map +0 -1
  142. package/out/tools/ogr/index.js.map +0 -1
  143. /package/lib/{geometries/index.ts → geometries.ts} +0 -0
  144. /package/lib/{google/index.ts → google.ts} +0 -0
  145. /package/lib/{regions/index.ts → regions.ts} +0 -0
@@ -8,94 +8,33 @@ import type { LineStringPath } from "#geometries/line-string";
8
8
  import type { GeoObjectLiteral } from "#objects";
9
9
  /**
10
10
  * An array of positions forming a closed shape, such as a country or a lake.
11
- *
12
- * @example
13
- * A polygon without holes:
14
- *
15
- * ```json
16
- * {
17
- * "type": "Polygon",
18
- * "coordinates": [
19
- * [
20
- * [100, 0],
21
- * [101, 0],
22
- * [101, 1],
23
- * [100, 1],
24
- * [100, 0]
25
- * ]
26
- * ]
27
- * }
28
- * ```
29
11
  */
30
12
  export type SolidPolygonPath = [
31
13
  /**
32
- * - A linear ring is a closed LineString with four or more positions.
33
- * - The first and last positions are equivalent (they represent equivalent points).
14
+ * A linear ring is a closed LineString with four or more positions.
34
15
  */
35
16
  exteriorRing: LineStringPath
36
17
  ];
37
18
  /**
38
- * An array of positions forming a closed shape with holes, such as a country with islands or a lake with islands.
39
- *
40
- * @example
41
- * A polygon with holes:
42
- *
43
- * ```json
44
- * {
45
- * "type": "Polygon",
46
- * "coordinates": [
47
- * [
48
- * [100.0, 0.0],
49
- * [101.0, 0.0],
50
- * [101.0, 1.0],
51
- * [100.0, 1.0],
52
- * [100.0, 0.0]
53
- * ],
54
- * [
55
- * [100.8, 0.8],
56
- * [100.8, 0.2],
57
- * [100.2, 0.2],
58
- * [100.2, 0.8],
59
- * [100.8, 0.8]
60
- * ]
61
- * ]
62
- * }
63
- * ```
19
+ * An array of positions forming a closed shape with holes, such as a country
20
+ * with islands or a lake with islands.
64
21
  */
65
22
  export type NestedPolygonPath = [
66
23
  /**
67
- * - A linear ring is a closed LineString with four or more positions.
68
- * - The first and last positions are equivalent (they represent equivalent points).
24
+ * A linear ring is a closed LineString with four or more positions.
69
25
  */
70
26
  exteriorRing: LineStringPath,
71
- /**
72
- * - The interior rings are arrays of positions forming holes in the polygon.
73
- */
74
27
  ...interiorRings: LineStringPath[]
75
28
  ];
76
29
  /**
77
30
  * A polygon geometry.
78
- *
79
- * @see {@linkcode PolygonLiteral} for applicable JSON schema.
80
- * @see {@linkcode SolidPolygonPath} for more information.
81
- * @see {@linkcode NestedPolygonPath} for more information.
82
31
  */
83
32
  export type PolygonPath = SolidPolygonPath | NestedPolygonPath;
84
33
  /**
85
34
  * An array of positions forming a closed shape, such as a country or a lake.
86
35
  */
87
36
  export interface PolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
88
- /**
89
- * Declares the type of GeoJSON object as a `Polygon` geometry.
90
- */
91
37
  type: "Polygon";
92
- /**
93
- * An array of positions for each point in the geometry.
94
- *
95
- * @see {@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6 | RFC 7946 Section 3.1.6}
96
- * @see {@linkcode SolidPolygonPath}
97
- * @see {@linkcode NestedPolygonPath}
98
- */
99
38
  coordinates: P;
100
39
  }
101
40
  /**
@@ -107,42 +46,31 @@ export declare function isPolygonLiteral<P extends PolygonPath = PolygonPath>(in
107
46
  */
108
47
  export declare function isSolidPolygonPath(input: PolygonLiteral<PolygonPath>): boolean;
109
48
  /**
110
- * A linear ring as the containment predicates read it: positions of `[lon, lat, …]`.
111
- *
112
- * Deliberately looser than {@link LineStringPath} — the ray cast only ever indexes `[0]` and `[1]`, and the callers
113
- * arrive with different position types (`[number, number, ...number[]]` from the resolver's GeoJSON reader, plain
114
- * `number[][]` from a `JSON.parse` of a stored geometry column). A tight tuple type here would force a cast at every
115
- * call site and buy nothing the predicate uses.
49
+ * A linear ring as the containment predicates read it, deliberately looser than
50
+ * {@link LineStringPath} because callers arrive with different position types.
116
51
  */
117
52
  export type ContainmentRing = readonly (readonly number[])[];
118
53
  /**
119
- * One polygon's rings: `[exterior, ...holes]` — a `Polygon`'s `coordinates`, read loosely (see
120
- * {@linkcode ContainmentRing}).
54
+ * One polygon's rings: `[exterior, ...holes]`.
121
55
  */
122
56
  export type PolygonRings = readonly ContainmentRing[];
123
57
  /**
124
- * A feature's polygons — `MultiPolygon` coordinates, with a bare `Polygon` lifted into the same shape by
125
- * {@linkcode arealPolygons}.
58
+ * A feature's polygons — `MultiPolygon` coordinates, with a bare `Polygon` lifted
59
+ * into the same shape by {@linkcode arealPolygons}.
126
60
  */
127
61
  export type MultiPolygonRings = readonly PolygonRings[];
128
62
  /**
129
- * Ray-cast a point against ONE linear ring — the even-odd crossing count. Shoot a ray along +lon and toggle on every
130
- * edge crossing.
131
- *
132
- * Points exactly on an edge are implementation-defined; either side is acceptable for geocoding, where admin boundaries
133
- * are Douglas-Peucker–simplified before they ever reach us.
63
+ * Ray-cast a point against one linear ring — the even-odd crossing count,
64
+ * with points exactly on an edge left implementation-defined.
134
65
  */
135
66
  export declare function pointInRing(lon: number, lat: number, ring: ContainmentRing): boolean;
136
67
  /**
137
- * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`).
138
- *
139
- * Being inside an odd number of rings means inside the polygon, which handles holes — and islands inside holes —
140
- * without depending on ring winding order. GeoJSON nominally specifies orientation, but the gazetteer sources do not
141
- * reliably honour it, so the orientation-free rule is the one that survives real data.
68
+ * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`), independent of
69
+ * ring winding order because the gazetteer sources do not honor it reliably.
142
70
  */
143
71
  export declare function pointInPolygon(lon: number, lat: number, rings: PolygonRings): boolean;
144
72
  /**
145
- * Inside ANY polygon of a multi-polygon.
73
+ * Inside any polygon of a multi-polygon.
146
74
  */
147
75
  export declare function pointInMultiPolygon(lon: number, lat: number, polygons: readonly (readonly ContainmentRing[])[]): boolean;
148
76
  /**
@@ -150,60 +78,33 @@ export declare function pointInMultiPolygon(lon: number, lat: number, polygons:
150
78
  */
151
79
  export interface MultiPolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
152
80
  type: "MultiPolygon";
153
- /**
154
- * One ring array per polygon — `coordinates[polygon][ring][position]`, matching a `Polygon`'s `coordinates` lifted by
155
- * exactly one level.
156
- *
157
- * @see {@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.7 | RFC 7946 Section 3.1.7}
158
- */
159
81
  coordinates: P[];
160
82
  }
161
83
  /**
162
- * A geometry as it arrives from `JSON.parse`, or a typed literal. Nothing has checked the arity of a position and
163
- * `type` is whatever the source wrote, so a reader narrows on `type` and casts `coordinates` — {@linkcode arealPolygons}
164
- * is the one place that happens for the areal types.
84
+ * A geometry as it arrives from `JSON.parse`, or a typed literal, with `type` unchecked
85
+ * and no arity validation on `coordinates`.
165
86
  */
166
87
  export type ParsedGeometry = GeometryLiteral | {
167
88
  type: string;
168
89
  coordinates?: unknown;
169
90
  };
170
91
  /**
171
- * A geometry's polygons in the `MultiPolygon` coordinate shape, whichever areal type it arrived as — `null` when the
172
- * geometry is not areal (a Point or a LineString bounds no area).
173
- *
174
- * The one place a `Polygon` is lifted to `[rings]`; a caller that must refuse a non-areal geometry does so on the
175
- * `null`, with its own message.
92
+ * A geometry's polygons in the `MultiPolygon` coordinate shape, with a bare `Polygon`
93
+ * lifted to `[rings]` and `null` for any non-areal geometry.
176
94
  */
177
95
  export declare function arealPolygons(geometry: ParsedGeometry | null | undefined): MultiPolygonRings | null;
178
96
  /**
179
- * The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
180
- * writing for itself.
181
- *
182
- * @param subject Names the feature in the refusal, e.g. `feature 41209`.
183
- * @param context Names the calling ingest, so a build log says which layer stopped.
184
- * @throws {Error} When the geometry is neither a `Polygon` nor a `MultiPolygon`.
97
+ * The polygons of a geometry that must be areal, throwing when the geometry
98
+ * is not a `Polygon` or `MultiPolygon`.
185
99
  */
186
100
  export declare function requireArealPolygons(geometry: ParsedGeometry, subject: string, context: string): MultiPolygonRings;
187
101
  /**
188
- * Does an areal GeoJSON geometry contain the point?
189
- *
190
- * The three-valued return is the point of the function. `null` means the geometry is NOT AREAL — a Point or a
191
- * LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
192
- * geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
193
- * containment pass instead of falling through to the approximate path.
194
- *
195
- * `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
196
- * HAND if this one changes — it is the one copy no import can reach.
102
+ * Does an areal GeoJSON geometry contain the point, returning `null` for a
103
+ * non-areal geometry rather than `false`.
197
104
  */
198
105
  export declare function geometryContains(geometry: ParsedGeometry | null | undefined, lon: number, lat: number): boolean | null;
199
106
  /**
200
- * An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise — the exterior
201
- * winding.
202
- *
203
- * SHARED BECAUSE THE WINDING IS A CONVENTION AND A SECOND COPY IS A SECOND PLACE FOR IT TO DRIFT. Three layer builders
204
- * hand-build rectangles for their fixture rungs, and each pairs this with {@link reversedRing} to make a hole. A copy
205
- * whose hole is wound the same way as its exterior produces a fixture that passes every structural check and tests
206
- * nothing about hole handling — which is the exact failure the area cross-check exists to catch in production data.
107
+ * An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise.
207
108
  */
208
109
  export declare function rectangleRing(minLon: number, minLat: number, maxLon: number, maxLat: number): number[][];
209
110
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../lib/geometries/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,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,EAC3C,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACT,OAAO,GAAG,IAAI,CAMhB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAQxG;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAQvG"}
@@ -14,17 +14,13 @@ export function isPolygonLiteral(input) {
14
14
  /**
15
15
  * Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
16
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.
17
+ // The parameter admits both paths because distinguishing them is the function's job.
19
18
  export function isSolidPolygonPath(input) {
20
19
  return input.coordinates.length === 1;
21
20
  }
22
21
  /**
23
- * Ray-cast a point against ONE linear ring — the even-odd crossing count. Shoot a ray along +lon and toggle on every
24
- * edge crossing.
25
- *
26
- * Points exactly on an edge are implementation-defined; either side is acceptable for geocoding, where admin boundaries
27
- * are Douglas-Peucker–simplified before they ever reach us.
22
+ * Ray-cast a point against one linear ring — the even-odd crossing count,
23
+ * with points exactly on an edge left implementation-defined.
28
24
  */
29
25
  export function pointInRing(lon, lat, ring) {
30
26
  let inside = false;
@@ -41,11 +37,8 @@ export function pointInRing(lon, lat, ring) {
41
37
  return inside;
42
38
  }
43
39
  /**
44
- * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`).
45
- *
46
- * Being inside an odd number of rings means inside the polygon, which handles holes — and islands inside holes —
47
- * without depending on ring winding order. GeoJSON nominally specifies orientation, but the gazetteer sources do not
48
- * reliably honour it, so the orientation-free rule is the one that survives real data.
40
+ * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`), independent of
41
+ * ring winding order because the gazetteer sources do not honor it reliably.
49
42
  */
50
43
  export function pointInPolygon(lon, lat, rings) {
51
44
  let inside = false;
@@ -57,17 +50,14 @@ export function pointInPolygon(lon, lat, rings) {
57
50
  return inside;
58
51
  }
59
52
  /**
60
- * Inside ANY polygon of a multi-polygon.
53
+ * Inside any polygon of a multi-polygon.
61
54
  */
62
55
  export function pointInMultiPolygon(lon, lat, polygons) {
63
56
  return polygons.some((rings) => pointInPolygon(lon, lat, rings));
64
57
  }
65
58
  /**
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.
59
+ * A geometry's polygons in the `MultiPolygon` coordinate shape, with a bare `Polygon`
60
+ * lifted to `[rings]` and `null` for any non-areal geometry.
71
61
  */
72
62
  export function arealPolygons(geometry) {
73
63
  if (!geometry)
@@ -79,12 +69,8 @@ export function arealPolygons(geometry) {
79
69
  return null;
80
70
  }
81
71
  /**
82
- * The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
83
- * writing for itself.
84
- *
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`.
72
+ * The polygons of a geometry that must be areal, throwing when the geometry
73
+ * is not a `Polygon` or `MultiPolygon`.
88
74
  */
89
75
  export function requireArealPolygons(geometry, subject, context) {
90
76
  const polygons = arealPolygons(geometry);
@@ -93,15 +79,8 @@ export function requireArealPolygons(geometry, subject, context) {
93
79
  throw new Error(`${context}: ${subject} is a ${geometry.type}, expected Polygon or MultiPolygon`);
94
80
  }
95
81
  /**
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.
102
- *
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.
82
+ * Does an areal GeoJSON geometry contain the point, returning `null` for a
83
+ * non-areal geometry rather than `false`.
105
84
  */
106
85
  export function geometryContains(geometry, lon, lat) {
107
86
  const polygons = arealPolygons(geometry);
@@ -110,13 +89,7 @@ export function geometryContains(geometry, lon, lat) {
110
89
  return polygons.some((rings) => pointInPolygon(lon, lat, rings));
111
90
  }
112
91
  /**
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.
92
+ * An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise.
120
93
  */
121
94
  export function rectangleRing(minLon, minLat, maxLon, maxLat) {
122
95
  return [
@@ -139,5 +112,4 @@ export function reversedRing(minLon, minLat, maxLon, maxLat) {
139
112
  [minLon, minLat],
140
113
  ];
141
114
  }
142
- //#endregion
143
115
  //# sourceMappingURL=polygon.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"polygon.js","sourceRoot":"","sources":["../../lib/geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsGH;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAsC,KAAc;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E1B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,MAAc,EAAE,MAAc,EAAE,MAAc;IAC3F,OAAO;QACN,CAAC,MAAM,EAAE,MAAM,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;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,MAAc,EAAE,MAAc,EAAE,MAAc;IAC1F,OAAO;QACN,CAAC,MAAM,EAAE,MAAM,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"}
@@ -3,120 +3,55 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
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.
6
+ * A polygon layer's stored ring blob: an 8-byte header, then a `(u32 pointCount, u32 polygonIndex)`
7
+ * pair per ring, then `[lon, lat]` pairs on an 8-byte boundary so the reader takes a
8
+ * `Float64Array` view; `polygonIndex` is required because one feature's rings belong to several polygons.
32
9
  */
10
+ import type { LatLonBounds } from "#bbox";
33
11
  import type { MultiPolygonRings } from "#geometries/polygon";
34
12
  /**
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.
13
+ * Format version stamped into every blob, rejected by a reader that meets a different number.
37
14
  */
38
15
  export declare const RING_BLOB_VERSION = 1;
39
16
  /**
40
- * One decoded feature: `[exteriorRing, ...holes]` per polygon, each ring a flat `[lon, lat, lon, lat, …]` run.
17
+ * One decoded feature: `[exteriorRing, ...holes]` per polygon, each ring a
18
+ * flat `[lon, lat, lon, lat, …]` run.
41
19
  */
42
20
  export interface DecodedRings {
43
- /**
44
- * `polygons[p][r]` is a flat coordinate run for ring `r` of polygon `p`.
45
- */
46
21
  polygons: number[][][];
47
22
  }
48
23
  /**
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).
24
+ * Pack a GeoJSON `MultiPolygon`/`Polygon` coordinate tree into the stored blob, throwing
25
+ * when the geometry has no ring or a ring has fewer than four positions.
53
26
  */
54
27
  export declare function encodeRings(polygons: MultiPolygonRings): Uint8Array;
55
28
  /**
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.
29
+ * Is the point inside the stored geometry, even-odd within each polygon's own ring list
30
+ * and inside-any-polygon across them, without allocating the ring arrays.
62
31
  */
63
32
  export declare function pointInEncodedRings(blob: Uint8Array, lon: number, lat: number): boolean;
64
33
  /**
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.
34
+ * Unpack the blob back into per-polygon flat coordinate runs.
67
35
  */
68
36
  export declare function decodeRings(blob: Uint8Array): DecodedRings;
69
37
  /**
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.
38
+ * Signed spherical area of one linear ring, in square meters, with clockwise positive
39
+ * and counter-clockwise negative.
82
40
  */
83
41
  export declare function ringSignedAreaM2(ring: ReadonlyArray<readonly number[]>): number;
84
42
  /**
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.
43
+ * Both readings of one feature's area, in square meters: `nested` respects ring
44
+ * orientation (holes subtract) and `allExterior` does not (holes add).
90
45
  */
91
46
  export declare function ringAreaReadings(polygons: MultiPolygonRings): {
92
47
  nested: number;
93
48
  allExterior: number;
94
49
  };
95
50
  /**
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.
51
+ * Refuse a feature whose reprojected vertices fall outside the publisher's own
52
+ * declared extent, throwing on the first vertex outside it.
118
53
  */
119
- export declare function assertRingsInsideExtent(polygons: MultiPolygonRings, label: string, extent: DegreeExtent, marginDegrees: number, context?: string): void;
54
+ export declare function assertRingsInsideExtent(polygons: MultiPolygonRings, label: string, extent: LatLonBounds, marginDegrees: number, context?: string): void;
120
55
  /**
121
56
  * One stored polygon's bounding box and geometry, as every polygon layer's truth table stores them.
122
57
  */
@@ -128,40 +63,19 @@ export interface EncodedArea {
128
63
  rings: Uint8Array;
129
64
  }
130
65
  /**
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.
66
+ * A point inside one stored polygon for a verification sampler, returning `undefined` when neither
67
+ * the bounding-box center nor any of the `gridSteps − 1` interior grid lines lands inside.
145
68
  */
146
69
  export declare function interiorPointOfEncodedRings(area: EncodedArea, gridSteps?: number): {
147
70
  latitude: number;
148
71
  longitude: number;
149
72
  } | undefined;
150
73
  /**
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.
74
+ * Whether a stored polygon's precomputed bounding box contains the point.
153
75
  */
154
76
  export declare function bboxContains(bounds: Pick<EncodedArea, "min_lat" | "min_lon" | "max_lat" | "max_lon">, longitude: number, latitude: number): boolean;
155
77
  /**
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.
78
+ * A reproducible sample of interior points drawn by a deterministic stride over a key list.
165
79
  */
166
80
  export declare function strideSampleInteriorPoints<Area extends EncodedArea, Point>(keys: readonly string[], count: number, options: {
167
81
  fetch: (key: string) => Area | undefined;
@@ -1 +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,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAe1D;AAOD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,MAAM,EAAE,CAAC,GAAG,MAAM,CAY/E;AAED;;;;;;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