webdggrid 1.5.0 → 1.7.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.
- package/dist/webdggrid.js +1 -1
- package/dist/webdggrid.js.map +1 -1
- package/dist/webdggrid.umd.js +1 -1
- package/dist/webdggrid.umd.js.map +1 -1
- package/lib-esm/libdggrid.wasm.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/webdggrid.js +1218 -16
- package/lib-esm/webdggrid.js.map +1 -1
- package/lib-wasm/CMakeCache.txt +3 -3
- package/lib-wasm/CMakeFiles/3.31.6/CMakeCCompiler.cmake +6 -6
- package/lib-wasm/CMakeFiles/3.31.6/CMakeCXXCompiler.cmake +6 -6
- package/lib-wasm/CMakeFiles/3.31.6/CMakeSystem.cmake +1 -1
- package/lib-wasm/CMakeFiles/Makefile.cmake +1 -1
- package/lib-wasm/CMakeFiles/libdggrid.dir/build.make +339 -339
- package/lib-wasm/CMakeFiles/libdggrid.dir/flags.make +2 -2
- package/lib-wasm/CMakeFiles/libdggrid.dir/link.txt +1 -1
- package/lib-wasm/CMakeFiles/libdggrid.dir/src-cpp/dggrid_transform.cpp.o +0 -0
- package/lib-wasm/CMakeFiles/libdggrid.dir/src-cpp/dggrid_transform.cpp.o.d +680 -673
- package/lib-wasm/CMakeFiles/libdggrid.dir/src-cpp/webdggrid.cpp.o +0 -0
- package/lib-wasm/CMakeFiles/libdggrid.dir/src-cpp/webdggrid.cpp.o.d +693 -693
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgAddressBase.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgAddressType.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgApSeq.cpp.o.d +670 -670
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBase.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedHexC2RF2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedHexC3C2RF2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedHexC3RF2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedIDGG.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedIDGGS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedRF2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedRFBase0.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgBoundedRFS2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgCell.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgColor.cpp.o.d +670 -670
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgConverterBase.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDVec2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDVec3D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDataFieldBase.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDataList.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDiscRFS2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDistanceBase.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDmdD4Grid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDmdD4Grid2DS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDmdD8Grid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDmdD8Grid2DS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgDmdIDGG.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgEllipsoidRF.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgGeoSphRF.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgGridTopo.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgHexC1Grid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgHexC2Grid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgHexC3Grid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgHexGrid2DS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgHexIDGG.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgHexIDGGS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGG.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGBase.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGS3H.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGS43H.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGS4D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGS4H.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGS4T.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGS7H.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGSBase.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIDGGutil.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIVec2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIVec3D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgIcosaMap.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgInAIGenFile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgInLocStreamFile.cpp.o.d +683 -683
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgInLocTextFile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgInShapefile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgInShapefileAtt.cpp.o.d +696 -696
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgInputStream.cpp.o.d +683 -683
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgLocBase.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgLocList.cpp.o.d +673 -673
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgLocVector.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgLocation.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutAIGenFile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutChildrenFile.cpp.o.d +691 -691
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutGeoJSONFile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutKMLfile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutLocFile.cpp.o.d +696 -696
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutLocTextFile.cpp.o.d +690 -690
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutNeighborsFile.cpp.o.d +691 -691
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutPRCellsFile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutPRPtsFile.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutPtsText.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutRandPtsText.cpp.o.d +692 -692
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutShapefile.cpp.o.d +699 -699
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgOutputStream.cpp.o.d +683 -683
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgPolygon.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgProjFuller.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgProjGnomonicRF.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgProjISEA.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgProjTriRF.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgRFBase.cpp.o.d +673 -673
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgRFNetwork.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgRandom.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgSeriesConverter.cpp.o.d +673 -673
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgSqrD4Grid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgSqrD4Grid2DS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgSqrD8Grid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgSqrD8Grid2DS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgSuperfund.cpp.o.d +663 -663
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgTriGrid2D.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgTriGrid2DS.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgTriIDGG.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgUtil.cpp.o.d +670 -670
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgZ3RF.cpp.o.d +675 -675
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgZ3StringRF.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgZ7RF.cpp.o.d +675 -675
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgZ7StringRF.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgZOrderRF.cpp.o.d +675 -675
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/dglib/lib/DgZOrderStringRF.cpp.o.d +672 -672
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/proj4lib/lib/adjlon.cpp.o.d +129 -129
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/proj4lib/lib/pj_auth.cpp.o.d +133 -133
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/proj4lib/lib/pj_mlfn.cpp.o.d +133 -133
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/proj4lib/lib/pj_msfn.cpp.o.d +132 -132
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/proj4lib/lib/pj_phi2.cpp.o.d +133 -133
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/proj4lib/lib/pj_qsfn.cpp.o.d +129 -129
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/proj4lib/lib/pj_tsfn.cpp.o.d +129 -129
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/shapelib/lib/dbfopen.c.o.d +25 -25
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/shapelib/lib/safileio.c.o.d +28 -28
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/shapelib/lib/sbnsearch.c.o.d +25 -25
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/shapelib/lib/shpopen.c.o.d +30 -30
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/shapelib/lib/shptree.c.o.d +28 -28
- package/lib-wasm/CMakeFiles/libdggrid.dir/submodules/DGGRID/src/lib/shapelib/lib/shputils.c.o.d +22 -22
- package/lib-wasm/cmake_install.cmake +1 -1
- package/lib-wasm/libdggrid.js +1 -1
- package/lib-wasm/libdggrid.wasm +0 -0
- package/package.json +1 -1
- package/readme.md +64 -3
- package/src-ts/webdggrid.ts +1559 -6
- package/types/webdggrid.d.ts +793 -1
- package/types/webdggrid.d.ts.map +1 -1
package/src-ts/webdggrid.ts
CHANGED
|
@@ -69,6 +69,25 @@ export interface Coordinate {
|
|
|
69
69
|
lng: number;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/**
|
|
73
|
+
* VERTEX2DD coordinate representation.
|
|
74
|
+
*
|
|
75
|
+
* Represents a position relative to the icosahedron vertices and triangular
|
|
76
|
+
* faces in DGGRID's coordinate system.
|
|
77
|
+
*/
|
|
78
|
+
export interface Vertex2DDCoordinate {
|
|
79
|
+
/** Whether to keep this vertex. */
|
|
80
|
+
keep: boolean;
|
|
81
|
+
/** Vertex number (0-11 for icosahedron). */
|
|
82
|
+
vertNum: number;
|
|
83
|
+
/** Triangle number on the icosahedron. */
|
|
84
|
+
triNum: number;
|
|
85
|
+
/** X coordinate within the triangle. */
|
|
86
|
+
x: number;
|
|
87
|
+
/** Y coordinate within the triangle. */
|
|
88
|
+
y: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
72
91
|
/**
|
|
73
92
|
* GeoJSON `properties` object attached to every cell feature returned by
|
|
74
93
|
* {@link Webdggrid.sequenceNumToGridFeatureCollection}.
|
|
@@ -138,8 +157,28 @@ export interface IDGGSProps {
|
|
|
138
157
|
* | 7 | 2 + 10 × 7^r |
|
|
139
158
|
*
|
|
140
159
|
* Aperture `4` is the most common choice and is the default.
|
|
160
|
+
* Ignored if `apertureSequence` is specified.
|
|
161
|
+
*/
|
|
162
|
+
aperture?: 3 | 4 | 5 | 7;
|
|
163
|
+
/**
|
|
164
|
+
* Mixed aperture sequence (e.g., `"434747"`).
|
|
165
|
+
*
|
|
166
|
+
* When specified, each character defines the aperture for that resolution level.
|
|
167
|
+
* The maximum resolution is limited to the length of the sequence string.
|
|
168
|
+
*
|
|
169
|
+
* **Constraints:**
|
|
170
|
+
* - Only valid for `HEXAGON` topology
|
|
171
|
+
* - Only characters `'3'`, `'4'`, and `'7'` are allowed
|
|
172
|
+
* - SEQNUM addressing is not supported (operations will fail)
|
|
173
|
+
* - Z3/Z7 hierarchical indexing is not supported
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* // Resolution 1 uses aperture 4, res 2 uses aperture 3, etc.
|
|
178
|
+
* apertureSequence: "434747"
|
|
179
|
+
* ```
|
|
141
180
|
*/
|
|
142
|
-
|
|
181
|
+
apertureSequence?: string;
|
|
143
182
|
/** Shape of each cell. See {@link Topology}. */
|
|
144
183
|
topology: Topology;
|
|
145
184
|
/** Projection used to map the polyhedron faces onto the sphere. See {@link Projection}. */
|
|
@@ -379,8 +418,12 @@ export class Webdggrid {
|
|
|
379
418
|
topology,
|
|
380
419
|
projection,
|
|
381
420
|
aperture,
|
|
421
|
+
apertureSequence,
|
|
382
422
|
} = this.dggs;
|
|
383
423
|
|
|
424
|
+
const isApertureSequence = !!apertureSequence;
|
|
425
|
+
const apSeq = apertureSequence || "";
|
|
426
|
+
|
|
384
427
|
const cellCount = this._module.nCells(
|
|
385
428
|
lng,
|
|
386
429
|
lat,
|
|
@@ -388,7 +431,9 @@ export class Webdggrid {
|
|
|
388
431
|
aperture,
|
|
389
432
|
resolution,
|
|
390
433
|
topology,
|
|
391
|
-
projection
|
|
434
|
+
projection,
|
|
435
|
+
isApertureSequence,
|
|
436
|
+
apSeq
|
|
392
437
|
);
|
|
393
438
|
|
|
394
439
|
return cellCount as number;
|
|
@@ -416,8 +461,12 @@ export class Webdggrid {
|
|
|
416
461
|
topology,
|
|
417
462
|
projection,
|
|
418
463
|
aperture,
|
|
464
|
+
apertureSequence,
|
|
419
465
|
} = this.dggs;
|
|
420
466
|
|
|
467
|
+
const isApertureSequence = !!apertureSequence;
|
|
468
|
+
const apSeq = apertureSequence || "";
|
|
469
|
+
|
|
421
470
|
const cellCount = this._module.cellAreaKM(
|
|
422
471
|
lng,
|
|
423
472
|
lat,
|
|
@@ -425,7 +474,9 @@ export class Webdggrid {
|
|
|
425
474
|
aperture,
|
|
426
475
|
resolution,
|
|
427
476
|
topology,
|
|
428
|
-
projection
|
|
477
|
+
projection,
|
|
478
|
+
isApertureSequence,
|
|
479
|
+
apSeq
|
|
429
480
|
);
|
|
430
481
|
|
|
431
482
|
return cellCount as number;
|
|
@@ -453,8 +504,12 @@ export class Webdggrid {
|
|
|
453
504
|
topology,
|
|
454
505
|
projection,
|
|
455
506
|
aperture,
|
|
507
|
+
apertureSequence,
|
|
456
508
|
} = this.dggs;
|
|
457
509
|
|
|
510
|
+
const isApertureSequence = !!apertureSequence;
|
|
511
|
+
const apSeq = apertureSequence || "";
|
|
512
|
+
|
|
458
513
|
const cellCount = this._module.cellDistKM(
|
|
459
514
|
lng,
|
|
460
515
|
lat,
|
|
@@ -462,7 +517,9 @@ export class Webdggrid {
|
|
|
462
517
|
aperture,
|
|
463
518
|
resolution,
|
|
464
519
|
topology,
|
|
465
|
-
projection
|
|
520
|
+
projection,
|
|
521
|
+
isApertureSequence,
|
|
522
|
+
apSeq
|
|
466
523
|
);
|
|
467
524
|
|
|
468
525
|
return cellCount as number;
|
|
@@ -491,8 +548,12 @@ export class Webdggrid {
|
|
|
491
548
|
topology,
|
|
492
549
|
projection,
|
|
493
550
|
aperture,
|
|
551
|
+
apertureSequence,
|
|
494
552
|
} = this.dggs;
|
|
495
553
|
|
|
554
|
+
const isApertureSequence = !!apertureSequence;
|
|
555
|
+
const apSeq = apertureSequence || "";
|
|
556
|
+
|
|
496
557
|
const cellCount = this._module.gridStatCLS(
|
|
497
558
|
lng,
|
|
498
559
|
lat,
|
|
@@ -500,7 +561,9 @@ export class Webdggrid {
|
|
|
500
561
|
aperture,
|
|
501
562
|
resolution,
|
|
502
563
|
topology,
|
|
503
|
-
projection
|
|
564
|
+
projection,
|
|
565
|
+
isApertureSequence,
|
|
566
|
+
apSeq
|
|
504
567
|
);
|
|
505
568
|
|
|
506
569
|
return cellCount as number;
|
|
@@ -545,8 +608,12 @@ export class Webdggrid {
|
|
|
545
608
|
topology,
|
|
546
609
|
projection,
|
|
547
610
|
aperture,
|
|
611
|
+
apertureSequence,
|
|
548
612
|
} = this.dggs;
|
|
549
613
|
|
|
614
|
+
const isApertureSequence = !!apertureSequence;
|
|
615
|
+
const apSeq = apertureSequence || "";
|
|
616
|
+
|
|
550
617
|
const xCoords = coordinates.map((coord) => coord[0]);
|
|
551
618
|
const yCoords = coordinates.map((coord) => coord[1]);
|
|
552
619
|
|
|
@@ -558,6 +625,8 @@ export class Webdggrid {
|
|
|
558
625
|
resolution,
|
|
559
626
|
topology,
|
|
560
627
|
projection,
|
|
628
|
+
isApertureSequence,
|
|
629
|
+
apSeq,
|
|
561
630
|
xCoords,
|
|
562
631
|
yCoords
|
|
563
632
|
);
|
|
@@ -593,8 +662,12 @@ export class Webdggrid {
|
|
|
593
662
|
topology,
|
|
594
663
|
projection,
|
|
595
664
|
aperture,
|
|
665
|
+
apertureSequence,
|
|
596
666
|
} = this.dggs;
|
|
597
667
|
|
|
668
|
+
const isApertureSequence = !!apertureSequence;
|
|
669
|
+
const apSeq = apertureSequence || "";
|
|
670
|
+
|
|
598
671
|
const resultArray = this._module.SEQNUM_to_GEO(
|
|
599
672
|
lng,
|
|
600
673
|
lat,
|
|
@@ -603,6 +676,8 @@ export class Webdggrid {
|
|
|
603
676
|
resolution,
|
|
604
677
|
topology,
|
|
605
678
|
projection,
|
|
679
|
+
isApertureSequence,
|
|
680
|
+
apSeq,
|
|
606
681
|
sequenceNum
|
|
607
682
|
);
|
|
608
683
|
|
|
@@ -652,8 +727,12 @@ export class Webdggrid {
|
|
|
652
727
|
topology,
|
|
653
728
|
projection,
|
|
654
729
|
aperture,
|
|
730
|
+
apertureSequence,
|
|
655
731
|
} = this.dggs;
|
|
656
732
|
|
|
733
|
+
const isApertureSequence = !!apertureSequence;
|
|
734
|
+
const apSeq = apertureSequence || "";
|
|
735
|
+
|
|
657
736
|
const xCoords = coordinates.map((coord) => coord[0]);
|
|
658
737
|
const yCoords = coordinates.map((coord) => coord[1]);
|
|
659
738
|
|
|
@@ -665,6 +744,8 @@ export class Webdggrid {
|
|
|
665
744
|
resolution,
|
|
666
745
|
topology,
|
|
667
746
|
projection,
|
|
747
|
+
isApertureSequence,
|
|
748
|
+
apSeq,
|
|
668
749
|
xCoords,
|
|
669
750
|
yCoords
|
|
670
751
|
);
|
|
@@ -711,8 +792,12 @@ export class Webdggrid {
|
|
|
711
792
|
topology,
|
|
712
793
|
projection,
|
|
713
794
|
aperture,
|
|
795
|
+
apertureSequence,
|
|
714
796
|
} = this.dggs;
|
|
715
797
|
|
|
798
|
+
const isApertureSequence = !!apertureSequence;
|
|
799
|
+
const apSeq = apertureSequence || "";
|
|
800
|
+
|
|
716
801
|
const inputSize = sequenceNum.length;
|
|
717
802
|
|
|
718
803
|
let resultArray = [];
|
|
@@ -725,11 +810,13 @@ export class Webdggrid {
|
|
|
725
810
|
resolution,
|
|
726
811
|
topology,
|
|
727
812
|
projection,
|
|
813
|
+
isApertureSequence,
|
|
814
|
+
apSeq,
|
|
728
815
|
sequenceNum
|
|
729
816
|
);
|
|
730
817
|
} catch (e) {
|
|
731
818
|
console.error(this._module.getExceptionMessage(e).toString());
|
|
732
|
-
throw(e);
|
|
819
|
+
throw (e);
|
|
733
820
|
}
|
|
734
821
|
|
|
735
822
|
const allShapeVertexes = resultArray.slice(0, inputSize);
|
|
@@ -817,4 +904,1470 @@ export class Webdggrid {
|
|
|
817
904
|
features,
|
|
818
905
|
};
|
|
819
906
|
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Returns all neighboring cells (sharing an edge) for each input cell.
|
|
910
|
+
*
|
|
911
|
+
* For hexagonal grids, each interior cell typically has 6 neighbors.
|
|
912
|
+
* Pentagon cells and boundary cells may have fewer. Triangle topology
|
|
913
|
+
* is not supported by the underlying DGGRID library.
|
|
914
|
+
*
|
|
915
|
+
* The output is a 2-D array: `result[i]` contains all neighbors of
|
|
916
|
+
* `sequenceNum[i]`.
|
|
917
|
+
*
|
|
918
|
+
* ```ts
|
|
919
|
+
* const neighbors = dggs.sequenceNumNeighbors([123n], 5);
|
|
920
|
+
* // neighbors[0] = [122n, 124n, 125n, 126n, 127n, 128n]
|
|
921
|
+
* ```
|
|
922
|
+
*
|
|
923
|
+
* ::: warning
|
|
924
|
+
* Triangle topology is **not supported**. Attempting to retrieve neighbors
|
|
925
|
+
* for a TRIANGLE grid will throw an error.
|
|
926
|
+
* :::
|
|
927
|
+
*
|
|
928
|
+
* @param sequenceNum - Array of `BigInt` cell IDs whose neighbors to find.
|
|
929
|
+
* @param resolution - Resolution at which the IDs were generated. Defaults
|
|
930
|
+
* to the instance's current {@link resolution}.
|
|
931
|
+
* @returns A 2-D array of `BigInt[]`: `result[i]` is the array of neighbor
|
|
932
|
+
* IDs for `sequenceNum[i]`.
|
|
933
|
+
* @throws If Triangle topology is used or if an invalid cell ID is provided.
|
|
934
|
+
*/
|
|
935
|
+
sequenceNumNeighbors(
|
|
936
|
+
sequenceNum: bigint[],
|
|
937
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
938
|
+
): bigint[][] {
|
|
939
|
+
const {
|
|
940
|
+
poleCoordinates: { lat, lng },
|
|
941
|
+
azimuth,
|
|
942
|
+
topology,
|
|
943
|
+
projection,
|
|
944
|
+
aperture,
|
|
945
|
+
apertureSequence,
|
|
946
|
+
} = this.dggs;
|
|
947
|
+
|
|
948
|
+
if (topology === Topology.TRIANGLE) {
|
|
949
|
+
throw new Error('Neighbor detection is not supported for TRIANGLE topology');
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
const isApertureSequence = !!apertureSequence;
|
|
953
|
+
const apSeq = apertureSequence || "";
|
|
954
|
+
|
|
955
|
+
try {
|
|
956
|
+
const resultArray = this._module.SEQNUMS_neighbors(
|
|
957
|
+
lng,
|
|
958
|
+
lat,
|
|
959
|
+
azimuth,
|
|
960
|
+
aperture,
|
|
961
|
+
resolution,
|
|
962
|
+
topology,
|
|
963
|
+
projection,
|
|
964
|
+
isApertureSequence,
|
|
965
|
+
apSeq,
|
|
966
|
+
sequenceNum
|
|
967
|
+
);
|
|
968
|
+
|
|
969
|
+
// The result is a flat array with format:
|
|
970
|
+
// [count0, count1, ..., countN, neighbor0_0, neighbor0_1, ..., neighbor0_(count0-1), neighbor1_0, ...]
|
|
971
|
+
const inputSize = sequenceNum.length;
|
|
972
|
+
const counts = resultArray.slice(0, inputSize);
|
|
973
|
+
const neighbors: bigint[][] = [];
|
|
974
|
+
|
|
975
|
+
let offset = inputSize;
|
|
976
|
+
for (let i = 0; i < inputSize; i++) {
|
|
977
|
+
const count = Number(counts[i]);
|
|
978
|
+
neighbors.push(resultArray.slice(offset, offset + count));
|
|
979
|
+
offset += count;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
return neighbors;
|
|
983
|
+
} catch (e) {
|
|
984
|
+
console.error(this._module.getExceptionMessage(e).toString());
|
|
985
|
+
throw e;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* Returns the parent cell at the next coarser resolution (resolution - 1)
|
|
991
|
+
* for each input cell.
|
|
992
|
+
*
|
|
993
|
+
* The parent-child relationship forms a hierarchical index structure. For
|
|
994
|
+
* aperture 4 grids, each parent contains 4 children; for aperture 7, each
|
|
995
|
+
* parent contains 7 children.
|
|
996
|
+
*
|
|
997
|
+
* ```ts
|
|
998
|
+
* const parents = dggs.sequenceNumParent([123n, 456n], 5);
|
|
999
|
+
* // parents = [30n, 114n] (at resolution 4)
|
|
1000
|
+
* ```
|
|
1001
|
+
*
|
|
1002
|
+
* ::: info
|
|
1003
|
+
* Calling this method at resolution 0 will throw an error because there
|
|
1004
|
+
* are no cells at resolution -1.
|
|
1005
|
+
* :::
|
|
1006
|
+
*
|
|
1007
|
+
* @param sequenceNum - Array of `BigInt` cell IDs whose parents to find.
|
|
1008
|
+
* @param resolution - Resolution at which the input IDs were generated.
|
|
1009
|
+
* Must be > 0. Defaults to the instance's current {@link resolution}.
|
|
1010
|
+
* @returns Array of `BigInt` parent cell IDs at resolution - 1, one per
|
|
1011
|
+
* input cell, in the same order.
|
|
1012
|
+
* @throws If resolution is 0 or if an invalid cell ID is provided.
|
|
1013
|
+
*/
|
|
1014
|
+
sequenceNumParent(
|
|
1015
|
+
sequenceNum: bigint[],
|
|
1016
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1017
|
+
): bigint[] {
|
|
1018
|
+
if (resolution <= 0) {
|
|
1019
|
+
throw new Error('Cannot get parent at resolution 0 or below');
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
const {
|
|
1023
|
+
poleCoordinates: { lat, lng },
|
|
1024
|
+
azimuth,
|
|
1025
|
+
topology,
|
|
1026
|
+
projection,
|
|
1027
|
+
aperture,
|
|
1028
|
+
apertureSequence,
|
|
1029
|
+
} = this.dggs;
|
|
1030
|
+
|
|
1031
|
+
const isApertureSequence = !!apertureSequence;
|
|
1032
|
+
const apSeq = apertureSequence || "";
|
|
1033
|
+
|
|
1034
|
+
try {
|
|
1035
|
+
const resultArray = this._module.SEQNUMS_parents(
|
|
1036
|
+
lng,
|
|
1037
|
+
lat,
|
|
1038
|
+
azimuth,
|
|
1039
|
+
aperture,
|
|
1040
|
+
resolution,
|
|
1041
|
+
topology,
|
|
1042
|
+
projection,
|
|
1043
|
+
isApertureSequence,
|
|
1044
|
+
apSeq,
|
|
1045
|
+
sequenceNum
|
|
1046
|
+
);
|
|
1047
|
+
|
|
1048
|
+
return resultArray;
|
|
1049
|
+
} catch (e) {
|
|
1050
|
+
console.error(this._module.getExceptionMessage(e).toString());
|
|
1051
|
+
throw e;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Returns **all** parent cells that touch each input cell at the coarser
|
|
1057
|
+
* resolution (resolution - 1).
|
|
1058
|
+
*
|
|
1059
|
+
* Unlike {@link sequenceNumParent} which returns only the primary
|
|
1060
|
+
* (containing) parent, this method returns every parent cell whose area
|
|
1061
|
+
* overlaps with the child cell. For interior cells this is typically 1;
|
|
1062
|
+
* for cells on a parent boundary it may be 2 or more.
|
|
1063
|
+
*
|
|
1064
|
+
* The **first element** of each inner array is always the primary
|
|
1065
|
+
* (containing) parent — the same value returned by
|
|
1066
|
+
* {@link sequenceNumParent}.
|
|
1067
|
+
*
|
|
1068
|
+
* ```ts
|
|
1069
|
+
* const allParents = dggs.sequenceNumAllParents([256n], 3);
|
|
1070
|
+
* // allParents[0] = [65n, 66n] — 65 is the containing parent,
|
|
1071
|
+
* // 66 is a touching neighbor parent
|
|
1072
|
+
* ```
|
|
1073
|
+
*
|
|
1074
|
+
* @param sequenceNum - Array of `BigInt` cell IDs to query.
|
|
1075
|
+
* @param resolution - Resolution at which the input IDs were generated
|
|
1076
|
+
* (must be > 0). Defaults to the instance's current {@link resolution}.
|
|
1077
|
+
* @returns A 2-D array: `result[i]` contains all parent cell IDs that
|
|
1078
|
+
* touch `sequenceNum[i]`, with the primary parent first.
|
|
1079
|
+
* @throws If `resolution` is 0 or negative, or if an invalid cell ID is
|
|
1080
|
+
* provided.
|
|
1081
|
+
*/
|
|
1082
|
+
sequenceNumAllParents(
|
|
1083
|
+
sequenceNum: bigint[],
|
|
1084
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1085
|
+
): bigint[][] {
|
|
1086
|
+
if (resolution <= 0) {
|
|
1087
|
+
throw new Error('Cannot get parents at resolution 0 or below');
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
try {
|
|
1091
|
+
const resultArray = this._module.SEQNUMS_all_parents(
|
|
1092
|
+
...this._getParams(resolution),
|
|
1093
|
+
sequenceNum
|
|
1094
|
+
);
|
|
1095
|
+
|
|
1096
|
+
// Convert from JS array of arrays to bigint[][]
|
|
1097
|
+
const result: bigint[][] = [];
|
|
1098
|
+
for (let i = 0; i < resultArray.length; i++) {
|
|
1099
|
+
const inner: bigint[] = [];
|
|
1100
|
+
for (let j = 0; j < resultArray[i].length; j++) {
|
|
1101
|
+
inner.push(resultArray[i][j]);
|
|
1102
|
+
}
|
|
1103
|
+
result.push(inner);
|
|
1104
|
+
}
|
|
1105
|
+
return result;
|
|
1106
|
+
} catch (e) {
|
|
1107
|
+
console.error(this._module.getExceptionMessage(e).toString());
|
|
1108
|
+
throw e;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Returns all child cells at the next finer resolution (resolution + 1)
|
|
1114
|
+
* for each input cell.
|
|
1115
|
+
*
|
|
1116
|
+
* The number of children depends on the aperture:
|
|
1117
|
+
* - Aperture 3: 3 children per parent
|
|
1118
|
+
* - Aperture 4: 4 children per parent
|
|
1119
|
+
* - Aperture 7: 7 children per parent
|
|
1120
|
+
*
|
|
1121
|
+
* The output is a 2-D array: `result[i]` contains all children of
|
|
1122
|
+
* `sequenceNum[i]`.
|
|
1123
|
+
*
|
|
1124
|
+
* ```ts
|
|
1125
|
+
* const children = dggs.sequenceNumChildren([30n], 4);
|
|
1126
|
+
* // children[0] = [120n, 121n, 122n, 123n] (at resolution 5, aperture 4)
|
|
1127
|
+
* ```
|
|
1128
|
+
*
|
|
1129
|
+
* ::: info
|
|
1130
|
+
* Children always include both boundary and interior cells. The returned
|
|
1131
|
+
* cells completely cover the parent cell's area.
|
|
1132
|
+
* :::
|
|
1133
|
+
*
|
|
1134
|
+
* @param sequenceNum - Array of `BigInt` cell IDs whose children to find.
|
|
1135
|
+
* @param resolution - Resolution at which the input IDs were generated.
|
|
1136
|
+
* Defaults to the instance's current {@link resolution}.
|
|
1137
|
+
* @returns A 2-D array of `BigInt[]`: `result[i]` is the array of child
|
|
1138
|
+
* IDs for `sequenceNum[i]` at resolution + 1.
|
|
1139
|
+
* @throws If an invalid cell ID is provided or if the maximum resolution
|
|
1140
|
+
* is exceeded.
|
|
1141
|
+
*/
|
|
1142
|
+
sequenceNumChildren(
|
|
1143
|
+
sequenceNum: bigint[],
|
|
1144
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1145
|
+
): bigint[][] {
|
|
1146
|
+
const {
|
|
1147
|
+
poleCoordinates: { lat, lng },
|
|
1148
|
+
azimuth,
|
|
1149
|
+
topology,
|
|
1150
|
+
projection,
|
|
1151
|
+
aperture,
|
|
1152
|
+
apertureSequence,
|
|
1153
|
+
} = this.dggs;
|
|
1154
|
+
|
|
1155
|
+
const isApertureSequence = !!apertureSequence;
|
|
1156
|
+
const apSeq = apertureSequence || "";
|
|
1157
|
+
|
|
1158
|
+
try {
|
|
1159
|
+
const resultArray = this._module.SEQNUMS_children(
|
|
1160
|
+
lng,
|
|
1161
|
+
lat,
|
|
1162
|
+
azimuth,
|
|
1163
|
+
aperture,
|
|
1164
|
+
resolution,
|
|
1165
|
+
topology,
|
|
1166
|
+
projection,
|
|
1167
|
+
isApertureSequence,
|
|
1168
|
+
apSeq,
|
|
1169
|
+
sequenceNum
|
|
1170
|
+
);
|
|
1171
|
+
|
|
1172
|
+
// The result is a flat array with format:
|
|
1173
|
+
// [count0, count1, ..., countN, child0_0, child0_1, ..., child0_(count0-1), child1_0, ...]
|
|
1174
|
+
const inputSize = sequenceNum.length;
|
|
1175
|
+
const counts = resultArray.slice(0, inputSize);
|
|
1176
|
+
const children: bigint[][] = [];
|
|
1177
|
+
|
|
1178
|
+
let offset = inputSize;
|
|
1179
|
+
for (let i = 0; i < inputSize; i++) {
|
|
1180
|
+
const count = Number(counts[i]);
|
|
1181
|
+
children.push(resultArray.slice(offset, offset + count));
|
|
1182
|
+
offset += count;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
return children;
|
|
1186
|
+
} catch (e) {
|
|
1187
|
+
console.error(this._module.getExceptionMessage(e).toString());
|
|
1188
|
+
throw e;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// =========================================================================
|
|
1193
|
+
// Hierarchical Address Type Conversions
|
|
1194
|
+
// These methods convert between SEQNUM and hierarchical indexing systems
|
|
1195
|
+
// =========================================================================
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Convert a SEQNUM cell ID to VERTEX2DD (icosahedral vertex) coordinates.
|
|
1199
|
+
*
|
|
1200
|
+
* VERTEX2DD addresses represent positions relative to the vertices and
|
|
1201
|
+
* triangular faces of the underlying icosahedron.
|
|
1202
|
+
*
|
|
1203
|
+
* ```ts
|
|
1204
|
+
* const vertex = dggs.sequenceNumToVertex2DD(100n, 5);
|
|
1205
|
+
* // vertex = { keep: true, vertNum: 1, triNum: 1, x: 0.0625, y: 0.054... }
|
|
1206
|
+
* ```
|
|
1207
|
+
*
|
|
1208
|
+
* @param sequenceNum - The cell sequence number to convert.
|
|
1209
|
+
* @param resolution - Resolution of the input cell. Defaults to the
|
|
1210
|
+
* instance's current {@link resolution}.
|
|
1211
|
+
* @returns An object with `{keep, vertNum, triNum, x, y}` representing
|
|
1212
|
+
* the vertex coordinate.
|
|
1213
|
+
*/
|
|
1214
|
+
sequenceNumToVertex2DD(
|
|
1215
|
+
sequenceNum: bigint,
|
|
1216
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1217
|
+
): Vertex2DDCoordinate {
|
|
1218
|
+
try {
|
|
1219
|
+
const result = this._module.SEQNUM_to_VERTEX2DD(
|
|
1220
|
+
...this._getParams(resolution),
|
|
1221
|
+
sequenceNum
|
|
1222
|
+
);
|
|
1223
|
+
return result;
|
|
1224
|
+
} catch (e) {
|
|
1225
|
+
console.error(this._module.getExceptionMessage(e).toString());
|
|
1226
|
+
throw e;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* Convert VERTEX2DD (icosahedral vertex) coordinates to a SEQNUM cell ID.
|
|
1232
|
+
*
|
|
1233
|
+
* ```ts
|
|
1234
|
+
* const seqnum = dggs.vertex2DDToSequenceNum(true, 1, 1, 0.0625, 0.054, 5);
|
|
1235
|
+
* // seqnum = 100n
|
|
1236
|
+
* ```
|
|
1237
|
+
*
|
|
1238
|
+
* @param keep - Whether to keep this vertex.
|
|
1239
|
+
* @param vertNum - Vertex number (0-11 for icosahedron).
|
|
1240
|
+
* @param triNum - Triangle number on the icosahedron.
|
|
1241
|
+
* @param x - X coordinate within the triangle.
|
|
1242
|
+
* @param y - Y coordinate within the triangle.
|
|
1243
|
+
* @param resolution - Resolution at which to compute the cell ID. Defaults
|
|
1244
|
+
* to the instance's current {@link resolution}.
|
|
1245
|
+
* @returns The sequence number (BigInt) of the cell containing this coordinate.
|
|
1246
|
+
*/
|
|
1247
|
+
vertex2DDToSequenceNum(
|
|
1248
|
+
keep: boolean,
|
|
1249
|
+
vertNum: number,
|
|
1250
|
+
triNum: number,
|
|
1251
|
+
x: number,
|
|
1252
|
+
y: number,
|
|
1253
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1254
|
+
): bigint {
|
|
1255
|
+
try {
|
|
1256
|
+
return this._module.VERTEX2DD_to_SEQNUM(
|
|
1257
|
+
...this._getParams(resolution),
|
|
1258
|
+
keep,
|
|
1259
|
+
vertNum,
|
|
1260
|
+
triNum,
|
|
1261
|
+
x,
|
|
1262
|
+
y
|
|
1263
|
+
);
|
|
1264
|
+
} catch (e) {
|
|
1265
|
+
console.error(this._module.getExceptionMessage(e).toString());
|
|
1266
|
+
throw e;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Convert a SEQNUM cell ID to ZORDER (Z-order curve) coordinate.
|
|
1272
|
+
*
|
|
1273
|
+
* ZORDER uses digit-interleaved coordinates to create a space-filling
|
|
1274
|
+
* curve index. This provides good spatial locality for range queries.
|
|
1275
|
+
*
|
|
1276
|
+
* **Compatibility:** ZORDER is only available for **aperture 3 and 4**
|
|
1277
|
+
* hexagon grids. It is **NOT supported** for aperture 7.
|
|
1278
|
+
*
|
|
1279
|
+
* ```ts
|
|
1280
|
+
* // With aperture 4:
|
|
1281
|
+
* const zorder = dggs.sequenceNumToZOrder(100n, 5);
|
|
1282
|
+
* // zorder = 1168684103302643712n
|
|
1283
|
+
* ```
|
|
1284
|
+
*
|
|
1285
|
+
* @param sequenceNum - The cell sequence number to convert.
|
|
1286
|
+
* @param resolution - Resolution of the input cell. Defaults to the
|
|
1287
|
+
* instance's current {@link resolution}.
|
|
1288
|
+
* @returns A BigInt representing the Z-order coordinate.
|
|
1289
|
+
* @throws If used with an incompatible aperture (7) or topology.
|
|
1290
|
+
*/
|
|
1291
|
+
sequenceNumToZOrder(
|
|
1292
|
+
sequenceNum: bigint,
|
|
1293
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1294
|
+
): bigint {
|
|
1295
|
+
const { aperture, apertureSequence } = this.dggs;
|
|
1296
|
+
|
|
1297
|
+
// Check aperture compatibility
|
|
1298
|
+
if (aperture === 7 && !apertureSequence) {
|
|
1299
|
+
throw new Error(
|
|
1300
|
+
'ZORDER is not available for aperture 7. ' +
|
|
1301
|
+
'Use Z7 hierarchical indexing instead, or switch to aperture 3 or 4.'
|
|
1302
|
+
);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
try {
|
|
1306
|
+
return this._module.SEQNUM_to_ZORDER(
|
|
1307
|
+
...this._getParams(resolution),
|
|
1308
|
+
sequenceNum
|
|
1309
|
+
);
|
|
1310
|
+
} catch (e) {
|
|
1311
|
+
const errMsg = this._module.getExceptionMessage(e).toString();
|
|
1312
|
+
if (errMsg.includes('aperture')) {
|
|
1313
|
+
throw new Error(
|
|
1314
|
+
`ZORDER error: ${errMsg}. ZORDER requires aperture 3 or 4 (not 7).`
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
console.error(errMsg);
|
|
1318
|
+
throw e;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Convert a ZORDER (Z-order curve) coordinate to a SEQNUM cell ID.
|
|
1324
|
+
*
|
|
1325
|
+
* ```ts
|
|
1326
|
+
* const seqnum = dggs.zOrderToSequenceNum(1168684103302643712n, 5);
|
|
1327
|
+
* // seqnum = 100n
|
|
1328
|
+
* ```
|
|
1329
|
+
*
|
|
1330
|
+
* @param zorderValue - The Z-order coordinate value (BigInt).
|
|
1331
|
+
* @param resolution - Resolution at which to compute the cell ID. Defaults
|
|
1332
|
+
* to the instance's current {@link resolution}.
|
|
1333
|
+
* @returns The sequence number (BigInt) corresponding to this Z-order value.
|
|
1334
|
+
* @throws If used with an incompatible aperture (7) or topology.
|
|
1335
|
+
*/
|
|
1336
|
+
zOrderToSequenceNum(
|
|
1337
|
+
zorderValue: bigint,
|
|
1338
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1339
|
+
): bigint {
|
|
1340
|
+
const { aperture, apertureSequence } = this.dggs;
|
|
1341
|
+
|
|
1342
|
+
if (aperture === 7 && !apertureSequence) {
|
|
1343
|
+
throw new Error(
|
|
1344
|
+
'ZORDER is not available for aperture 7. ' +
|
|
1345
|
+
'Use Z7 hierarchical indexing instead, or switch to aperture 3 or 4.'
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
try {
|
|
1350
|
+
return this._module.ZORDER_to_SEQNUM(
|
|
1351
|
+
...this._getParams(resolution),
|
|
1352
|
+
zorderValue
|
|
1353
|
+
);
|
|
1354
|
+
} catch (e) {
|
|
1355
|
+
const errMsg = this._module.getExceptionMessage(e).toString();
|
|
1356
|
+
if (errMsg.includes('aperture')) {
|
|
1357
|
+
throw new Error(
|
|
1358
|
+
`ZORDER error: ${errMsg}. ZORDER requires aperture 3 or 4 (not 7).`
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
console.error(errMsg);
|
|
1362
|
+
throw e;
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Convert a SEQNUM cell ID to Z3 (base-3 Central Place Indexing) coordinate.
|
|
1368
|
+
*
|
|
1369
|
+
* Z3 uses base-3 digit encoding optimized for aperture 3 hexagon grids.
|
|
1370
|
+
* Each parent cell contains exactly 3 children in the hierarchy.
|
|
1371
|
+
*
|
|
1372
|
+
* **Compatibility:** Z3 is **only available for aperture 3** hexagon grids.
|
|
1373
|
+
*
|
|
1374
|
+
* ```ts
|
|
1375
|
+
* // With aperture 3:
|
|
1376
|
+
* const z3 = dggs.sequenceNumToZ3(100n, 5);
|
|
1377
|
+
* // z3 = 1773292353277132799n
|
|
1378
|
+
* ```
|
|
1379
|
+
*
|
|
1380
|
+
* @param sequenceNum - The cell sequence number to convert.
|
|
1381
|
+
* @param resolution - Resolution of the input cell. Defaults to the
|
|
1382
|
+
* instance's current {@link resolution}.
|
|
1383
|
+
* @returns A BigInt representing the Z3 coordinate (INT64 format).
|
|
1384
|
+
* @throws If used with an incompatible aperture (not 3) or topology.
|
|
1385
|
+
*/
|
|
1386
|
+
sequenceNumToZ3(
|
|
1387
|
+
sequenceNum: bigint,
|
|
1388
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1389
|
+
): bigint {
|
|
1390
|
+
const { aperture, topology, apertureSequence } = this.dggs;
|
|
1391
|
+
|
|
1392
|
+
if ((aperture !== 3 || topology !== 'HEXAGON') && !apertureSequence) {
|
|
1393
|
+
throw new Error(
|
|
1394
|
+
'Z3 is only available for aperture 3 hexagon grids. ' +
|
|
1395
|
+
`Current configuration: aperture ${aperture}, topology ${topology}.`
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
try {
|
|
1400
|
+
return this._module.SEQNUM_to_Z3(
|
|
1401
|
+
...this._getParams(resolution),
|
|
1402
|
+
sequenceNum
|
|
1403
|
+
);
|
|
1404
|
+
} catch (e) {
|
|
1405
|
+
const errMsg = this._module.getExceptionMessage(e).toString();
|
|
1406
|
+
if (errMsg.includes('aperture') || errMsg.includes('Z3')) {
|
|
1407
|
+
throw new Error(
|
|
1408
|
+
`Z3 error: ${errMsg}. Z3 requires aperture 3 hexagon grids.`
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
console.error(errMsg);
|
|
1412
|
+
throw e;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Convert a Z3 (base-3 Central Place Indexing) coordinate to a SEQNUM cell ID.
|
|
1418
|
+
*
|
|
1419
|
+
* ```ts
|
|
1420
|
+
* const seqnum = dggs.z3ToSequenceNum(1773292353277132799n, 5);
|
|
1421
|
+
* // seqnum = 100n
|
|
1422
|
+
* ```
|
|
1423
|
+
*
|
|
1424
|
+
* @param z3Value - The Z3 coordinate value (BigInt, INT64 format).
|
|
1425
|
+
* @param resolution - Resolution at which to compute the cell ID. Defaults
|
|
1426
|
+
* to the instance's current {@link resolution}.
|
|
1427
|
+
* @returns The sequence number (BigInt) corresponding to this Z3 value.
|
|
1428
|
+
* @throws If used with an incompatible aperture (not 3) or topology.
|
|
1429
|
+
*/
|
|
1430
|
+
z3ToSequenceNum(
|
|
1431
|
+
z3Value: bigint,
|
|
1432
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1433
|
+
): bigint {
|
|
1434
|
+
const { aperture, topology, apertureSequence } = this.dggs;
|
|
1435
|
+
|
|
1436
|
+
if ((aperture !== 3 || topology !== 'HEXAGON') && !apertureSequence) {
|
|
1437
|
+
throw new Error(
|
|
1438
|
+
'Z3 is only available for aperture 3 hexagon grids. ' +
|
|
1439
|
+
`Current configuration: aperture ${aperture}, topology ${topology}.`
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
try {
|
|
1444
|
+
return this._module.Z3_to_SEQNUM(
|
|
1445
|
+
...this._getParams(resolution),
|
|
1446
|
+
z3Value
|
|
1447
|
+
);
|
|
1448
|
+
} catch (e) {
|
|
1449
|
+
const errMsg = this._module.getExceptionMessage(e).toString();
|
|
1450
|
+
if (errMsg.includes('aperture') || errMsg.includes('Z3')) {
|
|
1451
|
+
throw new Error(
|
|
1452
|
+
`Z3 error: ${errMsg}. Z3 requires aperture 3 hexagon grids.`
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
console.error(errMsg);
|
|
1456
|
+
throw e;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* Convert a SEQNUM cell ID to Z7 (base-7 Central Place Indexing) coordinate.
|
|
1462
|
+
*
|
|
1463
|
+
* Z7 uses base-7 digit encoding with pure bitarithmetic operations,
|
|
1464
|
+
* optimized for aperture 7 hexagon grids. Each parent cell contains
|
|
1465
|
+
* exactly 7 children in the hierarchy.
|
|
1466
|
+
*
|
|
1467
|
+
* **Compatibility:** Z7 is **only available for aperture 7** hexagon grids.
|
|
1468
|
+
*
|
|
1469
|
+
* ```ts
|
|
1470
|
+
* // With aperture 7:
|
|
1471
|
+
* const z7 = dggs.sequenceNumToZ7(100n, 5);
|
|
1472
|
+
* // z7 = 1153167795211468799n (displayed as hex: 0x1000000000000fff)
|
|
1473
|
+
* ```
|
|
1474
|
+
*
|
|
1475
|
+
* @param sequenceNum - The cell sequence number to convert.
|
|
1476
|
+
* @param resolution - Resolution of the input cell. Defaults to the
|
|
1477
|
+
* instance's current {@link resolution}.
|
|
1478
|
+
* @returns A BigInt representing the Z7 coordinate (INT64/hex format).
|
|
1479
|
+
* @throws If used with an incompatible aperture (not 7) or topology.
|
|
1480
|
+
*/
|
|
1481
|
+
sequenceNumToZ7(
|
|
1482
|
+
sequenceNum: bigint,
|
|
1483
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1484
|
+
): bigint {
|
|
1485
|
+
const { aperture, topology, apertureSequence } = this.dggs;
|
|
1486
|
+
|
|
1487
|
+
if ((aperture !== 7 || topology !== 'HEXAGON') && !apertureSequence) {
|
|
1488
|
+
throw new Error(
|
|
1489
|
+
'Z7 is only available for aperture 7 hexagon grids. ' +
|
|
1490
|
+
`Current configuration: aperture ${aperture}, topology ${topology}.`
|
|
1491
|
+
);
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
try {
|
|
1495
|
+
return this._module.SEQNUM_to_Z7(
|
|
1496
|
+
...this._getParams(resolution),
|
|
1497
|
+
sequenceNum
|
|
1498
|
+
);
|
|
1499
|
+
} catch (e) {
|
|
1500
|
+
const errMsg = this._module.getExceptionMessage(e).toString();
|
|
1501
|
+
if (errMsg.includes('aperture') || errMsg.includes('Z7')) {
|
|
1502
|
+
throw new Error(
|
|
1503
|
+
`Z7 error: ${errMsg}. Z7 requires aperture 7 hexagon grids.`
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
console.error(errMsg);
|
|
1507
|
+
throw e;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
/**
|
|
1512
|
+
* Convert a Z7 (base-7 Central Place Indexing) coordinate to a SEQNUM cell ID.
|
|
1513
|
+
*
|
|
1514
|
+
* ```ts
|
|
1515
|
+
* const seqnum = dggs.z7ToSequenceNum(1153167795211468799n, 5);
|
|
1516
|
+
* // seqnum = 100n
|
|
1517
|
+
* ```
|
|
1518
|
+
*
|
|
1519
|
+
* @param z7Value - The Z7 coordinate value (BigInt, INT64/hex format).
|
|
1520
|
+
* @param resolution - Resolution at which to compute the cell ID. Defaults
|
|
1521
|
+
* to the instance's current {@link resolution}.
|
|
1522
|
+
* @returns The sequence number (BigInt) corresponding to this Z7 value.
|
|
1523
|
+
* @throws If used with an incompatible aperture (not 7) or topology.
|
|
1524
|
+
*/
|
|
1525
|
+
z7ToSequenceNum(
|
|
1526
|
+
z7Value: bigint,
|
|
1527
|
+
resolution: number = DEFAULT_RESOLUTION
|
|
1528
|
+
): bigint {
|
|
1529
|
+
const { aperture, topology, apertureSequence } = this.dggs;
|
|
1530
|
+
|
|
1531
|
+
if ((aperture !== 7 || topology !== 'HEXAGON') && !apertureSequence) {
|
|
1532
|
+
throw new Error(
|
|
1533
|
+
'Z7 is only available for aperture 7 hexagon grids. ' +
|
|
1534
|
+
`Current configuration: aperture ${aperture}, topology ${topology}.`
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
try {
|
|
1539
|
+
return this._module.Z7_to_SEQNUM(
|
|
1540
|
+
...this._getParams(resolution),
|
|
1541
|
+
z7Value
|
|
1542
|
+
);
|
|
1543
|
+
} catch (e) {
|
|
1544
|
+
const errMsg = this._module.getExceptionMessage(e).toString();
|
|
1545
|
+
if (errMsg.includes('aperture') || errMsg.includes('Z7')) {
|
|
1546
|
+
throw new Error(
|
|
1547
|
+
`Z7 error: ${errMsg}. Z7 requires aperture 7 hexagon grids.`
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
console.error(errMsg);
|
|
1551
|
+
throw e;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// =========================================================================
|
|
1556
|
+
// Index digit manipulation
|
|
1557
|
+
// Pure bitwise operations on Z7, Z3, and ZORDER packed indices.
|
|
1558
|
+
// These match DGGRID's internal macros (Z7_GET_INDEX_DIGIT, etc.)
|
|
1559
|
+
// and do NOT require WASM calls.
|
|
1560
|
+
// =========================================================================
|
|
1561
|
+
|
|
1562
|
+
// --- Z7 constants (3 bits per digit, max 20 resolutions) ---
|
|
1563
|
+
/** @internal */ static readonly Z7_MAX_RES = 20;
|
|
1564
|
+
/** @internal */ static readonly Z7_BITS_PER_DIGIT = 3n;
|
|
1565
|
+
/** @internal */ static readonly Z7_DIGIT_MASK = 7n;
|
|
1566
|
+
/** @internal */ static readonly Z7_QUAD_OFFSET = 60n;
|
|
1567
|
+
/** @internal */ static readonly Z7_QUAD_MASK = 0xF000000000000000n;
|
|
1568
|
+
|
|
1569
|
+
// --- Z3 constants (2 bits per digit, max 30 resolutions) ---
|
|
1570
|
+
/** @internal */ static readonly Z3_MAX_RES = 30;
|
|
1571
|
+
/** @internal */ static readonly Z3_BITS_PER_DIGIT = 2n;
|
|
1572
|
+
/** @internal */ static readonly Z3_DIGIT_MASK = 3n;
|
|
1573
|
+
/** @internal */ static readonly Z3_QUAD_OFFSET = 60n;
|
|
1574
|
+
/** @internal */ static readonly Z3_QUAD_MASK = 0xF000000000000000n;
|
|
1575
|
+
|
|
1576
|
+
// --- ZORDER constants (2 bits per digit, max 30 resolutions) ---
|
|
1577
|
+
/** @internal */ static readonly ZORDER_MAX_RES = 30;
|
|
1578
|
+
/** @internal */ static readonly ZORDER_BITS_PER_DIGIT = 2n;
|
|
1579
|
+
/** @internal */ static readonly ZORDER_DIGIT_MASK = 3n;
|
|
1580
|
+
/** @internal */ static readonly ZORDER_QUAD_OFFSET = 60n;
|
|
1581
|
+
/** @internal */ static readonly ZORDER_QUAD_MASK = 0xF000000000000000n;
|
|
1582
|
+
|
|
1583
|
+
/**
|
|
1584
|
+
* Get the quad (icosahedron face) number from a Z7 index.
|
|
1585
|
+
*
|
|
1586
|
+
* The quad occupies bits 63–60 of the 64-bit packed value.
|
|
1587
|
+
*
|
|
1588
|
+
* ```ts
|
|
1589
|
+
* const quad = dggs.z7GetQuad(z7Value); // 0–11
|
|
1590
|
+
* ```
|
|
1591
|
+
*
|
|
1592
|
+
* @param z7Value - A Z7 packed index (BigInt).
|
|
1593
|
+
* @returns The quad number (0–11).
|
|
1594
|
+
*/
|
|
1595
|
+
z7GetQuad(z7Value: bigint): number {
|
|
1596
|
+
return Number((z7Value & Webdggrid.Z7_QUAD_MASK) >> Webdggrid.Z7_QUAD_OFFSET);
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* Get the digit at a specific resolution level from a Z7 index.
|
|
1601
|
+
*
|
|
1602
|
+
* Each digit is 3 bits wide and occupies a fixed position in the 64-bit value.
|
|
1603
|
+
* Valid digits are 0–6; the value 7 is the invalid/padding marker.
|
|
1604
|
+
*
|
|
1605
|
+
* ```ts
|
|
1606
|
+
* const digit = dggs.z7GetDigit(z7Value, 3); // 0–6 (or 7 = invalid)
|
|
1607
|
+
* ```
|
|
1608
|
+
*
|
|
1609
|
+
* @param z7Value - A Z7 packed index (BigInt).
|
|
1610
|
+
* @param res - Resolution level (1-based, 1 to 20).
|
|
1611
|
+
* @returns The digit value (0–7).
|
|
1612
|
+
*/
|
|
1613
|
+
z7GetDigit(z7Value: bigint, res: number): number {
|
|
1614
|
+
const shift = BigInt(Webdggrid.Z7_MAX_RES - res) * Webdggrid.Z7_BITS_PER_DIGIT;
|
|
1615
|
+
return Number((z7Value >> shift) & Webdggrid.Z7_DIGIT_MASK);
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Set the digit at a specific resolution level in a Z7 index.
|
|
1620
|
+
*
|
|
1621
|
+
* Returns a new Z7 value with the digit at position `res` replaced.
|
|
1622
|
+
*
|
|
1623
|
+
* ```ts
|
|
1624
|
+
* const child = dggs.z7SetDigit(z7Value, 6, 3); // set res-6 digit to 3
|
|
1625
|
+
* ```
|
|
1626
|
+
*
|
|
1627
|
+
* @param z7Value - A Z7 packed index (BigInt).
|
|
1628
|
+
* @param res - Resolution level (1-based, 1 to 20).
|
|
1629
|
+
* @param digit - The digit value to set (0–6, or 7 for invalid).
|
|
1630
|
+
* @returns A new Z7 value with the digit replaced.
|
|
1631
|
+
*/
|
|
1632
|
+
z7SetDigit(z7Value: bigint, res: number, digit: number): bigint {
|
|
1633
|
+
const shift = BigInt(Webdggrid.Z7_MAX_RES - res) * Webdggrid.Z7_BITS_PER_DIGIT;
|
|
1634
|
+
return (z7Value & ~(Webdggrid.Z7_DIGIT_MASK << shift)) | (BigInt(digit) << shift);
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
/**
|
|
1638
|
+
* Extract all digits from a Z7 index up to a given resolution.
|
|
1639
|
+
*
|
|
1640
|
+
* ```ts
|
|
1641
|
+
* const { quad, digits } = dggs.z7ExtractDigits(z7Value, 5);
|
|
1642
|
+
* // quad: 1, digits: [2, 0, 3, 4, 1]
|
|
1643
|
+
* ```
|
|
1644
|
+
*
|
|
1645
|
+
* @param z7Value - A Z7 packed index (BigInt).
|
|
1646
|
+
* @param resolution - Number of digits to extract (1-based).
|
|
1647
|
+
* @returns Object with `quad` (number) and `digits` (number array).
|
|
1648
|
+
*/
|
|
1649
|
+
z7ExtractDigits(z7Value: bigint, resolution: number): { quad: number; digits: number[] } {
|
|
1650
|
+
const quad = this.z7GetQuad(z7Value);
|
|
1651
|
+
const digits: number[] = [];
|
|
1652
|
+
for (let r = 1; r <= resolution; r++) {
|
|
1653
|
+
digits.push(this.z7GetDigit(z7Value, r));
|
|
1654
|
+
}
|
|
1655
|
+
return { quad, digits };
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
/**
|
|
1659
|
+
* Get the quad (icosahedron face) number from a Z3 index.
|
|
1660
|
+
*
|
|
1661
|
+
* ```ts
|
|
1662
|
+
* const quad = dggs.z3GetQuad(z3Value); // 0–11
|
|
1663
|
+
* ```
|
|
1664
|
+
*
|
|
1665
|
+
* @param z3Value - A Z3 packed index (BigInt).
|
|
1666
|
+
* @returns The quad number (0–11).
|
|
1667
|
+
*/
|
|
1668
|
+
z3GetQuad(z3Value: bigint): number {
|
|
1669
|
+
return Number((z3Value & Webdggrid.Z3_QUAD_MASK) >> Webdggrid.Z3_QUAD_OFFSET);
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
/**
|
|
1673
|
+
* Get the digit at a specific resolution level from a Z3 index.
|
|
1674
|
+
*
|
|
1675
|
+
* Each digit is 2 bits wide. Valid digits are 0–2; the value 3 is the
|
|
1676
|
+
* invalid/padding marker.
|
|
1677
|
+
*
|
|
1678
|
+
* ```ts
|
|
1679
|
+
* const digit = dggs.z3GetDigit(z3Value, 3); // 0–2 (or 3 = invalid)
|
|
1680
|
+
* ```
|
|
1681
|
+
*
|
|
1682
|
+
* @param z3Value - A Z3 packed index (BigInt).
|
|
1683
|
+
* @param res - Resolution level (1-based, 1 to 30).
|
|
1684
|
+
* @returns The digit value (0–3).
|
|
1685
|
+
*/
|
|
1686
|
+
z3GetDigit(z3Value: bigint, res: number): number {
|
|
1687
|
+
const shift = BigInt(Webdggrid.Z3_MAX_RES - res) * Webdggrid.Z3_BITS_PER_DIGIT;
|
|
1688
|
+
return Number((z3Value >> shift) & Webdggrid.Z3_DIGIT_MASK);
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
/**
|
|
1692
|
+
* Set the digit at a specific resolution level in a Z3 index.
|
|
1693
|
+
*
|
|
1694
|
+
* ```ts
|
|
1695
|
+
* const child = dggs.z3SetDigit(z3Value, 6, 1); // set res-6 digit to 1
|
|
1696
|
+
* ```
|
|
1697
|
+
*
|
|
1698
|
+
* @param z3Value - A Z3 packed index (BigInt).
|
|
1699
|
+
* @param res - Resolution level (1-based, 1 to 30).
|
|
1700
|
+
* @param digit - The digit value to set (0–2, or 3 for invalid).
|
|
1701
|
+
* @returns A new Z3 value with the digit replaced.
|
|
1702
|
+
*/
|
|
1703
|
+
z3SetDigit(z3Value: bigint, res: number, digit: number): bigint {
|
|
1704
|
+
const shift = BigInt(Webdggrid.Z3_MAX_RES - res) * Webdggrid.Z3_BITS_PER_DIGIT;
|
|
1705
|
+
return (z3Value & ~(Webdggrid.Z3_DIGIT_MASK << shift)) | (BigInt(digit) << shift);
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* Extract all digits from a Z3 index up to a given resolution.
|
|
1710
|
+
*
|
|
1711
|
+
* ```ts
|
|
1712
|
+
* const { quad, digits } = dggs.z3ExtractDigits(z3Value, 5);
|
|
1713
|
+
* // quad: 1, digits: [1, 0, 2, 1, 0]
|
|
1714
|
+
* ```
|
|
1715
|
+
*
|
|
1716
|
+
* @param z3Value - A Z3 packed index (BigInt).
|
|
1717
|
+
* @param resolution - Number of digits to extract (1-based).
|
|
1718
|
+
* @returns Object with `quad` (number) and `digits` (number array).
|
|
1719
|
+
*/
|
|
1720
|
+
z3ExtractDigits(z3Value: bigint, resolution: number): { quad: number; digits: number[] } {
|
|
1721
|
+
const quad = this.z3GetQuad(z3Value);
|
|
1722
|
+
const digits: number[] = [];
|
|
1723
|
+
for (let r = 1; r <= resolution; r++) {
|
|
1724
|
+
digits.push(this.z3GetDigit(z3Value, r));
|
|
1725
|
+
}
|
|
1726
|
+
return { quad, digits };
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
/**
|
|
1730
|
+
* Get the quad (icosahedron face) number from a ZORDER index.
|
|
1731
|
+
*
|
|
1732
|
+
* ```ts
|
|
1733
|
+
* const quad = dggs.zOrderGetQuad(zorderValue); // 0–11
|
|
1734
|
+
* ```
|
|
1735
|
+
*
|
|
1736
|
+
* @param zorderValue - A ZORDER packed index (BigInt).
|
|
1737
|
+
* @returns The quad number (0–11).
|
|
1738
|
+
*/
|
|
1739
|
+
zOrderGetQuad(zorderValue: bigint): number {
|
|
1740
|
+
return Number((zorderValue & Webdggrid.ZORDER_QUAD_MASK) >> Webdggrid.ZORDER_QUAD_OFFSET);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
/**
|
|
1744
|
+
* Get the digit at a specific resolution level from a ZORDER index.
|
|
1745
|
+
*
|
|
1746
|
+
* Each digit is 2 bits wide (values 0–3).
|
|
1747
|
+
*
|
|
1748
|
+
* ```ts
|
|
1749
|
+
* const digit = dggs.zOrderGetDigit(zorderValue, 3); // 0–3
|
|
1750
|
+
* ```
|
|
1751
|
+
*
|
|
1752
|
+
* @param zorderValue - A ZORDER packed index (BigInt).
|
|
1753
|
+
* @param res - Resolution level (1-based, 1 to 30).
|
|
1754
|
+
* @returns The digit value (0–3).
|
|
1755
|
+
*/
|
|
1756
|
+
zOrderGetDigit(zorderValue: bigint, res: number): number {
|
|
1757
|
+
const shift = BigInt(Webdggrid.ZORDER_MAX_RES - res) * Webdggrid.ZORDER_BITS_PER_DIGIT;
|
|
1758
|
+
return Number((zorderValue >> shift) & Webdggrid.ZORDER_DIGIT_MASK);
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/**
|
|
1762
|
+
* Set the digit at a specific resolution level in a ZORDER index.
|
|
1763
|
+
*
|
|
1764
|
+
* ```ts
|
|
1765
|
+
* const modified = dggs.zOrderSetDigit(zorderValue, 3, 2);
|
|
1766
|
+
* ```
|
|
1767
|
+
*
|
|
1768
|
+
* @param zorderValue - A ZORDER packed index (BigInt).
|
|
1769
|
+
* @param res - Resolution level (1-based, 1 to 30).
|
|
1770
|
+
* @param digit - The digit value to set (0–3).
|
|
1771
|
+
* @returns A new ZORDER value with the digit replaced.
|
|
1772
|
+
*/
|
|
1773
|
+
zOrderSetDigit(zorderValue: bigint, res: number, digit: number): bigint {
|
|
1774
|
+
const shift = BigInt(Webdggrid.ZORDER_MAX_RES - res) * Webdggrid.ZORDER_BITS_PER_DIGIT;
|
|
1775
|
+
return (zorderValue & ~(Webdggrid.ZORDER_DIGIT_MASK << shift)) | (BigInt(digit) << shift);
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
/**
|
|
1779
|
+
* Extract all digits from a ZORDER index up to a given resolution.
|
|
1780
|
+
*
|
|
1781
|
+
* ```ts
|
|
1782
|
+
* const { quad, digits } = dggs.zOrderExtractDigits(zorderValue, 5);
|
|
1783
|
+
* // quad: 1, digits: [2, 0, 3, 1, 0]
|
|
1784
|
+
* ```
|
|
1785
|
+
*
|
|
1786
|
+
* @param zorderValue - A ZORDER packed index (BigInt).
|
|
1787
|
+
* @param resolution - Number of digits to extract (1-based).
|
|
1788
|
+
* @returns Object with `quad` (number) and `digits` (number array).
|
|
1789
|
+
*/
|
|
1790
|
+
zOrderExtractDigits(zorderValue: bigint, resolution: number): { quad: number; digits: number[] } {
|
|
1791
|
+
const quad = this.zOrderGetQuad(zorderValue);
|
|
1792
|
+
const digits: number[] = [];
|
|
1793
|
+
for (let r = 1; r <= resolution; r++) {
|
|
1794
|
+
digits.push(this.zOrderGetDigit(zorderValue, r));
|
|
1795
|
+
}
|
|
1796
|
+
return { quad, digits };
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
// =========================================================================
|
|
1800
|
+
// Low-level coordinate transformation methods
|
|
1801
|
+
// These methods expose all DGGRID coordinate systems beyond GEO/SEQNUM
|
|
1802
|
+
// =========================================================================
|
|
1803
|
+
|
|
1804
|
+
/**
|
|
1805
|
+
* Helper to build the DGGS parameter array for WASM calls.
|
|
1806
|
+
* @private
|
|
1807
|
+
*/
|
|
1808
|
+
private _getParams(resolution: number = DEFAULT_RESOLUTION): any[] {
|
|
1809
|
+
const {
|
|
1810
|
+
poleCoordinates: { lat, lng },
|
|
1811
|
+
azimuth,
|
|
1812
|
+
topology,
|
|
1813
|
+
projection,
|
|
1814
|
+
aperture,
|
|
1815
|
+
apertureSequence,
|
|
1816
|
+
} = this.dggs;
|
|
1817
|
+
|
|
1818
|
+
const isApertureSequence = !!apertureSequence;
|
|
1819
|
+
const apSeq = apertureSequence || "";
|
|
1820
|
+
|
|
1821
|
+
return [
|
|
1822
|
+
lng,
|
|
1823
|
+
lat,
|
|
1824
|
+
azimuth,
|
|
1825
|
+
aperture,
|
|
1826
|
+
resolution,
|
|
1827
|
+
topology,
|
|
1828
|
+
projection,
|
|
1829
|
+
isApertureSequence,
|
|
1830
|
+
apSeq
|
|
1831
|
+
];
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
// -------------------------------------------------------------------------
|
|
1835
|
+
// GEO transformations (beyond the high-level methods above)
|
|
1836
|
+
// -------------------------------------------------------------------------
|
|
1837
|
+
|
|
1838
|
+
/**
|
|
1839
|
+
* Converts geographic coordinates to PLANE coordinates.
|
|
1840
|
+
*
|
|
1841
|
+
* @param coordinates - Array of `[lng, lat]` pairs
|
|
1842
|
+
* @param resolution - Resolution level
|
|
1843
|
+
* @returns Array of `{x, y}` plane coordinates
|
|
1844
|
+
*/
|
|
1845
|
+
geoToPlane(coordinates: number[][], resolution: number = DEFAULT_RESOLUTION): Array<{ x: number, y: number }> {
|
|
1846
|
+
const xCoords = coordinates.map(c => c[0]);
|
|
1847
|
+
const yCoords = coordinates.map(c => c[1]);
|
|
1848
|
+
|
|
1849
|
+
const result = this._module.GEO_to_PLANE(...this._getParams(resolution), xCoords, yCoords);
|
|
1850
|
+
|
|
1851
|
+
const size = result.length / 2;
|
|
1852
|
+
const output: any[] = [];
|
|
1853
|
+
for (let i = 0; i < size; i++) {
|
|
1854
|
+
output.push({ x: result[i], y: result[i + size] });
|
|
1855
|
+
}
|
|
1856
|
+
return output;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
/**
|
|
1860
|
+
* Converts geographic coordinates to PROJTRI coordinates.
|
|
1861
|
+
*
|
|
1862
|
+
* @param coordinates - Array of `[lng, lat]` pairs
|
|
1863
|
+
* @param resolution - Resolution level
|
|
1864
|
+
* @returns Array of `{tnum, x, y}` projection triangle coordinates
|
|
1865
|
+
*/
|
|
1866
|
+
geoToProjtri(coordinates: number[][], resolution: number = DEFAULT_RESOLUTION): Array<{ tnum: number, x: number, y: number }> {
|
|
1867
|
+
const xCoords = coordinates.map(c => c[0]);
|
|
1868
|
+
const yCoords = coordinates.map(c => c[1]);
|
|
1869
|
+
|
|
1870
|
+
const result = this._module.GEO_to_PROJTRI(...this._getParams(resolution), xCoords, yCoords);
|
|
1871
|
+
|
|
1872
|
+
const size = result.length / 3;
|
|
1873
|
+
const output: any[] = [];
|
|
1874
|
+
for (let i = 0; i < size; i++) {
|
|
1875
|
+
output.push({
|
|
1876
|
+
tnum: result[i],
|
|
1877
|
+
x: result[i + size],
|
|
1878
|
+
y: result[i + 2 * size]
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
return output;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
/**
|
|
1885
|
+
* Converts geographic coordinates to Q2DD coordinates.
|
|
1886
|
+
*
|
|
1887
|
+
* @param coordinates - Array of `[lng, lat]` pairs
|
|
1888
|
+
* @param resolution - Resolution level
|
|
1889
|
+
* @returns Array of `{quad, x, y}` quad 2D double coordinates
|
|
1890
|
+
*/
|
|
1891
|
+
geoToQ2dd(coordinates: number[][], resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, x: number, y: number }> {
|
|
1892
|
+
const xCoords = coordinates.map(c => c[0]);
|
|
1893
|
+
const yCoords = coordinates.map(c => c[1]);
|
|
1894
|
+
|
|
1895
|
+
const result = this._module.GEO_to_Q2DD(...this._getParams(resolution), xCoords, yCoords);
|
|
1896
|
+
|
|
1897
|
+
const size = result.length / 3;
|
|
1898
|
+
const output: any[] = [];
|
|
1899
|
+
for (let i = 0; i < size; i++) {
|
|
1900
|
+
output.push({
|
|
1901
|
+
quad: result[i],
|
|
1902
|
+
x: result[i + size],
|
|
1903
|
+
y: result[i + 2 * size]
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
return output;
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
/**
|
|
1910
|
+
* Converts geographic coordinates to Q2DI coordinates.
|
|
1911
|
+
*
|
|
1912
|
+
* @param coordinates - Array of `[lng, lat]` pairs
|
|
1913
|
+
* @param resolution - Resolution level
|
|
1914
|
+
* @returns Array of `{quad, i, j}` quad 2D integer coordinates
|
|
1915
|
+
*/
|
|
1916
|
+
geoToQ2di(coordinates: number[][], resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, i: bigint, j: bigint }> {
|
|
1917
|
+
const xCoords = coordinates.map(c => c[0]);
|
|
1918
|
+
const yCoords = coordinates.map(c => c[1]);
|
|
1919
|
+
|
|
1920
|
+
const result = this._module.GEO_to_Q2DI(...this._getParams(resolution), xCoords, yCoords);
|
|
1921
|
+
|
|
1922
|
+
const size = result.length / 3;
|
|
1923
|
+
const output: any[] = [];
|
|
1924
|
+
for (let i = 0; i < size; i++) {
|
|
1925
|
+
output.push({
|
|
1926
|
+
quad: result[i],
|
|
1927
|
+
i: BigInt(result[i + size]),
|
|
1928
|
+
j: BigInt(result[i + 2 * size])
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
return output;
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
// -------------------------------------------------------------------------
|
|
1935
|
+
// SEQNUM transformations (beyond the high-level methods above)
|
|
1936
|
+
// -------------------------------------------------------------------------
|
|
1937
|
+
|
|
1938
|
+
/**
|
|
1939
|
+
* Converts sequence numbers to PLANE coordinates.
|
|
1940
|
+
*
|
|
1941
|
+
* @param sequenceNum - Array of cell IDs
|
|
1942
|
+
* @param resolution - Resolution level
|
|
1943
|
+
* @returns Array of `{x, y}` plane coordinates
|
|
1944
|
+
*/
|
|
1945
|
+
sequenceNumToPlane(sequenceNum: bigint[], resolution: number = DEFAULT_RESOLUTION): Array<{ x: number, y: number }> {
|
|
1946
|
+
const result = this._module.SEQNUM_to_PLANE(...this._getParams(resolution), sequenceNum);
|
|
1947
|
+
|
|
1948
|
+
const size = result.length / 2;
|
|
1949
|
+
const output: any[] = [];
|
|
1950
|
+
for (let i = 0; i < size; i++) {
|
|
1951
|
+
output.push({ x: result[i], y: result[i + size] });
|
|
1952
|
+
}
|
|
1953
|
+
return output;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
/**
|
|
1957
|
+
* Converts sequence numbers to PROJTRI coordinates.
|
|
1958
|
+
*
|
|
1959
|
+
* @param sequenceNum - Array of cell IDs
|
|
1960
|
+
* @param resolution - Resolution level
|
|
1961
|
+
* @returns Array of `{tnum, x, y}` projection triangle coordinates
|
|
1962
|
+
*/
|
|
1963
|
+
sequenceNumToProjtri(sequenceNum: bigint[], resolution: number = DEFAULT_RESOLUTION): Array<{ tnum: number, x: number, y: number }> {
|
|
1964
|
+
const result = this._module.SEQNUM_to_PROJTRI(...this._getParams(resolution), sequenceNum);
|
|
1965
|
+
|
|
1966
|
+
const size = result.length / 3;
|
|
1967
|
+
const output: any[] = [];
|
|
1968
|
+
for (let i = 0; i < size; i++) {
|
|
1969
|
+
output.push({
|
|
1970
|
+
tnum: result[i],
|
|
1971
|
+
x: result[i + size],
|
|
1972
|
+
y: result[i + 2 * size]
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
return output;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
/**
|
|
1979
|
+
* Converts sequence numbers to Q2DD coordinates.
|
|
1980
|
+
*
|
|
1981
|
+
* @param sequenceNum - Array of cell IDs
|
|
1982
|
+
* @param resolution - Resolution level
|
|
1983
|
+
* @returns Array of `{quad, x, y}` quad 2D double coordinates
|
|
1984
|
+
*/
|
|
1985
|
+
sequenceNumToQ2dd(sequenceNum: bigint[], resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, x: number, y: number }> {
|
|
1986
|
+
const result = this._module.SEQNUM_to_Q2DD(...this._getParams(resolution), sequenceNum);
|
|
1987
|
+
|
|
1988
|
+
const size = result.length / 3;
|
|
1989
|
+
const output: any[] = [];
|
|
1990
|
+
for (let i = 0; i < size; i++) {
|
|
1991
|
+
output.push({
|
|
1992
|
+
quad: result[i],
|
|
1993
|
+
x: result[i + size],
|
|
1994
|
+
y: result[i + 2 * size]
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
return output;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* Converts sequence numbers to Q2DI coordinates.
|
|
2002
|
+
*
|
|
2003
|
+
* @param sequenceNum - Array of cell IDs
|
|
2004
|
+
* @param resolution - Resolution level
|
|
2005
|
+
* @returns Array of `{quad, i, j}` quad 2D integer coordinates
|
|
2006
|
+
*/
|
|
2007
|
+
sequenceNumToQ2di(sequenceNum: bigint[], resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, i: bigint, j: bigint }> {
|
|
2008
|
+
const result = this._module.SEQNUM_to_Q2DI(...this._getParams(resolution), sequenceNum);
|
|
2009
|
+
|
|
2010
|
+
const size = result.length / 3;
|
|
2011
|
+
const output: any[] = [];
|
|
2012
|
+
for (let i = 0; i < size; i++) {
|
|
2013
|
+
output.push({
|
|
2014
|
+
quad: result[i],
|
|
2015
|
+
i: BigInt(result[i + size]),
|
|
2016
|
+
j: BigInt(result[i + 2 * size])
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
return output;
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
// -------------------------------------------------------------------------
|
|
2023
|
+
// Q2DI transformations
|
|
2024
|
+
// -------------------------------------------------------------------------
|
|
2025
|
+
|
|
2026
|
+
/**
|
|
2027
|
+
* Converts Q2DI coordinates to geographic coordinates.
|
|
2028
|
+
*
|
|
2029
|
+
* @param coords - Array of `{quad, i, j}` coordinates
|
|
2030
|
+
* @param resolution - Resolution level
|
|
2031
|
+
* @returns Array of `[lng, lat]` positions
|
|
2032
|
+
*/
|
|
2033
|
+
q2diToGeo(coords: Array<{ quad: number, i: bigint, j: bigint }>, resolution: number = DEFAULT_RESOLUTION): Position[] {
|
|
2034
|
+
const quads = coords.map(c => c.quad);
|
|
2035
|
+
const is = coords.map(c => Number(c.i));
|
|
2036
|
+
const js = coords.map(c => Number(c.j));
|
|
2037
|
+
|
|
2038
|
+
const result = this._module.Q2DI_to_GEO(...this._getParams(resolution), quads, is, js);
|
|
2039
|
+
|
|
2040
|
+
const size = result.length / 2;
|
|
2041
|
+
const output: Position[] = [];
|
|
2042
|
+
for (let i = 0; i < size; i++) {
|
|
2043
|
+
output.push([result[i], result[i + size]]);
|
|
2044
|
+
}
|
|
2045
|
+
return output;
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
/**
|
|
2049
|
+
* Converts Q2DI coordinates to sequence numbers.
|
|
2050
|
+
*
|
|
2051
|
+
* @param coords - Array of `{quad, i, j}` coordinates
|
|
2052
|
+
* @param resolution - Resolution level
|
|
2053
|
+
* @returns Array of cell IDs
|
|
2054
|
+
*/
|
|
2055
|
+
q2diToSequenceNum(coords: Array<{ quad: number, i: bigint, j: bigint }>, resolution: number = DEFAULT_RESOLUTION): bigint[] {
|
|
2056
|
+
const quads = coords.map(c => c.quad);
|
|
2057
|
+
const is = coords.map(c => Number(c.i));
|
|
2058
|
+
const js = coords.map(c => Number(c.j));
|
|
2059
|
+
|
|
2060
|
+
return this._module.Q2DI_to_SEQNUM(...this._getParams(resolution), quads, is, js);
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
/**
|
|
2064
|
+
* Converts Q2DI coordinates to PLANE coordinates.
|
|
2065
|
+
*
|
|
2066
|
+
* @param coords - Array of `{quad, i, j}` coordinates
|
|
2067
|
+
* @param resolution - Resolution level
|
|
2068
|
+
* @returns Array of `{x, y}` plane coordinates
|
|
2069
|
+
*/
|
|
2070
|
+
q2diToPlane(coords: Array<{ quad: number, i: bigint, j: bigint }>, resolution: number = DEFAULT_RESOLUTION): Array<{ x: number, y: number }> {
|
|
2071
|
+
const quads = coords.map(c => c.quad);
|
|
2072
|
+
const is = coords.map(c => Number(c.i));
|
|
2073
|
+
const js = coords.map(c => Number(c.j));
|
|
2074
|
+
|
|
2075
|
+
const result = this._module.Q2DI_to_PLANE(...this._getParams(resolution), quads, is, js);
|
|
2076
|
+
|
|
2077
|
+
const size = result.length / 2;
|
|
2078
|
+
const output: any[] = [];
|
|
2079
|
+
for (let i = 0; i < size; i++) {
|
|
2080
|
+
output.push({ x: result[i], y: result[i + size] });
|
|
2081
|
+
}
|
|
2082
|
+
return output;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
/**
|
|
2086
|
+
* Converts Q2DI coordinates to PROJTRI coordinates.
|
|
2087
|
+
*
|
|
2088
|
+
* @param coords - Array of `{quad, i, j}` coordinates
|
|
2089
|
+
* @param resolution - Resolution level
|
|
2090
|
+
* @returns Array of `{tnum, x, y}` projection triangle coordinates
|
|
2091
|
+
*/
|
|
2092
|
+
q2diToProjtri(coords: Array<{ quad: number, i: bigint, j: bigint }>, resolution: number = DEFAULT_RESOLUTION): Array<{ tnum: number, x: number, y: number }> {
|
|
2093
|
+
const quads = coords.map(c => c.quad);
|
|
2094
|
+
const is = coords.map(c => Number(c.i));
|
|
2095
|
+
const js = coords.map(c => Number(c.j));
|
|
2096
|
+
|
|
2097
|
+
const result = this._module.Q2DI_to_PROJTRI(...this._getParams(resolution), quads, is, js);
|
|
2098
|
+
|
|
2099
|
+
const size = result.length / 3;
|
|
2100
|
+
const output: any[] = [];
|
|
2101
|
+
for (let i = 0; i < size; i++) {
|
|
2102
|
+
output.push({
|
|
2103
|
+
tnum: result[i],
|
|
2104
|
+
x: result[i + size],
|
|
2105
|
+
y: result[i + 2 * size]
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
return output;
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* Converts Q2DI coordinates to Q2DD coordinates.
|
|
2113
|
+
*
|
|
2114
|
+
* @param coords - Array of `{quad, i, j}` coordinates
|
|
2115
|
+
* @param resolution - Resolution level
|
|
2116
|
+
* @returns Array of `{quad, x, y}` quad 2D double coordinates
|
|
2117
|
+
*/
|
|
2118
|
+
q2diToQ2dd(coords: Array<{ quad: number, i: bigint, j: bigint }>, resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, x: number, y: number }> {
|
|
2119
|
+
const quads = coords.map(c => c.quad);
|
|
2120
|
+
const is = coords.map(c => Number(c.i));
|
|
2121
|
+
const js = coords.map(c => Number(c.j));
|
|
2122
|
+
|
|
2123
|
+
const result = this._module.Q2DI_to_Q2DD(...this._getParams(resolution), quads, is, js);
|
|
2124
|
+
|
|
2125
|
+
const size = result.length / 3;
|
|
2126
|
+
const output: any[] = [];
|
|
2127
|
+
for (let i = 0; i < size; i++) {
|
|
2128
|
+
output.push({
|
|
2129
|
+
quad: result[i],
|
|
2130
|
+
x: result[i + size],
|
|
2131
|
+
y: result[i + 2 * size]
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
return output;
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
// -------------------------------------------------------------------------
|
|
2138
|
+
// Q2DD transformations
|
|
2139
|
+
// -------------------------------------------------------------------------
|
|
2140
|
+
|
|
2141
|
+
/**
|
|
2142
|
+
* Converts Q2DD coordinates to geographic coordinates.
|
|
2143
|
+
*
|
|
2144
|
+
* @param coords - Array of `{quad, x, y}` coordinates
|
|
2145
|
+
* @param resolution - Resolution level
|
|
2146
|
+
* @returns Array of `[lng, lat]` positions
|
|
2147
|
+
*/
|
|
2148
|
+
q2ddToGeo(coords: Array<{ quad: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Position[] {
|
|
2149
|
+
const quads = coords.map(c => c.quad);
|
|
2150
|
+
const xs = coords.map(c => c.x);
|
|
2151
|
+
const ys = coords.map(c => c.y);
|
|
2152
|
+
|
|
2153
|
+
const result = this._module.Q2DD_to_GEO(...this._getParams(resolution), quads, xs, ys);
|
|
2154
|
+
|
|
2155
|
+
const size = result.length / 2;
|
|
2156
|
+
const output: Position[] = [];
|
|
2157
|
+
for (let i = 0; i < size; i++) {
|
|
2158
|
+
output.push([result[i], result[i + size]]);
|
|
2159
|
+
}
|
|
2160
|
+
return output;
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
/**
|
|
2164
|
+
* Converts Q2DD coordinates to sequence numbers.
|
|
2165
|
+
*
|
|
2166
|
+
* @param coords - Array of `{quad, x, y}` coordinates
|
|
2167
|
+
* @param resolution - Resolution level
|
|
2168
|
+
* @returns Array of cell IDs
|
|
2169
|
+
*/
|
|
2170
|
+
q2ddToSequenceNum(coords: Array<{ quad: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): bigint[] {
|
|
2171
|
+
const quads = coords.map(c => c.quad);
|
|
2172
|
+
const xs = coords.map(c => c.x);
|
|
2173
|
+
const ys = coords.map(c => c.y);
|
|
2174
|
+
|
|
2175
|
+
return this._module.Q2DD_to_SEQNUM(...this._getParams(resolution), quads, xs, ys);
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/**
|
|
2179
|
+
* Converts Q2DD coordinates to PLANE coordinates.
|
|
2180
|
+
*
|
|
2181
|
+
* @param coords - Array of `{quad, x, y}` coordinates
|
|
2182
|
+
* @param resolution - Resolution level
|
|
2183
|
+
* @returns Array of `{x, y}` plane coordinates
|
|
2184
|
+
*/
|
|
2185
|
+
q2ddToPlane(coords: Array<{ quad: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Array<{ x: number, y: number }> {
|
|
2186
|
+
const quads = coords.map(c => c.quad);
|
|
2187
|
+
const xs = coords.map(c => c.x);
|
|
2188
|
+
const ys = coords.map(c => c.y);
|
|
2189
|
+
|
|
2190
|
+
const result = this._module.Q2DD_to_PLANE(...this._getParams(resolution), quads, xs, ys);
|
|
2191
|
+
|
|
2192
|
+
const size = result.length / 2;
|
|
2193
|
+
const output: any[] = [];
|
|
2194
|
+
for (let i = 0; i < size; i++) {
|
|
2195
|
+
output.push({ x: result[i], y: result[i + size] });
|
|
2196
|
+
}
|
|
2197
|
+
return output;
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
/**
|
|
2201
|
+
* Converts Q2DD coordinates to PROJTRI coordinates.
|
|
2202
|
+
*
|
|
2203
|
+
* @param coords - Array of `{quad, x, y}` coordinates
|
|
2204
|
+
* @param resolution - Resolution level
|
|
2205
|
+
* @returns Array of `{tnum, x, y}` projection triangle coordinates
|
|
2206
|
+
*/
|
|
2207
|
+
q2ddToProjtri(coords: Array<{ quad: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Array<{ tnum: number, x: number, y: number }> {
|
|
2208
|
+
const quads = coords.map(c => c.quad);
|
|
2209
|
+
const xs = coords.map(c => c.x);
|
|
2210
|
+
const ys = coords.map(c => c.y);
|
|
2211
|
+
|
|
2212
|
+
const result = this._module.Q2DD_to_PROJTRI(...this._getParams(resolution), quads, xs, ys);
|
|
2213
|
+
|
|
2214
|
+
const size = result.length / 3;
|
|
2215
|
+
const output: any[] = [];
|
|
2216
|
+
for (let i = 0; i < size; i++) {
|
|
2217
|
+
output.push({
|
|
2218
|
+
tnum: result[i],
|
|
2219
|
+
x: result[i + size],
|
|
2220
|
+
y: result[i + 2 * size]
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
2223
|
+
return output;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Converts Q2DD coordinates to Q2DI coordinates.
|
|
2228
|
+
*
|
|
2229
|
+
* @param coords - Array of `{quad, x, y}` coordinates
|
|
2230
|
+
* @param resolution - Resolution level
|
|
2231
|
+
* @returns Array of `{quad, i, j}` quad 2D integer coordinates
|
|
2232
|
+
*/
|
|
2233
|
+
q2ddToQ2di(coords: Array<{ quad: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, i: bigint, j: bigint }> {
|
|
2234
|
+
const quads = coords.map(c => c.quad);
|
|
2235
|
+
const xs = coords.map(c => c.x);
|
|
2236
|
+
const ys = coords.map(c => c.y);
|
|
2237
|
+
|
|
2238
|
+
const result = this._module.Q2DD_to_Q2DI(...this._getParams(resolution), quads, xs, ys);
|
|
2239
|
+
|
|
2240
|
+
const size = result.length / 3;
|
|
2241
|
+
const output: any[] = [];
|
|
2242
|
+
for (let i = 0; i < size; i++) {
|
|
2243
|
+
output.push({
|
|
2244
|
+
quad: result[i],
|
|
2245
|
+
i: BigInt(result[i + size]),
|
|
2246
|
+
j: BigInt(result[i + 2 * size])
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
return output;
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
// -------------------------------------------------------------------------
|
|
2253
|
+
// PROJTRI transformations
|
|
2254
|
+
// -------------------------------------------------------------------------
|
|
2255
|
+
|
|
2256
|
+
/**
|
|
2257
|
+
* Converts PROJTRI coordinates to geographic coordinates.
|
|
2258
|
+
*
|
|
2259
|
+
* @param coords - Array of `{tnum, x, y}` coordinates
|
|
2260
|
+
* @param resolution - Resolution level
|
|
2261
|
+
* @returns Array of `[lng, lat]` positions
|
|
2262
|
+
*/
|
|
2263
|
+
projtriToGeo(coords: Array<{ tnum: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Position[] {
|
|
2264
|
+
const tnums = coords.map(c => c.tnum);
|
|
2265
|
+
const xs = coords.map(c => c.x);
|
|
2266
|
+
const ys = coords.map(c => c.y);
|
|
2267
|
+
|
|
2268
|
+
const result = this._module.PROJTRI_to_GEO(...this._getParams(resolution), tnums, xs, ys);
|
|
2269
|
+
|
|
2270
|
+
const size = result.length / 2;
|
|
2271
|
+
const output: Position[] = [];
|
|
2272
|
+
for (let i = 0; i < size; i++) {
|
|
2273
|
+
output.push([result[i], result[i + size]]);
|
|
2274
|
+
}
|
|
2275
|
+
return output;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
/**
|
|
2279
|
+
* Converts PROJTRI coordinates to sequence numbers.
|
|
2280
|
+
*
|
|
2281
|
+
* @param coords - Array of `{tnum, x, y}` coordinates
|
|
2282
|
+
* @param resolution - Resolution level
|
|
2283
|
+
* @returns Array of cell IDs
|
|
2284
|
+
*/
|
|
2285
|
+
projtriToSequenceNum(coords: Array<{ tnum: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): bigint[] {
|
|
2286
|
+
const tnums = coords.map(c => c.tnum);
|
|
2287
|
+
const xs = coords.map(c => c.x);
|
|
2288
|
+
const ys = coords.map(c => c.y);
|
|
2289
|
+
|
|
2290
|
+
return this._module.PROJTRI_to_SEQNUM(...this._getParams(resolution), tnums, xs, ys);
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
/**
|
|
2294
|
+
* Converts PROJTRI coordinates to PLANE coordinates.
|
|
2295
|
+
*
|
|
2296
|
+
* @param coords - Array of `{tnum, x, y}` coordinates
|
|
2297
|
+
* @param resolution - Resolution level
|
|
2298
|
+
* @returns Array of `{x, y}` plane coordinates
|
|
2299
|
+
*/
|
|
2300
|
+
projtriToPlane(coords: Array<{ tnum: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Array<{ x: number, y: number }> {
|
|
2301
|
+
const tnums = coords.map(c => c.tnum);
|
|
2302
|
+
const xs = coords.map(c => c.x);
|
|
2303
|
+
const ys = coords.map(c => c.y);
|
|
2304
|
+
|
|
2305
|
+
const result = this._module.PROJTRI_to_PLANE(...this._getParams(resolution), tnums, xs, ys);
|
|
2306
|
+
|
|
2307
|
+
const size = result.length / 2;
|
|
2308
|
+
const output: any[] = [];
|
|
2309
|
+
for (let i = 0; i < size; i++) {
|
|
2310
|
+
output.push({ x: result[i], y: result[i + size] });
|
|
2311
|
+
}
|
|
2312
|
+
return output;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
/**
|
|
2316
|
+
* Converts PROJTRI coordinates to Q2DD coordinates.
|
|
2317
|
+
*
|
|
2318
|
+
* @param coords - Array of `{tnum, x, y}` coordinates
|
|
2319
|
+
* @param resolution - Resolution level
|
|
2320
|
+
* @returns Array of `{quad, x, y}` quad 2D double coordinates
|
|
2321
|
+
*/
|
|
2322
|
+
projtriToQ2dd(coords: Array<{ tnum: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, x: number, y: number }> {
|
|
2323
|
+
const tnums = coords.map(c => c.tnum);
|
|
2324
|
+
const xs = coords.map(c => c.x);
|
|
2325
|
+
const ys = coords.map(c => c.y);
|
|
2326
|
+
|
|
2327
|
+
const result = this._module.PROJTRI_to_Q2DD(...this._getParams(resolution), tnums, xs, ys);
|
|
2328
|
+
|
|
2329
|
+
const size = result.length / 3;
|
|
2330
|
+
const output: any[] = [];
|
|
2331
|
+
for (let i = 0; i < size; i++) {
|
|
2332
|
+
output.push({
|
|
2333
|
+
quad: result[i],
|
|
2334
|
+
x: result[i + size],
|
|
2335
|
+
y: result[i + 2 * size]
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
return output;
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
/**
|
|
2342
|
+
* Converts PROJTRI coordinates to Q2DI coordinates.
|
|
2343
|
+
*
|
|
2344
|
+
* @param coords - Array of `{tnum, x, y}` coordinates
|
|
2345
|
+
* @param resolution - Resolution level
|
|
2346
|
+
* @returns Array of `{quad, i, j}` quad 2D integer coordinates
|
|
2347
|
+
*/
|
|
2348
|
+
projtriToQ2di(coords: Array<{ tnum: number, x: number, y: number }>, resolution: number = DEFAULT_RESOLUTION): Array<{ quad: number, i: bigint, j: bigint }> {
|
|
2349
|
+
const tnums = coords.map(c => c.tnum);
|
|
2350
|
+
const xs = coords.map(c => c.x);
|
|
2351
|
+
const ys = coords.map(c => c.y);
|
|
2352
|
+
|
|
2353
|
+
const result = this._module.PROJTRI_to_Q2DI(...this._getParams(resolution), tnums, xs, ys);
|
|
2354
|
+
|
|
2355
|
+
const size = result.length / 3;
|
|
2356
|
+
const output: any[] = [];
|
|
2357
|
+
for (let i = 0; i < size; i++) {
|
|
2358
|
+
output.push({
|
|
2359
|
+
quad: result[i],
|
|
2360
|
+
i: BigInt(result[i + size]),
|
|
2361
|
+
j: BigInt(result[i + 2 * size])
|
|
2362
|
+
});
|
|
2363
|
+
}
|
|
2364
|
+
return output;
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
// -------------------------------------------------------------------------
|
|
2368
|
+
// PLANE transformations
|
|
2369
|
+
// Note: PLANE is an output-only coordinate system in DGGRID.
|
|
2370
|
+
// There are no PLANE_to_* transformations available.
|
|
2371
|
+
// Use other coordinate systems (GEO, SEQNUM, Q2DI, Q2DD, PROJTRI) as input.
|
|
2372
|
+
// -------------------------------------------------------------------------
|
|
820
2373
|
}
|