@math.gl/geospatial 4.0.0-beta.1 → 4.0.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.
@@ -9,4 +9,3 @@ export declare const WGS84_CONSTANTS: {
9
9
  maximumRadius: number;
10
10
  centerToleranceSquared: number;
11
11
  };
12
- //# sourceMappingURL=constants.d.ts.map
package/dist/constants.js CHANGED
@@ -1,12 +1,22 @@
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
1
3
  export const WGS84_RADIUS_X = 6378137.0;
2
4
  export const WGS84_RADIUS_Y = 6378137.0;
3
5
  export const WGS84_RADIUS_Z = 6356752.3142451793;
6
+ // Pre-calculated ellipsoid defaults to avoid utils depending on `ellipsoid.js`
4
7
  export const WGS84_CONSTANTS = {
5
- radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
6
- radiiSquared: [WGS84_RADIUS_X * WGS84_RADIUS_X, WGS84_RADIUS_Y * WGS84_RADIUS_Y, WGS84_RADIUS_Z * WGS84_RADIUS_Z],
7
- oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],
8
- 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)],
9
- maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
10
- centerToleranceSquared: 1e-1
8
+ radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
9
+ radiiSquared: [
10
+ WGS84_RADIUS_X * WGS84_RADIUS_X,
11
+ WGS84_RADIUS_Y * WGS84_RADIUS_Y,
12
+ WGS84_RADIUS_Z * WGS84_RADIUS_Z
13
+ ],
14
+ oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],
15
+ oneOverRadiiSquared: [
16
+ 1.0 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
17
+ 1.0 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
18
+ 1.0 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
19
+ ],
20
+ maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
21
+ centerToleranceSquared: 1e-1 // EPSILON1;
11
22
  };
12
- //# sourceMappingURL=constants.js.map
@@ -1,5 +1,5 @@
1
1
  import { Vector3, Matrix4, NumericArray } from '@math.gl/core';
2
- import type { AxisDirection } from './helpers/ellipsoid-transform';
2
+ import type { AxisDirection } from "./helpers/ellipsoid-transform.js";
3
3
  /**
4
4
  * A quadratic surface defined in Cartesian coordinates by the equation
5
5
  * `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
@@ -66,4 +66,3 @@ export declare class Ellipsoid {
66
66
  /** Computes a point which is the intersection of the surface normal with the z-axis. */
67
67
  getSurfaceNormalIntersectionWithZAxis(position: number[], buffer?: number, result?: number[]): number[];
68
68
  }
69
- //# sourceMappingURL=ellipsoid.d.ts.map
@@ -1,4 +1,6 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
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
+ /* eslint-disable */
2
4
  import { Vector3, Matrix4, assert, equals, _MathUtils, vec3 } from '@math.gl/core';
3
5
  import { WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z } from "../constants.js";
4
6
  import { fromCartographicToRadians, toCartographicFromRadians } from "../type-utils.js";
@@ -10,143 +12,129 @@ const scratchK = new Vector3();
10
12
  const scratchPosition = new Vector3();
11
13
  const scratchHeight = new Vector3();
12
14
  const scratchCartesian = new Vector3();
15
+ /**
16
+ * A quadratic surface defined in Cartesian coordinates by the equation
17
+ * `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
18
+ * to represent the shape of planetary bodies.
19
+ */
13
20
  export class Ellipsoid {
14
- constructor(x = 0.0, y = 0.0, z = 0.0) {
15
- _defineProperty(this, "radii", void 0);
16
-
17
- _defineProperty(this, "radiiSquared", void 0);
18
-
19
- _defineProperty(this, "radiiToTheFourth", void 0);
20
-
21
- _defineProperty(this, "oneOverRadii", void 0);
22
-
23
- _defineProperty(this, "oneOverRadiiSquared", void 0);
24
-
25
- _defineProperty(this, "minimumRadius", void 0);
26
-
27
- _defineProperty(this, "maximumRadius", void 0);
28
-
29
- _defineProperty(this, "centerToleranceSquared", _MathUtils.EPSILON1);
30
-
31
- _defineProperty(this, "squaredXOverSquaredZ", void 0);
32
-
33
- assert(x >= 0.0);
34
- assert(y >= 0.0);
35
- assert(z >= 0.0);
36
- this.radii = new Vector3(x, y, z);
37
- this.radiiSquared = new Vector3(x * x, y * y, z * z);
38
- this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
39
- this.oneOverRadii = new 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);
40
- this.oneOverRadiiSquared = new 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));
41
- this.minimumRadius = Math.min(x, y, z);
42
- this.maximumRadius = Math.max(x, y, z);
43
-
44
- if (this.radiiSquared.z !== 0) {
45
- this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
21
+ constructor(x = 0.0, y = 0.0, z = 0.0) {
22
+ this.centerToleranceSquared = _MathUtils.EPSILON1;
23
+ assert(x >= 0.0);
24
+ assert(y >= 0.0);
25
+ assert(z >= 0.0);
26
+ this.radii = new Vector3(x, y, z);
27
+ this.radiiSquared = new Vector3(x * x, y * y, z * z);
28
+ this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
29
+ this.oneOverRadii = new 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);
30
+ this.oneOverRadiiSquared = new 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));
31
+ this.minimumRadius = Math.min(x, y, z);
32
+ this.maximumRadius = Math.max(x, y, z);
33
+ if (this.radiiSquared.z !== 0) {
34
+ this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
35
+ }
36
+ Object.freeze(this);
46
37
  }
47
-
48
- Object.freeze(this);
49
- }
50
-
51
- equals(right) {
52
- return this === right || Boolean(right && this.radii.equals(right.radii));
53
- }
54
-
55
- toString() {
56
- return this.radii.toString();
57
- }
58
-
59
- cartographicToCartesian(cartographic, result = [0, 0, 0]) {
60
- const normal = scratchNormal;
61
- const k = scratchK;
62
- const [,, height] = cartographic;
63
- this.geodeticSurfaceNormalCartographic(cartographic, normal);
64
- k.copy(this.radiiSquared).scale(normal);
65
- const gamma = Math.sqrt(normal.dot(k));
66
- k.scale(1 / gamma);
67
- normal.scale(height);
68
- k.add(normal);
69
- return k.to(result);
70
- }
71
-
72
- cartesianToCartographic(cartesian, result = [0, 0, 0]) {
73
- scratchCartesian.from(cartesian);
74
- const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
75
-
76
- if (!point) {
77
- return undefined;
38
+ /** Compares this Ellipsoid against the provided Ellipsoid componentwise */
39
+ equals(right) {
40
+ return this === right || Boolean(right && this.radii.equals(right.radii));
78
41
  }
79
-
80
- const normal = this.geodeticSurfaceNormal(point, scratchNormal);
81
- const h = scratchHeight;
82
- h.copy(scratchCartesian).subtract(point);
83
- const longitude = Math.atan2(normal.y, normal.x);
84
- const latitude = Math.asin(normal.z);
85
- const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
86
- return toCartographicFromRadians([longitude, latitude, height], result);
87
- }
88
-
89
- eastNorthUpToFixedFrame(origin, result = new Matrix4()) {
90
- return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);
91
- }
92
-
93
- localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {
94
- return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
95
- }
96
-
97
- geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
98
- return scratchVector.from(cartesian).normalize().to(result);
99
- }
100
-
101
- geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
102
- const cartographicVectorRadians = fromCartographicToRadians(cartographic);
103
- const longitude = cartographicVectorRadians[0];
104
- const latitude = cartographicVectorRadians[1];
105
- const cosLatitude = Math.cos(latitude);
106
- scratchVector.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude)).normalize();
107
- return scratchVector.to(result);
108
- }
109
-
110
- geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
111
- return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
112
- }
113
-
114
- scaleToGeodeticSurface(cartesian, result) {
115
- return scaleToGeodeticSurface(cartesian, this, result);
116
- }
117
-
118
- scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
119
- scratchPosition.from(cartesian);
120
- const positionX = scratchPosition.x;
121
- const positionY = scratchPosition.y;
122
- const positionZ = scratchPosition.z;
123
- const oneOverRadiiSquared = this.oneOverRadiiSquared;
124
- const beta = 1.0 / Math.sqrt(positionX * positionX * oneOverRadiiSquared.x + positionY * positionY * oneOverRadiiSquared.y + positionZ * positionZ * oneOverRadiiSquared.z);
125
- return scratchPosition.multiplyScalar(beta).to(result);
126
- }
127
-
128
- transformPositionToScaledSpace(position, result = [0, 0, 0]) {
129
- return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
130
- }
131
-
132
- transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
133
- return scratchPosition.from(position).scale(this.radii).to(result);
134
- }
135
-
136
- getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
137
- assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
138
- assert(this.radii.z > 0);
139
- scratchPosition.from(position);
140
- const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
141
-
142
- if (Math.abs(z) >= this.radii.z - buffer) {
143
- return undefined;
42
+ /** Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'. */
43
+ toString() {
44
+ return this.radii.toString();
45
+ }
46
+ cartographicToCartesian(cartographic, result = [0, 0, 0]) {
47
+ const normal = scratchNormal;
48
+ const k = scratchK;
49
+ const [, , height] = cartographic;
50
+ this.geodeticSurfaceNormalCartographic(cartographic, normal);
51
+ k.copy(this.radiiSquared).scale(normal);
52
+ const gamma = Math.sqrt(normal.dot(k));
53
+ k.scale(1 / gamma);
54
+ normal.scale(height);
55
+ k.add(normal);
56
+ return k.to(result);
57
+ }
58
+ cartesianToCartographic(cartesian, result = [0, 0, 0]) {
59
+ scratchCartesian.from(cartesian);
60
+ const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
61
+ if (!point) {
62
+ return undefined;
63
+ }
64
+ const normal = this.geodeticSurfaceNormal(point, scratchNormal);
65
+ const h = scratchHeight;
66
+ h.copy(scratchCartesian).subtract(point);
67
+ const longitude = Math.atan2(normal.y, normal.x);
68
+ const latitude = Math.asin(normal.z);
69
+ const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
70
+ return toCartographicFromRadians([longitude, latitude, height], result);
71
+ }
72
+ eastNorthUpToFixedFrame(origin, result = new Matrix4()) {
73
+ return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);
74
+ }
75
+ // Computes a 4x4 transformation matrix from a reference frame centered at
76
+ // the provided origin to the ellipsoid's fixed reference frame.
77
+ localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {
78
+ return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
79
+ }
80
+ geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
81
+ return scratchVector.from(cartesian).normalize().to(result);
82
+ }
83
+ geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
84
+ const cartographicVectorRadians = fromCartographicToRadians(cartographic);
85
+ const longitude = cartographicVectorRadians[0];
86
+ const latitude = cartographicVectorRadians[1];
87
+ const cosLatitude = Math.cos(latitude);
88
+ scratchVector
89
+ .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))
90
+ .normalize();
91
+ return scratchVector.to(result);
92
+ }
93
+ geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
94
+ return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
95
+ }
96
+ /** Scales the provided Cartesian position along the geodetic surface normal
97
+ * so that it is on the surface of this ellipsoid. If the position is
98
+ * at the center of the ellipsoid, this function returns undefined. */
99
+ scaleToGeodeticSurface(cartesian, result) {
100
+ return scaleToGeodeticSurface(cartesian, this, result);
101
+ }
102
+ /** Scales the provided Cartesian position along the geocentric surface normal
103
+ * so that it is on the surface of this ellipsoid. */
104
+ scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
105
+ scratchPosition.from(cartesian);
106
+ const positionX = scratchPosition.x;
107
+ const positionY = scratchPosition.y;
108
+ const positionZ = scratchPosition.z;
109
+ const oneOverRadiiSquared = this.oneOverRadiiSquared;
110
+ const beta = 1.0 /
111
+ Math.sqrt(positionX * positionX * oneOverRadiiSquared.x +
112
+ positionY * positionY * oneOverRadiiSquared.y +
113
+ positionZ * positionZ * oneOverRadiiSquared.z);
114
+ return scratchPosition.multiplyScalar(beta).to(result);
115
+ }
116
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
117
+ * its components by the result of `Ellipsoid#oneOverRadii` */
118
+ transformPositionToScaledSpace(position, result = [0, 0, 0]) {
119
+ return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
120
+ }
121
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
122
+ * its components by the result of `Ellipsoid#radii`. */
123
+ transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
124
+ return scratchPosition.from(position).scale(this.radii).to(result);
125
+ }
126
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
127
+ getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
128
+ // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)
129
+ assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
130
+ assert(this.radii.z > 0);
131
+ scratchPosition.from(position);
132
+ const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
133
+ if (Math.abs(z) >= this.radii.z - buffer) {
134
+ return undefined;
135
+ }
136
+ return scratchPosition.set(0.0, 0.0, z).to(result);
144
137
  }
145
-
146
- return scratchPosition.set(0.0, 0.0, z).to(result);
147
- }
148
-
149
138
  }
150
-
151
- _defineProperty(Ellipsoid, "WGS84", new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z));
152
- //# sourceMappingURL=ellipsoid.js.map
139
+ /** An Ellipsoid instance initialized to the WGS84 standard. */
140
+ Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
@@ -1,5 +1,4 @@
1
1
  import { NumericArray } from '@math.gl/core';
2
- import type { Ellipsoid } from '../ellipsoid';
3
- export declare type AxisDirection = 'up' | 'down' | 'north' | 'east' | 'south' | 'west';
2
+ import type { Ellipsoid } from "../ellipsoid.js";
3
+ export type AxisDirection = 'up' | 'down' | 'north' | 'east' | 'south' | 'west';
4
4
  export declare function localFrameToFixedFrame(ellipsoid: Ellipsoid, firstAxis: AxisDirection, secondAxis: AxisDirection, thirdAxis: AxisDirection, cartesianOrigin: Readonly<NumericArray>, result: number[]): number[];
5
- //# sourceMappingURL=ellipsoid-transform.d.ts.map
@@ -1,129 +1,124 @@
1
1
  import { Vector3, assert, equals as equalsEpsilon } from '@math.gl/core';
2
2
  const EPSILON14 = 1e-14;
3
3
  const scratchOrigin = new Vector3();
4
+ // Caclulate third axis from given two axii
4
5
  const VECTOR_PRODUCT_LOCAL_FRAME = {
5
- up: {
6
- south: 'east',
7
- north: 'west',
8
- west: 'south',
9
- east: 'north'
10
- },
11
- down: {
12
- south: 'west',
13
- north: 'east',
14
- west: 'north',
15
- east: 'south'
16
- },
17
- south: {
18
- up: 'west',
19
- down: 'east',
20
- west: 'down',
21
- east: 'up'
22
- },
23
- north: {
24
- up: 'east',
25
- down: 'west',
26
- west: 'up',
27
- east: 'down'
28
- },
29
- west: {
30
- up: 'north',
31
- down: 'south',
32
- north: 'down',
33
- south: 'up'
34
- },
35
- east: {
36
- up: 'south',
37
- down: 'north',
38
- north: 'up',
39
- south: 'down'
40
- }
6
+ up: {
7
+ south: 'east',
8
+ north: 'west',
9
+ west: 'south',
10
+ east: 'north'
11
+ },
12
+ down: {
13
+ south: 'west',
14
+ north: 'east',
15
+ west: 'north',
16
+ east: 'south'
17
+ },
18
+ south: {
19
+ up: 'west',
20
+ down: 'east',
21
+ west: 'down',
22
+ east: 'up'
23
+ },
24
+ north: {
25
+ up: 'east',
26
+ down: 'west',
27
+ west: 'up',
28
+ east: 'down'
29
+ },
30
+ west: {
31
+ up: 'north',
32
+ down: 'south',
33
+ north: 'down',
34
+ south: 'up'
35
+ },
36
+ east: {
37
+ up: 'south',
38
+ down: 'north',
39
+ north: 'up',
40
+ south: 'down'
41
+ }
41
42
  };
42
43
  const degeneratePositionLocalFrame = {
43
- north: [-1, 0, 0],
44
- east: [0, 1, 0],
45
- up: [0, 0, 1],
46
- south: [1, 0, 0],
47
- west: [0, -1, 0],
48
- down: [0, 0, -1]
44
+ north: [-1, 0, 0],
45
+ east: [0, 1, 0],
46
+ up: [0, 0, 1],
47
+ south: [1, 0, 0],
48
+ west: [0, -1, 0],
49
+ down: [0, 0, -1]
49
50
  };
50
51
  const scratchAxisVectors = {
51
- east: new Vector3(),
52
- north: new Vector3(),
53
- up: new Vector3(),
54
- west: new Vector3(),
55
- south: new Vector3(),
56
- down: new Vector3()
52
+ east: new Vector3(),
53
+ north: new Vector3(),
54
+ up: new Vector3(),
55
+ west: new Vector3(),
56
+ south: new Vector3(),
57
+ down: new Vector3()
57
58
  };
58
59
  const scratchVector1 = new Vector3();
59
60
  const scratchVector2 = new Vector3();
60
61
  const scratchVector3 = new Vector3();
62
+ // Computes a 4x4 transformation matrix from a reference frame
63
+ // centered at the provided origin to the provided ellipsoid's fixed reference frame.
64
+ // eslint-disable-next-line max-statements, max-params, complexity
61
65
  export function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
62
- const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
63
- assert(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
64
- let firstAxisVector;
65
- let secondAxisVector;
66
- let thirdAxisVector;
67
- const origin = scratchOrigin.copy(cartesianOrigin);
68
- const atPole = equalsEpsilon(origin.x, 0.0, EPSILON14) && equalsEpsilon(origin.y, 0.0, EPSILON14);
69
-
70
- if (atPole) {
71
- const sign = Math.sign(origin.z);
72
- firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
73
-
74
- if (firstAxis !== 'east' && firstAxis !== 'west') {
75
- firstAxisVector.scale(sign);
76
- }
77
-
78
- secondAxisVector = scratchVector2.fromArray(degeneratePositionLocalFrame[secondAxis]);
79
-
80
- if (secondAxis !== 'east' && secondAxis !== 'west') {
81
- secondAxisVector.scale(sign);
66
+ const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
67
+ // firstAxis and secondAxis must be east, north, up, west, south or down.');
68
+ assert(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
69
+ let firstAxisVector;
70
+ let secondAxisVector;
71
+ let thirdAxisVector;
72
+ const origin = scratchOrigin.copy(cartesianOrigin);
73
+ // If x and y are zero, assume origin is at a pole, which is a special case.
74
+ const atPole = equalsEpsilon(origin.x, 0.0, EPSILON14) && equalsEpsilon(origin.y, 0.0, EPSILON14);
75
+ if (atPole) {
76
+ // Look up axis value and adjust
77
+ const sign = Math.sign(origin.z);
78
+ firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
79
+ if (firstAxis !== 'east' && firstAxis !== 'west') {
80
+ firstAxisVector.scale(sign);
81
+ }
82
+ secondAxisVector = scratchVector2.fromArray(degeneratePositionLocalFrame[secondAxis]);
83
+ if (secondAxis !== 'east' && secondAxis !== 'west') {
84
+ secondAxisVector.scale(sign);
85
+ }
86
+ thirdAxisVector = scratchVector3.fromArray(degeneratePositionLocalFrame[thirdAxis]);
87
+ if (thirdAxis !== 'east' && thirdAxis !== 'west') {
88
+ thirdAxisVector.scale(sign);
89
+ }
82
90
  }
83
-
84
- thirdAxisVector = scratchVector3.fromArray(degeneratePositionLocalFrame[thirdAxis]);
85
-
86
- if (thirdAxis !== 'east' && thirdAxis !== 'west') {
87
- thirdAxisVector.scale(sign);
91
+ else {
92
+ // Calculate all axis
93
+ const { up, east, north } = scratchAxisVectors;
94
+ east.set(-origin.y, origin.x, 0.0).normalize();
95
+ ellipsoid.geodeticSurfaceNormal(origin, up);
96
+ north.copy(up).cross(east);
97
+ const { down, west, south } = scratchAxisVectors;
98
+ down.copy(up).scale(-1);
99
+ west.copy(east).scale(-1);
100
+ south.copy(north).scale(-1);
101
+ // Pick three axis based on desired orientation
102
+ firstAxisVector = scratchAxisVectors[firstAxis];
103
+ secondAxisVector = scratchAxisVectors[secondAxis];
104
+ thirdAxisVector = scratchAxisVectors[thirdAxis];
88
105
  }
89
- } else {
90
- const {
91
- up,
92
- east,
93
- north
94
- } = scratchAxisVectors;
95
- east.set(-origin.y, origin.x, 0.0).normalize();
96
- ellipsoid.geodeticSurfaceNormal(origin, up);
97
- north.copy(up).cross(east);
98
- const {
99
- down,
100
- west,
101
- south
102
- } = scratchAxisVectors;
103
- down.copy(up).scale(-1);
104
- west.copy(east).scale(-1);
105
- south.copy(north).scale(-1);
106
- firstAxisVector = scratchAxisVectors[firstAxis];
107
- secondAxisVector = scratchAxisVectors[secondAxis];
108
- thirdAxisVector = scratchAxisVectors[thirdAxis];
109
- }
110
-
111
- result[0] = firstAxisVector.x;
112
- result[1] = firstAxisVector.y;
113
- result[2] = firstAxisVector.z;
114
- result[3] = 0.0;
115
- result[4] = secondAxisVector.x;
116
- result[5] = secondAxisVector.y;
117
- result[6] = secondAxisVector.z;
118
- result[7] = 0.0;
119
- result[8] = thirdAxisVector.x;
120
- result[9] = thirdAxisVector.y;
121
- result[10] = thirdAxisVector.z;
122
- result[11] = 0.0;
123
- result[12] = origin.x;
124
- result[13] = origin.y;
125
- result[14] = origin.z;
126
- result[15] = 1.0;
127
- return result;
106
+ // TODO - assuming the result is column-major
107
+ result[0] = firstAxisVector.x;
108
+ result[1] = firstAxisVector.y;
109
+ result[2] = firstAxisVector.z;
110
+ result[3] = 0.0;
111
+ result[4] = secondAxisVector.x;
112
+ result[5] = secondAxisVector.y;
113
+ result[6] = secondAxisVector.z;
114
+ result[7] = 0.0;
115
+ result[8] = thirdAxisVector.x;
116
+ result[9] = thirdAxisVector.y;
117
+ result[10] = thirdAxisVector.z;
118
+ result[11] = 0.0;
119
+ result[12] = origin.x;
120
+ result[13] = origin.y;
121
+ result[14] = origin.z;
122
+ result[15] = 1.0;
123
+ return result;
128
124
  }
129
- //# sourceMappingURL=ellipsoid-transform.js.map
@@ -1,3 +1,2 @@
1
- import type { Ellipsoid } from '../ellipsoid';
1
+ import type { Ellipsoid } from "../ellipsoid.js";
2
2
  export declare function scaleToGeodeticSurface(cartesian: number[], ellipsoid: Ellipsoid, result?: number[]): number[];
3
- //# sourceMappingURL=scale-to-geodetic-surface.d.ts.map