@mailwoman/spatial 10.0.0 → 10.2.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 (148) 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 +21 -33
  5. package/lib/distance.ts +56 -28
  6. package/lib/feature.ts +2 -2
  7. package/lib/geometries/point.ts +42 -35
  8. package/lib/geometries/polygon.ts +27 -135
  9. package/lib/geometries/ring-blob.ts +35 -132
  10. package/lib/google/place-id.ts +4 -2
  11. package/lib/h3/cell.ts +23 -78
  12. package/lib/h3/coverage.ts +13 -9
  13. package/lib/h3/interior-cells.ts +13 -34
  14. package/lib/h3/polygon-cells.ts +61 -167
  15. package/lib/{h3/index.ts → h3.ts} +1 -1
  16. package/lib/index.ts +6 -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 +39 -20
  22. package/lib/projection/transform.ts +43 -44
  23. package/lib/{projection/index.ts → projection.ts} +1 -1
  24. package/lib/well-known-text.ts +9 -9
  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 +17 -16
  32. package/out/coordinate/formats.d.ts.map +1 -1
  33. package/out/coordinate/formats.js +20 -32
  34. package/out/coordinate/formats.js.map +1 -1
  35. package/out/distance.d.ts +51 -26
  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 +37 -30
  44. package/out/geometries/point.js.map +1 -1
  45. package/out/geometries/polygon.d.ts +27 -126
  46. package/out/geometries/polygon.d.ts.map +1 -1
  47. package/out/geometries/polygon.js +14 -42
  48. package/out/geometries/polygon.js.map +1 -1
  49. package/out/geometries/ring-blob.d.ts +24 -110
  50. package/out/geometries/ring-blob.d.ts.map +1 -1
  51. package/out/geometries/ring-blob.js +30 -116
  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 +22 -65
  67. package/out/h3/cell.js.map +1 -1
  68. package/out/h3/coverage.d.ts +12 -8
  69. package/out/h3/coverage.d.ts.map +1 -1
  70. package/out/h3/coverage.js +12 -8
  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 +50 -148
  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 +6 -5
  85. package/out/index.d.ts.map +1 -1
  86. package/out/index.js +6 -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 +36 -20
  102. package/out/position.d.ts.map +1 -1
  103. package/out/position.js +0 -1
  104. package/out/position.js.map +1 -1
  105. package/out/projection/transform.d.ts +33 -30
  106. package/out/projection/transform.d.ts.map +1 -1
  107. package/out/projection/transform.js +15 -17
  108. package/out/projection/transform.js.map +1 -1
  109. package/out/{projection/index.d.ts → projection.d.ts} +2 -2
  110. package/out/projection.d.ts.map +1 -0
  111. package/out/{projection/index.js → projection.js} +2 -2
  112. package/out/projection.js.map +1 -0
  113. package/out/{regions/index.js → regions.d.ts} +1 -1
  114. package/out/regions.d.ts.map +1 -0
  115. package/out/{regions/index.d.ts → regions.js} +1 -1
  116. package/out/regions.js.map +1 -0
  117. package/out/tools/ogr/stream.d.ts +21 -11
  118. package/out/tools/ogr/stream.d.ts.map +1 -1
  119. package/out/tools/ogr/stream.js +17 -10
  120. package/out/tools/ogr/stream.js.map +1 -1
  121. package/out/tools/{ogr/index.d.ts → ogr.d.ts} +25 -15
  122. package/out/tools/ogr.d.ts.map +1 -0
  123. package/out/tools/{ogr/index.js → ogr.js} +25 -21
  124. package/out/tools/ogr.js.map +1 -0
  125. package/out/tools/tsconfig.tsbuildinfo +1 -0
  126. package/out/tsconfig.test.tsbuildinfo +1 -1
  127. package/out/well-known-text.d.ts +9 -9
  128. package/out/well-known-text.d.ts.map +1 -1
  129. package/out/well-known-text.js +7 -7
  130. package/out/well-known-text.js.map +1 -1
  131. package/package.json +37 -129
  132. package/{lib/tools → tools}/ogr/stream.ts +26 -15
  133. package/{lib/tools/ogr/index.ts → tools/ogr.ts} +44 -30
  134. package/out/geometries/index.d.ts.map +0 -1
  135. package/out/geometries/index.js.map +0 -1
  136. package/out/google/index.d.ts.map +0 -1
  137. package/out/google/index.js.map +0 -1
  138. package/out/h3/index.d.ts.map +0 -1
  139. package/out/h3/index.js.map +0 -1
  140. package/out/projection/index.d.ts.map +0 -1
  141. package/out/projection/index.js.map +0 -1
  142. package/out/regions/index.d.ts.map +0 -1
  143. package/out/regions/index.js.map +0 -1
  144. package/out/tools/ogr/index.d.ts.map +0 -1
  145. package/out/tools/ogr/index.js.map +0 -1
  146. /package/lib/{geometries/index.ts → geometries.ts} +0 -0
  147. /package/lib/{google/index.ts → google.ts} +0 -0
  148. /package/lib/{regions/index.ts → regions.ts} +0 -0
@@ -6,11 +6,12 @@
6
6
 
7
7
  import type google from "@googlemaps/google-maps-services-js"
8
8
  import type { LatLng, LatLngLiteral } from "@googlemaps/google-maps-services-js"
9
- import { tryParsingJSON } from "@mailwoman/core/json"
9
+ import { tryParsingJSON, stringifyJSON } from "@mailwoman/core/json"
10
10
  import { convert as convertCoords } from "geo-coordinates-parser"
11
11
  import { latLngToCell } from "h3-js"
12
12
 
13
13
  import { type BBox2DLiteral, type BBox3DLiteral, GeoBoundingBox, isBBox } from "#bbox"
14
+ import { isValidLatitude, isValidLongitude } from "#coordinate/bounds"
14
15
  import { type H3Cell, shortenH3Cell } from "#h3/cell"
15
16
  import { type GeoObjectLiteral, GeometryType } from "#objects"
16
17
  import {
@@ -21,13 +22,12 @@ import {
21
22
  isCoordPairLiteral,
22
23
  isGoogleMapsLatLngLiteral,
23
24
  isInterpolatedCoordinates,
24
- isValidLatitude,
25
- isValidLongitude,
26
25
  wrapLongitude,
27
26
  } from "#position"
28
27
 
29
28
  /**
30
- * A JSON-serializeable single point geometry, such as a specific location, address, or longitude, latitude pair.
29
+ * A JSON-serializable single point geometry, such as a specific location,
30
+ * address, or longitude, latitude pair.
31
31
  *
32
32
  * ```js
33
33
  * {
@@ -79,8 +79,8 @@ export interface GeolocationCoordinatesLike {
79
79
  }
80
80
 
81
81
  /**
82
- * Type-predicate to determine if the given input appears to be a {@linkcode GeolocationCoordinatesLike} object — the
83
- * shape the browser's `GeolocationCoordinates` presents, without depending on the DOM type.
82
+ * Type-predicate to determine if the given input appears to be a {@linkcode GeolocationCoordinatesLike}
83
+ * object — the shape the browser's `GeolocationCoordinates` presents, without depending on the DOM type.
84
84
  */
85
85
  export function isGeolocationCoordinatesLike(input: unknown): input is GeolocationCoordinatesLike {
86
86
  if (!input || typeof input !== "object") return false
@@ -103,13 +103,13 @@ export type GeoPointInput =
103
103
  | LatLngLiteral
104
104
  | LatLng
105
105
 
106
- //#region GeoPoint
106
+ // #region GeoPoint
107
107
 
108
108
  /**
109
109
  * A single point geometry, such as a specific location, address, or longitude, latitude pair.
110
110
  */
111
111
  export class GeoPoint implements PointLiteral {
112
- //#region Properties
112
+ // #region Properties
113
113
 
114
114
  /**
115
115
  * Declares the type of GeoJSON object as a `Point` geometry.
@@ -148,9 +148,10 @@ export class GeoPoint implements PointLiteral {
148
148
  }
149
149
 
150
150
  /**
151
- * Assigns the pair as GeoJSON [longitude, latitude(, altitude)] — the axis order is the contract, never inferred from
152
- * the magnitudes — and REJECTS a coordinate that is not on the globe. See {@link GeoPoint.from} for why both halves of
153
- * that sentence are required.
151
+ * Assigns the pair as GeoJSON [longitude, latitude(, altitude)] — the axis order is the interface,
152
+ * never inferred from the magnitudes — and rejects a coordinate that is not on the globe.
153
+ *
154
+ * See {@link GeoPoint.from} for why both halves of that sentence are required.
154
155
  *
155
156
  * @throws {RangeError} When longitude is outside [-180, 180] or latitude is outside [-90, 90].
156
157
  */
@@ -217,9 +218,9 @@ export class GeoPoint implements PointLiteral {
217
218
  this.#altitude = value
218
219
  }
219
220
 
220
- //#endregion
221
+ // #endregion
221
222
 
222
- //#region Constructors
223
+ // #region Constructors
223
224
 
224
225
  /**
225
226
  * Create a new GeoPoint object with default coordinates.
@@ -241,7 +242,8 @@ export class GeoPoint implements PointLiteral {
241
242
  constructor(geoLocationCoordinates: GeolocationCoordinatesLike, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox)
242
243
 
243
244
  /**
244
- * Creates a new GeoPoint instance from a Google Maps API {@linkcode google.LatLngLiteral | LatLngLiteral} object.
245
+ * Creates a new GeoPoint instance from a Google Maps API
246
+ * {@linkcode google.LatLngLiteral | LatLngLiteral} object.
245
247
  */
246
248
  constructor(latLngLiteral: google.LatLngLiteral, bbox?: BBox2DLiteral | BBox3DLiteral | GeoBoundingBox)
247
249
 
@@ -287,23 +289,28 @@ export class GeoPoint implements PointLiteral {
287
289
  }
288
290
 
289
291
  /**
290
- * Attempts to create a new GeoPoint instance from the given input, returning `null` rather than throwing when the
291
- * input is not a coordinate this class will stand behind.
292
+ * Attempts to create a new GeoPoint instance from the given input, returning `null`
293
+ * rather than throwing when the input is not a coordinate this class will stand behind.
292
294
  *
293
- * Two rules, both of which this constructor got wrong until 2026-08-05 (the defect was recorded in `e9bfd139` and
294
- * routed around rather than fixed):
295
+ * Two rules, both of which this constructor got wrong until 2026-08-05
296
+ * (the defect was recorded in `e9bfd139` and routed around rather than fixed):
295
297
  *
296
- * 1. **A 2-tuple is GeoJSON [longitude, latitude]. The axis order is never inferred.** The old path ran the pair through
297
- * `inferGeoJSONCoordOrder`, whose only signal is the [-90, 90] latitude range, so it transposed a pair exactly
298
- * when |the second magnitude| > 90. A caller handing it `[latitude, longitude]` therefore got the pair repaired in
299
- * Dallas and left corrupted in Berlin — behaviour selected by the data, from one code path. This change is a no-op
300
- * for every WELL-FORMED input: a valid `[longitude, latitude]` pair can never have an out-of-range second element,
301
- * so the heuristic never fired on one.
302
- * 2. **An out-of-range magnitude is rejected, not repaired.** `[999, 999]` used to produce a GeoPoint reporting latitude 999.
303
- * It now returns `null` here and throws a `RangeError` from the constructor. Note the deliberate asymmetry with
304
- * the scalar `longitude` / `latitude` setters, which still wrap and clamp: mutating a point is a pan gesture,
305
- * where 190° meaning -170° is right; PARSING one is a claim about the world, where an impossible magnitude means
306
- * the input was malformed and any repair invents a location.
298
+ * 1. **A 2-tuple is GeoJSON [longitude, latitude].
299
+ * The axis order is never inferred.** The old path ran the pair through
300
+ * `inferGeoJSONCoordOrder`, whose only signal is the [-90, 90] latitude range,
301
+ * so it transposed a pair exactly when |the second magnitude| > 90.
302
+ * A caller handing it `[latitude, longitude]` therefore got the pair repaired in Dallas
303
+ * and left corrupted in Berlin — behavior selected by the data, from one code path.
304
+ * This change is a no-op for every well-formed input: a valid `[longitude, latitude]` pair
305
+ * can never have an out-of-range second element, so the heuristic never fired on one.
306
+ * 2. **An out-of-range magnitude is rejected rather than repaired.** `[999, 999]`
307
+ * used to produce a GeoPoint reporting latitude 999.
308
+ * It now returns `null` here and throws a `RangeError` from the constructor.
309
+ * Note the deliberate asymmetry with the scalar `longitude` / `latitude` setters.
310
+ * which still wrap and clamp: mutating a point is a pan gesture, where 190°.
311
+ * This means -170° is right.
312
+ * A parse result is a claim about the world.
313
+ * An impossible magnitude means the input was malformed and any repair invents a location.
307
314
  *
308
315
  * A 0/0 result is treated as the "missing coordinate" sentinel (Null Island) and also returns `null`.
309
316
  */
@@ -331,9 +338,9 @@ export class GeoPoint implements PointLiteral {
331
338
  }
332
339
  }
333
340
 
334
- //#endregion
341
+ // #endregion
335
342
 
336
- //#region Predicates
343
+ // #region Predicates
337
344
 
338
345
  /**
339
346
  * Whether the GeoPoint is 2-dimensional.
@@ -356,9 +363,9 @@ export class GeoPoint implements PointLiteral {
356
363
  return this.#latitude === 0 && this.#longitude === 0
357
364
  }
358
365
 
359
- //#endregion
366
+ // #endregion
360
367
 
361
- //#region Conversion
368
+ // #region Conversion
362
369
 
363
370
  public toJSON(): PointLiteral {
364
371
  return {
@@ -413,9 +420,9 @@ export class GeoPoint implements PointLiteral {
413
420
  }
414
421
 
415
422
  public toString(): string {
416
- return JSON.stringify(this.toJSON())
423
+ return stringifyJSON(this.toJSON())
417
424
  }
418
- //#endregion
425
+ // #endregion
419
426
 
420
427
  public [Symbol.iterator](): Iterator<number> {
421
428
  return this.coordinates[Symbol.iterator]()
@@ -10,79 +10,28 @@ import type { GeoObjectLiteral } from "#objects"
10
10
 
11
11
  /**
12
12
  * An array of positions forming a closed shape, such as a country or a lake.
13
- *
14
- * @example
15
- * A polygon without holes:
16
- *
17
- * ```json
18
- * {
19
- * "type": "Polygon",
20
- * "coordinates": [
21
- * [
22
- * [100, 0],
23
- * [101, 0],
24
- * [101, 1],
25
- * [100, 1],
26
- * [100, 0]
27
- * ]
28
- * ]
29
- * }
30
- * ```
31
13
  */
32
14
  export type SolidPolygonPath = [
33
15
  /**
34
- * - A linear ring is a closed LineString with four or more positions.
35
- * - The first and last positions are equivalent (they represent equivalent points).
16
+ * A linear ring is a closed LineString with four or more positions.
36
17
  */
37
18
  exteriorRing: LineStringPath,
38
19
  ]
39
20
 
40
21
  /**
41
- * An array of positions forming a closed shape with holes, such as a country with islands or a lake with islands.
42
- *
43
- * @example
44
- * A polygon with holes:
45
- *
46
- * ```json
47
- * {
48
- * "type": "Polygon",
49
- * "coordinates": [
50
- * [
51
- * [100.0, 0.0],
52
- * [101.0, 0.0],
53
- * [101.0, 1.0],
54
- * [100.0, 1.0],
55
- * [100.0, 0.0]
56
- * ],
57
- * [
58
- * [100.8, 0.8],
59
- * [100.8, 0.2],
60
- * [100.2, 0.2],
61
- * [100.2, 0.8],
62
- * [100.8, 0.8]
63
- * ]
64
- * ]
65
- * }
66
- * ```
22
+ * An array of positions forming a closed shape with holes, such as a country
23
+ * with islands or a lake with islands.
67
24
  */
68
25
  export type NestedPolygonPath = [
69
26
  /**
70
- * - A linear ring is a closed LineString with four or more positions.
71
- * - The first and last positions are equivalent (they represent equivalent points).
27
+ * A linear ring is a closed LineString with four or more positions.
72
28
  */
73
29
  exteriorRing: LineStringPath,
74
- /**
75
- * - The interior rings are arrays of positions forming holes in the polygon.
76
- */
77
30
  ...interiorRings: LineStringPath[],
78
31
  ]
79
32
 
80
33
  /**
81
34
  * A polygon geometry.
82
- *
83
- * @see {@linkcode PolygonLiteral} for applicable JSON schema.
84
- * @see {@linkcode SolidPolygonPath} for more information.
85
- * @see {@linkcode NestedPolygonPath} for more information.
86
35
  */
87
36
  export type PolygonPath = SolidPolygonPath | NestedPolygonPath
88
37
 
@@ -90,17 +39,7 @@ export type PolygonPath = SolidPolygonPath | NestedPolygonPath
90
39
  * An array of positions forming a closed shape, such as a country or a lake.
91
40
  */
92
41
  export interface PolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
93
- /**
94
- * Declares the type of GeoJSON object as a `Polygon` geometry.
95
- */
96
42
  type: "Polygon"
97
- /**
98
- * An array of positions for each point in the geometry.
99
- *
100
- * @see {@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6 | RFC 7946 Section 3.1.6}
101
- * @see {@linkcode SolidPolygonPath}
102
- * @see {@linkcode NestedPolygonPath}
103
- */
104
43
  coordinates: P
105
44
  }
106
45
 
@@ -108,7 +47,7 @@ export interface PolygonLiteral<P extends PolygonPath = PolygonPath> extends Geo
108
47
  * Predicate for checking if a GeoJSON object is a `Polygon` geometry.
109
48
  */
110
49
  export function isPolygonLiteral<P extends PolygonPath = PolygonPath>(input: unknown): input is PolygonLiteral<P> {
111
- if (typeof input !== "object" || input === null) return false
50
+ if (typeof input !== "object" || !input) return false
112
51
 
113
52
  return "type" in input && input.type === "Polygon" && "coordinates" in input && Array.isArray(input.coordinates)
114
53
  }
@@ -116,40 +55,31 @@ export function isPolygonLiteral<P extends PolygonPath = PolygonPath>(input: unk
116
55
  /**
117
56
  * Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
118
57
  */
119
- // The parameter admits BOTH paths because distinguishing them is the function's job: defaulted to
120
- // `SolidPolygonPath`, it cannot be asked about a polygon with holes without the caller asserting past the signature.
58
+ // The parameter admits both paths because distinguishing them is the function's job.
121
59
  export function isSolidPolygonPath(input: PolygonLiteral<PolygonPath>): boolean {
122
60
  return input.coordinates.length === 1
123
61
  }
124
62
 
125
63
  /**
126
- * A linear ring as the containment predicates read it: positions of `[lon, lat, …]`.
127
- *
128
- * Deliberately looser than {@link LineStringPath} — the ray cast only ever indexes `[0]` and `[1]`, and the callers
129
- * arrive with different position types (`[number, number, ...number[]]` from the resolver's GeoJSON reader, plain
130
- * `number[][]` from a `JSON.parse` of a stored geometry column). A tight tuple type here would force a cast at every
131
- * call site and buy nothing the predicate uses.
64
+ * A linear ring as the containment predicates read it, deliberately looser than
65
+ * {@link LineStringPath} because callers arrive with different position types.
132
66
  */
133
67
  export type ContainmentRing = readonly (readonly number[])[]
134
68
 
135
69
  /**
136
- * One polygon's rings: `[exterior, ...holes]` — a `Polygon`'s `coordinates`, read loosely (see
137
- * {@linkcode ContainmentRing}).
70
+ * One polygon's rings: `[exterior, ...holes]`.
138
71
  */
139
72
  export type PolygonRings = readonly ContainmentRing[]
140
73
 
141
74
  /**
142
- * A feature's polygons — `MultiPolygon` coordinates, with a bare `Polygon` lifted into the same shape by
143
- * {@linkcode arealPolygons}.
75
+ * A feature's polygons — `MultiPolygon` coordinates, with a bare `Polygon` lifted
76
+ * into the same shape by {@linkcode arealPolygons}.
144
77
  */
145
78
  export type MultiPolygonRings = readonly PolygonRings[]
146
79
 
147
80
  /**
148
- * Ray-cast a point against ONE linear ring — the even-odd crossing count. Shoot a ray along +lon and toggle on every
149
- * edge crossing.
150
- *
151
- * Points exactly on an edge are implementation-defined; either side is acceptable for geocoding, where admin boundaries
152
- * are Douglas-Peucker–simplified before they ever reach us.
81
+ * Ray-cast a point against one linear ring — the even-odd crossing count,
82
+ * with points exactly on an edge left implementation-defined.
153
83
  */
154
84
  export function pointInRing(lon: number, lat: number, ring: ContainmentRing): boolean {
155
85
  let inside = false
@@ -170,11 +100,8 @@ export function pointInRing(lon: number, lat: number, ring: ContainmentRing): bo
170
100
  }
171
101
 
172
102
  /**
173
- * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`).
174
- *
175
- * Being inside an odd number of rings means inside the polygon, which handles holes — and islands inside holes —
176
- * without depending on ring winding order. GeoJSON nominally specifies orientation, but the gazetteer sources do not
177
- * reliably honour it, so the orientation-free rule is the one that survives real data.
103
+ * Even-odd containment over a polygon's ring list (`[outer, hole₁, …]`), independent of
104
+ * ring winding order because the gazetteer sources do not honor it reliably.
178
105
  */
179
106
  export function pointInPolygon(lon: number, lat: number, rings: PolygonRings): boolean {
180
107
  let inside = false
@@ -189,7 +116,7 @@ export function pointInPolygon(lon: number, lat: number, rings: PolygonRings): b
189
116
  }
190
117
 
191
118
  /**
192
- * Inside ANY polygon of a multi-polygon.
119
+ * Inside any polygon of a multi-polygon.
193
120
  */
194
121
  export function pointInMultiPolygon(
195
122
  lon: number,
@@ -205,32 +132,20 @@ export function pointInMultiPolygon(
205
132
  export interface MultiPolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
206
133
  type: "MultiPolygon"
207
134
 
208
- /**
209
- * One ring array per polygon — `coordinates[polygon][ring][position]`, matching a `Polygon`'s `coordinates` lifted by
210
- * exactly one level.
211
- *
212
- * @see {@link https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.7 | RFC 7946 Section 3.1.7}
213
- */
214
135
  coordinates: P[]
215
136
  }
216
137
 
217
- //#region Ring-list geometry — the parsed-GeoJSON shape
218
-
219
138
  /**
220
- * A geometry as it arrives from `JSON.parse`, or a typed literal. Nothing has checked the arity of a position and
221
- * `type` is whatever the source wrote, so a reader narrows on `type` and casts `coordinates` — {@linkcode arealPolygons}
222
- * is the one place that happens for the areal types.
139
+ * A geometry as it arrives from `JSON.parse`, or a typed literal, with `type` unchecked
140
+ * and no arity validation on `coordinates`.
223
141
  */
224
142
  export type ParsedGeometry = GeometryLiteral | { type: string; coordinates?: unknown }
225
143
 
226
144
  /**
227
- * A geometry's polygons in the `MultiPolygon` coordinate shape, whichever areal type it arrived as — `null` when the
228
- * geometry is not areal (a Point or a LineString bounds no area).
229
- *
230
- * The one place a `Polygon` is lifted to `[rings]`; a caller that must refuse a non-areal geometry does so on the
231
- * `null`, with its own message.
145
+ * A geometry's polygons in the `MultiPolygon` coordinate shape, with a bare `Polygon`
146
+ * lifted to `[rings]` and `null` for any non-areal geometry.
232
147
  */
233
- export function arealPolygons(geometry: ParsedGeometry | null | undefined): MultiPolygonRings | null {
148
+ export function arealPolygons(geometry: ParsedGeometry | null): MultiPolygonRings | null {
234
149
  if (!geometry) return null
235
150
 
236
151
  if (geometry.type === "Polygon") return [geometry.coordinates as PolygonRings]
@@ -241,12 +156,8 @@ export function arealPolygons(geometry: ParsedGeometry | null | undefined): Mult
241
156
  }
242
157
 
243
158
  /**
244
- * The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
245
- * writing for itself.
246
- *
247
- * @param subject Names the feature in the refusal, e.g. `feature 41209`.
248
- * @param context Names the calling ingest, so a build log says which layer stopped.
249
- * @throws {Error} When the geometry is neither a `Polygon` nor a `MultiPolygon`.
159
+ * The polygons of a geometry that must be areal, throwing when the geometry
160
+ * is not a `Polygon` or `MultiPolygon`.
250
161
  */
251
162
  export function requireArealPolygons(geometry: ParsedGeometry, subject: string, context: string): MultiPolygonRings {
252
163
  const polygons = arealPolygons(geometry)
@@ -257,21 +168,10 @@ export function requireArealPolygons(geometry: ParsedGeometry, subject: string,
257
168
  }
258
169
 
259
170
  /**
260
- * Does an areal GeoJSON geometry contain the point?
261
- *
262
- * The three-valued return is the point of the function. `null` means the geometry is NOT AREAL — a Point or a
263
- * LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
264
- * geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
265
- * containment pass instead of falling through to the approximate path.
266
- *
267
- * `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
268
- * HAND if this one changes — it is the one copy no import can reach.
171
+ * Does an areal GeoJSON geometry contain the point, returning `null` for a
172
+ * non-areal geometry rather than `false`.
269
173
  */
270
- export function geometryContains(
271
- geometry: ParsedGeometry | null | undefined,
272
- lon: number,
273
- lat: number
274
- ): boolean | null {
174
+ export function geometryContains(geometry: ParsedGeometry | null, lon: number, lat: number): boolean | null {
275
175
  const polygons = arealPolygons(geometry)
276
176
 
277
177
  if (!polygons) return null
@@ -280,13 +180,7 @@ export function geometryContains(
280
180
  }
281
181
 
282
182
  /**
283
- * An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise — the exterior
284
- * winding.
285
- *
286
- * SHARED BECAUSE THE WINDING IS A CONVENTION AND A SECOND COPY IS A SECOND PLACE FOR IT TO DRIFT. Three layer builders
287
- * hand-build rectangles for their fixture rungs, and each pairs this with {@link reversedRing} to make a hole. A copy
288
- * whose hole is wound the same way as its exterior produces a fixture that passes every structural check and tests
289
- * nothing about hole handling — which is the exact failure the area cross-check exists to catch in production data.
183
+ * An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise.
290
184
  */
291
185
  export function rectangleRing(minLon: number, minLat: number, maxLon: number, maxLat: number): number[][] {
292
186
  return [
@@ -310,5 +204,3 @@ export function reversedRing(minLon: number, minLat: number, maxLon: number, max
310
204
  [minLon, minLat],
311
205
  ]
312
206
  }
313
-
314
- //#endregion