@mailwoman/spatial 9.2.0 → 9.4.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 (160) hide show
  1. package/{bbox.ts → lib/bbox.ts} +4 -4
  2. package/{coordinate-bounds.ts → lib/coordinate-bounds.ts} +11 -0
  3. package/{coordinate-formats.ts → lib/coordinate-formats.ts} +3 -1
  4. package/lib/distance.ts +204 -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 +4 -4
  9. package/{geometries → lib/geometries}/point.ts +14 -13
  10. package/{geometries → lib/geometries}/polygon.ts +82 -158
  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/{open-location-code.ts → lib/open-location-code.ts} +1 -1
  21. package/{osgb36.ts → lib/osgb36.ts} +2 -2
  22. package/{polyline.ts → lib/polyline.ts} +5 -5
  23. package/{position.ts → lib/position.ts} +2 -2
  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/out/bbox.d.ts +2 -2
  30. package/out/bbox.d.ts.map +1 -1
  31. package/out/bbox.js +3 -3
  32. package/out/bbox.js.map +1 -1
  33. package/out/coordinate-bounds.d.ts +9 -0
  34. package/out/coordinate-bounds.d.ts.map +1 -1
  35. package/out/coordinate-bounds.js +9 -0
  36. package/out/coordinate-bounds.js.map +1 -1
  37. package/out/coordinate-formats.d.ts.map +1 -1
  38. package/out/coordinate-formats.js +2 -1
  39. package/out/coordinate-formats.js.map +1 -1
  40. package/out/distance.d.ts +64 -1
  41. package/out/distance.d.ts.map +1 -1
  42. package/out/distance.js +85 -1
  43. package/out/distance.js.map +1 -1
  44. package/out/feature.d.ts +1 -1
  45. package/out/feature.d.ts.map +1 -1
  46. package/out/feature.js.map +1 -1
  47. package/out/geometries/collection.d.ts +4 -4
  48. package/out/geometries/collection.d.ts.map +1 -1
  49. package/out/geometries/collection.js.map +1 -1
  50. package/out/geometries/index.d.ts +5 -4
  51. package/out/geometries/index.d.ts.map +1 -1
  52. package/out/geometries/index.js +5 -4
  53. package/out/geometries/index.js.map +1 -1
  54. package/out/geometries/line-string.d.ts +4 -4
  55. package/out/geometries/line-string.d.ts.map +1 -1
  56. package/out/geometries/line-string.js.map +1 -1
  57. package/out/geometries/point.d.ts +14 -13
  58. package/out/geometries/point.d.ts.map +1 -1
  59. package/out/geometries/point.js +11 -10
  60. package/out/geometries/point.js.map +1 -1
  61. package/out/geometries/polygon.d.ts +51 -100
  62. package/out/geometries/polygon.d.ts.map +1 -1
  63. package/out/geometries/polygon.js +60 -90
  64. package/out/geometries/polygon.js.map +1 -1
  65. package/out/geometries/ring-blob.d.ts +183 -0
  66. package/out/geometries/ring-blob.d.ts.map +1 -0
  67. package/out/geometries/ring-blob.js +376 -0
  68. package/out/geometries/ring-blob.js.map +1 -0
  69. package/out/google/index.d.ts +1 -1
  70. package/out/google/index.d.ts.map +1 -1
  71. package/out/google/index.js +1 -1
  72. package/out/google/index.js.map +1 -1
  73. package/out/google/place-id.d.ts.map +1 -1
  74. package/out/google/place-id.js.map +1 -1
  75. package/out/h3/cell.d.ts +32 -0
  76. package/out/h3/cell.d.ts.map +1 -1
  77. package/out/h3/cell.js +68 -1
  78. package/out/h3/cell.js.map +1 -1
  79. package/out/h3/coverage.d.ts +32 -0
  80. package/out/h3/coverage.d.ts.map +1 -0
  81. package/out/h3/coverage.js +27 -0
  82. package/out/h3/coverage.js.map +1 -0
  83. package/out/h3/index.d.ts +5 -3
  84. package/out/h3/index.d.ts.map +1 -1
  85. package/out/h3/index.js +5 -3
  86. package/out/h3/index.js.map +1 -1
  87. package/out/h3/interior-cells.d.ts +54 -0
  88. package/out/h3/interior-cells.d.ts.map +1 -0
  89. package/out/h3/interior-cells.js +111 -0
  90. package/out/h3/interior-cells.js.map +1 -0
  91. package/out/h3/polygon-cells.d.ts +182 -0
  92. package/out/h3/polygon-cells.d.ts.map +1 -0
  93. package/out/h3/polygon-cells.js +339 -0
  94. package/out/h3/polygon-cells.js.map +1 -0
  95. package/out/index.d.ts +15 -15
  96. package/out/index.d.ts.map +1 -1
  97. package/out/index.js +15 -15
  98. package/out/index.js.map +1 -1
  99. package/out/objects.d.ts +1 -1
  100. package/out/objects.d.ts.map +1 -1
  101. package/out/objects.js +1 -1
  102. package/out/objects.js.map +1 -1
  103. package/out/open-location-code.d.ts.map +1 -1
  104. package/out/open-location-code.js +1 -1
  105. package/out/open-location-code.js.map +1 -1
  106. package/out/osgb36.d.ts +2 -2
  107. package/out/osgb36.d.ts.map +1 -1
  108. package/out/osgb36.js +1 -1
  109. package/out/osgb36.js.map +1 -1
  110. package/out/polyline.d.ts +4 -4
  111. package/out/polyline.d.ts.map +1 -1
  112. package/out/polyline.js +5 -5
  113. package/out/polyline.js.map +1 -1
  114. package/out/position.d.ts +1 -1
  115. package/out/position.d.ts.map +1 -1
  116. package/out/position.js +2 -2
  117. package/out/position.js.map +1 -1
  118. package/out/projection-transform.d.ts +67 -0
  119. package/out/projection-transform.d.ts.map +1 -0
  120. package/out/projection-transform.js +48 -0
  121. package/out/projection-transform.js.map +1 -0
  122. package/out/projection.d.ts.map +1 -1
  123. package/out/projection.js.map +1 -1
  124. package/out/regions/codes.d.ts.map +1 -1
  125. package/out/regions/codes.js.map +1 -1
  126. package/out/regions/index.d.ts +2 -2
  127. package/out/regions/index.d.ts.map +1 -1
  128. package/out/regions/index.js +2 -2
  129. package/out/regions/index.js.map +1 -1
  130. package/out/regions/names.d.ts.map +1 -1
  131. package/out/regions/names.js.map +1 -1
  132. package/out/tools/ogr-stream.d.ts +34 -0
  133. package/out/tools/ogr-stream.d.ts.map +1 -0
  134. package/out/tools/ogr-stream.js +74 -0
  135. package/out/tools/ogr-stream.js.map +1 -0
  136. package/out/tools/ogr.d.ts +87 -0
  137. package/out/tools/ogr.d.ts.map +1 -0
  138. package/out/tools/ogr.js +84 -0
  139. package/out/tools/ogr.js.map +1 -0
  140. package/out/tsconfig.test.tsbuildinfo +1 -1
  141. package/out/well-known-text.d.ts.map +1 -0
  142. package/out/well-known-text.js.map +1 -0
  143. package/package.json +94 -25
  144. package/distance.ts +0 -84
  145. package/geometries/index.ts +0 -12
  146. package/index.ts +0 -21
  147. package/out/sdk/index.d.ts +0 -7
  148. package/out/sdk/index.d.ts.map +0 -1
  149. package/out/sdk/index.js +0 -7
  150. package/out/sdk/index.js.map +0 -1
  151. package/out/sdk/well-known-text.d.ts.map +0 -1
  152. package/out/sdk/well-known-text.js.map +0 -1
  153. package/out/tsconfig.tsbuildinfo +0 -1
  154. package/sdk/index.ts +0 -7
  155. /package/{google → lib/google}/place-id.ts +0 -0
  156. /package/{projection.ts → lib/projection.ts} +0 -0
  157. /package/{regions → lib/regions}/names.ts +0 -0
  158. /package/{sdk → lib}/well-known-text.ts +0 -0
  159. /package/out/{sdk/well-known-text.d.ts → well-known-text.d.ts} +0 -0
  160. /package/out/{sdk/well-known-text.js → well-known-text.js} +0 -0
@@ -6,10 +6,10 @@
6
6
  * GeoJSON Bounding Boxes
7
7
  */
8
8
 
9
- import { toRad } from "./coordinate-formats.ts"
10
- import type { PolygonLiteral, SolidPolygonPath } from "./geometries/polygon.ts"
11
- import { clampLatitude, wrapLongitude } from "./position.ts"
12
- import { CoordinateProjection } from "./projection.ts"
9
+ import { toRad } from "#coordinate-formats"
10
+ import type { PolygonLiteral, SolidPolygonPath } from "#geometries/polygon"
11
+ import { clampLatitude, wrapLongitude } from "#position"
12
+ import { CoordinateProjection } from "#projection"
13
13
 
14
14
  /**
15
15
  * Kilometres per degree of latitude, which is very nearly constant on a sphere.
@@ -26,6 +26,17 @@ export const LONGITUDE_MIN = -180
26
26
  */
27
27
  export const LONGITUDE_MAX = 180
28
28
 
29
+ /**
30
+ * Southern limit of the Web Mercator projection in WGS-84 degrees — the latitude at which the square projection's
31
+ * vertical extent equals its horizontal one.
32
+ */
33
+ export const MERCATOR_LATITUDE_MIN = -85.05112878
34
+
35
+ /**
36
+ * Northern limit of the Web Mercator projection in WGS-84 degrees.
37
+ */
38
+ export const MERCATOR_LATITUDE_MAX = 85.05112878
39
+
29
40
  /**
30
41
  * Whether a finite number is a latitude on the globe, including both poles.
31
42
  */
@@ -11,6 +11,8 @@
11
11
 
12
12
  import type { AnnotationSet, Annotator } from "@mailwoman/annotations"
13
13
 
14
+ import { MERCATOR_LATITUDE_MAX, MERCATOR_LATITUDE_MIN } from "#coordinate-bounds"
15
+
14
16
  /**
15
17
  * Bits packed into each base-32 geohash character.
16
18
  */
@@ -67,7 +69,7 @@ const WEB_MERCATOR_R = 6_378_137
67
69
  * Web Mercator (EPSG:3857) projection of a coordinate.
68
70
  */
69
71
  export function toMercator(lat: number, lon: number): { x: number; y: number } {
70
- const clampedLat = Math.max(-85.05112878, Math.min(85.05112878, lat))
72
+ const clampedLat = Math.max(MERCATOR_LATITUDE_MIN, Math.min(MERCATOR_LATITUDE_MAX, lat))
71
73
 
72
74
  return {
73
75
  x: WEB_MERCATOR_R * toRad(lon),
@@ -0,0 +1,204 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ * @file Great-circle distance utilities. This module imports geometry directly so spatial's
6
+ * lowest-level math never reaches back through its public barrel.
7
+ */
8
+
9
+ import { GeoPoint, type GeoPointInput } from "#geometries/point"
10
+ import { arealPolygons } from "#geometries/polygon"
11
+
12
+ /**
13
+ * Conversion factors for converting between degrees and radians.
14
+ *
15
+ * @category Position
16
+ * @see {@link https://en.wikipedia.org/wiki/Radian Wikipedia: Radian}
17
+ * @see {@link https://en.wikipedia.org/wiki/Degree_(angle) Wikipedia: Degree (angle)}
18
+ */
19
+ export const ConversionFactor = {
20
+ DegreesToRadians: Math.PI / 180,
21
+ RadiansToDegrees: 180 / Math.PI,
22
+ } as const
23
+
24
+ /**
25
+ * Available conversion units for the radius of the Earth.
26
+ */
27
+ export type EarthRadiusUnit = "km" | "miles" | "meters"
28
+
29
+ /**
30
+ * Radius of the Earth in various units.
31
+ */
32
+ const RADII = {
33
+ km: 6371,
34
+ miles: 3958.8,
35
+ meters: 6_371_000,
36
+ } as const satisfies Record<EarthRadiusUnit, number>
37
+
38
+ export type PlanetaryBodyID = "earth" | "moon" | "mars"
39
+
40
+ /**
41
+ * Mean radii in kilometres. Earth's is the value `RADII` scales to its units; the Moon's and Mars's are the IAU mean
42
+ * radii the USGS planetary products reference (the Moon as a sphere; Mars's mean radius, its DEM being on the areoid).
43
+ * A distance on a body other than Earth is meaningless without one of these.
44
+ */
45
+ export const BODY_RADII_KM = {
46
+ earth: RADII.km,
47
+ moon: 1737.4,
48
+ mars: 3389.5,
49
+ } as const satisfies Record<PlanetaryBodyID, number>
50
+
51
+ export interface GreatCircleOptions {
52
+ unit?: EarthRadiusUnit
53
+ /**
54
+ * Which body's mean radius scales the arc. @default "earth"
55
+ */
56
+ body?: PlanetaryBodyID
57
+ }
58
+
59
+ /**
60
+ * Shared great-circle math with no sentinel handling. `unit` selects the Earth radius.
61
+ */
62
+ function greatCircle(lat1: number, lon1: number, lat2: number, lon2: number, unit: EarthRadiusUnit): number {
63
+ const dLat = (lat2 - lat1) * ConversionFactor.DegreesToRadians
64
+ const dLon = (lon2 - lon1) * ConversionFactor.DegreesToRadians
65
+
66
+ const a =
67
+ Math.pow(Math.sin(dLat / 2), 2) +
68
+ Math.cos(lat1 * ConversionFactor.DegreesToRadians) *
69
+ Math.cos(lat2 * ConversionFactor.DegreesToRadians) *
70
+ Math.pow(Math.sin(dLon / 2), 2)
71
+
72
+ return RADII[unit] * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
73
+ }
74
+
75
+ /**
76
+ * Calculate the distance between two points on the Earth's surface.
77
+ *
78
+ * @category Position
79
+ * @param point1 The first point to calculate the distance from.
80
+ * @param point2 The second point to calculate the distance to.
81
+ * @param unit The unit of measurement to return the distance in.
82
+ *
83
+ * @returns The distance between the two points in the specified unit.
84
+ */
85
+ export function haversine(point1: GeoPointInput, point2: GeoPointInput, unit: EarthRadiusUnit = "km"): number {
86
+ const p1 = GeoPoint.from(point1)
87
+ const p2 = GeoPoint.from(point2)
88
+
89
+ if (!p1 || !p2) return Number.NaN
90
+
91
+ return greatCircle(p1.latitude, p1.longitude, p2.latitude, p2.longitude, unit)
92
+ }
93
+
94
+ /**
95
+ * Great-circle distance on the named body. {@link haversine} is this function on Earth; a caller with a body passes it
96
+ * here. The Null-Island sentinel of the object form applies: a `(0, 0)` input answers `NaN`.
97
+ *
98
+ * @category Position
99
+ */
100
+ export function greatCircleDistance(
101
+ point1: GeoPointInput,
102
+ point2: GeoPointInput,
103
+ options: GreatCircleOptions = {}
104
+ ): number {
105
+ const unit = options.unit ?? "km"
106
+ const body = options.body ?? "earth"
107
+ const scale = BODY_RADII_KM[body] / BODY_RADII_KM.earth
108
+
109
+ return haversine(point1, point2, unit) * scale
110
+ }
111
+
112
+ /**
113
+ * Great-circle distance in kilometres between two lat/lon pairs given as raw scalars. The formula's one true home —
114
+ * every resolver + eval consumer of the `(aLat, aLon, bLat, bLon)` shape imports this instead of re-declaring it.
115
+ *
116
+ * Unlike {@link haversine}, this is pure math with NO Null-Island sentinel: `(0, 0)` is the Gulf of Guinea — a real
117
+ * point, not "missing coordinate". That sentinel convention belongs to the `GeoPointInput` object form (where a 0/0
118
+ * input means "no coordinate"), not to a raw scalar distance.
119
+ *
120
+ * @category Position
121
+ */
122
+ export function haversineKm(aLat: number, aLon: number, bLat: number, bLon: number): number {
123
+ return greatCircle(aLat, aLon, bLat, bLon, "km")
124
+ }
125
+
126
+ /**
127
+ * Metres per degree of latitude — the scale {@link segmentDistanceMetres} reports in, and the constant the bounding-box
128
+ * estimates in `#h3/polygon-cells` are built on.
129
+ */
130
+ export const METRES_PER_DEGREE = 111_320
131
+
132
+ /**
133
+ * Square metres in a square kilometre — the conversion every polygon layer's area receipt reports through.
134
+ */
135
+ export const M2_PER_KM2 = 1_000_000
136
+
137
+ /**
138
+ * Metres from a point to a line SEGMENT, with longitude scaled for the latitude so the two axes are comparable.
139
+ *
140
+ * MEASURE TO THE EDGE, NOT TO THE NEAREST VERTEX. A point a centimetre from a long edge can be metres from every vertex
141
+ * of it, so a vertex distance overstates the gap without bound — measured on the flood layer's verification, one
142
+ * near-miss read 1.58 m to vertices and 0.009 m to edges, a 9 mm difference overstated 175-fold. That is the difference
143
+ * between "two channels rendered the same edge slightly differently" and "the conversion is wrong".
144
+ *
145
+ * The longitude scaling matters at the same scale: comparing raw degrees treats a degree of longitude as a degree of
146
+ * latitude, which at 54°N overstates east-west distance by 70%.
147
+ *
148
+ * @category Position
149
+ */
150
+ export function segmentDistanceMetres(
151
+ lon: number,
152
+ lat: number,
153
+ from: readonly number[],
154
+ to: readonly number[]
155
+ ): number {
156
+ const scale = Math.cos((lat * Math.PI) / 180)
157
+ const px = (lon - from[0]!) * scale
158
+ const py = lat - from[1]!
159
+ const vx = (to[0]! - from[0]!) * scale
160
+ const vy = to[1]! - from[1]!
161
+ const lengthSquared = vx * vx + vy * vy
162
+
163
+ // A zero-length segment is a repeated vertex; the distance to it is the distance to the point.
164
+ const t = lengthSquared === 0 ? 0 : Math.max(0, Math.min(1, (px * vx + py * vy) / lengthSquared))
165
+
166
+ return Math.hypot(px - t * vx, py - t * vy) * METRES_PER_DEGREE
167
+ }
168
+
169
+ /**
170
+ * Metres from a point to the nearest ring EDGE of an areal geometry — `Infinity` when the geometry bounds no area or
171
+ * carries no segment.
172
+ *
173
+ * To the edge, not to the nearest vertex: a point a centimetre from a long edge can be metres from every vertex of it,
174
+ * so a vertex distance overstates the gap without bound — measured on the flood layer's verification, one near-miss
175
+ * read 1.58 m to vertices and 0.009 m to edges, a 9 mm difference overstated 175-fold. Every polygon layer's two-path
176
+ * verification measures its boundary tolerance with this.
177
+ *
178
+ * @category Position
179
+ */
180
+ export function nearestRingEdgeMetres(
181
+ geometry: { type: string; coordinates: unknown },
182
+ longitude: number,
183
+ latitude: number
184
+ ): number {
185
+ const polygons = arealPolygons(geometry)
186
+
187
+ let nearest = Infinity
188
+
189
+ if (!polygons) return nearest
190
+
191
+ for (const rings of polygons) {
192
+ for (const ring of rings) {
193
+ for (let index = 1; index < ring.length; index++) {
194
+ const distance = segmentDistanceMetres(longitude, latitude, ring[index - 1]!, ring[index]!)
195
+
196
+ if (distance < nearest) {
197
+ nearest = distance
198
+ }
199
+ }
200
+ }
201
+ }
202
+
203
+ return nearest
204
+ }
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  /* eslint-disable @typescript-eslint/no-explicit-any */
8
- import type { GeometryLiteral } from "./geometries/index.ts"
8
+ import type { GeometryLiteral } from "#geometries/index"
9
9
 
10
10
  export interface IdentifiableGeoFeature {
11
11
  GEOID: string | number
@@ -6,10 +6,10 @@
6
6
  * GeoJSON Geometry Collection
7
7
  */
8
8
 
9
- import type { GeoObjectLiteral } from "../objects.ts"
10
- import type { LineStringLiteral, MultiLineStringLiteral } from "./line-string.ts"
11
- import type { MultiPointLiteral, PointLiteral } from "./point.ts"
12
- import type { MultiPolygonLiteral, PolygonLiteral } from "./polygon.ts"
9
+ import type { LineStringLiteral, MultiLineStringLiteral } from "#geometries/line-string"
10
+ import type { MultiPointLiteral, PointLiteral } from "#geometries/point"
11
+ import type { MultiPolygonLiteral, PolygonLiteral } from "#geometries/polygon"
12
+ import type { GeoObjectLiteral } from "#objects"
13
13
 
14
14
  /**
15
15
  * Union of the GeoJSON geometry types.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * GeoJSON Geometry Entry Point
7
+ */
8
+
9
+ export * from "#geometries/collection"
10
+ export * from "#geometries/line-string"
11
+ export * from "#geometries/point"
12
+ export * from "#geometries/polygon"
13
+ export * from "#geometries/ring-blob"
@@ -6,8 +6,8 @@
6
6
  * GeoJSON Line String
7
7
  */
8
8
 
9
- import type { GeoObjectLiteral } from "../objects.ts"
10
- import type { Coordinates2D, Coordinates3D } from "../position.ts"
9
+ import type { GeoObjectLiteral } from "#objects"
10
+ import type { Coordinates2D, Coordinates3D } from "#position"
11
11
 
12
12
  /**
13
13
  * An array of positions forming a line, such as a road or a path.
@@ -25,7 +25,7 @@ export interface LineStringLiteral extends GeoObjectLiteral {
25
25
  /**
26
26
  * An array of positions for each point in the geometry.
27
27
  *
28
- * @see {@linkcode GeoJSONPosition} for more information.
28
+ * @see {@linkcode Coordinates2D} for more information.
29
29
  */
30
30
  coordinates: LineStringPath
31
31
  }
@@ -41,7 +41,7 @@ export interface MultiLineStringLiteral extends GeoObjectLiteral {
41
41
  /**
42
42
  * An array for each line in the geometry.
43
43
  *
44
- * @see {@linkcode GeoJSONPosition} for more information.
44
+ * @see {@linkcode Coordinates2D} for more information.
45
45
  */
46
46
  coordinates: LineStringPath[]
47
47
  }
@@ -6,13 +6,13 @@
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/objects"
9
+ import { tryParsingJSON } from "@mailwoman/core/json"
10
10
  import { convert as convertCoords } from "geo-coordinates-parser"
11
11
  import { latLngToCell } from "h3-js"
12
12
 
13
- import { type BBox2DLiteral, type BBox3DLiteral, GeoBoundingBox, isBBox } from "../bbox.ts"
14
- import { type H3Cell, shortenH3Cell } from "../h3/cell.ts"
15
- import { type GeoObjectLiteral, GeometryType } from "../objects.ts"
13
+ import { type BBox2DLiteral, type BBox3DLiteral, GeoBoundingBox, isBBox } from "#bbox"
14
+ import { type H3Cell, shortenH3Cell } from "#h3/cell"
15
+ import { type GeoObjectLiteral, GeometryType } from "#objects"
16
16
  import {
17
17
  type InternalPointCoordinates,
18
18
  type Coordinates2D as Point2DCoordinates,
@@ -24,7 +24,7 @@ import {
24
24
  isValidLatitude,
25
25
  isValidLongitude,
26
26
  wrapLongitude,
27
- } from "../position.ts"
27
+ } from "#position"
28
28
 
29
29
  /**
30
30
  * A JSON-serializeable single point geometry, such as a specific location, address, or longitude, latitude pair.
@@ -79,7 +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 GeolocationCoordinates} object.
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.
83
84
  */
84
85
  export function isGeolocationCoordinatesLike(input: unknown): input is GeolocationCoordinatesLike {
85
86
  if (!input || typeof input !== "object") return false
@@ -149,7 +150,7 @@ export class GeoPoint implements PointLiteral {
149
150
  /**
150
151
  * Assigns the pair as GeoJSON [longitude, latitude(, altitude)] — the axis order is the contract, never inferred from
151
152
  * the magnitudes — and REJECTS a coordinate that is not on the globe. See {@link GeoPoint.from} for why both halves of
152
- * that sentence are load-bearing.
153
+ * that sentence are required.
153
154
  *
154
155
  * @throws {RangeError} When longitude is outside [-180, 180] or latitude is outside [-90, 90].
155
156
  */
@@ -225,7 +226,7 @@ export class GeoPoint implements PointLiteral {
225
226
  */
226
227
  constructor()
227
228
  /**
228
- * Create a new GeoPoint instance from another {@linkcode GeoJSONPosition} coordinates.
229
+ * Create a new GeoPoint instance from another {@linkcode Point2DCoordinates} coordinates.
229
230
  */
230
231
  constructor(
231
232
  geoJSONPosition: Point2DCoordinates | Point3DCoordinates,
@@ -298,9 +299,9 @@ export class GeoPoint implements PointLiteral {
298
299
  * Dallas and left corrupted in Berlin — behaviour selected by the data, from one code path. This change is a no-op
299
300
  * for every WELL-FORMED input: a valid `[longitude, latitude]` pair can never have an out-of-range second element,
300
301
  * so the heuristic never fired on one.
301
- * 2. **An out-of-range magnitude is rejected, not repaired.** `[999, 999]` used to produce a GeoPoint reporting latitude
302
- * 999. It now returns `null` here and throws a `RangeError` from the constructor. Note the deliberate asymmetry
303
- * with the scalar `longitude` / `latitude` setters, which still wrap and clamp: mutating a point is a pan gesture,
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,
304
305
  * where 190° meaning -170° is right; PARSING one is a claim about the world, where an impossible magnitude means
305
306
  * the input was malformed and any repair invents a location.
306
307
  *
@@ -424,7 +425,7 @@ export class GeoPoint implements PointLiteral {
424
425
  /**
425
426
  * An array of positions for each point in the geometry.
426
427
  *
427
- * @see {@linkcode GeoJSONPosition} for more information.
428
+ * @see {@linkcode Point2DCoordinates} for more information.
428
429
  */
429
430
  export type MultiPointPath = [...points: Array<Point2DCoordinates | Point3DCoordinates>]
430
431
 
@@ -439,7 +440,7 @@ export interface MultiPointLiteral extends GeoObjectLiteral {
439
440
  /**
440
441
  * An array of positions for each point in the geometry.
441
442
  *
442
- * @see {@linkcode GeoJSONPosition} for more information.
443
+ * @see {@linkcode Point2DCoordinates} for more information.
443
444
  */
444
445
  coordinates: MultiPointPath
445
446
  }