@math.gl/geospatial 3.6.3 → 4.0.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 (48) hide show
  1. package/dist/constants.js.map +1 -0
  2. package/dist/ellipsoid/ellipsoid.d.ts +9 -8
  3. package/dist/ellipsoid/ellipsoid.d.ts.map +1 -1
  4. package/dist/{esm/ellipsoid → ellipsoid}/ellipsoid.js +5 -6
  5. package/dist/ellipsoid/ellipsoid.js.map +1 -0
  6. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts +4 -4
  7. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts.map +1 -1
  8. package/dist/{esm/ellipsoid → ellipsoid}/helpers/ellipsoid-transform.js +1 -1
  9. package/dist/ellipsoid/helpers/ellipsoid-transform.js.map +1 -0
  10. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts +2 -2
  11. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts.map +1 -1
  12. package/dist/{esm/ellipsoid → ellipsoid}/helpers/scale-to-geodetic-surface.js +1 -1
  13. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -0
  14. package/dist/index.cjs +407 -0
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/type-utils.d.ts +6 -6
  20. package/dist/type-utils.d.ts.map +1 -1
  21. package/dist/{esm/type-utils.js → type-utils.js} +1 -1
  22. package/dist/type-utils.js.map +1 -0
  23. package/package.json +7 -6
  24. package/src/ellipsoid/ellipsoid.ts +33 -33
  25. package/src/ellipsoid/helpers/ellipsoid-transform.ts +14 -12
  26. package/src/ellipsoid/helpers/scale-to-geodetic-surface.ts +2 -2
  27. package/src/index.ts +1 -1
  28. package/src/type-utils.ts +15 -9
  29. package/dist/es5/constants.js +0 -22
  30. package/dist/es5/constants.js.map +0 -1
  31. package/dist/es5/ellipsoid/ellipsoid.js +0 -210
  32. package/dist/es5/ellipsoid/ellipsoid.js.map +0 -1
  33. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js +0 -134
  34. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js.map +0 -1
  35. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js +0 -74
  36. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js.map +0 -1
  37. package/dist/es5/index.js +0 -24
  38. package/dist/es5/index.js.map +0 -1
  39. package/dist/es5/type-utils.js +0 -96
  40. package/dist/es5/type-utils.js.map +0 -1
  41. package/dist/esm/constants.js.map +0 -1
  42. package/dist/esm/ellipsoid/ellipsoid.js.map +0 -1
  43. package/dist/esm/ellipsoid/helpers/ellipsoid-transform.js.map +0 -1
  44. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js.map +0 -1
  45. package/dist/esm/index.js +0 -3
  46. package/dist/esm/index.js.map +0 -1
  47. package/dist/esm/type-utils.js.map +0 -1
  48. /package/dist/{esm/constants.js → constants.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { default as Ellipsoid } from './ellipsoid/ellipsoid';
1
+ export { Ellipsoid } from './ellipsoid/ellipsoid';
2
2
  export { isWGS84 } from './type-utils';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Ellipsoid } from "./ellipsoid/ellipsoid.js";
2
+ export { isWGS84 } from "./type-utils.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["Ellipsoid","isWGS84"],"mappings":"SAAQA,S;SACAC,O","sourcesContent":["export {Ellipsoid} from './ellipsoid/ellipsoid';\nexport {isWGS84} from './type-utils';\n"],"file":"index.js"}
@@ -10,12 +10,12 @@ declare type XYZObject = {
10
10
  z: number;
11
11
  };
12
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;
13
+ export declare function fromCartographic(cartographic: Readonly<Cartographic>): number[];
14
+ export declare function fromCartographic<NumArrayT>(cartographic: Readonly<Cartographic>, result: NumArrayT, map?: (x: number) => number): NumArrayT;
15
+ export declare function fromCartographicToRadians(cartographic: Readonly<Cartographic>, result?: number[]): number[];
16
+ export declare function fromCartographicToRadians<TArray>(cartographic: Readonly<Cartographic>, result: TArray): TArray;
17
+ export declare function fromCartographicToDegrees(cartographic: Readonly<Cartographic>, result?: number[]): number[];
18
+ export declare function fromCartographicToDegrees<TArray>(cartographic: Readonly<Cartographic>, result: TArray): TArray;
19
19
  export declare function toCartographic<T extends Cartographic>(vector: Readonly<NumericArray>, cartographic: T, map?: (x: number) => number): T;
20
20
  export declare function toCartographicFromRadians<T extends Cartographic>(vector: Readonly<NumericArray>, cartographic: T): T;
21
21
  export declare function toCartographicFromDegrees<T extends Cartographic>(vector: Readonly<NumericArray>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,MAAM,EAAE,GAChB,MAAM,EAAE,CAAC;AACZ,wBAAgB,yBAAyB,CAAC,MAAM,EAC9C,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,EACpC,MAAM,EAAE,MAAM,GACb,MAAM,CAAC;AAQV,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,EACpC,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,MAAM,EAAE,CAAC;AACZ,wBAAgB,yBAAyB,CAAC,MAAM,EAC9C,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,EACpC,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"}
@@ -1,5 +1,5 @@
1
1
  import { Vector3, toRadians, toDegrees, config } from '@math.gl/core';
2
- import { WGS84_CONSTANTS } from './constants';
2
+ import { WGS84_CONSTANTS } from "./constants.js";
3
3
 
4
4
  function identity(x) {
5
5
  return x;
@@ -0,0 +1 @@
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;SACQC,e;;AAgBR,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,CAACF,YAAY,CAACI,QAAd,CAAf;AACAH,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYD,YAAY,CAACK,MAAzB;AACD,GAJD,MAIO,IAAI,OAAOL,YAAX,EAAyB;AAC9BC,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAACH,CAAd,CAAf;AACAI,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYC,GAAG,CAACF,YAAY,CAACM,CAAd,CAAf;AACAL,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYD,YAAY,CAACO,CAAzB;AACD,GAJM,MAIA;AACLN,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,CAAx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AAAA,YAAY,CAAC,CAAD,CAAZ,GAAkBS,MAAM,CAAC,CAAD,CAAxB;AACD;;AACD,SAAOT,YAAP;AACD;AAED,OAAO,SAASa,yBAAT,CACLJ,MADK,EAELT,YAFK,EAGF;AACH,SAAOY,cAAc,CAACH,MAAD,EAAST,YAAT,EAAuBN,MAAM,CAACgB,oBAAP,GAA8Bd,QAA9B,GAAyCH,SAAhE,CAArB;AACD;AAED,OAAO,SAASqB,yBAAT,CACLL,MADK,EAELT,YAFK,EAGF;AACH,SAAOY,cAAc,CAACH,MAAD,EAAST,YAAT,EAAuBN,MAAM,CAACgB,oBAAP,GAA8BlB,SAA9B,GAA0CI,QAAjE,CAArB;AACD;AAGD,OAAO,SAASmB,OAAT,CAAiBN,MAAjB,EAA0D;AAC/D,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 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: Readonly<Cartographic>): number[];\nexport function fromCartographic<NumArrayT>(\n cartographic: Readonly<Cartographic>,\n result: NumArrayT,\n map?: (x: number) => number\n): NumArrayT;\nexport function fromCartographic(\n cartographic: Readonly<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(\n cartographic: Readonly<Cartographic>,\n result?: number[]\n): number[];\nexport function fromCartographicToRadians<TArray>(\n cartographic: Readonly<Cartographic>,\n result: TArray\n): TArray;\nexport function fromCartographicToRadians(\n cartographic: Readonly<Cartographic>,\n vector = [] as number[]\n): number[] {\n return fromCartographic(cartographic, vector, config._cartographicRadians ? identity : toRadians);\n}\n\nexport function fromCartographicToDegrees(\n cartographic: Readonly<Cartographic>,\n result?: number[]\n): number[];\nexport function fromCartographicToDegrees<TArray>(\n cartographic: Readonly<Cartographic>,\n result: TArray\n): TArray;\nexport function fromCartographicToDegrees(\n cartographic: Readonly<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"}
package/package.json CHANGED
@@ -2,10 +2,11 @@
2
2
  "name": "@math.gl/geospatial",
3
3
  "description": "Geospatial classes",
4
4
  "license": "MIT",
5
+ "type": "module",
5
6
  "publishConfig": {
6
7
  "access": "public"
7
8
  },
8
- "version": "3.6.3",
9
+ "version": "4.0.0-alpha.2",
9
10
  "keywords": [
10
11
  "webgl",
11
12
  "javascript",
@@ -24,16 +25,16 @@
24
25
  "url": "https://github.com/uber-web/math.gl.git"
25
26
  },
26
27
  "types": "dist/index.d.ts",
27
- "main": "dist/es5/index.js",
28
- "module": "dist/esm/index.js",
28
+ "main": "dist/index.cjs",
29
+ "module": "dist/index.js",
29
30
  "files": [
30
31
  "dist",
31
32
  "src"
32
33
  ],
33
34
  "dependencies": {
34
35
  "@babel/runtime": "^7.12.0",
35
- "@math.gl/core": "3.6.3",
36
- "gl-matrix": "^3.4.0"
36
+ "@math.gl/core": "4.0.0-alpha.2",
37
+ "gl-matrix": "^3.4.3"
37
38
  },
38
- "gitHead": "0efab394df9babad7ed93027c1003f30528b2090"
39
+ "gitHead": "2e693639e3cf898fee8e323c93efdd07be7c2ca7"
39
40
  }
@@ -2,23 +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 {
6
- Vector3,
7
- Matrix4,
8
- toRadians,
9
- toDegrees,
10
- assert,
11
- equals,
12
- _MathUtils,
13
- NumericArray
14
- } from '@math.gl/core';
5
+ import {Vector3, Matrix4, assert, equals, _MathUtils, NumericArray} from '@math.gl/core';
6
+ // @ts-ignore gl-matrix typings...
15
7
  import * as vec3 from 'gl-matrix/vec3';
16
8
 
17
9
  import {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';
18
10
  import {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';
19
11
 
20
- import scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
21
- import localFrameToFixedFrame from './helpers/ellipsoid-transform';
12
+ import type {AxisDirection} from './helpers/ellipsoid-transform';
13
+ import {localFrameToFixedFrame} from './helpers/ellipsoid-transform';
14
+ import {scaleToGeodeticSurface} from './helpers/scale-to-geodetic-surface';
22
15
 
23
16
  const scratchVector = new Vector3();
24
17
  const scratchNormal = new Vector3();
@@ -27,14 +20,12 @@ const scratchPosition = new Vector3();
27
20
  const scratchHeight = new Vector3();
28
21
  const scratchCartesian = new Vector3();
29
22
 
30
- let wgs84;
31
-
32
23
  /**
33
24
  * A quadratic surface defined in Cartesian coordinates by the equation
34
25
  * `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
35
26
  * to represent the shape of planetary bodies.
36
27
  */
37
- export default class Ellipsoid {
28
+ export class Ellipsoid {
38
29
  /** An Ellipsoid instance initialized to the WGS84 standard. */
39
30
  static readonly WGS84: Ellipsoid = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
40
31
 
@@ -100,7 +91,7 @@ export default class Ellipsoid {
100
91
  cartographicToCartesian(cartographic: number[], result: Vector3): Vector3;
101
92
  cartographicToCartesian(cartographic: number[], result?: number[]): number[];
102
93
 
103
- cartographicToCartesian(cartographic, result = [0, 0, 0]) {
94
+ cartographicToCartesian(cartographic: Readonly<NumericArray>, result = [0, 0, 0]) {
104
95
  const normal = scratchNormal;
105
96
  const k = scratchK;
106
97
 
@@ -120,10 +111,10 @@ export default class Ellipsoid {
120
111
 
121
112
  /** Converts the provided cartesian to cartographic (lng/lat/z) representation.
122
113
  * The cartesian is undefined at the center of the ellipsoid. */
123
- cartesianToCartographic(cartesian: number[], result: Vector3): Vector3;
124
- cartesianToCartographic(cartesian: number[], result?: number[]): number[];
114
+ cartesianToCartographic(cartesian: Readonly<NumericArray>, result: Vector3): Vector3;
115
+ cartesianToCartographic(cartesian: Readonly<NumericArray>, result?: number[]): number[];
125
116
 
126
- cartesianToCartographic(cartesian, result = [0, 0, 0]) {
117
+ cartesianToCartographic(cartesian: Readonly<NumericArray>, result = [0, 0, 0]) {
127
118
  scratchCartesian.from(cartesian);
128
119
  const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
129
120
 
@@ -145,10 +136,10 @@ export default class Ellipsoid {
145
136
 
146
137
  /** Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes
147
138
  * 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[];
139
+ eastNorthUpToFixedFrame(origin: Readonly<NumericArray>, result?: Matrix4): Matrix4;
140
+ eastNorthUpToFixedFrame(origin: Readonly<NumericArray>, result: number[]): number[];
150
141
 
151
- eastNorthUpToFixedFrame(origin, result = new Matrix4()) {
142
+ eastNorthUpToFixedFrame(origin: Readonly<NumericArray>, result = new Matrix4()) {
152
143
  return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);
153
144
  }
154
145
 
@@ -156,23 +147,29 @@ export default class Ellipsoid {
156
147
  * the provided origin to the ellipsoid's fixed reference frame.
157
148
  */
158
149
  localFrameToFixedFrame(
159
- firstAxis: string,
160
- secondAxis: string,
161
- thirdAxis: string,
150
+ firstAxis: AxisDirection,
151
+ secondAxis: AxisDirection,
152
+ thirdAxis: AxisDirection,
162
153
  origin: Readonly<NumericArray>,
163
154
  result?: Matrix4
164
155
  ): Matrix4;
165
156
  localFrameToFixedFrame<Matrix4T>(
166
- firstAxis: string,
167
- secondAxis: string,
168
- thirdAxis: string,
157
+ firstAxis: AxisDirection,
158
+ secondAxis: AxisDirection,
159
+ thirdAxis: AxisDirection,
169
160
  origin: Readonly<NumericArray>,
170
161
  result: number[]
171
162
  ): number[];
172
163
 
173
164
  // Computes a 4x4 transformation matrix from a reference frame centered at
174
165
  // the provided origin to the ellipsoid's fixed reference frame.
175
- localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {
166
+ localFrameToFixedFrame(
167
+ firstAxis: AxisDirection,
168
+ secondAxis: AxisDirection,
169
+ thirdAxis: AxisDirection,
170
+ origin: Readonly<NumericArray>,
171
+ result = new Matrix4()
172
+ ) {
176
173
  return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
177
174
  }
178
175
 
@@ -180,14 +177,17 @@ export default class Ellipsoid {
180
177
  * the provided Cartesian position. */
181
178
  geocentricSurfaceNormal(cartesian: number[], result?: number[]): number[];
182
179
  geocentricSurfaceNormal<NumArray>(cartesian: number[], result: NumArray): NumArray;
183
- geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
180
+ geocentricSurfaceNormal(cartesian: Readonly<NumericArray>, result = [0, 0, 0]) {
184
181
  return scratchVector.from(cartesian).normalize().to(result);
185
182
  }
186
183
 
187
184
  /** Computes the normal of the plane tangent to the surface of the ellipsoid at provided position. */
188
- geodeticSurfaceNormalCartographic<NumArray>(cartographic: number[], result: NumArray): NumArray;
185
+ geodeticSurfaceNormalCartographic<NumArray>(
186
+ cartographic: Readonly<NumericArray>,
187
+ result: NumArray
188
+ ): NumArray;
189
189
  geodeticSurfaceNormalCartographic(cartographic: number[]): number[];
190
- geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
190
+ geodeticSurfaceNormalCartographic(cartographic: Readonly<NumericArray>, result = [0, 0, 0]) {
191
191
  const cartographicVectorRadians = fromCartographicToRadians(cartographic);
192
192
 
193
193
  const longitude = cartographicVectorRadians[0];
@@ -205,7 +205,7 @@ export default class Ellipsoid {
205
205
  /** Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position. */
206
206
  geodeticSurfaceNormal<NumArrayT>(cartesian: number[], result: NumArrayT): NumArrayT;
207
207
  geodeticSurfaceNormal(cartesian: number[]): number[];
208
- geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
208
+ geodeticSurfaceNormal(cartesian: Readonly<NumericArray>, result = [0, 0, 0]) {
209
209
  return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
210
210
  }
211
211
 
@@ -1,13 +1,18 @@
1
- import {Vector3, assert, equals as equalsEpsilon} from '@math.gl/core';
1
+ import {NumericArray, Vector3, assert, equals as equalsEpsilon} from '@math.gl/core';
2
2
 
3
- import type Ellipsoid from '../ellipsoid';
3
+ import type {Ellipsoid} from '../ellipsoid';
4
4
 
5
5
  const EPSILON14 = 1e-14;
6
6
 
7
7
  const scratchOrigin = new Vector3();
8
8
 
9
+ export type AxisDirection = 'up' | 'down' | 'north' | 'east' | 'south' | 'west';
10
+
9
11
  // Caclulate third axis from given two axii
10
- const VECTOR_PRODUCT_LOCAL_FRAME = {
12
+ const VECTOR_PRODUCT_LOCAL_FRAME: Record<
13
+ AxisDirection,
14
+ Partial<Record<AxisDirection, AxisDirection>>
15
+ > = {
11
16
  up: {
12
17
  south: 'east',
13
18
  north: 'west',
@@ -68,22 +73,19 @@ const scratchVector1 = new Vector3();
68
73
  const scratchVector2 = new Vector3();
69
74
  const scratchVector3 = new Vector3();
70
75
 
71
- type Axis = 'up' | 'down' | 'north' | 'east' | 'south' | 'west';
72
-
73
76
  // Computes a 4x4 transformation matrix from a reference frame
74
77
  // centered at the provided origin to the provided ellipsoid's fixed reference frame.
75
78
  // eslint-disable-next-line max-statements, max-params, complexity
76
- export default function localFrameToFixedFrame(
79
+ export function localFrameToFixedFrame(
77
80
  ellipsoid: Ellipsoid,
78
- firstAxis: Axis,
79
- secondAxis: Axis,
80
- thirdAxis: Axis,
81
- cartesianOrigin: number[],
81
+ firstAxis: AxisDirection,
82
+ secondAxis: AxisDirection,
83
+ thirdAxis: AxisDirection,
84
+ cartesianOrigin: Readonly<NumericArray>,
82
85
  result: number[]
83
86
  ): number[] {
84
87
  const thirdAxisInferred =
85
- VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] &&
86
- (VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis] as Axis);
88
+ VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
87
89
  // firstAxis and secondAxis must be east, north, up, west, south or down.');
88
90
  assert(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
89
91
 
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable */
2
2
  import {Vector3, _MathUtils} from '@math.gl/core';
3
- import type Ellipsoid from '../ellipsoid';
3
+ import type {Ellipsoid} from '../ellipsoid';
4
4
 
5
5
  const scratchVector = new Vector3();
6
6
  const scaleToGeodeticSurfaceIntersection = new Vector3();
@@ -9,7 +9,7 @@ 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(
12
+ export function scaleToGeodeticSurface(
13
13
  cartesian: number[],
14
14
  ellipsoid: Ellipsoid,
15
15
  result: number[] = []
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export {default as Ellipsoid} from './ellipsoid/ellipsoid';
1
+ export {Ellipsoid} from './ellipsoid/ellipsoid';
2
2
  export {isWGS84} from './type-utils';
package/src/type-utils.ts CHANGED
@@ -25,14 +25,14 @@ function identity(x: number): number {
25
25
 
26
26
  const scratchVector = new Vector3();
27
27
 
28
- export function fromCartographic(cartographic: Cartographic): number[];
28
+ export function fromCartographic(cartographic: Readonly<Cartographic>): number[];
29
29
  export function fromCartographic<NumArrayT>(
30
- cartographic: Cartographic,
30
+ cartographic: Readonly<Cartographic>,
31
31
  result: NumArrayT,
32
32
  map?: (x: number) => number
33
33
  ): NumArrayT;
34
34
  export function fromCartographic(
35
- cartographic: Cartographic,
35
+ cartographic: Readonly<Cartographic>,
36
36
  result = [] as number[],
37
37
  map = identity
38
38
  ): number[] {
@@ -52,25 +52,31 @@ export function fromCartographic(
52
52
  return result;
53
53
  }
54
54
 
55
- export function fromCartographicToRadians(cartographic: Cartographic, result?: number[]): number[];
55
+ export function fromCartographicToRadians(
56
+ cartographic: Readonly<Cartographic>,
57
+ result?: number[]
58
+ ): number[];
56
59
  export function fromCartographicToRadians<TArray>(
57
- cartographic: Cartographic,
60
+ cartographic: Readonly<Cartographic>,
58
61
  result: TArray
59
62
  ): TArray;
60
63
  export function fromCartographicToRadians(
61
- cartographic: Cartographic,
64
+ cartographic: Readonly<Cartographic>,
62
65
  vector = [] as number[]
63
66
  ): number[] {
64
67
  return fromCartographic(cartographic, vector, config._cartographicRadians ? identity : toRadians);
65
68
  }
66
69
 
67
- export function fromCartographicToDegrees(cartographic: Cartographic, result?: number[]): number[];
70
+ export function fromCartographicToDegrees(
71
+ cartographic: Readonly<Cartographic>,
72
+ result?: number[]
73
+ ): number[];
68
74
  export function fromCartographicToDegrees<TArray>(
69
- cartographic: Cartographic,
75
+ cartographic: Readonly<Cartographic>,
70
76
  result: TArray
71
77
  ): TArray;
72
78
  export function fromCartographicToDegrees(
73
- cartographic: Cartographic,
79
+ cartographic: Readonly<Cartographic>,
74
80
  vector = [] as number[]
75
81
  ): number[] {
76
82
  return fromCartographic(cartographic, vector, config._cartographicRadians ? toDegrees : identity);
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.WGS84_CONSTANTS = exports.WGS84_RADIUS_Z = exports.WGS84_RADIUS_Y = exports.WGS84_RADIUS_X = void 0;
7
- var WGS84_RADIUS_X = 6378137.0;
8
- exports.WGS84_RADIUS_X = WGS84_RADIUS_X;
9
- var WGS84_RADIUS_Y = 6378137.0;
10
- exports.WGS84_RADIUS_Y = WGS84_RADIUS_Y;
11
- var WGS84_RADIUS_Z = 6356752.3142451793;
12
- exports.WGS84_RADIUS_Z = WGS84_RADIUS_Z;
13
- var WGS84_CONSTANTS = {
14
- radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
15
- radiiSquared: [WGS84_RADIUS_X * WGS84_RADIUS_X, WGS84_RADIUS_Y * WGS84_RADIUS_Y, WGS84_RADIUS_Z * WGS84_RADIUS_Z],
16
- oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],
17
- oneOverRadiiSquared: [1.0 / (WGS84_RADIUS_X * WGS84_RADIUS_X), 1.0 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y), 1.0 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)],
18
- maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
19
- centerToleranceSquared: 1e-1
20
- };
21
- exports.WGS84_CONSTANTS = WGS84_CONSTANTS;
22
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/constants.ts"],"names":["WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","WGS84_CONSTANTS","radii","radiiSquared","oneOverRadii","oneOverRadiiSquared","maximumRadius","Math","max","centerToleranceSquared"],"mappings":";;;;;;AAGO,IAAMA,cAAc,GAAG,SAAvB;;AACA,IAAMC,cAAc,GAAG,SAAvB;;AACA,IAAMC,cAAc,GAAG,kBAAvB;;AAIA,IAAMC,eAAe,GAAG;AAC7BC,EAAAA,KAAK,EAAE,CAACJ,cAAD,EAAiBC,cAAjB,EAAiCC,cAAjC,CADsB;AAE7BG,EAAAA,YAAY,EAAE,CACZL,cAAc,GAAGA,cADL,EAEZC,cAAc,GAAGA,cAFL,EAGZC,cAAc,GAAGA,cAHL,CAFe;AAO7BI,EAAAA,YAAY,EAAE,CAAC,MAAMN,cAAP,EAAuB,MAAMC,cAA7B,EAA6C,MAAMC,cAAnD,CAPe;AAQ7BK,EAAAA,mBAAmB,EAAE,CACnB,OAAOP,cAAc,GAAGA,cAAxB,CADmB,EAEnB,OAAOC,cAAc,GAAGA,cAAxB,CAFmB,EAGnB,OAAOC,cAAc,GAAGA,cAAxB,CAHmB,CARQ;AAa7BM,EAAAA,aAAa,EAAEC,IAAI,CAACC,GAAL,CAASV,cAAT,EAAyBC,cAAzB,EAAyCC,cAAzC,CAbc;AAc7BS,EAAAA,sBAAsB,EAAE;AAdK,CAAxB","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\nexport const WGS84_RADIUS_X = 6378137.0;\nexport const WGS84_RADIUS_Y = 6378137.0;\nexport const WGS84_RADIUS_Z = 6356752.3142451793;\n\n// Pre-calculated ellipsoid defaults to avoid utils depending on `ellipsoid.js`\n\nexport const WGS84_CONSTANTS = {\n radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],\n radiiSquared: [\n WGS84_RADIUS_X * WGS84_RADIUS_X,\n WGS84_RADIUS_Y * WGS84_RADIUS_Y,\n WGS84_RADIUS_Z * WGS84_RADIUS_Z\n ],\n oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],\n oneOverRadiiSquared: [\n 1.0 / (WGS84_RADIUS_X * WGS84_RADIUS_X),\n 1.0 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),\n 1.0 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)\n ],\n maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),\n centerToleranceSquared: 1e-1 // EPSILON1;\n};\n"],"file":"constants.js"}
@@ -1,210 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.default = void 0;
11
-
12
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
-
20
- var _core = require("@math.gl/core");
21
-
22
- var vec3 = _interopRequireWildcard(require("gl-matrix/vec3"));
23
-
24
- var _constants = require("../constants");
25
-
26
- var _typeUtils = require("../type-utils");
27
-
28
- var _scaleToGeodeticSurface2 = _interopRequireDefault(require("./helpers/scale-to-geodetic-surface"));
29
-
30
- var _ellipsoidTransform = _interopRequireDefault(require("./helpers/ellipsoid-transform"));
31
-
32
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
-
34
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
-
36
- var scratchVector = new _core.Vector3();
37
- var scratchNormal = new _core.Vector3();
38
- var scratchK = new _core.Vector3();
39
- var scratchPosition = new _core.Vector3();
40
- var scratchHeight = new _core.Vector3();
41
- var scratchCartesian = new _core.Vector3();
42
- var wgs84;
43
-
44
- var Ellipsoid = function () {
45
- function Ellipsoid() {
46
- var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0.0;
47
- var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
48
- var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.0;
49
- (0, _classCallCheck2.default)(this, Ellipsoid);
50
- (0, _defineProperty2.default)(this, "radii", void 0);
51
- (0, _defineProperty2.default)(this, "radiiSquared", void 0);
52
- (0, _defineProperty2.default)(this, "radiiToTheFourth", void 0);
53
- (0, _defineProperty2.default)(this, "oneOverRadii", void 0);
54
- (0, _defineProperty2.default)(this, "oneOverRadiiSquared", void 0);
55
- (0, _defineProperty2.default)(this, "minimumRadius", void 0);
56
- (0, _defineProperty2.default)(this, "maximumRadius", void 0);
57
- (0, _defineProperty2.default)(this, "centerToleranceSquared", _core._MathUtils.EPSILON1);
58
- (0, _defineProperty2.default)(this, "squaredXOverSquaredZ", void 0);
59
- (0, _core.assert)(x >= 0.0);
60
- (0, _core.assert)(y >= 0.0);
61
- (0, _core.assert)(z >= 0.0);
62
- this.radii = new _core.Vector3(x, y, z);
63
- this.radiiSquared = new _core.Vector3(x * x, y * y, z * z);
64
- this.radiiToTheFourth = new _core.Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
65
- this.oneOverRadii = new _core.Vector3(x === 0.0 ? 0.0 : 1.0 / x, y === 0.0 ? 0.0 : 1.0 / y, z === 0.0 ? 0.0 : 1.0 / z);
66
- this.oneOverRadiiSquared = new _core.Vector3(x === 0.0 ? 0.0 : 1.0 / (x * x), y === 0.0 ? 0.0 : 1.0 / (y * y), z === 0.0 ? 0.0 : 1.0 / (z * z));
67
- this.minimumRadius = Math.min(x, y, z);
68
- this.maximumRadius = Math.max(x, y, z);
69
-
70
- if (this.radiiSquared.z !== 0) {
71
- this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
72
- }
73
-
74
- Object.freeze(this);
75
- }
76
-
77
- (0, _createClass2.default)(Ellipsoid, [{
78
- key: "equals",
79
- value: function equals(right) {
80
- return this === right || Boolean(right && this.radii.equals(right.radii));
81
- }
82
- }, {
83
- key: "toString",
84
- value: function toString() {
85
- return this.radii.toString();
86
- }
87
- }, {
88
- key: "cartographicToCartesian",
89
- value: function cartographicToCartesian(cartographic) {
90
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
91
- var normal = scratchNormal;
92
- var k = scratchK;
93
-
94
- var _cartographic = (0, _slicedToArray2.default)(cartographic, 3),
95
- height = _cartographic[2];
96
-
97
- this.geodeticSurfaceNormalCartographic(cartographic, normal);
98
- k.copy(this.radiiSquared).scale(normal);
99
- var gamma = Math.sqrt(normal.dot(k));
100
- k.scale(1 / gamma);
101
- normal.scale(height);
102
- k.add(normal);
103
- return k.to(result);
104
- }
105
- }, {
106
- key: "cartesianToCartographic",
107
- value: function cartesianToCartographic(cartesian) {
108
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
109
- scratchCartesian.from(cartesian);
110
- var point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
111
-
112
- if (!point) {
113
- return undefined;
114
- }
115
-
116
- var normal = this.geodeticSurfaceNormal(point, scratchNormal);
117
- var h = scratchHeight;
118
- h.copy(scratchCartesian).subtract(point);
119
- var longitude = Math.atan2(normal.y, normal.x);
120
- var latitude = Math.asin(normal.z);
121
- var height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
122
- return (0, _typeUtils.toCartographicFromRadians)([longitude, latitude, height], result);
123
- }
124
- }, {
125
- key: "eastNorthUpToFixedFrame",
126
- value: function eastNorthUpToFixedFrame(origin) {
127
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _core.Matrix4();
128
- return (0, _ellipsoidTransform.default)(this, 'east', 'north', 'up', origin, result);
129
- }
130
- }, {
131
- key: "localFrameToFixedFrame",
132
- value: function localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin) {
133
- var result = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : new _core.Matrix4();
134
- return (0, _ellipsoidTransform.default)(this, firstAxis, secondAxis, thirdAxis, origin, result);
135
- }
136
- }, {
137
- key: "geocentricSurfaceNormal",
138
- value: function geocentricSurfaceNormal(cartesian) {
139
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
140
- return scratchVector.from(cartesian).normalize().to(result);
141
- }
142
- }, {
143
- key: "geodeticSurfaceNormalCartographic",
144
- value: function geodeticSurfaceNormalCartographic(cartographic) {
145
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
146
- var cartographicVectorRadians = (0, _typeUtils.fromCartographicToRadians)(cartographic);
147
- var longitude = cartographicVectorRadians[0];
148
- var latitude = cartographicVectorRadians[1];
149
- var cosLatitude = Math.cos(latitude);
150
- scratchVector.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude)).normalize();
151
- return scratchVector.to(result);
152
- }
153
- }, {
154
- key: "geodeticSurfaceNormal",
155
- value: function geodeticSurfaceNormal(cartesian) {
156
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
157
- return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
158
- }
159
- }, {
160
- key: "scaleToGeodeticSurface",
161
- value: function scaleToGeodeticSurface(cartesian, result) {
162
- return (0, _scaleToGeodeticSurface2.default)(cartesian, this, result);
163
- }
164
- }, {
165
- key: "scaleToGeocentricSurface",
166
- value: function scaleToGeocentricSurface(cartesian) {
167
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
168
- scratchPosition.from(cartesian);
169
- var positionX = scratchPosition.x;
170
- var positionY = scratchPosition.y;
171
- var positionZ = scratchPosition.z;
172
- var oneOverRadiiSquared = this.oneOverRadiiSquared;
173
- var beta = 1.0 / Math.sqrt(positionX * positionX * oneOverRadiiSquared.x + positionY * positionY * oneOverRadiiSquared.y + positionZ * positionZ * oneOverRadiiSquared.z);
174
- return scratchPosition.multiplyScalar(beta).to(result);
175
- }
176
- }, {
177
- key: "transformPositionToScaledSpace",
178
- value: function transformPositionToScaledSpace(position) {
179
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
180
- return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
181
- }
182
- }, {
183
- key: "transformPositionFromScaledSpace",
184
- value: function transformPositionFromScaledSpace(position) {
185
- var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
186
- return scratchPosition.from(position).scale(this.radii).to(result);
187
- }
188
- }, {
189
- key: "getSurfaceNormalIntersectionWithZAxis",
190
- value: function getSurfaceNormalIntersectionWithZAxis(position) {
191
- var buffer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
192
- var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
193
- (0, _core.assert)((0, _core.equals)(this.radii.x, this.radii.y, _core._MathUtils.EPSILON15));
194
- (0, _core.assert)(this.radii.z > 0);
195
- scratchPosition.from(position);
196
- var z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
197
-
198
- if (Math.abs(z) >= this.radii.z - buffer) {
199
- return undefined;
200
- }
201
-
202
- return scratchPosition.set(0.0, 0.0, z).to(result);
203
- }
204
- }]);
205
- return Ellipsoid;
206
- }();
207
-
208
- exports.default = Ellipsoid;
209
- (0, _defineProperty2.default)(Ellipsoid, "WGS84", new Ellipsoid(_constants.WGS84_RADIUS_X, _constants.WGS84_RADIUS_Y, _constants.WGS84_RADIUS_Z));
210
- //# sourceMappingURL=ellipsoid.js.map