🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@math.gl/geospatial

Package Overview
Dependencies
Maintainers
2
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@math.gl/geospatial - npm Package Compare versions

Comparing version
3.0.0-alpha.4
to
3.0.0-alpha.5
+5
-3
dist/es5/ellipsoid/ellipsoid.js

@@ -35,2 +35,3 @@ "use strict";

var scratchHeight = new _math.Vector3();
var scratchCartesian = new _math.Vector3();
var wgs84;

@@ -103,3 +104,4 @@

var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
var point = this.scaleToGeodeticSurface(cartesian, scratchPosition);
scratchCartesian.from(cartesian);
var point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);

@@ -112,6 +114,6 @@ if (!point) {

var h = scratchHeight;
h.copy(cartesian).subtract(point);
h.copy(scratchCartesian).subtract(point);
var longitude = Math.atan2(normal.y, normal.x);
var latitude = Math.asin(normal.z);
var height = Math.sign(vec3.dot(h, cartesian)) * vec3.length(h);
var height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
return (0, _typeUtils.toCartographicFromRadians)([longitude, latitude, height], result);

@@ -118,0 +120,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../../src/ellipsoid/ellipsoid.js"],"names":["scratchVector","Vector3","scratchNormal","scratchK","scratchPosition","scratchHeight","wgs84","Ellipsoid","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","x","y","z","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","centerToleranceSquared","_MathUtils","EPSILON1","squaredXOverSquaredZ","Object","freeze","right","Boolean","equals","toString","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesian","point","scaleToGeodeticSurface","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","vec3","length","origin","Matrix4","firstAxis","secondAxis","thirdAxis","from","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","positionX","positionY","positionZ","beta","multiplyScalar","position","buffer","EPSILON15","abs"],"mappings":";;;;;;;;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AACA,IAAME,QAAQ,GAAG,IAAIF,aAAJ,EAAjB;AACA,IAAMG,eAAe,GAAG,IAAIH,aAAJ,EAAxB;AACA,IAAMI,aAAa,GAAG,IAAIJ,aAAJ,EAAtB;AAEA,IAAIK,KAAJ;;IAKqBC,S;;;wBAEA;AACjBD,MAAAA,KAAK,GAAGA,KAAK,IAAI,IAAIC,SAAJ,CAAcC,yBAAd,EAA8BC,yBAA9B,EAA8CC,yBAA9C,CAAjB;AACA,aAAOJ,KAAP;AACD;;;AAGD,uBAAuC;AAAA,QAA3BK,CAA2B,uEAAvB,GAAuB;AAAA,QAAlBC,CAAkB,uEAAd,GAAc;AAAA,QAATC,CAAS,uEAAL,GAAK;AAAA;AACrC,sBAAOF,CAAC,IAAI,GAAZ;AACA,sBAAOC,CAAC,IAAI,GAAZ;AACA,sBAAOC,CAAC,IAAI,GAAZ;AAEA,SAAKC,KAAL,GAAa,IAAIb,aAAJ,CAAYU,CAAZ,EAAeC,CAAf,EAAkBC,CAAlB,CAAb;AAEA,SAAKE,YAAL,GAAoB,IAAId,aAAJ,CAAYU,CAAC,GAAGA,CAAhB,EAAmBC,CAAC,GAAGA,CAAvB,EAA0BC,CAAC,GAAGA,CAA9B,CAApB;AAEA,SAAKG,gBAAL,GAAwB,IAAIf,aAAJ,CAAYU,CAAC,GAAGA,CAAJ,GAAQA,CAAR,GAAYA,CAAxB,EAA2BC,CAAC,GAAGA,CAAJ,GAAQA,CAAR,GAAYA,CAAvC,EAA0CC,CAAC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;;mDAI8B2C,Q,EAA8B;AAAA,UAApB3C,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAC3D,aAAO/B,eAAe,CACnB8D,IADI,CACCY,QADD,EAEJrC,KAFI,CAEE,KAAKxB,YAFP,EAGJ6B,EAHI,CAGDX,MAHC,CAAP;AAID;;;qDAIgC2C,Q,EAA8B;AAAA,UAApB3C,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAC7D,aAAO/B,eAAe,CACnB8D,IADI,CACCY,QADD,EAEJrC,KAFI,CAEE,KAAK3B,KAFP,EAGJgC,EAHI,CAGDX,MAHC,CAAP;AAID;;;0DAGqC2C,Q,EAA4C;AAAA,UAAlCC,MAAkC,uEAAzB,GAAyB;AAAA,UAApB5C,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAEhF,wBAAO,kBAAO,KAAKrB,KAAL,CAAWH,CAAlB,EAAqB,KAAKG,KAAL,CAAWF,CAAhC,EAAmCa,iBAAWuD,SAA9C,CAAP;AACA,wBAAO,KAAKlE,KAAL,CAAWD,CAAX,GAAe,CAAtB;AAEAT,MAAAA,eAAe,CAAC8D,IAAhB,CAAqBY,QAArB;AACA,UAAMjE,CAAC,GAAGT,eAAe,CAACS,CAAhB,IAAqB,IAAI,KAAKc,oBAA9B,CAAV;;AAEA,UAAIP,IAAI,CAAC6D,GAAL,CAASpE,CAAT,KAAe,KAAKC,KAAL,CAAWD,CAAX,GAAekE,MAAlC,EAA0C;AACxC,eAAO7B,SAAP;AACD;;AAED,aAAO9C,eAAe,CAACmE,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8B1D,CAA9B,EAAiCiC,EAAjC,CAAoCX,MAApC,CAAP;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\n/* eslint-disable */\nimport {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from 'math.gl';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\n\nlet wgs84;\n\n// A quadratic surface defined in Cartesian coordinates by the equation\n// <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used\n// to represent the shape of planetary bodies.\nexport default class Ellipsoid {\n // An Ellipsoid instance initialized to the WGS84 standard.\n static get WGS84() {\n wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n return wgs84;\n }\n\n // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n this.centerToleranceSquared = _MathUtils.EPSILON1;\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n equals(right) {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n toString() {\n return this.radii.toString();\n }\n\n // Converts the provided cartographic to Cartesian representation.\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n // Converts the provided cartesian to cartographic (lng/lat/z) representation.\n // The cartesian is undefined at the center of the ellipsoid.\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n const point = this.scaleToGeodeticSurface(cartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(cartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, cartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n // centered at the provided origin to the provided ellipsoid's fixed reference frame.\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n // Computes the unit vector directed from the center of this ellipsoid toward\n // the provided Cartesian position.\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .normalize()\n .to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .scale(this.oneOverRadiiSquared)\n .normalize()\n .to(result);\n }\n\n // Scales the provided Cartesian position along the geodetic surface normal\n // so that it is on the surface of this ellipsoid. If the position is\n // at the center of the ellipsoid, this function returns undefined.\n scaleToGeodeticSurface(cartesian, result) {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n // Scales the provided Cartesian position along the geocentric surface normal\n // so that it is on the surface of this ellipsoid.\n scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#oneOverRadii`\n transformPositionToScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.oneOverRadii)\n .to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#radii`.\n transformPositionFromScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.radii)\n .to(result);\n }\n\n // Computes a point which is the intersection of the surface normal with the z-axis.\n getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}
{"version":3,"sources":["../../../src/ellipsoid/ellipsoid.js"],"names":["scratchVector","Vector3","scratchNormal","scratchK","scratchPosition","scratchHeight","scratchCartesian","wgs84","Ellipsoid","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","x","y","z","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","centerToleranceSquared","_MathUtils","EPSILON1","squaredXOverSquaredZ","Object","freeze","right","Boolean","equals","toString","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesian","from","point","scaleToGeodeticSurface","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","vec3","length","origin","Matrix4","firstAxis","secondAxis","thirdAxis","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","positionX","positionY","positionZ","beta","multiplyScalar","position","buffer","EPSILON15","abs"],"mappings":";;;;;;;;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,a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AEJrC,KAFI,CAEE,KAAKxB,YAFP,EAGJ6B,EAHI,CAGDX,MAHC,CAAP;AAID;;;qDAIgC2C,Q,EAA8B;AAAA,UAApB3C,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAC7D,aAAOhC,eAAe,CACnB6C,IADI,CACC8B,QADD,EAEJrC,KAFI,CAEE,KAAK3B,KAFP,EAGJgC,EAHI,CAGDX,MAHC,CAAP;AAID;;;0DAGqC2C,Q,EAA4C;AAAA,UAAlCC,MAAkC,uEAAzB,GAAyB;AAAA,UAApB5C,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAEhF,wBAAO,kBAAO,KAAKrB,KAAL,CAAWH,CAAlB,EAAqB,KAAKG,KAAL,CAAWF,CAAhC,EAAmCa,iBAAWuD,SAA9C,CAAP;AACA,wBAAO,KAAKlE,KAAL,CAAWD,CAAX,GAAe,CAAtB;AAEAV,MAAAA,eAAe,CAAC6C,IAAhB,CAAqB8B,QAArB;AACA,UAAMjE,CAAC,GAAGV,eAAe,CAACU,CAAhB,IAAqB,IAAI,KAAKc,oBAA9B,CAAV;;AAEA,UAAIP,IAAI,CAAC6D,GAAL,CAASpE,CAAT,KAAe,KAAKC,KAAL,CAAWD,CAAX,GAAekE,MAAlC,EAA0C;AACxC,eAAO5B,SAAP;AACD;;AAED,aAAOhD,eAAe,CAACoE,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8B1D,CAA9B,EAAiCiC,EAAjC,CAAoCX,MAApC,CAAP;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\n/* eslint-disable */\nimport {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from 'math.gl';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\nconst scratchCartesian = new Vector3();\n\nlet wgs84;\n\n// A quadratic surface defined in Cartesian coordinates by the equation\n// <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used\n// to represent the shape of planetary bodies.\nexport default class Ellipsoid {\n // An Ellipsoid instance initialized to the WGS84 standard.\n static get WGS84() {\n wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n return wgs84;\n }\n\n // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n this.centerToleranceSquared = _MathUtils.EPSILON1;\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n equals(right) {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n toString() {\n return this.radii.toString();\n }\n\n // Converts the provided cartographic to Cartesian representation.\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n // Converts the provided cartesian to cartographic (lng/lat/z) representation.\n // The cartesian is undefined at the center of the ellipsoid.\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n scratchCartesian.from(cartesian);\n const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(scratchCartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n // centered at the provided origin to the provided ellipsoid's fixed reference frame.\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n // Computes the unit vector directed from the center of this ellipsoid toward\n // the provided Cartesian position.\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .normalize()\n .to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .scale(this.oneOverRadiiSquared)\n .normalize()\n .to(result);\n }\n\n // Scales the provided Cartesian position along the geodetic surface normal\n // so that it is on the surface of this ellipsoid. If the position is\n // at the center of the ellipsoid, this function returns undefined.\n scaleToGeodeticSurface(cartesian, result) {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n // Scales the provided Cartesian position along the geocentric surface normal\n // so that it is on the surface of this ellipsoid.\n scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#oneOverRadii`\n transformPositionToScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.oneOverRadii)\n .to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#radii`.\n transformPositionFromScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.radii)\n .to(result);\n }\n\n // Computes a point which is the intersection of the surface normal with the z-axis.\n getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}

@@ -12,2 +12,3 @@ import { Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils } from 'math.gl';

const scratchHeight = new Vector3();
const scratchCartesian = new Vector3();
let wgs84;

@@ -67,3 +68,4 @@ export default class Ellipsoid {

let result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
const point = this.scaleToGeodeticSurface(cartesian, scratchPosition);
scratchCartesian.from(cartesian);
const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);

@@ -76,6 +78,6 @@ if (!point) {

const h = scratchHeight;
h.copy(cartesian).subtract(point);
h.copy(scratchCartesian).subtract(point);
const longitude = Math.atan2(normal.y, normal.x);
const latitude = Math.asin(normal.z);
const height = Math.sign(vec3.dot(h, cartesian)) * vec3.length(h);
const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
return toCartographicFromRadians([longitude, latitude, height], result);

@@ -82,0 +84,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../../src/ellipsoid/ellipsoid.js"],"names":["Vector3","Matrix4","toRadians","toDegrees","assert","equals","_MathUtils","vec3","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","fromCartographicToRadians","toCartographicFromRadians","scaleToGeodeticSurface","localFrameToFixedFrame","scratchVector","scratchNormal","scratchK","scratchPosition","scratchHeight","wgs84","Ellipsoid","WGS84","constructor","x","y","z","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","centerToleranceSquared","EPSILON1","squaredXOverSquaredZ","Object","freeze","right","Boolean","toString","cartographicToCartesian","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesianToCartographic","cartesian","point","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","length","eastNorthUpToFixedFrame","origin","firstAxis","secondAxis","thirdAxis","geocentricSurfaceNormal","from","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","scaleToGeocentricSurface","positionX","positionY","positionZ","beta","multiplyScalar","transformPositionToScaledSpace","position","transformPositionFromScaledSpace","getSurfaceNormalIntersectionWithZAxis","buffer","EPSILON15","abs"],"mappings":"AAIA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,SAA1B,EAAqCC,SAArC,EAAgDC,MAAhD,EAAwDC,MAAxD,EAAgEC,UAAhE,QAAiF,SAAjF;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAEA,SAAQC,cAAR,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA6D,cAA7D;AACA,SAAQC,yBAAR,EAAmCC,yBAAnC,QAAmE,eAAnE;AAEA,OAAOC,sBAAP,MAAmC,qCAAnC;AACA,OAAOC,sBAAP,MAAmC,+BAAnC;AAEA,MAAMC,aAAa,GAAG,IAAIf,OAAJ,EAAtB;AACA,MAAMgB,aAAa,GAAG,IAAIhB,OAAJ,EAAtB;AACA,MAAMiB,QAAQ,GAAG,IAAIjB,OAAJ,EAAjB;AACA,MAAMkB,eAAe,GAAG,IAAIlB,OAAJ,EAAxB;AACA,MAAMmB,aAAa,GAAG,IAAInB,OAAJ,EAAtB;AAEA,IAAIoB,KAAJ;AAKA,eAAe,MA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C,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAC3D,WAAO7B,eAAe,CACnB4D,IADI,CACCc,QADD,EAEJvC,KAFI,CAEE,KAAKvB,YAFP,EAGJ4B,EAHI,CAGDX,MAHC,CAAP;AAID;;AAID8C,EAAAA,gCAAgC,CAACD,QAAD,EAA+B;AAAA,QAApB7C,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAC7D,WAAO7B,eAAe,CACnB4D,IADI,CACCc,QADD,EAEJvC,KAFI,CAEE,KAAK1B,KAFP,EAGJ+B,EAHI,CAGDX,MAHC,CAAP;AAID;;AAGD+C,EAAAA,qCAAqC,CAACF,QAAD,EAA6C;AAAA,QAAlCG,MAAkC,uEAAzB,GAAyB;AAAA,QAApBhD,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAEhF3C,IAAAA,MAAM,CAACC,MAAM,CAAC,KAAKsB,KAAL,CAAWH,CAAZ,EAAe,KAAKG,KAAL,CAAWF,CAA1B,EAA6BnB,UAAU,CAAC0F,SAAxC,CAAP,CAAN;AACA5F,IAAAA,MAAM,CAAC,KAAKuB,KAAL,CAAWD,CAAX,GAAe,CAAhB,CAAN;AAEAR,IAAAA,eAAe,CAAC4D,IAAhB,CAAqBc,QAArB;AACA,UAAMlE,CAAC,GAAGR,eAAe,CAACQ,CAAhB,IAAqB,IAAI,KAAKa,oBAA9B,CAAV;;AAEA,QAAIN,IAAI,CAACgE,GAAL,CAASvE,CAAT,KAAe,KAAKC,KAAL,CAAWD,CAAX,GAAeqE,MAAlC,EAA0C;AACxC,aAAOjC,SAAP;AACD;;AAED,WAAO5C,eAAe,CAACiE,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8BzD,CAA9B,EAAiCgC,EAAjC,CAAoCX,MAApC,CAAP;AACD;;AAxM4B","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\n/* eslint-disable */\nimport {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from 'math.gl';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\n\nlet wgs84;\n\n// A quadratic surface defined in Cartesian coordinates by the equation\n// <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used\n// to represent the shape of planetary bodies.\nexport default class Ellipsoid {\n // An Ellipsoid instance initialized to the WGS84 standard.\n static get WGS84() {\n wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n return wgs84;\n }\n\n // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n this.centerToleranceSquared = _MathUtils.EPSILON1;\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n equals(right) {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n toString() {\n return this.radii.toString();\n }\n\n // Converts the provided cartographic to Cartesian representation.\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n // Converts the provided cartesian to cartographic (lng/lat/z) representation.\n // The cartesian is undefined at the center of the ellipsoid.\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n const point = this.scaleToGeodeticSurface(cartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(cartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, cartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n // centered at the provided origin to the provided ellipsoid's fixed reference frame.\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n // Computes the unit vector directed from the center of this ellipsoid toward\n // the provided Cartesian position.\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .normalize()\n .to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .scale(this.oneOverRadiiSquared)\n .normalize()\n .to(result);\n }\n\n // Scales the provided Cartesian position along the geodetic surface normal\n // so that it is on the surface of this ellipsoid. If the position is\n // at the center of the ellipsoid, this function returns undefined.\n scaleToGeodeticSurface(cartesian, result) {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n // Scales the provided Cartesian position along the geocentric surface normal\n // so that it is on the surface of this ellipsoid.\n scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#oneOverRadii`\n transformPositionToScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.oneOverRadii)\n .to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#radii`.\n transformPositionFromScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.radii)\n .to(result);\n }\n\n // Computes a point which is the intersection of the surface normal with the z-axis.\n getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}
{"version":3,"sources":["../../../src/ellipsoid/ellipsoid.js"],"names":["Vector3","Matrix4","toRadians","toDegrees","assert","equals","_MathUtils","vec3","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","fromCartographicToRadians","toCartographicFromRadians","scaleToGeodeticSurface","localFrameToFixedFrame","scratchVector","scratchNormal","scratchK","scratchPosition","scratchHeight","scratchCartesian","wgs84","Ellipsoid","WGS84","constructor","x","y","z","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","centerToleranceSquared","EPSILON1","squaredXOverSquaredZ","Object","freeze","right","Boolean","toString","cartographicToCartesian","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesianToCartographic","cartesian","from","point","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","length","eastNorthUpToFixedFrame","origin","firstAxis","secondAxis","thirdAxis","geocentricSurfaceNormal","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","scaleToGeocentricSurface","positionX","positionY","positionZ","beta","multiplyScalar","transformPositionToScaledSpace","position","transformPositionFromScaledSpace","getSurfaceNormalIntersectionWithZAxis","buffer","EPSILON15","abs"],"mappings":"AAIA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,SAA1B,EAAqCC,SAArC,EAAgDC,MAAhD,EAAwDC,MAAxD,EAAgEC,UAAhE,QAAiF,SAAjF;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAEA,SAAQC,cAAR,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA6D,cAA7D;AACA,SAAQC,yBAAR,EAAmCC,yBAAnC,QAAmE,eAAnE;AAEA,OAAOC,sBAAP,MAAmC,qCAAnC;AACA,OAAOC,sBAAP,MAAmC,+BAAnC;AAEA,MAAMC,aAAa,GAAG,IAAIf,OAAJ,EAAtB;AACA,MAAMgB,aAAa,GAAG,IAAIhB,OAAJ,EAAtB;AACA,MAAMiB,QAAQ,GAAG,IAAIjB,OAAJ,EAAjB;AACA,MAAMkB,eAAe,GAAG,IAAIlB,OAAJ,EAAxB;AACA,MAAMmB,aAAa,GAAG,IAAInB,OAAJ,EAAtB;AACA,MAAMoB,gBAAgB,GAAG,IAAIpB,OAAJ,EAAzB;AAEA,IAAIqB,KAAJ;AAKA,eAAe,MAAMC,SAAN,CAAgB;AAE7B,aAAWC,KAAX,GAAmB;AACjBF,IAAAA,KAAK,GAAGA,KAAK,IAAI,IAAIC,SAAJ,CAAcd,cAAd,EAA8BC,cAA9B,EAA8CC,cAA9C,CAAjB;AACA,WAAOW,KAAP;AACD;;AAGDG,EAAAA,WAAW,GAA4B;AAAA,QAA3BC,CAA2B,uEAAvB,GAAuB;AAAA,QAAlBC,CAAkB,uEAAd,GAAc;AAAA,QAATC,CAAS,uEAAL,GAAK;AACrCvB,IAAAA,MAAM,CAACqB,CAAC,IAAI,GAAN,CAAN;AACArB,IAAAA,MAAM,CAACsB,CAAC,IAAI,G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KAFP,EAGJ+B,EAHI,CAGDX,MAHC,CAAP;AAID;;AAGD+C,EAAAA,qCAAqC,CAACF,QAAD,EAA6C;AAAA,QAAlCG,MAAkC,uEAAzB,GAAyB;AAAA,QAApBhD,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAEhF5C,IAAAA,MAAM,CAACC,MAAM,CAAC,KAAKuB,KAAL,CAAWH,CAAZ,EAAe,KAAKG,KAAL,CAAWF,CAA1B,EAA6BpB,UAAU,CAAC2F,SAAxC,CAAP,CAAN;AACA7F,IAAAA,MAAM,CAAC,KAAKwB,KAAL,CAAWD,CAAX,GAAe,CAAhB,CAAN;AAEAT,IAAAA,eAAe,CAAC4C,IAAhB,CAAqB+B,QAArB;AACA,UAAMlE,CAAC,GAAGT,eAAe,CAACS,CAAhB,IAAqB,IAAI,KAAKa,oBAA9B,CAAV;;AAEA,QAAIN,IAAI,CAACgE,GAAL,CAASvE,CAAT,KAAe,KAAKC,KAAL,CAAWD,CAAX,GAAeqE,MAAlC,EAA0C;AACxC,aAAOhC,SAAP;AACD;;AAED,WAAO9C,eAAe,CAACkE,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8BzD,CAA9B,EAAiCgC,EAAjC,CAAoCX,MAApC,CAAP;AACD;;AAzM4B","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\n/* eslint-disable */\nimport {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from 'math.gl';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\nconst scratchCartesian = new Vector3();\n\nlet wgs84;\n\n// A quadratic surface defined in Cartesian coordinates by the equation\n// <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used\n// to represent the shape of planetary bodies.\nexport default class Ellipsoid {\n // An Ellipsoid instance initialized to the WGS84 standard.\n static get WGS84() {\n wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n return wgs84;\n }\n\n // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n this.centerToleranceSquared = _MathUtils.EPSILON1;\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n equals(right) {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n toString() {\n return this.radii.toString();\n }\n\n // Converts the provided cartographic to Cartesian representation.\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n // Converts the provided cartesian to cartographic (lng/lat/z) representation.\n // The cartesian is undefined at the center of the ellipsoid.\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n scratchCartesian.from(cartesian);\n const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(scratchCartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n // centered at the provided origin to the provided ellipsoid's fixed reference frame.\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n // Computes the unit vector directed from the center of this ellipsoid toward\n // the provided Cartesian position.\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .normalize()\n .to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .scale(this.oneOverRadiiSquared)\n .normalize()\n .to(result);\n }\n\n // Scales the provided Cartesian position along the geodetic surface normal\n // so that it is on the surface of this ellipsoid. If the position is\n // at the center of the ellipsoid, this function returns undefined.\n scaleToGeodeticSurface(cartesian, result) {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n // Scales the provided Cartesian position along the geocentric surface normal\n // so that it is on the surface of this ellipsoid.\n scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#oneOverRadii`\n transformPositionToScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.oneOverRadii)\n .to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#radii`.\n transformPositionFromScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.radii)\n .to(result);\n }\n\n // Computes a point which is the intersection of the surface normal with the z-axis.\n getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}

@@ -15,2 +15,3 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";

var scratchHeight = new Vector3();
var scratchCartesian = new Vector3();
var wgs84;

@@ -85,3 +86,4 @@

var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
var point = this.scaleToGeodeticSurface(cartesian, scratchPosition);
scratchCartesian.from(cartesian);
var point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);

@@ -94,6 +96,6 @@ if (!point) {

var h = scratchHeight;
h.copy(cartesian).subtract(point);
h.copy(scratchCartesian).subtract(point);
var longitude = Math.atan2(normal.y, normal.x);
var latitude = Math.asin(normal.z);
var height = Math.sign(vec3.dot(h, cartesian)) * vec3.length(h);
var height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
return toCartographicFromRadians([longitude, latitude, height], result);

@@ -100,0 +102,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"sources":["../../../src/ellipsoid/ellipsoid.js"],"names":["Vector3","Matrix4","toRadians","toDegrees","assert","equals","_MathUtils","vec3","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","fromCartographicToRadians","toCartographicFromRadians","scaleToGeodeticSurface","localFrameToFixedFrame","scratchVector","scratchNormal","scratchK","scratchPosition","scratchHeight","wgs84","Ellipsoid","x","y","z","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","centerToleranceSquared","EPSILON1","squaredXOverSquaredZ","Object","freeze","right","Boolean","toString","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesian","point","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","length","origin","firstAxis","secondAxis","thirdAxis","from","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","positionX","positionY","positionZ","beta","multiplyScalar","position","buffer","EPSILON15","abs"],"mappings":";;;AAIA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,SAA1B,EAAqCC,SAArC,EAAgDC,MAAhD,EAAwDC,MAAxD,EAAgEC,UAAhE,QAAiF,SAAjF;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAEA,SAAQC,cAAR,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA6D,cAA7D;AACA,SAAQC,yBAAR,EAAmCC,yBAAnC,QAAmE,eAAnE;AAEA,OAAOC,uBAAP,MAAmC,qCAAnC;AACA,OAAOC,uBAAP,MAAmC,+BAAnC;AAEA,IAAMC,aAAa,GAAG,IAAIf,OAAJ,EAAtB;AACA,IAAMgB,aAAa,GAAG,IAAIhB,OAAJ,EAAtB;AACA,IAAMiB,QAAQ,GAAG,IAAIjB,OAAJ,EAAjB;AACA,IAAMkB,eAAe,GAAG,IAAIlB,OAAJ,EAAxB;AACA,IAAMmB,aAAa,GAAG,IAAInB,OAAJ,EAAtB;AAEA,IAAIoB,KAAJ;;IAKqBC,S;;;wBAEA;AACjBD,MAAAA,KAAK,GAAGA,KAAK,IAAI,IAAIC,SAAJ,CAAcb,cAAd,EAA8BC,cAA9B,EAA8CC,cAA9C,CAAjB;AACA,aAAOU,KAAP;AACD;;;AAGD,uBAAuC;AAAA,QAA3BE,CAA2B,uEAAvB,GAAuB;AAAA,QAAlBC,CAAkB,uEAAd,GAAc;AAAA,QAATC,CAAS,uEAAL,GAAK;;AAAA;;AACrCpB,IAAAA,MAAM,CAACkB,CAAC,IAAI,GAAN,CAAN;AACAlB,IAAAA,M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,CAAN;AACAlF,MAAAA,MAAM,CAAC,KAAKqB,KAAL,CAAWD,CAAX,GAAe,CAAhB,CAAN;AAEAN,MAAAA,eAAe,CAACsD,IAAhB,CAAqBY,QAArB;AACA,UAAM5D,CAAC,GAAGN,eAAe,CAACM,CAAhB,IAAqB,IAAI,KAAKa,oBAA9B,CAAV;;AAEA,UAAIN,IAAI,CAACwD,GAAL,CAAS/D,CAAT,KAAe,KAAKC,KAAL,CAAWD,CAAX,GAAe6D,MAAlC,EAA0C;AACxC,eAAO3B,SAAP;AACD;;AAED,aAAOxC,eAAe,CAAC2D,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8BrD,CAA9B,EAAiC+B,EAAjC,CAAoCX,MAApC,CAAP;AACD;;;;;;SAxMkBvB,S","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\n/* eslint-disable */\nimport {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from 'math.gl';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\n\nlet wgs84;\n\n// A quadratic surface defined in Cartesian coordinates by the equation\n// <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used\n// to represent the shape of planetary bodies.\nexport default class Ellipsoid {\n // An Ellipsoid instance initialized to the WGS84 standard.\n static get WGS84() {\n wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n return wgs84;\n }\n\n // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n this.centerToleranceSquared = _MathUtils.EPSILON1;\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n equals(right) {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n toString() {\n return this.radii.toString();\n }\n\n // Converts the provided cartographic to Cartesian representation.\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n // Converts the provided cartesian to cartographic (lng/lat/z) representation.\n // The cartesian is undefined at the center of the ellipsoid.\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n const point = this.scaleToGeodeticSurface(cartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(cartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, cartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n // centered at the provided origin to the provided ellipsoid's fixed reference frame.\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n // Computes the unit vector directed from the center of this ellipsoid toward\n // the provided Cartesian position.\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .normalize()\n .to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .scale(this.oneOverRadiiSquared)\n .normalize()\n .to(result);\n }\n\n // Scales the provided Cartesian position along the geodetic surface normal\n // so that it is on the surface of this ellipsoid. If the position is\n // at the center of the ellipsoid, this function returns undefined.\n scaleToGeodeticSurface(cartesian, result) {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n // Scales the provided Cartesian position along the geocentric surface normal\n // so that it is on the surface of this ellipsoid.\n scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#oneOverRadii`\n transformPositionToScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.oneOverRadii)\n .to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#radii`.\n transformPositionFromScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.radii)\n .to(result);\n }\n\n // Computes a point which is the intersection of the surface normal with the z-axis.\n getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}
{"version":3,"sources":["../../../src/ellipsoid/ellipsoid.js"],"names":["Vector3","Matrix4","toRadians","toDegrees","assert","equals","_MathUtils","vec3","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","fromCartographicToRadians","toCartographicFromRadians","scaleToGeodeticSurface","localFrameToFixedFrame","scratchVector","scratchNormal","scratchK","scratchPosition","scratchHeight","scratchCartesian","wgs84","Ellipsoid","x","y","z","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","centerToleranceSquared","EPSILON1","squaredXOverSquaredZ","Object","freeze","right","Boolean","toString","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesian","from","point","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","length","origin","firstAxis","secondAxis","thirdAxis","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","positionX","positionY","positionZ","beta","multiplyScalar","position","buffer","EPSILON15","abs"],"mappings":";;;AAIA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,SAA1B,EAAqCC,SAArC,EAAgDC,MAAhD,EAAwDC,MAAxD,EAAgEC,UAAhE,QAAiF,SAAjF;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAEA,SAAQC,cAAR,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA6D,cAA7D;AACA,SAAQC,yBAAR,EAAmCC,yBAAnC,QAAmE,eAAnE;AAEA,OAAOC,uBAAP,MAAmC,qCAAnC;AACA,OAAOC,uBAAP,MAAmC,+BAAnC;AAEA,IAAMC,aAAa,GAAG,IAAIf,OAAJ,EAAtB;AACA,IAAMgB,aAAa,GAAG,IAAIhB,OAAJ,EAAtB;AACA,IAAMiB,QAAQ,GAAG,IAAIjB,OAAJ,EAAjB;AACA,IAAMkB,eAAe,GAAG,IAAIlB,OAAJ,EAAxB;AACA,IAAMmB,aAAa,GAAG,IAAInB,OAAJ,EAAtB;AACA,IAAMoB,gBAAgB,GAAG,IAAIpB,OAAJ,EAAzB;AAEA,IAAIqB,KAAJ;;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CAAP,CAAW;AAC7D,aAAO3B,eAAe,CACnBwC,IADI,CACC2B,QADD,EAEJlC,KAFI,CAEE,KAAKzB,KAFP,EAGJ8B,EAHI,CAGDX,MAHC,CAAP;AAID;;;0DAGqCwC,Q,EAA4C;AAAA,UAAlCC,MAAkC,uEAAzB,GAAyB;AAAA,UAApBzC,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAEhFzC,MAAAA,MAAM,CAACC,MAAM,CAAC,KAAKqB,KAAL,CAAWH,CAAZ,EAAe,KAAKG,KAAL,CAAWF,CAA1B,EAA6BlB,UAAU,CAACiF,SAAxC,CAAP,CAAN;AACAnF,MAAAA,MAAM,CAAC,KAAKsB,KAAL,CAAWD,CAAX,GAAe,CAAhB,CAAN;AAEAP,MAAAA,eAAe,CAACwC,IAAhB,CAAqB2B,QAArB;AACA,UAAM5D,CAAC,GAAGP,eAAe,CAACO,CAAhB,IAAqB,IAAI,KAAKa,oBAA9B,CAAV;;AAEA,UAAIN,IAAI,CAACwD,GAAL,CAAS/D,CAAT,KAAe,KAAKC,KAAL,CAAWD,CAAX,GAAe6D,MAAlC,EAA0C;AACxC,eAAO1B,SAAP;AACD;;AAED,aAAO1C,eAAe,CAAC4D,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8BrD,CAA9B,EAAiC+B,EAAjC,CAAoCX,MAApC,CAAP;AACD;;;;;;SAzMkBvB,S","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\n/* eslint-disable */\nimport {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from 'math.gl';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\nconst scratchCartesian = new Vector3();\n\nlet wgs84;\n\n// A quadratic surface defined in Cartesian coordinates by the equation\n// <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used\n// to represent the shape of planetary bodies.\nexport default class Ellipsoid {\n // An Ellipsoid instance initialized to the WGS84 standard.\n static get WGS84() {\n wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n return wgs84;\n }\n\n // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n this.centerToleranceSquared = _MathUtils.EPSILON1;\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n equals(right) {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n toString() {\n return this.radii.toString();\n }\n\n // Converts the provided cartographic to Cartesian representation.\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n // Converts the provided cartesian to cartographic (lng/lat/z) representation.\n // The cartesian is undefined at the center of the ellipsoid.\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n scratchCartesian.from(cartesian);\n const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(scratchCartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n // centered at the provided origin to the provided ellipsoid's fixed reference frame.\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n // Computes the unit vector directed from the center of this ellipsoid toward\n // the provided Cartesian position.\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .normalize()\n .to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector\n .from(cartesian)\n .scale(this.oneOverRadiiSquared)\n .normalize()\n .to(result);\n }\n\n // Scales the provided Cartesian position along the geodetic surface normal\n // so that it is on the surface of this ellipsoid. If the position is\n // at the center of the ellipsoid, this function returns undefined.\n scaleToGeodeticSurface(cartesian, result) {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n // Scales the provided Cartesian position along the geocentric surface normal\n // so that it is on the surface of this ellipsoid.\n scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#oneOverRadii`\n transformPositionToScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.oneOverRadii)\n .to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#radii`.\n transformPositionFromScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition\n .from(position)\n .scale(this.radii)\n .to(result);\n }\n\n // Computes a point which is the intersection of the surface normal with the z-axis.\n getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}

@@ -8,3 +8,3 @@ {

},
"version": "3.0.0-alpha.4",
"version": "3.0.0-alpha.5",
"keywords": [

@@ -37,5 +37,5 @@ "webgl",

"gl-matrix": "^3.0.0",
"math.gl": "3.0.0-alpha.4"
"math.gl": "3.0.0-alpha.5"
},
"gitHead": "90158f9659da040d75517b7f07c169fd0d015577"
"gitHead": "ed165ad1fd1461c74e7f9b765c7a264d8132a312"
}

@@ -19,2 +19,3 @@ // This file is derived from the Cesium math library under Apache 2 license

const scratchHeight = new Vector3();
const scratchCartesian = new Vector3();

@@ -102,3 +103,4 @@ let wgs84;

cartesianToCartographic(cartesian, result = [0, 0, 0]) {
const point = this.scaleToGeodeticSurface(cartesian, scratchPosition);
scratchCartesian.from(cartesian);
const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);

@@ -112,7 +114,7 @@ if (!point) {

const h = scratchHeight;
h.copy(cartesian).subtract(point);
h.copy(scratchCartesian).subtract(point);
const longitude = Math.atan2(normal.y, normal.x);
const latitude = Math.asin(normal.z);
const height = Math.sign(vec3.dot(h, cartesian)) * vec3.length(h);
const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);

@@ -119,0 +121,0 @@ return toCartographicFromRadians([longitude, latitude, height], result);