@math.gl/geospatial 3.5.6 → 3.6.0-alpha.2

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 (53) 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 +142 -0
  7. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts +5 -0
  8. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts.map +1 -0
  9. package/dist/ellipsoid/helpers/ellipsoid-transform.js +125 -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.map +1 -1
  14. package/dist/es5/ellipsoid/ellipsoid.js +13 -8
  15. package/dist/es5/ellipsoid/ellipsoid.js.map +1 -1
  16. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  17. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js +5 -13
  18. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  19. package/dist/es5/index.js.map +1 -1
  20. package/dist/es5/type-utils.js +24 -23
  21. package/dist/es5/type-utils.js.map +1 -1
  22. package/dist/esm/constants.js.map +1 -1
  23. package/dist/esm/ellipsoid/ellipsoid.js +23 -8
  24. package/dist/esm/ellipsoid/ellipsoid.js.map +1 -1
  25. package/dist/esm/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  26. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js +6 -7
  27. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/type-utils.js +24 -22
  30. package/dist/esm/type-utils.js.map +1 -1
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +2 -0
  34. package/dist/type-utils.d.ts +24 -0
  35. package/dist/type-utils.d.ts.map +1 -0
  36. package/dist/type-utils.js +96 -0
  37. package/package.json +5 -5
  38. package/src/{constants.js → constants.ts} +0 -0
  39. package/src/ellipsoid/{ellipsoid.js → ellipsoid.ts} +96 -40
  40. package/src/ellipsoid/helpers/{ellipsoid-transform.js → ellipsoid-transform.ts} +18 -13
  41. package/src/ellipsoid/helpers/{scale-to-geodetic-surface.js → scale-to-geodetic-surface.ts} +11 -7
  42. package/src/{index.js → index.ts} +0 -0
  43. package/src/type-utils.ts +154 -0
  44. package/dist/es5/ellipsoid/ellipsoid.d.ts +0 -95
  45. package/dist/es5/index.d.ts +0 -1
  46. package/dist/es5/type-utils.d.ts +0 -55
  47. package/dist/esm/ellipsoid/ellipsoid.d.ts +0 -95
  48. package/dist/esm/index.d.ts +0 -1
  49. package/dist/esm/type-utils.d.ts +0 -55
  50. package/src/ellipsoid/ellipsoid.d.ts +0 -95
  51. package/src/index.d.ts +0 -1
  52. package/src/type-utils.d.ts +0 -55
  53. package/src/type-utils.js +0 -71
@@ -1,54 +1,56 @@
1
- import { Vector3, isArray, toRadians, toDegrees, config } from '@math.gl/core';
1
+ import { Vector3, toRadians, toDegrees, config } from '@math.gl/core';
2
2
  import { WGS84_CONSTANTS } from './constants';
3
3
 
4
- const noop = x => x;
4
+ function identity(x) {
5
+ return x;
6
+ }
5
7
 
6
8
  const scratchVector = new Vector3();
7
- export function fromCartographic(cartographic, result, map = noop) {
8
- if (isArray(cartographic)) {
9
- result[0] = map(cartographic[0]);
10
- result[1] = map(cartographic[1]);
11
- result[2] = cartographic[2];
12
- } else if ('longitude' in cartographic) {
9
+ export function fromCartographic(cartographic, result = [], map = identity) {
10
+ if ('longitude' in cartographic) {
13
11
  result[0] = map(cartographic.longitude);
14
12
  result[1] = map(cartographic.latitude);
15
13
  result[2] = cartographic.height;
16
- } else {
14
+ } else if ('x' in cartographic) {
17
15
  result[0] = map(cartographic.x);
18
16
  result[1] = map(cartographic.y);
19
17
  result[2] = cartographic.z;
18
+ } else {
19
+ result[0] = map(cartographic[0]);
20
+ result[1] = map(cartographic[1]);
21
+ result[2] = cartographic[2];
20
22
  }
21
23
 
22
24
  return result;
23
25
  }
24
- export function fromCartographicToRadians(cartographic, vector = scratchVector) {
25
- return fromCartographic(cartographic, vector, config._cartographicRadians ? noop : toRadians);
26
+ export function fromCartographicToRadians(cartographic, vector = []) {
27
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? identity : toRadians);
26
28
  }
27
- export function fromCartographicToDegrees(cartographic, vector = scratchVector) {
28
- return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : noop);
29
+ export function fromCartographicToDegrees(cartographic, vector = []) {
30
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : identity);
29
31
  }
30
- export function toCartographic(vector, cartographic, map = noop) {
31
- if (isArray(cartographic)) {
32
- cartographic[0] = map(vector[0]);
33
- cartographic[1] = map(vector[1]);
34
- cartographic[2] = vector[2];
35
- } else if ('longitude' in cartographic) {
32
+ export function toCartographic(vector, cartographic, map = identity) {
33
+ if ('longitude' in cartographic) {
36
34
  cartographic.longitude = map(vector[0]);
37
35
  cartographic.latitude = map(vector[1]);
38
36
  cartographic.height = vector[2];
39
- } else {
37
+ } else if ('x' in cartographic) {
40
38
  cartographic.x = map(vector[0]);
41
39
  cartographic.y = map(vector[1]);
42
40
  cartographic.z = vector[2];
41
+ } else {
42
+ cartographic[0] = map(vector[0]);
43
+ cartographic[1] = map(vector[1]);
44
+ cartographic[2] = vector[2];
43
45
  }
44
46
 
45
47
  return cartographic;
46
48
  }
47
49
  export function toCartographicFromRadians(vector, cartographic) {
48
- return toCartographic(vector, cartographic, config._cartographicRadians ? noop : toDegrees);
50
+ return toCartographic(vector, cartographic, config._cartographicRadians ? identity : toDegrees);
49
51
  }
50
52
  export function toCartographicFromDegrees(vector, cartographic) {
51
- return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : noop);
53
+ return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : identity);
52
54
  }
53
55
  export function isWGS84(vector) {
54
56
  if (!vector) {
@@ -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,SAA1B,EAAqCC,SAArC,EAAgDC,MAAhD,QAA6D,eAA7D;AACA,SAAQC,eAAR,QAA8B,aAA9B;;AAEA,MAAMC,IAAI,GAAIC,CAAD,IAAOA,CAApB;;AAEA,MAAMC,aAAa,GAAG,IAAIR,OAAJ,EAAtB;AAEA,OAAO,SAASS,gBAAT,CAA0BC,YAA1B,EAAwCC,MAAxC,EAAgDC,GAAG,GAAGN,IAAtD,EAA4D;AACjE,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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MG,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","toRadians","toDegrees","config","WGS84_CONSTANTS","identity","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,SAAjB,EAA4BC,SAA5B,EAAuCC,MAAvC,QAAoD,eAApD;AACA,SAAQC,eAAR,QAA8B,aAA9B;;AAgBA,SAASC,QAAT,CAAkBC,CAAlB,EAAqC;AACnC,SAAOA,CAAP;AACD;;AAED,MAAMC,aAAa,GAAG,IAAIP,OAAJ,EAAtB;AAQA,OAAO,SAASQ,gBAAT,CACLC,YADK,EAELC,MAAM,GAAG,EAFJ,EAGLC,GAAG,GAAGN,QAHD,EAIK;AACV,MAAI,eAAeI,YAAnB,EAAiC;AAC/BC,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAACG,SAAd,CAAf;AACAF,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG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AAD;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 type {NumericArray} from '@math.gl/core';\nimport {Vector3, 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\nfunction identity(x: number): number {\n return x;\n}\n\nconst scratchVector = new Vector3();\n\nexport function fromCartographic(cartographic: Cartographic): number[];\nexport function fromCartographic<NumArrayT>(\n cartographic: Cartographic,\n result: NumArrayT,\n map?: (x: number) => number\n): NumArrayT;\nexport function fromCartographic(\n cartographic: Cartographic,\n result = [] as number[],\n map = identity\n): number[] {\n if ('longitude' in cartographic) {\n result[0] = map(cartographic.longitude);\n result[1] = map(cartographic.latitude);\n result[2] = cartographic.height;\n } else if ('x' in cartographic) {\n result[0] = map(cartographic.x);\n result[1] = map(cartographic.y);\n result[2] = cartographic.z;\n } else {\n result[0] = map(cartographic[0]);\n result[1] = map(cartographic[1]);\n result[2] = cartographic[2];\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(\n cartographic: Cartographic,\n vector = [] as number[]\n): number[] {\n return fromCartographic(cartographic, vector, config._cartographicRadians ? identity : 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(\n cartographic: Cartographic,\n vector = [] as number[]\n): number[] {\n return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : identity);\n}\n\nexport function toCartographic<T extends Cartographic>(\n vector: Readonly<NumericArray>,\n cartographic: T,\n map: (x: number) => number = identity\n): T {\n if ('longitude' in cartographic) {\n cartographic.longitude = map(vector[0]);\n cartographic.latitude = map(vector[1]);\n cartographic.height = vector[2];\n } else if ('x' in cartographic) {\n cartographic.x = map(vector[0]);\n cartographic.y = map(vector[1]);\n cartographic.z = vector[2];\n } else {\n cartographic[0] = map(vector[0]);\n cartographic[1] = map(vector[1]);\n cartographic[2] = vector[2];\n }\n return cartographic;\n}\n\nexport function toCartographicFromRadians<T extends Cartographic>(\n vector: Readonly<NumericArray>,\n cartographic: T\n): T {\n return toCartographic(vector, cartographic, config._cartographicRadians ? identity : toDegrees);\n}\n\nexport function toCartographicFromDegrees<T extends Cartographic>(\n vector: Readonly<NumericArray>,\n cartographic: T\n): T {\n return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : identity);\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 type { NumericArray } from '@math.gl/core';
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?: (x: number) => number): 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<T extends Cartographic>(vector: Readonly<NumericArray>, cartographic: T, map?: (x: number) => number): T;
20
+ export declare function toCartographicFromRadians<T extends Cartographic>(vector: Readonly<NumericArray>, cartographic: T): T;
21
+ export declare function toCartographicFromDegrees<T extends Cartographic>(vector: Readonly<NumericArray>, cartographic: T): T;
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,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAIhD,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;AAQlE,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,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAC1B,SAAS,CAAC;AAsBb,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;AAQV,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;AAQV,wBAAgB,cAAc,CAAC,CAAC,SAAS,YAAY,EACnD,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,YAAY,EAAE,CAAC,EACf,GAAG,GAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAiB,GACpC,CAAC,CAeH;AAED,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,YAAY,EAC9D,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,YAAY,EAAE,CAAC,GACd,CAAC,CAEH;AAED,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,YAAY,EAC9D,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,YAAY,EAAE,CAAC,GACd,CAAC,CAEH;AAGD,wBAAgB,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,OAAO,CAU/D"}
@@ -0,0 +1,96 @@
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, toRadians, toDegrees, config } from '@math.gl/core';
4
+ import { WGS84_CONSTANTS } from './constants';
5
+ function identity(x) {
6
+ return x;
7
+ }
8
+ const scratchVector = new Vector3();
9
+ export function fromCartographic(cartographic, result = [], map = identity) {
10
+ if ('longitude' in cartographic) {
11
+ result[0] = map(cartographic.longitude);
12
+ result[1] = map(cartographic.latitude);
13
+ result[2] = cartographic.height;
14
+ }
15
+ else if ('x' in cartographic) {
16
+ result[0] = map(cartographic.x);
17
+ result[1] = map(cartographic.y);
18
+ result[2] = cartographic.z;
19
+ }
20
+ else {
21
+ result[0] = map(cartographic[0]);
22
+ result[1] = map(cartographic[1]);
23
+ result[2] = cartographic[2];
24
+ }
25
+ return result;
26
+ }
27
+ export function fromCartographicToRadians(cartographic, vector = []) {
28
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? identity : toRadians);
29
+ }
30
+ export function fromCartographicToDegrees(cartographic, vector = []) {
31
+ return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : identity);
32
+ }
33
+ export function toCartographic(vector, cartographic, map = identity) {
34
+ if ('longitude' in cartographic) {
35
+ cartographic.longitude = map(vector[0]);
36
+ cartographic.latitude = map(vector[1]);
37
+ cartographic.height = vector[2];
38
+ }
39
+ else if ('x' in cartographic) {
40
+ cartographic.x = map(vector[0]);
41
+ cartographic.y = map(vector[1]);
42
+ cartographic.z = vector[2];
43
+ }
44
+ else {
45
+ cartographic[0] = map(vector[0]);
46
+ cartographic[1] = map(vector[1]);
47
+ cartographic[2] = vector[2];
48
+ }
49
+ return cartographic;
50
+ }
51
+ export function toCartographicFromRadians(vector, cartographic) {
52
+ return toCartographic(vector, cartographic, config._cartographicRadians ? identity : toDegrees);
53
+ }
54
+ export function toCartographicFromDegrees(vector, cartographic) {
55
+ return toCartographic(vector, cartographic, config._cartographicRadians ? toRadians : identity);
56
+ }
57
+ // Estimates if a vector is close to the surface of the WGS84 Ellipsoid
58
+ export function isWGS84(vector) {
59
+ if (!vector) {
60
+ return false;
61
+ }
62
+ scratchVector.from(vector);
63
+ const { oneOverRadiiSquared, centerToleranceSquared } = WGS84_CONSTANTS;
64
+ const x2 = vector[0] * vector[0] * oneOverRadiiSquared[0];
65
+ const y2 = vector[1] * vector[1] * oneOverRadiiSquared[1];
66
+ const z2 = vector[2] * vector[2] * oneOverRadiiSquared[2];
67
+ return Math.abs(x2 + y2 + z2 - 1) < centerToleranceSquared;
68
+ }
69
+ /*
70
+
71
+ export function fromCartographic(cartographic: Cartographic, result?: number[]): number[];
72
+ export function fromCartographic(cartographic: Cartographic, result: TypedArray): TypedArray;
73
+ export function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];
74
+ export function fromCartographicToRadians(
75
+ cartographic: Cartographic,
76
+ result: TypedArray
77
+ ): TypedArray;
78
+ export function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];
79
+ export function fromCartographicToDegrees(
80
+ cartographic: Cartographic,
81
+ result: TypedArray
82
+ ): TypedArray;
83
+
84
+ export function toCartographic(vector: number[] | TypedArray, result: Cartographic): number[];
85
+ export function toCartographicFromRadians(
86
+ vector: number[] | TypedArray,
87
+ result: Cartographic
88
+ ): number[];
89
+ export function toCartographicFromDegrees(
90
+ vector: number[] | TypedArray,
91
+ result: Cartographic
92
+ ): number[];
93
+
94
+ // Estimates if a vector is close to the surface of the WGS84 Ellipsoid
95
+ export function isWGS84(vector: number[] | TypedArray): boolean;
96
+ */
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "3.5.6",
8
+ "version": "3.6.0-alpha.2",
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.6",
36
- "gl-matrix": "~3.3.0"
35
+ "@math.gl/core": "3.6.0-alpha.2",
36
+ "gl-matrix": "^3.4.0"
37
37
  },
38
- "gitHead": "0e69c70ff2e6373fed84d303cbf8198a6972944f"
38
+ "gitHead": "ea7dc265c98b68af56218302d1d42b7d65f74ccb"
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: Ellipsoid = 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,21 +202,23 @@ 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.
163
- scaleToGeodeticSurface(cartesian, result) {
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[] {
164
216
  return scaleToGeodeticSurface(cartesian, this, result);
165
217
  }
166
218
 
167
- // Scales the provided Cartesian position along the geocentric surface normal
168
- // so that it is on the surface of this ellipsoid.
169
- scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
219
+ /** Scales the provided Cartesian position along the geocentric surface normal
220
+ * so that it is on the surface of this ellipsoid. */
221
+ scaleToGeocentricSurface(cartesian: number[], result: number[] = [0, 0, 0]): number[] {
170
222
  scratchPosition.from(cartesian);
171
223
 
172
224
  const positionX = scratchPosition.x;
@@ -185,20 +237,24 @@ export default class Ellipsoid {
185
237
  return scratchPosition.multiplyScalar(beta).to(result);
186
238
  }
187
239
 
188
- // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
189
- // its components by the result of `Ellipsoid#oneOverRadii`
190
- transformPositionToScaledSpace(position, result = [0, 0, 0]) {
240
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
241
+ * its components by the result of `Ellipsoid#oneOverRadii` */
242
+ transformPositionToScaledSpace(position: number[], result: number[] = [0, 0, 0]): number[] {
191
243
  return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
192
244
  }
193
245
 
194
- // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
195
- // its components by the result of `Ellipsoid#radii`.
196
- transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
246
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
247
+ * its components by the result of `Ellipsoid#radii`. */
248
+ transformPositionFromScaledSpace(position: number[], result: number[] = [0, 0, 0]): number[] {
197
249
  return scratchPosition.from(position).scale(this.radii).to(result);
198
250
  }
199
251
 
200
- // Computes a point which is the intersection of the surface normal with the z-axis.
201
- getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {
252
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
253
+ getSurfaceNormalIntersectionWithZAxis(
254
+ position: number[],
255
+ buffer: number = 0,
256
+ result: number[] = [0, 0, 0]
257
+ ): number[] {
202
258
  // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)
203
259
  assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
204
260
  assert(this.radii.z > 0);
@@ -1,5 +1,7 @@
1
1
  import {Vector3, assert, equals as equalsEpsilon} from '@math.gl/core';
2
2
 
3
+ import type Ellipsoid from '../ellipsoid';
4
+
3
5
  const EPSILON14 = 1e-14;
4
6
 
5
7
  const scratchOrigin = new Vector3();
@@ -42,7 +44,7 @@ const VECTOR_PRODUCT_LOCAL_FRAME = {
42
44
  north: 'up',
43
45
  south: 'down'
44
46
  }
45
- };
47
+ } as const;
46
48
 
47
49
  const degeneratePositionLocalFrame = {
48
50
  north: [-1, 0, 0],
@@ -51,7 +53,7 @@ const degeneratePositionLocalFrame = {
51
53
  south: [1, 0, 0],
52
54
  west: [0, -1, 0],
53
55
  down: [0, 0, -1]
54
- };
56
+ } as const;
55
57
 
56
58
  const scratchAxisVectors = {
57
59
  east: new Vector3(),
@@ -66,25 +68,28 @@ const scratchVector1 = new Vector3();
66
68
  const scratchVector2 = new Vector3();
67
69
  const scratchVector3 = new Vector3();
68
70
 
71
+ type Axis = 'up' | 'down' | 'north' | 'east' | 'south' | 'west';
72
+
69
73
  // Computes a 4x4 transformation matrix from a reference frame
70
74
  // centered at the provided origin to the provided ellipsoid's fixed reference frame.
71
75
  // eslint-disable-next-line max-statements, max-params, complexity
72
76
  export default function localFrameToFixedFrame(
73
- ellipsoid,
74
- firstAxis,
75
- secondAxis,
76
- thirdAxis,
77
- cartesianOrigin,
78
- result
79
- ) {
77
+ ellipsoid: Ellipsoid,
78
+ firstAxis: Axis,
79
+ secondAxis: Axis,
80
+ thirdAxis: Axis,
81
+ cartesianOrigin: number[],
82
+ result: number[]
83
+ ): number[] {
80
84
  const thirdAxisInferred =
81
- VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
85
+ VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] &&
86
+ (VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis] as Axis);
82
87
  // firstAxis and secondAxis must be east, north, up, west, south or down.');
83
88
  assert(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
84
89
 
85
- let firstAxisVector;
86
- let secondAxisVector;
87
- let thirdAxisVector;
90
+ let firstAxisVector: Vector3;
91
+ let secondAxisVector: Vector3;
92
+ let thirdAxisVector: Vector3;
88
93
 
89
94
  const origin = scratchOrigin.copy(cartesianOrigin);
90
95
 
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable */
2
- import {Vector3, assert, _MathUtils} from '@math.gl/core';
3
- import * as vec3 from 'gl-matrix/vec3';
2
+ import {Vector3, _MathUtils} from '@math.gl/core';
3
+ import type Ellipsoid from '../ellipsoid';
4
4
 
5
5
  const scratchVector = new Vector3();
6
6
  const scaleToGeodeticSurfaceIntersection = new Vector3();
@@ -9,14 +9,18 @@ const scaleToGeodeticSurfaceGradient = new Vector3();
9
9
  // Scales the provided Cartesian position along the geodetic surface normal
10
10
  // so that it is on the surface of this ellipsoid. If the position is
11
11
  // at the center of the ellipsoid, this function returns undefined.
12
- export default function scaleToGeodeticSurface(cartesian, ellipsoid, result = new Vector3()) {
12
+ export default function scaleToGeodeticSurface(
13
+ cartesian: number[],
14
+ ellipsoid: Ellipsoid,
15
+ result: number[] = []
16
+ ): number[] {
13
17
  const {oneOverRadii, oneOverRadiiSquared, centerToleranceSquared} = ellipsoid;
14
18
 
15
19
  scratchVector.from(cartesian);
16
20
 
17
- const positionX = cartesian.x;
18
- const positionY = cartesian.y;
19
- const positionZ = cartesian.z;
21
+ const positionX = scratchVector.x;
22
+ const positionY = scratchVector.y;
23
+ const positionZ = scratchVector.z;
20
24
 
21
25
  const oneOverRadiiX = oneOverRadii.x;
22
26
  const oneOverRadiiY = oneOverRadii.y;
@@ -58,7 +62,7 @@ export default function scaleToGeodeticSurface(cartesian, ellipsoid, result = ne
58
62
  );
59
63
 
60
64
  // Compute the initial guess at the normal vector multiplier, lambda.
61
- let lambda = ((1.0 - ratio) * cartesian.len()) / (0.5 * gradient.len());
65
+ let lambda = ((1.0 - ratio) * scratchVector.len()) / (0.5 * gradient.len());
62
66
  let correction = 0.0;
63
67
 
64
68
  let xMultiplier;
File without changes