@loaders.gl/gis 4.0.0-alpha.21 → 4.0.0-alpha.22
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/es5/lib/transform.js +1 -1
- package/dist/es5/lib/transform.js.map +1 -1
- package/dist/esm/lib/transform.js +1 -1
- package/dist/esm/lib/transform.js.map +1 -1
- package/dist/lib/transform.d.ts +2 -2
- package/dist/lib/transform.d.ts.map +1 -1
- package/dist/lib/transform.js +1 -1
- package/package.json +4 -4
- package/src/lib/transform.ts +8 -8
|
@@ -52,6 +52,6 @@ function coordMap(array, fn) {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
function isCoord(array) {
|
|
55
|
-
return Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
55
|
+
return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
56
56
|
}
|
|
57
57
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","_iterator","_createForOfIteratorHelper","_step","s","n","done","feature","geometry","coordinates","coordMap","err","e","f","array","isCoord","map","item","Number","isFinite"],"sources":["../../../src/lib/transform.ts"],"sourcesContent":["import type {BinaryFeatures, BinaryGeometry} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features:
|
|
1
|
+
{"version":3,"file":"transform.js","names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","_iterator","_createForOfIteratorHelper","_step","s","n","done","feature","geometry","coordinates","coordMap","err","e","f","array","isCoord","map","item","isArray","Number","isFinite"],"sources":["../../../src/lib/transform.ts"],"sourcesContent":["import type {BinaryFeatures, BinaryGeometry, Feature} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features: Feature[],\n fn: (coord: number[]) => number[]\n): Feature[] {\n for (const feature of features) {\n // @ts-ignore\n feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);\n }\n return features;\n}\n\nfunction coordMap(array: unknown, fn: (coord: number[]) => number[]): unknown[] {\n if (isCoord(array)) {\n return fn(array as number[]);\n }\n\n return (array as unknown[]).map((item) => {\n return coordMap(item, fn);\n });\n}\n\nfunction isCoord(array: unknown) {\n return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);\n}\n"],"mappings":";;;;;;;;;;AAUO,SAASA,qBAAqBA,CACnCC,cAA8B,EAC9BC,mBAAwC,EACxB;EAChB,IAAID,cAAc,CAACE,MAAM,EAAE;IACzBC,gCAAgC,CAACH,cAAc,CAACE,MAAM,EAAED,mBAAmB,CAAC;EAC9E;EACA,IAAID,cAAc,CAACI,KAAK,EAAE;IACxBD,gCAAgC,CAACH,cAAc,CAACI,KAAK,EAAEH,mBAAmB,CAAC;EAC7E;EACA,IAAID,cAAc,CAACK,QAAQ,EAAE;IAC3BF,gCAAgC,CAACH,cAAc,CAACK,QAAQ,EAAEJ,mBAAmB,CAAC;EAChF;EACA,OAAOD,cAAc;AACvB;AAGA,SAASG,gCAAgCA,CAACG,cAA8B,EAAEC,EAAuB,EAAE;EACjG,IAAOC,SAAS,GAAIF,cAAc,CAA3BE,SAAS;EAChB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,SAAS,CAACE,KAAK,CAACC,MAAM,EAAEF,CAAC,IAAID,SAAS,CAACI,IAAI,EAAE;IAE/D,IAAMC,MAAoB,GAAGC,KAAK,CAACC,IAAI,CAACP,SAAS,CAACE,KAAK,CAACM,QAAQ,CAACP,CAAC,EAAEA,CAAC,GAAGD,SAAS,CAACI,IAAI,CAAC,CAAC;IACxF,IAAMK,gBAAgB,GAAGV,EAAE,CAACM,MAAK,CAAC;IAElCL,SAAS,CAACE,KAAK,CAACQ,GAAG,CAACD,gBAAgB,EAAER,CAAC,CAAC;EAC1C;AACF;AASO,SAASU,sBAAsBA,CACpCC,QAAmB,EACnBb,EAAiC,EACtB;EAAA,IAAAc,SAAA,GAAAC,0BAAA,CACWF,QAAQ;IAAAG,KAAA;EAAA;IAA9B,KAAAF,SAAA,CAAAG,CAAA,MAAAD,KAAA,GAAAF,SAAA,CAAAI,CAAA,IAAAC,IAAA,GAAgC;MAAA,IAArBC,OAAO,GAAAJ,KAAA,CAAAb,KAAA;MAEhBiB,OAAO,CAACC,QAAQ,CAACC,WAAW,GAAGC,QAAQ,CAACH,OAAO,CAACC,QAAQ,CAACC,WAAW,EAAEtB,EAAE,CAAC;IAC3E;EAAC,SAAAwB,GAAA;IAAAV,SAAA,CAAAW,CAAA,CAAAD,GAAA;EAAA;IAAAV,SAAA,CAAAY,CAAA;EAAA;EACD,OAAOb,QAAQ;AACjB;AAEA,SAASU,QAAQA,CAACI,KAAc,EAAE3B,EAAiC,EAAa;EAC9E,IAAI4B,OAAO,CAACD,KAAK,CAAC,EAAE;IAClB,OAAO3B,EAAE,CAAC2B,KAAiB,CAAC;EAC9B;EAEA,OAAQA,KAAK,CAAeE,GAAG,CAAC,UAACC,IAAI,EAAK;IACxC,OAAOP,QAAQ,CAACO,IAAI,EAAE9B,EAAE,CAAC;EAC3B,CAAC,CAAC;AACJ;AAEA,SAAS4B,OAAOA,CAACD,KAAc,EAAE;EAC/B,OAAOpB,KAAK,CAACwB,OAAO,CAACJ,KAAK,CAAC,IAAIK,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC,IAAIK,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC;AACvF"}
|
|
@@ -35,6 +35,6 @@ function coordMap(array, fn) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
function isCoord(array) {
|
|
38
|
-
return Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
38
|
+
return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
39
39
|
}
|
|
40
40
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","Number","isFinite"],"sources":["../../../src/lib/transform.ts"],"sourcesContent":["import type {BinaryFeatures, BinaryGeometry} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features:
|
|
1
|
+
{"version":3,"file":"transform.js","names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","isArray","Number","isFinite"],"sources":["../../../src/lib/transform.ts"],"sourcesContent":["import type {BinaryFeatures, BinaryGeometry, Feature} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatures,\n transformCoordinate: TransformCoordinate\n): BinaryFeatures {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features: Feature[],\n fn: (coord: number[]) => number[]\n): Feature[] {\n for (const feature of features) {\n // @ts-ignore\n feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);\n }\n return features;\n}\n\nfunction coordMap(array: unknown, fn: (coord: number[]) => number[]): unknown[] {\n if (isCoord(array)) {\n return fn(array as number[]);\n }\n\n return (array as unknown[]).map((item) => {\n return coordMap(item, fn);\n });\n}\n\nfunction isCoord(array: unknown) {\n return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);\n}\n"],"mappings":"AAUA,OAAO,SAASA,qBAAqBA,CACnCC,cAA8B,EAC9BC,mBAAwC,EACxB;EAChB,IAAID,cAAc,CAACE,MAAM,EAAE;IACzBC,gCAAgC,CAACH,cAAc,CAACE,MAAM,EAAED,mBAAmB,CAAC;EAC9E;EACA,IAAID,cAAc,CAACI,KAAK,EAAE;IACxBD,gCAAgC,CAACH,cAAc,CAACI,KAAK,EAAEH,mBAAmB,CAAC;EAC7E;EACA,IAAID,cAAc,CAACK,QAAQ,EAAE;IAC3BF,gCAAgC,CAACH,cAAc,CAACK,QAAQ,EAAEJ,mBAAmB,CAAC;EAChF;EACA,OAAOD,cAAc;AACvB;AAGA,SAASG,gCAAgCA,CAACG,cAA8B,EAAEC,EAAuB,EAAE;EACjG,MAAM;IAACC;EAAS,CAAC,GAAGF,cAAc;EAClC,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,SAAS,CAACE,KAAK,CAACC,MAAM,EAAEF,CAAC,IAAID,SAAS,CAACI,IAAI,EAAE;IAE/D,MAAMC,KAAoB,GAAGC,KAAK,CAACC,IAAI,CAACP,SAAS,CAACE,KAAK,CAACM,QAAQ,CAACP,CAAC,EAAEA,CAAC,GAAGD,SAAS,CAACI,IAAI,CAAC,CAAC;IACxF,MAAMK,gBAAgB,GAAGV,EAAE,CAACM,KAAK,CAAC;IAElCL,SAAS,CAACE,KAAK,CAACQ,GAAG,CAACD,gBAAgB,EAAER,CAAC,CAAC;EAC1C;AACF;AASA,OAAO,SAASU,sBAAsBA,CACpCC,QAAmB,EACnBb,EAAiC,EACtB;EACX,KAAK,MAAMc,OAAO,IAAID,QAAQ,EAAE;IAE9BC,OAAO,CAACC,QAAQ,CAACC,WAAW,GAAGC,QAAQ,CAACH,OAAO,CAACC,QAAQ,CAACC,WAAW,EAAEhB,EAAE,CAAC;EAC3E;EACA,OAAOa,QAAQ;AACjB;AAEA,SAASI,QAAQA,CAACC,KAAc,EAAElB,EAAiC,EAAa;EAC9E,IAAImB,OAAO,CAACD,KAAK,CAAC,EAAE;IAClB,OAAOlB,EAAE,CAACkB,KAAiB,CAAC;EAC9B;EAEA,OAAQA,KAAK,CAAeE,GAAG,CAAEC,IAAI,IAAK;IACxC,OAAOJ,QAAQ,CAACI,IAAI,EAAErB,EAAE,CAAC;EAC3B,CAAC,CAAC;AACJ;AAEA,SAASmB,OAAOA,CAACD,KAAc,EAAE;EAC/B,OAAOX,KAAK,CAACe,OAAO,CAACJ,KAAK,CAAC,IAAIK,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC,IAAIK,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC;AACvF"}
|
package/dist/lib/transform.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BinaryFeatures } from '@loaders.gl/schema';
|
|
1
|
+
import type { BinaryFeatures, Feature } from '@loaders.gl/schema';
|
|
2
2
|
type TransformCoordinate = (coord: number[]) => number[];
|
|
3
3
|
/**
|
|
4
4
|
* Apply transformation to every coordinate of binary features
|
|
@@ -14,6 +14,6 @@ export declare function transformBinaryCoords(binaryFeatures: BinaryFeatures, tr
|
|
|
14
14
|
* @param fn Function to call on each coordinate
|
|
15
15
|
* @return Transformed GeoJSON features
|
|
16
16
|
*/
|
|
17
|
-
export declare function transformGeoJsonCoords(features:
|
|
17
|
+
export declare function transformGeoJsonCoords(features: Feature[], fn: (coord: number[]) => number[]): Feature[];
|
|
18
18
|
export {};
|
|
19
19
|
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/lib/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/lib/transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAkB,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAEhF,KAAK,mBAAmB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,cAAc,EAC9B,mBAAmB,EAAE,mBAAmB,GACvC,cAAc,CAWhB;AAcD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,OAAO,EAAE,EACnB,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,GAChC,OAAO,EAAE,CAMX"}
|
package/dist/lib/transform.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/gis",
|
|
3
3
|
"description": "Helpers for GIS category data",
|
|
4
|
-
"version": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.22",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
28
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
27
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.22",
|
|
28
|
+
"@loaders.gl/schema": "4.0.0-alpha.22",
|
|
29
29
|
"@mapbox/vector-tile": "^1.3.1",
|
|
30
30
|
"@math.gl/polygon": "^3.5.1",
|
|
31
31
|
"pbf": "^3.2.1"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@math.gl/proj4": "^3.5.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "0da838c506d1275383f2fd3d244d9c72b25397d2"
|
|
37
37
|
}
|
package/src/lib/transform.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {BinaryFeatures, BinaryGeometry} from '@loaders.gl/schema';
|
|
1
|
+
import type {BinaryFeatures, BinaryGeometry, Feature} from '@loaders.gl/schema';
|
|
2
2
|
|
|
3
3
|
type TransformCoordinate = (coord: number[]) => number[];
|
|
4
4
|
|
|
@@ -44,9 +44,9 @@ function transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: Tr
|
|
|
44
44
|
* @return Transformed GeoJSON features
|
|
45
45
|
*/
|
|
46
46
|
export function transformGeoJsonCoords(
|
|
47
|
-
features:
|
|
47
|
+
features: Feature[],
|
|
48
48
|
fn: (coord: number[]) => number[]
|
|
49
|
-
):
|
|
49
|
+
): Feature[] {
|
|
50
50
|
for (const feature of features) {
|
|
51
51
|
// @ts-ignore
|
|
52
52
|
feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);
|
|
@@ -54,16 +54,16 @@ export function transformGeoJsonCoords(
|
|
|
54
54
|
return features;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function coordMap(array, fn) {
|
|
57
|
+
function coordMap(array: unknown, fn: (coord: number[]) => number[]): unknown[] {
|
|
58
58
|
if (isCoord(array)) {
|
|
59
|
-
return fn(array);
|
|
59
|
+
return fn(array as number[]);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
return array.map((item) => {
|
|
62
|
+
return (array as unknown[]).map((item) => {
|
|
63
63
|
return coordMap(item, fn);
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function isCoord(array) {
|
|
68
|
-
return Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
67
|
+
function isCoord(array: unknown) {
|
|
68
|
+
return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);
|
|
69
69
|
}
|