@math.gl/geospatial 3.5.3 → 3.6.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/constants.d.ts +12 -0
  2. package/dist/constants.d.ts.map +1 -0
  3. package/dist/constants.js +22 -0
  4. package/dist/ellipsoid/ellipsoid.d.ts +68 -0
  5. package/dist/ellipsoid/ellipsoid.d.ts.map +1 -0
  6. package/dist/ellipsoid/ellipsoid.js +132 -0
  7. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts +2 -0
  8. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts.map +1 -0
  9. package/dist/ellipsoid/helpers/ellipsoid-transform.js +124 -0
  10. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts +3 -0
  11. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts.map +1 -0
  12. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.js +70 -0
  13. package/dist/es5/constants.js +4 -4
  14. package/dist/es5/constants.js.map +1 -1
  15. package/dist/es5/ellipsoid/ellipsoid.js +123 -161
  16. package/dist/es5/ellipsoid/ellipsoid.js.map +1 -1
  17. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js +25 -21
  18. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  19. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js +39 -46
  20. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  21. package/dist/es5/index.js +2 -2
  22. package/dist/es5/index.js.map +1 -1
  23. package/dist/es5/type-utils.js +13 -19
  24. package/dist/es5/type-utils.js.map +1 -1
  25. package/dist/esm/constants.js.map +1 -1
  26. package/dist/esm/ellipsoid/ellipsoid.js +22 -7
  27. package/dist/esm/ellipsoid/ellipsoid.js.map +1 -1
  28. package/dist/esm/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  29. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js +1 -2
  30. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/type-utils.js +3 -3
  33. package/dist/esm/type-utils.js.map +1 -1
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +2 -0
  37. package/dist/type-utils.d.ts +24 -0
  38. package/dist/type-utils.d.ts.map +1 -0
  39. package/dist/type-utils.js +94 -0
  40. package/package.json +5 -5
  41. package/src/{constants.js → constants.ts} +0 -0
  42. package/src/ellipsoid/{ellipsoid.js → ellipsoid.ts} +96 -35
  43. package/src/ellipsoid/helpers/{ellipsoid-transform.js → ellipsoid-transform.ts} +0 -0
  44. package/src/ellipsoid/helpers/{scale-to-geodetic-surface.js → scale-to-geodetic-surface.ts} +0 -0
  45. package/src/{index.js → index.ts} +0 -0
  46. package/src/type-utils.ts +143 -0
  47. package/dist/es5/ellipsoid/ellipsoid.d.ts +0 -95
  48. package/dist/es5/index.d.ts +0 -1
  49. package/dist/es5/type-utils.d.ts +0 -55
  50. package/dist/esm/ellipsoid/ellipsoid.d.ts +0 -95
  51. package/dist/esm/index.d.ts +0 -1
  52. package/dist/esm/type-utils.d.ts +0 -55
  53. package/src/ellipsoid/ellipsoid.d.ts +0 -95
  54. package/src/index.d.ts +0 -1
  55. package/src/type-utils.d.ts +0 -55
  56. package/src/type-utils.js +0 -71
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/type-utils.js"],"names":["Vector3","isArray","toRadians","toDegrees","config","WGS84_CONSTANTS","noop","x","scratchVector","fromCartographic","cartographic","result","map","longitude","latitude","height","y","z","fromCartographicToRadians","vector","_cartographicRadians","fromCartographicToDegrees","toCartographic","toCartographicFromRadians","toCartographicFromDegrees","isWGS84","from","oneOverRadiiSquared","centerToleranceSquared","x2","y2","z2","Math","abs"],"mappings":"AAGA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,SAA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CJ,MAAnC,EAA2CT,YAA3C,EAAyD;AAC9D,SAAOY,cAAc,CAACH,MAAD,EAAST,YAAT,EAAuBN,MAAM,CAACgB,oBAAP,GAA8Bd,IAA9B,GAAqCH,SAA5D,CAArB;AACD;AAED,OAAO,SAASqB,yBAAT,CAAmCL,MAAnC,EAA2CT,YAA3C,EAAyD;AAC9D,SAAOY,cAAc,CAACH,MAAD,EAAST,YAAT,EAAuBN,MAAM,CAACgB,oBAAP,GAA8BlB,SAA9B,GAA0CI,IAAjE,CAArB;AACD;AAED,OAAO,SAASmB,OAAT,CAAiBN,MAAjB,EAAyB;AAC9B,MAAI,CAACA,MAAL,EAAa;AACX,WAAO,KAAP;AACD;;AACDX,EAAAA,aAAa,CAACkB,IAAd,CAAmBP,MAAnB;AACA,QAAM;AAACQ,IAAAA,mBAAD;AAAsBC,IAAAA;AAAtB,MAAgDvB,eAAtD;AACA,QAAMwB,EAAE,GAAGV,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAAlB,GAAwBQ,mBAAmB,CAAC,CAAD,CAAtD;AACA,QAAMG,EAAE,GAAGX,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAAlB,GAAwBQ,mBAAmB,CAAC,CAAD,CAAtD;AACA,QAAMI,EAAE,GAAGZ,MAAM,CAAC,CAAD,CAAN,GAAYA,MAAM,CAAC,CAAD,CAAlB,GAAwBQ,mBAAmB,CAAC,CAAD,CAAtD;AACA,SAAOK,IAAI,CAACC,GAAL,CAASJ,EAAE,GAAGC,EAAL,GAAUC,EAAV,GAAe,CAAxB,IAA6BH,sBAApC;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, isArray, toRadians, toDegrees, config} from '@math.gl/core';\nimport {WGS84_CONSTANTS} from './constants';\n\nconst noop = (x) => x;\n\nconst scratchVector = new Vector3();\n\nexport function fromCartographic(cartographic, result, map = noop) {\n if (isArray(cartographic)) {\n result[0] = map(cartographic[0]);\n result[1] = map(cartographic[1]);\n result[2] = cartographic[2];\n } else if ('longitude' in cartographic) {\n result[0] = map(cartographic.longitude);\n result[1] = map(cartographic.latitude);\n result[2] = cartographic.height;\n } else {\n result[0] = map(cartographic.x);\n result[1] = map(cartographic.y);\n result[2] = cartographic.z;\n }\n return result;\n}\n\nexport function fromCartographicToRadians(cartographic, vector = scratchVector) {\n return fromCartographic(cartographic, vector, config._cartographicRadians ? noop : toRadians);\n}\n\nexport function fromCartographicToDegrees(cartographic, vector = scratchVector) {\n return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : noop);\n}\n\nexport function toCartographic(vector, cartographic, map = noop) {\n if (isArray(cartographic)) {\n cartographic[0] = map(vector[0]);\n cartographic[1] = map(vector[1]);\n cartographic[2] = vector[2];\n } else if ('longitude' in cartographic) {\n cartographic.longitude = map(vector[0]);\n cartographic.latitude = map(vector[1]);\n cartographic.height = vector[2];\n } else {\n cartographic.x = map(vector[0]);\n cartographic.y = map(vector[1]);\n cartographic.z = vector[2];\n }\n return cartographic;\n}\n\nexport function toCartographicFromRadians(vector, cartographic) {\n return toCartographic(vector, cartographic, config._cartographicRadians ? noop : toDegrees);\n}\n\nexport function toCartographicFromDegrees(vector, cartographic) {\n return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : noop);\n}\n\nexport function isWGS84(vector) {\n if (!vector) {\n return false;\n }\n scratchVector.from(vector);\n const {oneOverRadiiSquared, centerToleranceSquared} = WGS84_CONSTANTS;\n const x2 = vector[0] * vector[0] * oneOverRadiiSquared[0];\n const y2 = vector[1] * vector[1] * oneOverRadiiSquared[1];\n const z2 = vector[2] * vector[2] * oneOverRadiiSquared[2];\n return Math.abs(x2 + y2 + z2 - 1) < centerToleranceSquared;\n}\n"],"file":"type-utils.js"}
1
+ {"version":3,"sources":["../../src/type-utils.ts"],"names":["Vector3","isArray","toRadians","toDegrees","config","WGS84_CONSTANTS","noop","x","scratchVector","fromCartographic","cartographic","result","map","longitude","latitude","height","y","z","fromCartographicToRadians","vector","_cartographicRadians","fromCartographicToDegrees","toCartographic","toCartographicFromRadians","toCartographicFromDegrees","isWGS84","from","oneOverRadiiSquared","centerToleranceSquared","x2","y2","z2","Math","abs"],"mappings":"AAIA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,SAA1B,EAAqCC,SAArC,EAAgDC,MAAhD,QAA6D,eAA7D;AACA,SAAQC,eAAR,QAA8B,aAA9B;;AAgBA,MAAMC,IAAI,GAAIC,CAAD,IAAOA,CAApB;;AAEA,MAAMC,aAAa,GAAG,IAAIR,OAAJ,EAAtB;AAQA,OAAO,SAASS,gBAAT,CAA0BC,YAA1B,EAAwCC,MAAM,GAAG,CAAC,CAAC,CAAF,EAAK,CAAC,CAAN,EAAS,CAAC,CAAV,CAAjD,EAA+DC,GAAG,GAAGN,IAArE,EAA2E;AAChF,MAAIL,OAAO,CAACS,YAAD,CAAX,EAA2B;AACzBC,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAAC,CAAD,CAAb,CAAf;AACAC,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAAC,CAAD,CAAb,CAAf;AACAC,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYD,YAAY,CAAC,CAAD,CAAxB;AACD,GAJD,MAIO,IAAI,eAAeA,YAAnB,EAAiC;AACtCC,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAACG,SAAd,CAAf;AACAF,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAACI,QAAd,CAAf;AACAH,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYD,YAAY,CAACK,MAAzB;AACD,GAJM,MAIA;AACLJ,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAACH,CAA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,CAASJ,EAAE,GAAGC,EAAL,GAAUC,EAAV,GAAe,CAAxB,IAA6BH,sBAApC;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {NumericArray} from '@math.gl/types';\nimport {Vector3, isArray, toRadians, toDegrees, config} from '@math.gl/core';\nimport {WGS84_CONSTANTS} from './constants';\n\ntype LngLatHeightObject = {\n longitude: number;\n latitude: number;\n height: number;\n};\n\ntype XYZObject = {\n x: number;\n y: number;\n z: number;\n};\n\ntype Cartographic = LngLatHeightObject | XYZObject | NumericArray;\n\nconst noop = (x) => x;\n\nconst scratchVector = new Vector3();\n\nexport function fromCartographic(cartographic: Cartographic): number[];\nexport function fromCartographic<NumArrayT>(\n cartographic: Cartographic,\n result: NumArrayT,\n map: any\n): NumArrayT;\nexport function fromCartographic(cartographic, result = [-0, -0, -0], map = noop) {\n if (isArray(cartographic)) {\n result[0] = map(cartographic[0]);\n result[1] = map(cartographic[1]);\n result[2] = cartographic[2];\n } else if ('longitude' in cartographic) {\n result[0] = map(cartographic.longitude);\n result[1] = map(cartographic.latitude);\n result[2] = cartographic.height;\n } else {\n result[0] = map(cartographic.x);\n result[1] = map(cartographic.y);\n result[2] = cartographic.z;\n }\n return result;\n}\n\nexport function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];\nexport function fromCartographicToRadians<TArray>(\n cartographic: Cartographic,\n result: TArray\n): TArray;\nexport function fromCartographicToRadians(cartographic, vector = []) {\n return fromCartographic(cartographic, vector, config._cartographicRadians ? noop : toRadians);\n}\n\nexport function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];\nexport function fromCartographicToDegrees<TArray>(\n cartographic: Cartographic,\n result: TArray\n): TArray;\nexport function fromCartographicToDegrees(cartographic, vector = []) {\n return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : noop);\n}\n\nexport function toCartographic(\n vector: Readonly<NumericArray>,\n result: Cartographic,\n map: any\n): number[];\nexport function toCartographic(vector, cartographic, map = noop) {\n if (isArray(cartographic)) {\n cartographic[0] = map(vector[0]);\n cartographic[1] = map(vector[1]);\n cartographic[2] = vector[2];\n } else if ('longitude' in cartographic) {\n cartographic.longitude = map(vector[0]);\n cartographic.latitude = map(vector[1]);\n cartographic.height = vector[2];\n } else {\n cartographic.x = map(vector[0]);\n cartographic.y = map(vector[1]);\n cartographic.z = vector[2];\n }\n return cartographic;\n}\n\nexport function toCartographicFromRadians(\n vector: Readonly<NumericArray>,\n cartographic: Cartographic\n): number[] {\n return toCartographic(vector, cartographic, config._cartographicRadians ? noop : toDegrees);\n}\n\nexport function toCartographicFromDegrees(\n vector: Readonly<NumericArray>,\n cartographic: Cartographic\n): number[] {\n return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : noop);\n}\n\n// Estimates if a vector is close to the surface of the WGS84 Ellipsoid\nexport function isWGS84(vector: Readonly<NumericArray>): boolean {\n if (!vector) {\n return false;\n }\n scratchVector.from(vector);\n const {oneOverRadiiSquared, centerToleranceSquared} = WGS84_CONSTANTS;\n const x2 = vector[0] * vector[0] * oneOverRadiiSquared[0];\n const y2 = vector[1] * vector[1] * oneOverRadiiSquared[1];\n const z2 = vector[2] * vector[2] * oneOverRadiiSquared[2];\n return Math.abs(x2 + y2 + z2 - 1) < centerToleranceSquared;\n}\n\n/*\n\nexport function fromCartographic(cartographic: Cartographic, result?: number[]): number[];\nexport function fromCartographic(cartographic: Cartographic, result: TypedArray): TypedArray;\nexport function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];\nexport function fromCartographicToRadians(\n cartographic: Cartographic,\n result: TypedArray\n): TypedArray;\nexport function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];\nexport function fromCartographicToDegrees(\n cartographic: Cartographic,\n result: TypedArray\n): TypedArray;\n\nexport function toCartographic(vector: number[] | TypedArray, result: Cartographic): number[];\nexport function toCartographicFromRadians(\n vector: number[] | TypedArray,\n result: Cartographic\n): number[];\nexport function toCartographicFromDegrees(\n vector: number[] | TypedArray,\n result: Cartographic\n): number[];\n\n// Estimates if a vector is close to the surface of the WGS84 Ellipsoid\nexport function isWGS84(vector: number[] | TypedArray): boolean;\n*/\n"],"file":"type-utils.js"}
@@ -0,0 +1,3 @@
1
+ export { default as Ellipsoid } from './ellipsoid/ellipsoid';
2
+ export { isWGS84 } from './type-utils';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default as Ellipsoid } from './ellipsoid/ellipsoid';
2
+ export { isWGS84 } from './type-utils';
@@ -0,0 +1,24 @@
1
+ import { NumericArray } from '@math.gl/types';
2
+ declare type LngLatHeightObject = {
3
+ longitude: number;
4
+ latitude: number;
5
+ height: number;
6
+ };
7
+ declare type XYZObject = {
8
+ x: number;
9
+ y: number;
10
+ z: number;
11
+ };
12
+ declare type Cartographic = LngLatHeightObject | XYZObject | NumericArray;
13
+ export declare function fromCartographic(cartographic: Cartographic): number[];
14
+ export declare function fromCartographic<NumArrayT>(cartographic: Cartographic, result: NumArrayT, map: any): NumArrayT;
15
+ export declare function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];
16
+ export declare function fromCartographicToRadians<TArray>(cartographic: Cartographic, result: TArray): TArray;
17
+ export declare function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];
18
+ export declare function fromCartographicToDegrees<TArray>(cartographic: Cartographic, result: TArray): TArray;
19
+ export declare function toCartographic(vector: Readonly<NumericArray>, result: Cartographic, map: any): number[];
20
+ export declare function toCartographicFromRadians(vector: Readonly<NumericArray>, cartographic: Cartographic): number[];
21
+ export declare function toCartographicFromDegrees(vector: Readonly<NumericArray>, cartographic: Cartographic): number[];
22
+ export declare function isWGS84(vector: Readonly<NumericArray>): boolean;
23
+ export {};
24
+ //# sourceMappingURL=type-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-utils.d.ts","sourceRoot":"","sources":["../src/type-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C,aAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,aAAK,SAAS,GAAG;IACf,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,aAAK,YAAY,GAAG,kBAAkB,GAAG,SAAS,GAAG,YAAY,CAAC;AAMlE,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,EAAE,CAAC;AACvE,wBAAgB,gBAAgB,CAAC,SAAS,EACxC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,SAAS,EACjB,GAAG,EAAE,GAAG,GACP,SAAS,CAAC;AAkBb,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;AACnG,wBAAgB,yBAAyB,CAAC,MAAM,EAC9C,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,GACb,MAAM,CAAC;AAKV,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;AACnG,wBAAgB,yBAAyB,CAAC,MAAM,EAC9C,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,GACb,MAAM,CAAC;AAKV,wBAAgB,cAAc,CAC5B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,GAAG,GACP,MAAM,EAAE,CAAC;AAkBZ,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,YAAY,EAAE,YAAY,GACzB,MAAM,EAAE,CAEV;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,YAAY,EAAE,YAAY,GACzB,MAAM,EAAE,CAEV;AAGD,wBAAgB,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,OAAO,CAU/D"}
@@ -0,0 +1,94 @@
1
+ // This file is derived from the Cesium math library under Apache 2 license
2
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
+ import { Vector3, isArray, toRadians, toDegrees, config } from '@math.gl/core';
4
+ import { WGS84_CONSTANTS } from './constants';
5
+ const noop = (x) => x;
6
+ const scratchVector = new Vector3();
7
+ export function fromCartographic(cartographic, result = [-0, -0, -0], map = noop) {
8
+ if (isArray(cartographic)) {
9
+ result[0] = map(cartographic[0]);
10
+ result[1] = map(cartographic[1]);
11
+ result[2] = cartographic[2];
12
+ }
13
+ else if ('longitude' in cartographic) {
14
+ result[0] = map(cartographic.longitude);
15
+ result[1] = map(cartographic.latitude);
16
+ result[2] = cartographic.height;
17
+ }
18
+ else {
19
+ result[0] = map(cartographic.x);
20
+ result[1] = map(cartographic.y);
21
+ result[2] = cartographic.z;
22
+ }
23
+ return result;
24
+ }
25
+ export function fromCartographicToRadians(cartographic, vector = []) {
26
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? noop : toRadians);
27
+ }
28
+ export function fromCartographicToDegrees(cartographic, vector = []) {
29
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : noop);
30
+ }
31
+ export function toCartographic(vector, cartographic, map = noop) {
32
+ if (isArray(cartographic)) {
33
+ cartographic[0] = map(vector[0]);
34
+ cartographic[1] = map(vector[1]);
35
+ cartographic[2] = vector[2];
36
+ }
37
+ else if ('longitude' in cartographic) {
38
+ cartographic.longitude = map(vector[0]);
39
+ cartographic.latitude = map(vector[1]);
40
+ cartographic.height = vector[2];
41
+ }
42
+ else {
43
+ cartographic.x = map(vector[0]);
44
+ cartographic.y = map(vector[1]);
45
+ cartographic.z = vector[2];
46
+ }
47
+ return cartographic;
48
+ }
49
+ export function toCartographicFromRadians(vector, cartographic) {
50
+ return toCartographic(vector, cartographic, config._cartographicRadians ? noop : toDegrees);
51
+ }
52
+ export function toCartographicFromDegrees(vector, cartographic) {
53
+ return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : noop);
54
+ }
55
+ // Estimates if a vector is close to the surface of the WGS84 Ellipsoid
56
+ export function isWGS84(vector) {
57
+ if (!vector) {
58
+ return false;
59
+ }
60
+ scratchVector.from(vector);
61
+ const { oneOverRadiiSquared, centerToleranceSquared } = WGS84_CONSTANTS;
62
+ const x2 = vector[0] * vector[0] * oneOverRadiiSquared[0];
63
+ const y2 = vector[1] * vector[1] * oneOverRadiiSquared[1];
64
+ const z2 = vector[2] * vector[2] * oneOverRadiiSquared[2];
65
+ return Math.abs(x2 + y2 + z2 - 1) < centerToleranceSquared;
66
+ }
67
+ /*
68
+
69
+ export function fromCartographic(cartographic: Cartographic, result?: number[]): number[];
70
+ export function fromCartographic(cartographic: Cartographic, result: TypedArray): TypedArray;
71
+ export function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];
72
+ export function fromCartographicToRadians(
73
+ cartographic: Cartographic,
74
+ result: TypedArray
75
+ ): TypedArray;
76
+ export function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];
77
+ export function fromCartographicToDegrees(
78
+ cartographic: Cartographic,
79
+ result: TypedArray
80
+ ): TypedArray;
81
+
82
+ export function toCartographic(vector: number[] | TypedArray, result: Cartographic): number[];
83
+ export function toCartographicFromRadians(
84
+ vector: number[] | TypedArray,
85
+ result: Cartographic
86
+ ): number[];
87
+ export function toCartographicFromDegrees(
88
+ vector: number[] | TypedArray,
89
+ result: Cartographic
90
+ ): number[];
91
+
92
+ // Estimates if a vector is close to the surface of the WGS84 Ellipsoid
93
+ export function isWGS84(vector: number[] | TypedArray): boolean;
94
+ */
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "3.5.3",
8
+ "version": "3.6.0-alpha.1",
9
9
  "keywords": [
10
10
  "webgl",
11
11
  "javascript",
@@ -23,7 +23,7 @@
23
23
  "type": "git",
24
24
  "url": "https://github.com/uber-web/math.gl.git"
25
25
  },
26
- "types": "src/index.js",
26
+ "types": "dist/index.d.ts",
27
27
  "main": "dist/es5/index.js",
28
28
  "module": "dist/esm/index.js",
29
29
  "files": [
@@ -32,8 +32,8 @@
32
32
  ],
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.12.0",
35
- "@math.gl/core": "3.5.3",
36
- "gl-matrix": "^3.0.0"
35
+ "@math.gl/core": "3.6.0-alpha.1",
36
+ "gl-matrix": "~3.3.0"
37
37
  },
38
- "gitHead": "b9183c9ec46dd309a601e1de7beb90a18a3e0fea"
38
+ "gitHead": "45386981340895bf201c2ebb76257c9bbffd8ff6"
39
39
  }
File without changes
@@ -2,7 +2,16 @@
2
2
  // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
3
 
4
4
  /* eslint-disable */
5
- import {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from '@math.gl/core';
5
+ import {
6
+ Vector3,
7
+ Matrix4,
8
+ toRadians,
9
+ toDegrees,
10
+ assert,
11
+ equals,
12
+ _MathUtils,
13
+ NumericArray
14
+ } from '@math.gl/core';
6
15
  import * as vec3 from 'gl-matrix/vec3';
7
16
 
8
17
  import {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';
@@ -20,17 +29,29 @@ const scratchCartesian = new Vector3();
20
29
 
21
30
  let wgs84;
22
31
 
23
- // A quadratic surface defined in Cartesian coordinates by the equation
24
- // <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used
25
- // to represent the shape of planetary bodies.
32
+ /**
33
+ * A quadratic surface defined in Cartesian coordinates by the equation
34
+ * `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
35
+ * to represent the shape of planetary bodies.
36
+ */
26
37
  export default class Ellipsoid {
27
- // An Ellipsoid instance initialized to the WGS84 standard.
28
- static get WGS84() {
29
- wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
30
- return wgs84;
31
- }
38
+ /** An Ellipsoid instance initialized to the WGS84 standard. */
39
+ static readonly WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
40
+
41
+ readonly radii: Vector3;
42
+ readonly radiiSquared: Vector3;
43
+ readonly radiiToTheFourth: Vector3;
44
+ readonly oneOverRadii: Vector3;
45
+ readonly oneOverRadiiSquared: Vector3;
46
+ readonly minimumRadius: number;
47
+ readonly maximumRadius: number;
48
+ readonly centerToleranceSquared: number = _MathUtils.EPSILON1;
49
+ readonly squaredXOverSquaredZ: number;
50
+
51
+ /** Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions. */
52
+ constructor(x: number, y: number, z: number);
53
+ constructor();
32
54
 
33
- // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.
34
55
  constructor(x = 0.0, y = 0.0, z = 0.0) {
35
56
  assert(x >= 0.0);
36
57
  assert(y >= 0.0);
@@ -58,8 +79,6 @@ export default class Ellipsoid {
58
79
 
59
80
  this.maximumRadius = Math.max(x, y, z);
60
81
 
61
- this.centerToleranceSquared = _MathUtils.EPSILON1;
62
-
63
82
  if (this.radiiSquared.z !== 0) {
64
83
  this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
65
84
  }
@@ -67,17 +86,20 @@ export default class Ellipsoid {
67
86
  Object.freeze(this);
68
87
  }
69
88
 
70
- // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns
71
- equals(right) {
89
+ /** Compares this Ellipsoid against the provided Ellipsoid componentwise */
90
+ equals(right: Ellipsoid): boolean {
72
91
  return this === right || Boolean(right && this.radii.equals(right.radii));
73
92
  }
74
93
 
75
- // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.
76
- toString() {
94
+ /** Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'. */
95
+ toString(): string {
77
96
  return this.radii.toString();
78
97
  }
79
98
 
80
- // Converts the provided cartographic to Cartesian representation.
99
+ /** Converts the provided cartographic to Cartesian representation. */
100
+ cartographicToCartesian(cartographic: number[], result: Vector3): Vector3;
101
+ cartographicToCartesian(cartographic: number[], result?: number[]): number[];
102
+
81
103
  cartographicToCartesian(cartographic, result = [0, 0, 0]) {
82
104
  const normal = scratchNormal;
83
105
  const k = scratchK;
@@ -96,8 +118,11 @@ export default class Ellipsoid {
96
118
  return k.to(result);
97
119
  }
98
120
 
99
- // Converts the provided cartesian to cartographic (lng/lat/z) representation.
100
- // The cartesian is undefined at the center of the ellipsoid.
121
+ /** Converts the provided cartesian to cartographic (lng/lat/z) representation.
122
+ * The cartesian is undefined at the center of the ellipsoid. */
123
+ cartesianToCartographic(cartesian: number[], result: Vector3): Vector3;
124
+ cartesianToCartographic(cartesian: number[], result?: number[]): number[];
125
+
101
126
  cartesianToCartographic(cartesian, result = [0, 0, 0]) {
102
127
  scratchCartesian.from(cartesian);
103
128
  const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
@@ -118,25 +143,50 @@ export default class Ellipsoid {
118
143
  return toCartographicFromRadians([longitude, latitude, height], result);
119
144
  }
120
145
 
121
- // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes
122
- // centered at the provided origin to the provided ellipsoid's fixed reference frame.
146
+ /** Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes
147
+ * centered at the provided origin to the provided ellipsoid's fixed reference frame. */
148
+ eastNorthUpToFixedFrame(origin: number[], result?: Matrix4): Matrix4;
149
+ eastNorthUpToFixedFrame(origin: number[], result: number[]): number[];
150
+
123
151
  eastNorthUpToFixedFrame(origin, result = new Matrix4()) {
124
152
  return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);
125
153
  }
126
154
 
155
+ /** Computes a 4x4 transformation matrix from a reference frame centered at
156
+ * the provided origin to the ellipsoid's fixed reference frame.
157
+ */
158
+ localFrameToFixedFrame(
159
+ firstAxis: string,
160
+ secondAxis: string,
161
+ thirdAxis: string,
162
+ origin: Readonly<NumericArray>,
163
+ result?: Matrix4
164
+ ): Matrix4;
165
+ localFrameToFixedFrame<Matrix4T>(
166
+ firstAxis: string,
167
+ secondAxis: string,
168
+ thirdAxis: string,
169
+ origin: Readonly<NumericArray>,
170
+ result: number[]
171
+ ): number[];
172
+
127
173
  // Computes a 4x4 transformation matrix from a reference frame centered at
128
174
  // the provided origin to the ellipsoid's fixed reference frame.
129
175
  localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {
130
176
  return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
131
177
  }
132
178
 
133
- // Computes the unit vector directed from the center of this ellipsoid toward
134
- // the provided Cartesian position.
179
+ /** Computes the unit vector directed from the center of this ellipsoid toward
180
+ * the provided Cartesian position. */
181
+ geocentricSurfaceNormal(cartesian: number[], result?: number[]): number[];
182
+ geocentricSurfaceNormal<NumArray>(cartesian: number[], result: NumArray): NumArray;
135
183
  geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
136
184
  return scratchVector.from(cartesian).normalize().to(result);
137
185
  }
138
186
 
139
- // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.
187
+ /** Computes the normal of the plane tangent to the surface of the ellipsoid at provided position. */
188
+ geodeticSurfaceNormalCartographic<NumArray>(cartographic: number[], result: NumArray): NumArray;
189
+ geodeticSurfaceNormalCartographic(cartographic: number[]): number[];
140
190
  geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
141
191
  const cartographicVectorRadians = fromCartographicToRadians(cartographic);
142
192
 
@@ -152,20 +202,24 @@ export default class Ellipsoid {
152
202
  return scratchVector.to(result);
153
203
  }
154
204
 
155
- // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
205
+ /** Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position. */
206
+ geodeticSurfaceNormal<NumArrayT>(cartesian: number[], result: NumArrayT): NumArrayT;
207
+ geodeticSurfaceNormal(cartesian: number[]): number[];
156
208
  geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
157
209
  return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
158
210
  }
159
211
 
160
- // Scales the provided Cartesian position along the geodetic surface normal
161
- // so that it is on the surface of this ellipsoid. If the position is
162
- // at the center of the ellipsoid, this function returns undefined.
212
+ /** Scales the provided Cartesian position along the geodetic surface normal
213
+ * so that it is on the surface of this ellipsoid. If the position is
214
+ * at the center of the ellipsoid, this function returns undefined. */
215
+ scaleToGeodeticSurface(cartesian: number[], result?: number[]): number[];
163
216
  scaleToGeodeticSurface(cartesian, result) {
164
217
  return scaleToGeodeticSurface(cartesian, this, result);
165
218
  }
166
219
 
167
- // Scales the provided Cartesian position along the geocentric surface normal
168
- // so that it is on the surface of this ellipsoid.
220
+ /** Scales the provided Cartesian position along the geocentric surface normal
221
+ * so that it is on the surface of this ellipsoid. */
222
+ scaleToGeocentricSurface(cartesian: number[], result?: number[]): number[];
169
223
  scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
170
224
  scratchPosition.from(cartesian);
171
225
 
@@ -185,19 +239,26 @@ export default class Ellipsoid {
185
239
  return scratchPosition.multiplyScalar(beta).to(result);
186
240
  }
187
241
 
188
- // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
189
- // its components by the result of `Ellipsoid#oneOverRadii`
242
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
243
+ * its components by the result of `Ellipsoid#oneOverRadii` */
244
+ transformPositionToScaledSpace(position: number[], result?: number[]): number[];
190
245
  transformPositionToScaledSpace(position, result = [0, 0, 0]) {
191
246
  return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
192
247
  }
193
248
 
194
- // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
195
- // its components by the result of `Ellipsoid#radii`.
249
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
250
+ * its components by the result of `Ellipsoid#radii`. */
251
+ transformPositionFromScaledSpace(position: number[], result?: number[]): number[];
196
252
  transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
197
253
  return scratchPosition.from(position).scale(this.radii).to(result);
198
254
  }
199
255
 
200
- // Computes a point which is the intersection of the surface normal with the z-axis.
256
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
257
+ getSurfaceNormalIntersectionWithZAxis(
258
+ position: number[],
259
+ buffer?: number,
260
+ result?: number[]
261
+ ): number[];
201
262
  getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {
202
263
  // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)
203
264
  assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
File without changes
@@ -0,0 +1,143 @@
1
+ // This file is derived from the Cesium math library under Apache 2 license
2
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
+
4
+ import {NumericArray} from '@math.gl/types';
5
+ import {Vector3, isArray, toRadians, toDegrees, config} from '@math.gl/core';
6
+ import {WGS84_CONSTANTS} from './constants';
7
+
8
+ type LngLatHeightObject = {
9
+ longitude: number;
10
+ latitude: number;
11
+ height: number;
12
+ };
13
+
14
+ type XYZObject = {
15
+ x: number;
16
+ y: number;
17
+ z: number;
18
+ };
19
+
20
+ type Cartographic = LngLatHeightObject | XYZObject | NumericArray;
21
+
22
+ const noop = (x) => x;
23
+
24
+ const scratchVector = new Vector3();
25
+
26
+ export function fromCartographic(cartographic: Cartographic): number[];
27
+ export function fromCartographic<NumArrayT>(
28
+ cartographic: Cartographic,
29
+ result: NumArrayT,
30
+ map: any
31
+ ): NumArrayT;
32
+ export function fromCartographic(cartographic, result = [-0, -0, -0], map = noop) {
33
+ if (isArray(cartographic)) {
34
+ result[0] = map(cartographic[0]);
35
+ result[1] = map(cartographic[1]);
36
+ result[2] = cartographic[2];
37
+ } else if ('longitude' in cartographic) {
38
+ result[0] = map(cartographic.longitude);
39
+ result[1] = map(cartographic.latitude);
40
+ result[2] = cartographic.height;
41
+ } else {
42
+ result[0] = map(cartographic.x);
43
+ result[1] = map(cartographic.y);
44
+ result[2] = cartographic.z;
45
+ }
46
+ return result;
47
+ }
48
+
49
+ export function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];
50
+ export function fromCartographicToRadians<TArray>(
51
+ cartographic: Cartographic,
52
+ result: TArray
53
+ ): TArray;
54
+ export function fromCartographicToRadians(cartographic, vector = []) {
55
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? noop : toRadians);
56
+ }
57
+
58
+ export function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];
59
+ export function fromCartographicToDegrees<TArray>(
60
+ cartographic: Cartographic,
61
+ result: TArray
62
+ ): TArray;
63
+ export function fromCartographicToDegrees(cartographic, vector = []) {
64
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : noop);
65
+ }
66
+
67
+ export function toCartographic(
68
+ vector: Readonly<NumericArray>,
69
+ result: Cartographic,
70
+ map: any
71
+ ): number[];
72
+ export function toCartographic(vector, cartographic, map = noop) {
73
+ if (isArray(cartographic)) {
74
+ cartographic[0] = map(vector[0]);
75
+ cartographic[1] = map(vector[1]);
76
+ cartographic[2] = vector[2];
77
+ } else if ('longitude' in cartographic) {
78
+ cartographic.longitude = map(vector[0]);
79
+ cartographic.latitude = map(vector[1]);
80
+ cartographic.height = vector[2];
81
+ } else {
82
+ cartographic.x = map(vector[0]);
83
+ cartographic.y = map(vector[1]);
84
+ cartographic.z = vector[2];
85
+ }
86
+ return cartographic;
87
+ }
88
+
89
+ export function toCartographicFromRadians(
90
+ vector: Readonly<NumericArray>,
91
+ cartographic: Cartographic
92
+ ): number[] {
93
+ return toCartographic(vector, cartographic, config._cartographicRadians ? noop : toDegrees);
94
+ }
95
+
96
+ export function toCartographicFromDegrees(
97
+ vector: Readonly<NumericArray>,
98
+ cartographic: Cartographic
99
+ ): number[] {
100
+ return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : noop);
101
+ }
102
+
103
+ // Estimates if a vector is close to the surface of the WGS84 Ellipsoid
104
+ export function isWGS84(vector: Readonly<NumericArray>): boolean {
105
+ if (!vector) {
106
+ return false;
107
+ }
108
+ scratchVector.from(vector);
109
+ const {oneOverRadiiSquared, centerToleranceSquared} = WGS84_CONSTANTS;
110
+ const x2 = vector[0] * vector[0] * oneOverRadiiSquared[0];
111
+ const y2 = vector[1] * vector[1] * oneOverRadiiSquared[1];
112
+ const z2 = vector[2] * vector[2] * oneOverRadiiSquared[2];
113
+ return Math.abs(x2 + y2 + z2 - 1) < centerToleranceSquared;
114
+ }
115
+
116
+ /*
117
+
118
+ export function fromCartographic(cartographic: Cartographic, result?: number[]): number[];
119
+ export function fromCartographic(cartographic: Cartographic, result: TypedArray): TypedArray;
120
+ export function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];
121
+ export function fromCartographicToRadians(
122
+ cartographic: Cartographic,
123
+ result: TypedArray
124
+ ): TypedArray;
125
+ export function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];
126
+ export function fromCartographicToDegrees(
127
+ cartographic: Cartographic,
128
+ result: TypedArray
129
+ ): TypedArray;
130
+
131
+ export function toCartographic(vector: number[] | TypedArray, result: Cartographic): number[];
132
+ export function toCartographicFromRadians(
133
+ vector: number[] | TypedArray,
134
+ result: Cartographic
135
+ ): number[];
136
+ export function toCartographicFromDegrees(
137
+ vector: number[] | TypedArray,
138
+ result: Cartographic
139
+ ): number[];
140
+
141
+ // Estimates if a vector is close to the surface of the WGS84 Ellipsoid
142
+ export function isWGS84(vector: number[] | TypedArray): boolean;
143
+ */