@mailwoman/spatial 8.6.0 → 9.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 (52) hide show
  1. package/README.md +4 -0
  2. package/geometries/point.ts +37 -15
  3. package/geometries/polygon.ts +70 -2
  4. package/h3/cell.ts +78 -39
  5. package/h3/index.ts +1 -1
  6. package/index.ts +1 -1
  7. package/osgb36.ts +371 -0
  8. package/out/geometries/point.d.ts +26 -1
  9. package/out/geometries/point.d.ts.map +1 -1
  10. package/out/geometries/point.js +33 -16
  11. package/out/geometries/point.js.map +1 -1
  12. package/out/geometries/polygon.d.ts +34 -2
  13. package/out/geometries/polygon.d.ts.map +1 -1
  14. package/out/geometries/polygon.js +43 -0
  15. package/out/geometries/polygon.js.map +1 -1
  16. package/out/h3/cell.d.ts +43 -15
  17. package/out/h3/cell.d.ts.map +1 -1
  18. package/out/h3/cell.js +63 -34
  19. package/out/h3/cell.js.map +1 -1
  20. package/out/h3/index.d.ts +1 -1
  21. package/out/h3/index.js +1 -1
  22. package/out/index.d.ts +1 -1
  23. package/out/index.d.ts.map +1 -1
  24. package/out/index.js +1 -1
  25. package/out/index.js.map +1 -1
  26. package/out/osgb36.d.ts +125 -0
  27. package/out/osgb36.d.ts.map +1 -0
  28. package/out/osgb36.js +301 -0
  29. package/out/osgb36.js.map +1 -0
  30. package/out/position.d.ts +28 -1
  31. package/out/position.d.ts.map +1 -1
  32. package/out/position.js +40 -1
  33. package/out/position.js.map +1 -1
  34. package/out/tsconfig.test.tsbuildinfo +1 -1
  35. package/out/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +3 -3
  37. package/position.ts +44 -1
  38. package/countries/codes.ts +0 -534
  39. package/countries/index.ts +0 -8
  40. package/countries/names.ts +0 -274
  41. package/out/countries/codes.d.ts +0 -529
  42. package/out/countries/codes.d.ts.map +0 -1
  43. package/out/countries/codes.js +0 -519
  44. package/out/countries/codes.js.map +0 -1
  45. package/out/countries/index.d.ts +0 -8
  46. package/out/countries/index.d.ts.map +0 -1
  47. package/out/countries/index.js +0 -8
  48. package/out/countries/index.js.map +0 -1
  49. package/out/countries/names.d.ts +0 -23
  50. package/out/countries/names.d.ts.map +0 -1
  51. package/out/countries/names.js +0 -264
  52. package/out/countries/names.js.map +0 -1
package/out/osgb36.js ADDED
@@ -0,0 +1,301 @@
1
+ /**
2
+ * @copyright Sister Software.
3
+ * @license AGPL-3.0
4
+ * @author Teffen Ellis, et al.
5
+ *
6
+ * OSGB36 / British National Grid (EPSG:27700) → WGS84 (EPSG:4326).
7
+ *
8
+ * Ordnance Survey ships its open products in eastings/northings on the National Grid, not in
9
+ * degrees — Code-Point Open, OS Open UPRN, OS Open Names all do. Nothing else in the repo speaks
10
+ * that coordinate system, so this module is the one place that converts it, and it lives in
11
+ * `@mailwoman/spatial` because that is the math home (`projection.ts` names the datums; this file
12
+ * moves between two of them).
13
+ *
14
+ * Two steps, both from OS's own "A Guide to Coordinate Systems in Great Britain":
15
+ *
16
+ * 1. **Inverse transverse Mercator (Redfearn's series)** — National Grid E/N → OSGB36 geodetic
17
+ * lat/lon on the Airy 1830 ellipsoid. This step is EXACT to well below a millimetre; it is
18
+ * plain map-projection algebra with no empirical content, and {@link osgb36GridToAiryLatLon}
19
+ * reproduces the guide's Annexe C.2 worked example to **1.3e-5 arc-seconds (~0.4 mm)**, which
20
+ * is that example's own published rounding rather than our error.
21
+ * 2. **Seven-parameter Helmert** — Airy-1830 geodetic → geocentric cartesian → rotate/scale/shift
22
+ * → WGS84 (GRS80) geodetic. This step is APPROXIMATE, and that is the whole accuracy story
23
+ * below. Against the guide's own Annexe D Helmert worked example — which uses this same
24
+ * transform, so it tests the implementation and not the approximation — the round trip lands
25
+ * **8.4 mm** out, i.e. the published DMS rounding plus the ignored ellipsoidal height.
26
+ *
27
+ * ## Accuracy: ±5 m, measured, and why we accept it
28
+ *
29
+ * OSGB36 is a 1936 theodolite triangulation, not a geocentric datum. Its distortions relative to
30
+ * WGS84 are irregular across GB — a couple of metres of local warp that no rigid-body transform can
31
+ * absorb. OS's exact answer is **OSTN15**, a published ~1.5 MB grid of per-cell E/N shifts; the
32
+ * seven-parameter Helmert implemented here is OS's own documented approximation to it, which the
33
+ * guide rates at "up to 3.5 m (95%)".
34
+ *
35
+ * MEASURED against OS's official 40-point OSTN15/OSGM15 test set (`OSTN15_OSGM15_TestInput_*`, the
36
+ * developer-pack vectors, joining each point's published OSGB36 E/N to its published ETRS89 lat/lon):
37
+ *
38
+ * | p50 | p90 | p95 | max | mean |
39
+ * | ------ | ------ | ------ | ------ | ------ |
40
+ * | 1.74 m | 3.23 m | 4.18 m | 4.91 m | 1.94 m |
41
+ *
42
+ * All 40 land under 5 m. The worst are exactly where OS warns the datum thins out — TP31 St Kilda
43
+ * (4.91 m), TP01 Scilly (4.72 m), TP32 Outer Hebrides (4.18 m); the mainland points sit near 1–2 m.
44
+ * p95 runs a little above the guide's 3.5 m because we discard ellipsoidal height (see
45
+ * {@link osgb36AiryToWGS84}), and because two of the three worst points are offshore rocks where
46
+ * "OSGB36 does not exist" in OS's own words.
47
+ *
48
+ * We take that error deliberately, because of what the coordinates are FOR. A Code-Point Open
49
+ * centroid is the mean position of a postcode unit's delivery points snapped to the nearest real
50
+ * address — the unit itself spans tens to hundreds of metres, and the resolver uses the centroid to
51
+ * pick a locality and rank candidates within a few hundred metres. A 2 m datum error is one to two
52
+ * orders of magnitude below the quantity being represented. Nothing downstream reads a postcode
53
+ * centroid at metre precision.
54
+ *
55
+ * **Do not use this module for anything that does.** Surveying, cadastral work, or any consumer
56
+ * comparing our coordinates against another OSGB36-derived dataset at sub-10 m tolerance needs
57
+ * OSTN15, which means shipping the shift grid. If that day comes, the seam is
58
+ * {@link osgb36AiryToWGS84} — swap the Helmert for a grid interpolation and the projection step
59
+ * above it is unchanged.
60
+ *
61
+ * @see https://www.ordnancesurvey.co.uk/documents/resources/guide-coordinate-systems-great-britain.pdf
62
+ */
63
+ /**
64
+ * Semi-major axis of the Airy 1830 ellipsoid, in metres — the figure of the Earth OSGB36 is referenced to.
65
+ */
66
+ const AIRY_1830_A = 6_377_563.396;
67
+ /**
68
+ * Semi-minor axis of the Airy 1830 ellipsoid, in metres.
69
+ */
70
+ const AIRY_1830_B = 6_356_256.909;
71
+ /**
72
+ * Semi-major axis of the GRS80 ellipsoid, in metres. WGS84's own semi-major axis is identical; the two ellipsoids
73
+ * differ only in the flattening's last digits (~0.1 mm at the pole), far below this module's error budget.
74
+ */
75
+ const GRS80_A = 6_378_137;
76
+ /**
77
+ * Semi-minor axis of the GRS80 ellipsoid, in metres.
78
+ */
79
+ const GRS80_B = 6_356_752.3141;
80
+ /**
81
+ * Scale factor on the National Grid's central meridian.
82
+ */
83
+ const NATIONAL_GRID_F0 = 0.9996012717;
84
+ /**
85
+ * Latitude of the National Grid's true origin, 49° N, in radians.
86
+ */
87
+ const NATIONAL_GRID_LAT0 = (49 * Math.PI) / 180;
88
+ /**
89
+ * Longitude of the National Grid's true origin, 2° W, in radians.
90
+ */
91
+ const NATIONAL_GRID_LON0 = (-2 * Math.PI) / 180;
92
+ /**
93
+ * Easting of the National Grid's true origin (the "false easting"), in metres.
94
+ */
95
+ const NATIONAL_GRID_E0 = 400_000;
96
+ /**
97
+ * Northing of the National Grid's true origin (the "false northing"), in metres. Negative because the true origin sits
98
+ * south-west of the grid's own zero.
99
+ */
100
+ const NATIONAL_GRID_N0 = -100_000;
101
+ /**
102
+ * Arc-seconds → radians. The Helmert rotations are published in arc-seconds.
103
+ */
104
+ const ARCSEC_TO_RAD = Math.PI / (180 * 3600);
105
+ /**
106
+ * Parts-per-million → unitless scale. The Helmert scale factor is published in ppm.
107
+ */
108
+ const PPM = 1e-6;
109
+ /**
110
+ * Convergence threshold for the meridional-arc iteration in {@link osgb36GridToAiryLatLon}, in METRES of northing. OS's
111
+ * guide specifies 0.01 mm; this is that figure. It bounds the northing residual, not the latitude, which is why it is
112
+ * expressed in metres and compared against `northing - N0 - M`.
113
+ */
114
+ const MERIDIONAL_ARC_TOLERANCE_M = 1e-5;
115
+ /**
116
+ * Convergence threshold for the cartesian→geodetic latitude iteration in {@link osgb36AiryToWGS84}, in RADIANS. 1e-13
117
+ * rad is ~0.6 µm on the ground — far below anything this module claims, and reached in four or five passes at GB
118
+ * latitudes.
119
+ */
120
+ const GEODETIC_LATITUDE_TOLERANCE_RAD = 1e-13;
121
+ /**
122
+ * The seven-parameter Helmert transformation taking OSGB36 (Airy 1830) geocentric cartesian coordinates to WGS84.
123
+ *
124
+ * OS publishes this transform in the ETRS89/WGS84 → OSGB36 direction (guide table 4), as `tx = -446.448, ty = +125.157,
125
+ * tz = -542.060, s = +20.4894 ppm, rx = -0.1502", ry = -0.2470", rz = -0.8421"`. We need the OTHER direction, so every
126
+ * parameter is negated — valid to well inside the transform's own metre-scale error because the rotations are
127
+ * microradian-scale and the second-order terms of a proper inversion are sub-millimetre.
128
+ *
129
+ * The rotation convention is **Position Vector** (EPSG method 1033), NOT Coordinate Frame Rotation (EPSG 1032). The two
130
+ * differ only in the sign of the three rotations, which is why citing the method code matters more than it looks: paste
131
+ * these numbers into a library expecting 1032 and every result moves by roughly 20 m with no error raised.
132
+ *
133
+ * Getting a sign wrong here does not produce a subtly worse answer; it produces a coordinate tens to hundreds of metres
134
+ * out, in a consistent direction — which reads as a plausible coordinate. That is what the Annexe D test is for.
135
+ */
136
+ const OSGB36_TO_WGS84_HELMERT = {
137
+ /**
138
+ * X translation, metres.
139
+ */
140
+ tx: 446.448,
141
+ /**
142
+ * Y translation, metres.
143
+ */
144
+ ty: -125.157,
145
+ /**
146
+ * Z translation, metres.
147
+ */
148
+ tz: 542.06,
149
+ /**
150
+ * Scale correction, parts per million.
151
+ */
152
+ scalePPM: -20.4894,
153
+ /**
154
+ * Rotation about the X axis, arc-seconds.
155
+ */
156
+ rx: 0.1502,
157
+ /**
158
+ * Rotation about the Y axis, arc-seconds.
159
+ */
160
+ ry: 0.247,
161
+ /**
162
+ * Rotation about the Z axis, arc-seconds.
163
+ */
164
+ rz: 0.8421,
165
+ };
166
+ /**
167
+ * Convert National Grid eastings/northings to OSGB36 geodetic lat/lon on the Airy 1830 ellipsoid, by Redfearn's inverse
168
+ * transverse Mercator series.
169
+ *
170
+ * This is the EXACT half of the pipeline — pure projection algebra, no datum shift. The result is still on Airy 1830,
171
+ * so it is NOT a WGS84 coordinate and must not be handed to anything expecting one; feed it to
172
+ * {@link osgb36AiryToWGS84}. Exported separately so the projection can be tested against OS's worked example
173
+ * independently of the Helmert, which is the only way to tell a projection bug from a datum-shift bug.
174
+ */
175
+ export function osgb36GridToAiryLatLon({ easting, northing }) {
176
+ const a = AIRY_1830_A;
177
+ const b = AIRY_1830_B;
178
+ const f0 = NATIONAL_GRID_F0;
179
+ const lat0 = NATIONAL_GRID_LAT0;
180
+ const lon0 = NATIONAL_GRID_LON0;
181
+ const e0 = NATIONAL_GRID_E0;
182
+ const n0 = NATIONAL_GRID_N0;
183
+ // Eccentricity squared of the Airy ellipsoid, and the `n` series parameter.
184
+ const e2 = (a * a - b * b) / (a * a);
185
+ const n = (a - b) / (a + b);
186
+ const n2 = n * n;
187
+ const n3 = n2 * n;
188
+ // Iterate latitude until the meridional arc `M` matches the northing. OS's guide specifies a 0.01 mm
189
+ // threshold; it converges in three or four passes anywhere in GB.
190
+ let lat = lat0;
191
+ let m = 0;
192
+ do {
193
+ lat = (northing - n0 - m) / (a * f0) + lat;
194
+ const dLat = lat - lat0;
195
+ const sLat = lat + lat0;
196
+ m =
197
+ b *
198
+ f0 *
199
+ ((1 + n + (5 / 4) * n2 + (5 / 4) * n3) * dLat -
200
+ (3 * n + 3 * n2 + (21 / 8) * n3) * Math.sin(dLat) * Math.cos(sLat) +
201
+ ((15 / 8) * n2 + (15 / 8) * n3) * Math.sin(2 * dLat) * Math.cos(2 * sLat) -
202
+ (35 / 24) * n3 * Math.sin(3 * dLat) * Math.cos(3 * sLat));
203
+ } while (Math.abs(northing - n0 - m) >= MERIDIONAL_ARC_TOLERANCE_M);
204
+ const sinLat = Math.sin(lat);
205
+ const cosLat = Math.cos(lat);
206
+ const tanLat = Math.tan(lat);
207
+ const tan2 = tanLat * tanLat;
208
+ const tan4 = tan2 * tan2;
209
+ const tan6 = tan4 * tan2;
210
+ // `nu` = transverse radius of curvature; `rho` = meridional radius; `eta2` = their ratio less one.
211
+ const nu = a * f0 * (1 - e2 * sinLat * sinLat) ** -0.5;
212
+ const rho = a * f0 * (1 - e2) * (1 - e2 * sinLat * sinLat) ** -1.5;
213
+ const eta2 = nu / rho - 1;
214
+ const secLat = 1 / cosLat;
215
+ const vii = tanLat / (2 * rho * nu);
216
+ const viii = (tanLat / (24 * rho * nu ** 3)) * (5 + 3 * tan2 + eta2 - 9 * tan2 * eta2);
217
+ const ix = (tanLat / (720 * rho * nu ** 5)) * (61 + 90 * tan2 + 45 * tan4);
218
+ const x = secLat / nu;
219
+ const xi = (secLat / (6 * nu ** 3)) * (nu / rho + 2 * tan2);
220
+ const xii = (secLat / (120 * nu ** 5)) * (5 + 28 * tan2 + 24 * tan4);
221
+ const xiia = (secLat / (5040 * nu ** 7)) * (61 + 662 * tan2 + 1320 * tan4 + 720 * tan6);
222
+ const dE = easting - e0;
223
+ const dE2 = dE * dE;
224
+ const dE3 = dE2 * dE;
225
+ const dE4 = dE2 * dE2;
226
+ const dE5 = dE4 * dE;
227
+ const dE6 = dE4 * dE2;
228
+ const dE7 = dE6 * dE;
229
+ const latitude = lat - vii * dE2 + viii * dE4 - ix * dE6;
230
+ const longitude = lon0 + x * dE - xi * dE3 + xii * dE5 - xiia * dE7;
231
+ return {
232
+ latitude: (latitude * 180) / Math.PI,
233
+ longitude: (longitude * 180) / Math.PI,
234
+ };
235
+ }
236
+ /**
237
+ * Convert OSGB36 geodetic lat/lon (Airy 1830) to WGS84 lat/lon (GRS80) via the seven-parameter Helmert.
238
+ *
239
+ * This is the APPROXIMATE half — see the module docstring for the ±5 m budget and when it stops being acceptable.
240
+ * Heights are not modelled: the input is treated as sitting on the Airy ellipsoid and the output's ellipsoidal height
241
+ * is discarded. For a horizontal postcode centroid that costs well under a metre; for anything vertical it is wrong by
242
+ * the ~50 m geoid–ellipsoid separation over GB, so this function does not pretend to return a height.
243
+ */
244
+ export function osgb36AiryToWGS84({ latitude, longitude }) {
245
+ const { tx, ty, tz, scalePPM, rx, ry, rz } = OSGB36_TO_WGS84_HELMERT;
246
+ // --- Airy 1830 geodetic → geocentric cartesian.
247
+ const phi = (latitude * Math.PI) / 180;
248
+ const lambda = (longitude * Math.PI) / 180;
249
+ const sinPhi = Math.sin(phi);
250
+ const cosPhi = Math.cos(phi);
251
+ const e2Airy = (AIRY_1830_A * AIRY_1830_A - AIRY_1830_B * AIRY_1830_B) / (AIRY_1830_A * AIRY_1830_A);
252
+ const nuAiry = AIRY_1830_A / Math.sqrt(1 - e2Airy * sinPhi * sinPhi);
253
+ const x1 = nuAiry * cosPhi * Math.cos(lambda);
254
+ const y1 = nuAiry * cosPhi * Math.sin(lambda);
255
+ const z1 = (1 - e2Airy) * nuAiry * sinPhi;
256
+ // --- Helmert: rotate, scale, translate.
257
+ const s = 1 + scalePPM * PPM;
258
+ const rxRad = rx * ARCSEC_TO_RAD;
259
+ const ryRad = ry * ARCSEC_TO_RAD;
260
+ const rzRad = rz * ARCSEC_TO_RAD;
261
+ const x2 = tx + s * x1 - rzRad * y1 + ryRad * z1;
262
+ const y2 = ty + rzRad * x1 + s * y1 - rxRad * z1;
263
+ const z2 = tz - ryRad * x1 + rxRad * y1 + s * z1;
264
+ // --- GRS80 geocentric cartesian → geodetic, by the standard iteration on latitude.
265
+ const e2GRS = (GRS80_A * GRS80_A - GRS80_B * GRS80_B) / (GRS80_A * GRS80_A);
266
+ const p = Math.sqrt(x2 * x2 + y2 * y2);
267
+ let phi2 = Math.atan2(z2, p * (1 - e2GRS));
268
+ let phiPrev = 2 * Math.PI;
269
+ // Converges in a handful of passes at GB latitudes; the guard bounds it regardless.
270
+ for (let i = 0; i < 100 && Math.abs(phi2 - phiPrev) > GEODETIC_LATITUDE_TOLERANCE_RAD; i++) {
271
+ phiPrev = phi2;
272
+ const nuGRS = GRS80_A / Math.sqrt(1 - e2GRS * Math.sin(phi2) * Math.sin(phi2));
273
+ const height = p / Math.cos(phi2) - nuGRS;
274
+ phi2 = Math.atan2(z2, p * (1 - (e2GRS * nuGRS) / (nuGRS + height)));
275
+ }
276
+ return {
277
+ latitude: (phi2 * 180) / Math.PI,
278
+ longitude: (Math.atan2(y2, x2) * 180) / Math.PI,
279
+ };
280
+ }
281
+ /**
282
+ * Convert a British National Grid (EPSG:27700) easting/northing straight to WGS84 (EPSG:4326) lat/lon — the composition
283
+ * of {@link osgb36GridToAiryLatLon} and {@link osgb36AiryToWGS84}, and the function callers actually want.
284
+ *
285
+ * Accurate to about ±5 m across GB (see the module docstring). Does NOT validate that the input lies within the grid's
286
+ * GB extent: `{easting: 0, northing: 0}` is a real point in the Atlantic south-west of the Scillies, and Code-Point
287
+ * Open uses exactly that to mean "no coordinate available" (its 865 positional-quality-90 rows). Callers must filter
288
+ * those rows themselves — a zero here is a legitimate coordinate, so this module cannot tell the difference.
289
+ */
290
+ export function osgb36ToWGS84(point) {
291
+ return osgb36AiryToWGS84(osgb36GridToAiryLatLon(point));
292
+ }
293
+ /**
294
+ * {@link osgb36ToWGS84} in GeoJSON axis order — `[longitude, latitude]`, matching {@link Coordinates2D} and every
295
+ * geometry helper in this package.
296
+ */
297
+ export function osgb36ToCoordinates2D(point) {
298
+ const { latitude, longitude } = osgb36ToWGS84(point);
299
+ return [longitude, latitude];
300
+ }
301
+ //# sourceMappingURL=osgb36.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osgb36.js","sourceRoot":"","sources":["../osgb36.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAIH;;GAEG;AACH,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC;;GAEG;AACH,MAAM,W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,aAAa,CAAC,KAAK,CAAC,CAAA;IAEpD,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAC7B,CAAC"}
package/out/position.d.ts CHANGED
@@ -7,6 +7,23 @@
7
7
  */
8
8
  import type { LatLngLiteral } from "@googlemaps/google-maps-services-js";
9
9
  import { type GeoPointInput } from "@mailwoman/spatial";
10
+ /**
11
+ * Whether a number is a latitude a point can actually sit at: finite, and within [-90, 90] inclusive (the poles count).
12
+ * Distinct from {@link clampLatitude}, which folds an out-of-range value onto the nearest pole — clamping is right for a
13
+ * viewport edge and wrong for a coordinate, where an out-of-range value means the input was malformed and the repaired
14
+ * point is fiction.
15
+ *
16
+ * @category Position
17
+ */
18
+ export declare function isValidLatitude(value: number): boolean;
19
+ /**
20
+ * Whether a number is a longitude a point can actually sit at: finite, and within [-180, 180] inclusive. Same
21
+ * distinction from {@link wrapLongitude} that {@link isValidLatitude} draws from `clampLatitude` — wrapping 190° to -170°
22
+ * is correct for a pan gesture and a silent relocation for a parsed coordinate.
23
+ *
24
+ * @category Position
25
+ */
26
+ export declare function isValidLongitude(value: number): boolean;
10
27
  /**
11
28
  * An ordered pair of coordinates in the form of [longitude, latitude].
12
29
  *
@@ -55,8 +72,18 @@ export declare function orderGeoJSONToCoordPair([longitude, latitude]: Coordinat
55
72
  * Given an input which appears to be reversed GeoJSON coordinates (i.e. [latitude, longitude]), returns the coordinates
56
73
  * in the correct order of [longitude, latitude].
57
74
  *
58
- * Note that this is a heuristic and is only accurate for North American coordinates.
75
+ * **This cannot do what its name promises, and nothing in this repo calls it.** The only signal it has is the [-90, 90]
76
+ * latitude range, so it transposes a pair only when the SECOND magnitude falls outside that range — i.e. only where
77
+ * |longitude| > 90. It is therefore inert across every longitude in [-90, 90]: all of Europe and Africa, western
78
+ * Russia, the Middle East, India, and the Atlantic. A caller who hands it `[latitude, longitude]` gets the pair
79
+ * repaired in Dallas and left corrupted in Berlin, from one code path, decided by the data. That is why `GeoPoint`
80
+ * stopped calling it on 2026-08-05 (recorded in `e9bfd139`; `registry/tools/geocoder-vs-provided-coords.ts` had already
81
+ * routed around it) and now reads a 2-tuple as GeoJSON [longitude, latitude], full stop.
82
+ *
83
+ * Retained as an explicit, opt-in escape hatch for a caller who knows their source is lat-first AND North American. If
84
+ * you know the axis order, use {@link orderCoordPairToGeoJSON}; if you do not, no function can tell you.
59
85
  *
86
+ * @deprecated Axis order is metadata, not something a magnitude can recover. Prefer `orderCoordPairToGeoJSON`.
60
87
  * @category GeoJSON
61
88
  * @category Position
62
89
  */
@@ -1 +1 @@
1
- {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../position.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAsBjE;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B;;;;;OAKG;IACH,SAAS,EAAE,MAAM;IACjB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM;CAChB,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAE9F;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAE9F;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,aAAa,CAkBxF;AAED;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG;IAC3B;;;;;OAKG;IACH,SAAS,EAAE,MAAM;IACjB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM;IAChB;;OAEG;IACH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AAE,MAAM,EAAE,MAAM,CAAC,CAMvG;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAMhF;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,wBAAwB,CAQ3F;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB;+BACoB,aAAa;+BACb,aAAa;CACpD,CAAA;AAEV;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,OAAO,GAAG,QAAQ,CAAA;AAqCvD,wBAAgB,SAAS,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,GAAE,eAAsB,GAAG,MAAM,CAO5G;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1F"}
package/out/position.js CHANGED
@@ -14,6 +14,35 @@ const LATITUDE_MIN = -90;
14
14
  * Northern limit of latitude in WGS84 degrees.
15
15
  */
16
16
  const LATITUDE_MAX = 90;
17
+ /**
18
+ * Western limit of longitude in WGS84 degrees (the antimeridian, which is itself a valid longitude).
19
+ */
20
+ const LONGITUDE_MIN = -180;
21
+ /**
22
+ * Eastern limit of longitude in WGS84 degrees.
23
+ */
24
+ const LONGITUDE_MAX = 180;
25
+ /**
26
+ * Whether a number is a latitude a point can actually sit at: finite, and within [-90, 90] inclusive (the poles count).
27
+ * Distinct from {@link clampLatitude}, which folds an out-of-range value onto the nearest pole — clamping is right for a
28
+ * viewport edge and wrong for a coordinate, where an out-of-range value means the input was malformed and the repaired
29
+ * point is fiction.
30
+ *
31
+ * @category Position
32
+ */
33
+ export function isValidLatitude(value) {
34
+ return Number.isFinite(value) && value >= LATITUDE_MIN && value <= LATITUDE_MAX;
35
+ }
36
+ /**
37
+ * Whether a number is a longitude a point can actually sit at: finite, and within [-180, 180] inclusive. Same
38
+ * distinction from {@link wrapLongitude} that {@link isValidLatitude} draws from `clampLatitude` — wrapping 190° to -170°
39
+ * is correct for a pan gesture and a silent relocation for a parsed coordinate.
40
+ *
41
+ * @category Position
42
+ */
43
+ export function isValidLongitude(value) {
44
+ return Number.isFinite(value) && value >= LONGITUDE_MIN && value <= LONGITUDE_MAX;
45
+ }
17
46
  /**
18
47
  * Arity of a `[lon, lat]` coordinate tuple.
19
48
  */
@@ -48,8 +77,18 @@ export function orderGeoJSONToCoordPair([longitude, latitude]) {
48
77
  * Given an input which appears to be reversed GeoJSON coordinates (i.e. [latitude, longitude]), returns the coordinates
49
78
  * in the correct order of [longitude, latitude].
50
79
  *
51
- * Note that this is a heuristic and is only accurate for North American coordinates.
80
+ * **This cannot do what its name promises, and nothing in this repo calls it.** The only signal it has is the [-90, 90]
81
+ * latitude range, so it transposes a pair only when the SECOND magnitude falls outside that range — i.e. only where
82
+ * |longitude| > 90. It is therefore inert across every longitude in [-90, 90]: all of Europe and Africa, western
83
+ * Russia, the Middle East, India, and the Atlantic. A caller who hands it `[latitude, longitude]` gets the pair
84
+ * repaired in Dallas and left corrupted in Berlin, from one code path, decided by the data. That is why `GeoPoint`
85
+ * stopped calling it on 2026-08-05 (recorded in `e9bfd139`; `registry/tools/geocoder-vs-provided-coords.ts` had already
86
+ * routed around it) and now reads a 2-tuple as GeoJSON [longitude, latitude], full stop.
87
+ *
88
+ * Retained as an explicit, opt-in escape hatch for a caller who knows their source is lat-first AND North American. If
89
+ * you know the axis order, use {@link orderCoordPairToGeoJSON}; if you do not, no function can tell you.
52
90
  *
91
+ * @deprecated Axis order is metadata, not something a magnitude can recover. Prefer `orderCoordPairToGeoJSON`.
53
92
  * @category GeoJSON
54
93
  * @category Position
55
94
  */
@@ -1 +1 @@
1
- {"version":3,"file":"position.js","sourceRoot":"","sources":["../position.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,QAAQ,EAAsB,MAAM,oBAAoB,CAAA;AAEjE;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,EAAE,CAAA;AAExB;;GAEG;AACH,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAE3B;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAA;AA6B7B;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAmB;IAC9E,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAA;AAC7B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,CAAC,SAAS,EAAE,QAAQ,CAAgB;IAC3E,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AAC7B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,CAAC,MAAM,EAAE,MAAM,CAAmB;IACxE,iDAAiD;IACjD,MAAM,WAAW,GAAG,MAAM,IAAI,YAAY,IAAI,MAAM,IAAI,YAAY,CAAA;IACpE,MAAM,WAAW,GAAG,MAAM,IAAI,YAAY,IAAI,MAAM,IAAI,YAAY,CAAA;IAEpE,IAAI,WAAW,IAAI,CAAC,WAAW,EAAE,CAAC;QACjC,0CAA0C;QAC1C,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxB,CAAC;IAED,IAAI,CAAC,WAAW,IAAI,WAAW,EAAE,CAAC;QACjC,0CAA0C;QAC1C,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxB,CAAC;IAED,sFAAsF;IACtF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IAEjC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AACpE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAqB,EAAE,MAAqB,EAAE,OAAwB,IAAI;IACnG,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAChC,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAEhC,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,MAAM,CAAC,GAAG,CAAA;IAEjC,OAAO,WAAW,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;AAC/E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY;IACjF,OAAO,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AACjD,CAAC"}
@@ -1 +1 @@
1
- {"root":["../bbox.test.ts","../coordinate-formats.test.ts","../position.test.ts","../geometries/point.test.ts","../geometries/polygon.test.ts","../google/place-id.test.ts","../h3/cell.test.ts","../sdk/well-known-text.test.ts"],"version":"6.0.3"}
1
+ {"root":["../bbox.test.ts","../coordinate-formats.test.ts","../osgb36.test.ts","../position.test.ts","../geometries/point.test.ts","../geometries/polygon.test.ts","../google/place-id.test.ts","../h3/cell.test.ts","../sdk/well-known-text.test.ts"],"version":"6.0.3"}