@math.gl/dggs 5.0.0-alpha.6 → 5.0.0-alpha.8

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 (60) hide show
  1. package/dist/a5-decoder.d.ts +3 -3
  2. package/dist/a5-decoder.d.ts.map +1 -1
  3. package/dist/a5-decoder.js +3 -3
  4. package/dist/a5-decoder.js.map +1 -1
  5. package/dist/a5.cjs +59 -2
  6. package/dist/a5.cjs.map +3 -3
  7. package/dist/dggs-decoder.d.ts +12 -3
  8. package/dist/dggs-decoder.d.ts.map +1 -1
  9. package/dist/dggs-decoder.js +24 -0
  10. package/dist/dggs-decoder.js.map +1 -1
  11. package/dist/geohash-decoder.d.ts +3 -3
  12. package/dist/geohash-decoder.d.ts.map +1 -1
  13. package/dist/geohash-decoder.js +3 -3
  14. package/dist/geohash-decoder.js.map +1 -1
  15. package/dist/geohash.cjs +75 -2
  16. package/dist/geohash.cjs.map +2 -2
  17. package/dist/h3-decoder.d.ts +3 -3
  18. package/dist/h3-decoder.d.ts.map +1 -1
  19. package/dist/h3-decoder.js +3 -3
  20. package/dist/h3-decoder.js.map +1 -1
  21. package/dist/h3.cjs +59 -2
  22. package/dist/h3.cjs.map +3 -3
  23. package/dist/index.cjs +71 -13
  24. package/dist/index.cjs.map +3 -3
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +1 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/plus-code-decoder.d.ts +3 -3
  30. package/dist/plus-code-decoder.d.ts.map +1 -1
  31. package/dist/plus-code-decoder.js +3 -3
  32. package/dist/plus-code-decoder.js.map +1 -1
  33. package/dist/plus-code.cjs +75 -2
  34. package/dist/plus-code.cjs.map +2 -2
  35. package/dist/quadkey-decoder.d.ts +3 -3
  36. package/dist/quadkey-decoder.d.ts.map +1 -1
  37. package/dist/quadkey-decoder.js +3 -3
  38. package/dist/quadkey-decoder.js.map +1 -1
  39. package/dist/quadkey.cjs +75 -2
  40. package/dist/quadkey.cjs.map +2 -2
  41. package/dist/s2-decoder.d.ts +3 -3
  42. package/dist/s2-decoder.d.ts.map +1 -1
  43. package/dist/s2-decoder.js +3 -2
  44. package/dist/s2-decoder.js.map +1 -1
  45. package/dist/s2.cjs +77 -2
  46. package/dist/s2.cjs.map +2 -2
  47. package/dist/unwrap-dggs-boundary.d.ts +12 -0
  48. package/dist/unwrap-dggs-boundary.d.ts.map +1 -0
  49. package/dist/unwrap-dggs-boundary.js +49 -0
  50. package/dist/unwrap-dggs-boundary.js.map +1 -0
  51. package/package.json +3 -3
  52. package/src/a5-decoder.ts +8 -3
  53. package/src/dggs-decoder.ts +40 -3
  54. package/src/geohash-decoder.ts +8 -3
  55. package/src/h3-decoder.ts +8 -3
  56. package/src/index.ts +2 -0
  57. package/src/plus-code-decoder.ts +8 -3
  58. package/src/quadkey-decoder.ts +8 -3
  59. package/src/s2-decoder.ts +3 -3
  60. package/src/unwrap-dggs-boundary.ts +54 -0
@@ -3,12 +3,17 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {type Bounds2D} from '@math.gl/types';
6
- import {type DGGSCell, type DGGSDecoder, getDGGSCellToken} from './dggs-decoder';
6
+ import {
7
+ withDGGSBoundaryOptions,
8
+ type DGGSCell,
9
+ type DGGSDecoder,
10
+ getDGGSCellToken
11
+ } from './dggs-decoder';
7
12
 
8
13
  const TILE_SIZE = 512;
9
14
 
10
15
  /** Decoder for the quadkey DGGS */
11
- export const QuadkeyDecoder = {
16
+ export const QuadkeyDecoder = withDGGSBoundaryOptions({
12
17
  name: 'quadkey',
13
18
  hasNumericRepresentation: false,
14
19
  cellColumnNames: ['quadkey', 'quadkeyId', 'quadkey_id'],
@@ -19,7 +24,7 @@ export const QuadkeyDecoder = {
19
24
  cellToBoundaryFlat: (cell: DGGSCell): number[] =>
20
25
  getQuadkeyBoundaryFlat(getDGGSCellToken(cell, 'Quadkey')),
21
26
  cellToBounds: (cell: DGGSCell): Bounds2D => getQuadkeyBounds(getDGGSCellToken(cell, 'Quadkey'))
22
- } as const satisfies DGGSDecoder;
27
+ } as const satisfies DGGSDecoder);
23
28
 
24
29
  function getQuadkeyLngLat(quadkey: string): [number, number] {
25
30
  const [topLeft, bottomRight] = quadkeyToWorldBounds(quadkey);
package/src/s2-decoder.ts CHANGED
@@ -3,14 +3,14 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {type Bounds2D} from '@math.gl/types';
6
- import {type DGGSCell, type DGGSDecoder} from './dggs-decoder';
6
+ import {withDGGSBoundaryOptions, type DGGSCell, type DGGSDecoder} from './dggs-decoder';
7
7
 
8
8
  import {getS2IndexFromToken, getS2TokenFromIndex} from './s2-geometry/s2-token';
9
9
  import {getS2GeoBounds} from './s2-geometry/s2-to-boundary';
10
10
  import {getS2Cell, IJToST, STToUV, FaceUVToXYZ, XYZToLngLat} from './s2-geometry/s2-geometry';
11
11
 
12
12
  /** Decoder for the S2 DGGS */
13
- export const S2Decoder = {
13
+ export const S2Decoder = withDGGSBoundaryOptions({
14
14
  name: 's2',
15
15
  hasNumericRepresentation: true,
16
16
  cellColumnNames: ['s2', 's2Token', 's2_token', 's2Cell', 's2_cell', 's2CellId', 's2_cell_id'],
@@ -20,7 +20,7 @@ export const S2Decoder = {
20
20
  cellToBoundary: (cell: DGGSCell): [number, number][] => getS2Boundary(cell),
21
21
  cellToBoundaryFlat: (cell: DGGSCell): number[] => getS2BoundaryFlat(cell),
22
22
  cellToBounds: (cell: DGGSCell): Bounds2D => getS2Bounds(cell)
23
- } as const satisfies DGGSDecoder;
23
+ } as const satisfies DGGSDecoder);
24
24
 
25
25
  /**
26
26
  * Retrieve S2 geometry center
@@ -0,0 +1,54 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * Copy a cell boundary, unwrapping longitudes across the antimeridian.
7
+ * @param boundary Open or closed longitude/latitude pairs in degrees.
8
+ * @param referenceLongitude Optional longitude near which to place the first vertex.
9
+ * @returns Fresh pairs with each longitude nearest the preceding longitude. Exact
10
+ * 180-degree ties retain their direction. Latitudes and vertex order are preserved.
11
+ * @remarks Explicit boundaries spanning at least 360 degrees and closed rings with
12
+ * net longitude winding are copied unchanged. Polar cells need additional topology
13
+ * handling. This helper neither splits polygons nor calculates geodesic edges.
14
+ */
15
+ export function unwrapDGGSBoundary(
16
+ boundary: ReadonlyArray<readonly [number, number]>,
17
+ referenceLongitude?: number
18
+ ): [number, number][] {
19
+ const result: [number, number][] = boundary.map(([longitude, latitude]) => [longitude, latitude]);
20
+ if (result.length === 0) {
21
+ return result;
22
+ }
23
+
24
+ let west = Infinity;
25
+ let east = -Infinity;
26
+ for (const [longitude] of boundary) {
27
+ west = Math.min(west, longitude);
28
+ east = Math.max(east, longitude);
29
+ }
30
+ if (east - west >= 360) {
31
+ return result;
32
+ }
33
+
34
+ let previous = referenceLongitude ?? result[0][0];
35
+ for (const point of result) {
36
+ const delta = point[0] - previous;
37
+ if (delta > 180) {
38
+ point[0] -= 360 * Math.ceil((delta - 180) / 360);
39
+ } else if (delta < -180) {
40
+ point[0] += 360 * Math.ceil((-delta - 180) / 360);
41
+ }
42
+ previous = point[0];
43
+ }
44
+
45
+ const first = boundary[0];
46
+ const last = boundary[boundary.length - 1];
47
+ if (first[0] === last[0] && first[1] === last[1]) {
48
+ if (Math.abs(result[result.length - 1][0] - result[0][0]) > 180) {
49
+ return boundary.map(([longitude, latitude]) => [longitude, latitude]);
50
+ }
51
+ result[result.length - 1] = [...result[0]];
52
+ }
53
+ return result;
54
+ }