Socket
Socket
Sign inDemoInstall

@loaders.gl/math

Package Overview
Dependencies
Maintainers
9
Versions
310
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/math - npm Package Compare versions

Comparing version 1.1.0-alpha.1 to 1.1.0-beta.1

dist/es5/geospatial/cartographic-rectangle.js

152

dist/es5/geospatial/cartographic.js

@@ -16,2 +16,8 @@ "use strict";

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _math = require("math.gl");

@@ -21,28 +27,47 @@

var _constants = require("./constants");
var _scaleToGeodeticSurface = _interopRequireDefault(require("./helpers/scale-to-geodetic-surface"));
var _scaleToGeodeticSurface = _interopRequireDefault(require("./scale-to-geodetic-surface"));
var _getEllipsoidProperties = _interopRequireDefault(require("./helpers/get-ellipsoid-properties"));
var WGS84_RADII_SQUARED = [_constants.WGS84_RADIUS_X * _constants.WGS84_RADIUS_X, _constants.WGS84_RADIUS_Y * _constants.WGS84_RADIUS_Y, _constants.WGS84_RADIUS_Z * _constants.WGS84_RADIUS_Z];
var wgs84OneOverRadii = [1.0 / _constants.WGS84_RADIUS_X, 1.0 / _constants.WGS84_RADIUS_Y, 1.0 / _constants.WGS84_RADIUS_Z];
var wgs84OneOverRadiiSquared = [1.0 / _constants.WGS84_RADIUS_X * _constants.WGS84_RADIUS_X, 1.0 / _constants.WGS84_RADIUS_Y * _constants.WGS84_RADIUS_Y, 1.0 / _constants.WGS84_RADIUS_Z * _constants.WGS84_RADIUS_Z];
var wgs84CenterToleranceSquared = 1e-1;
var scratchN = new _math.Vector3();
var scratchK = new _math.Vector3();
var Cartographic = function () {
var Cartographic = function (_Vector) {
(0, _inherits2["default"])(Cartographic, _Vector);
function Cartographic() {
(0, _classCallCheck2["default"])(this, Cartographic);
return (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(Cartographic).apply(this, arguments));
}
(0, _createClass2["default"])(Cartographic, [{
key: "degreesToVector3",
value: function degreesToVector3(longitude, latitude, height, ellipsoid, result) {
(0, _assert["default"])(Number.isFinite(longitude));
(0, _assert["default"])(Number.isFinite(latitude));
longitude = (0, _math.radians)(longitude);
latitude = (0, _math.radians)(latitude);
return _math.Vector3.fromRadians(longitude, latitude, height, ellipsoid, result);
key: "longitude",
get: function get() {
return this[0];
},
set: function set(value) {
this[0] = value;
return value;
}
}, {
key: "radiansToVector3",
value: function radiansToVector3(_ref, ellipsoid, result) {
key: "latitude",
get: function get() {
return this[1];
},
set: function set(value) {
this[1] = value;
return value;
}
}, {
key: "height",
get: function get() {
return this[2];
},
set: function set(value) {
this[2] = value;
return value;
}
}], [{
key: "toRadians",
value: function toRadians(_ref) {
var _ref2 = (0, _slicedToArray2["default"])(_ref, 3),

@@ -52,7 +77,43 @@ longitude = _ref2[0],

_ref2$ = _ref2[2],
height = _ref2$ === void 0 ? 0 : _ref2$;
z = _ref2$ === void 0 ? 0 : _ref2$;
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
(0, _assert["default"])(Number.isFinite(longitude));
(0, _assert["default"])(Number.isFinite(latitude));
var radiiSquared = ellipsoid ? ellipsoid.radiiSquared : WGS84_RADII_SQUARED;
result[0] = (0, _math.radians)(longitude);
result[1] = (0, _math.radians)(latitude);
result[2] = z;
return result;
}
}, {
key: "toDegrees",
value: function toDegrees(_ref3) {
var _ref4 = (0, _slicedToArray2["default"])(_ref3, 3),
longitude = _ref4[0],
latitude = _ref4[1],
_ref4$ = _ref4[2],
z = _ref4$ === void 0 ? 0 : _ref4$;
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
(0, _assert["default"])(Number.isFinite(longitude));
(0, _assert["default"])(Number.isFinite(latitude));
result[0] = (0, _math.degrees)(longitude);
result[1] = (0, _math.degrees)(latitude);
result[2] = z;
}
}, {
key: "toCartesian",
value: function toCartesian(_ref5, ellipsoid, result) {
var _ref6 = (0, _slicedToArray2["default"])(_ref5, 3),
longitude = _ref6[0],
latitude = _ref6[1],
_ref6$ = _ref6[2],
z = _ref6$ === void 0 ? 0 : _ref6$;
(0, _assert["default"])(Number.isFinite(longitude));
(0, _assert["default"])(Number.isFinite(latitude));
var _getEllipsoidProperti = (0, _getEllipsoidProperties["default"])(ellipsoid),
radiiSquared = _getEllipsoidProperti.radiiSquared;
var cosLatitude = Math.cos(latitude);

@@ -62,31 +123,20 @@ scratchN.x = cosLatitude * Math.cos(longitude);

scratchN.z = Math.sin(latitude);
scratchN = _math.Vector3.normalize(scratchN, scratchN);
scratchN.normalize();
scratchK.set(scratchN).scale(radiiSquared);
var gamma = Math.sqrt(scratchN.dot(scratchK));
scratchK.scale(1 / gamma);
scratchN.scale = height;
return scratchN.add(scratchK);
}
}, {
key: "fromCartesian",
value: function fromCartesian(cartesian) {
var ellipsoid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : WSG84;
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
_math.Vector3.multiplyComponents(radiiSquared, scratchN, scratchK);
var _getEllipsoidFields = getEllipsoidFields(ellipsoid),
oneOverRadii = _getEllipsoidFields.oneOverRadii,
oneOverRadiiSquared = _getEllipsoidFields.oneOverRadiiSquared,
centerToleranceSquared = _getEllipsoidFields.centerToleranceSquared;
var gamma = Math.sqrt(_math.Vector3.dot(scratchN, scratchK));
scratchK = _math.Vector3.divideByScalar(scratchK, gamma, scratchK);
scratchN = _math.Vector3.multiplyByScalar(scratchN, height, scratchN);
if (!defined(result)) {
result = new _math.Vector3();
}
return _math.Vector3.add(scratchK, scratchN, result);
}
}, {
key: "vector3ToDegrees",
value: function vector3ToDegrees(cartesian, ellipsoid) {
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new _math.Vector3();
Cartographic.vector3(vector, ellipsoid, result);
result[0] = (0, _math.degrees)(result[0]);
result[1] = (0, _math.degrees)(result[1]);
}
}, {
key: "vector3ToRadians",
value: function vector3ToRadians(cartesian, ellipsoid) {
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new _math.Vector3();
var oneOverRadii = ellipsoid ? ellipsoid.oneOverRadii : wgs84OneOverRadii;
var oneOverRadiiSquared = ellipsoid ? ellipsoid.oneOverRadiiSquared : wgs84OneOverRadiiSquared;
var centerToleranceSquared = ellipsoid ? ellipsoid._centerToleranceSquared : wgs84CenterToleranceSquared;
var p = (0, _scaleToGeodeticSurface["default"])(cartesian, oneOverRadii, oneOverRadiiSquared, centerToleranceSquared, cartesianToCartographicP);

@@ -109,9 +159,5 @@

if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
result[0] = longitude;
result[1] = latitude;
result[2] = height;
return result;

@@ -121,5 +167,5 @@ }

return Cartographic;
}();
}(_math.Vector3);
exports["default"] = Cartographic;
//# sourceMappingURL=cartographic.js.map
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

@@ -10,2 +12,4 @@

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

@@ -17,6 +21,12 @@

var vec3 = _interopRequireWildcard(require("gl-matrix/vec3"));
var _assert = _interopRequireDefault(require("../utils/assert"));
var _constants = require("./constants");
var _scaleToGeodeticSurface2 = _interopRequireDefault(require("./scale-to-geodetic-surface"));
var _scaleToGeodeticSurface2 = _interopRequireDefault(require("./helpers/scale-to-geodetic-surface"));
var _mathUtils = _interopRequireDefault(require("./helpers/math-utils"));
var LUNAR_RADIUS = 1737400.0;

@@ -63,9 +73,9 @@ var cartographicToCartesianNormal = new _math.Vector3();

key: "initialize",
value: function initialize(ellipsoid, x, y, z) {
x = defaultValue(x, 0.0);
y = defaultValue(y, 0.0);
z = defaultValue(z, 0.0);
Check.typeOf.number.greaterThanOrEquals('x', x, 0.0);
Check.typeOf.number.greaterThanOrEquals('y', y, 0.0);
Check.typeOf.number.greaterThanOrEquals('z', z, 0.0);
value: function initialize(ellipsoid) {
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.0;
var z = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.0;
(0, _assert["default"])(x >= 0.0);
(0, _assert["default"])(y >= 0.0);
(0, _assert["default"])(z >= 0.0);
ellipsoid._radii = new _math.Vector3(x, y, z);

@@ -78,3 +88,3 @@ ellipsoid._radiiSquared = new _math.Vector3(x * x, y * y, z * z);

ellipsoid._maximumRadius = Math.max(x, y, z);
ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;
ellipsoid._centerToleranceSquared = _mathUtils["default"].EPSILON1;

@@ -86,12 +96,2 @@ if (ellipsoid._radiiSquared.z !== 0) {

}, {
key: "fromVector3",
value: function fromVector3(cartesian) {
if (!defined(cartesian)) {
return result;
}
initialize(result, cartesian.x, cartesian.y, cartesian.z);
return result;
}
}, {
key: "clone",

@@ -114,6 +114,6 @@ value: function clone(ellipsoid) {

key: "geodeticSurfaceNormalCartographic",
value: function geodeticSurfaceNormalCartographic(cartographic, result) {
Check.typeOf.object('cartographic', cartographic);
var longitude = cartographic.longitude;
var latitude = cartographic.latitude;
value: function geodeticSurfaceNormalCartographic(cartographic) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _math.Vector3();
var longitude = (0, _math.radians)(cartographic[0]);
var latitude = (0, _math.radians)(cartographic[1]);
var cosLatitude = Math.cos(latitude);

@@ -123,21 +123,13 @@ var x = cosLatitude * Math.cos(longitude);

var z = Math.sin(latitude);
if (!defined(result)) {
result = new _math.Vector3();
}
result.x = x;
result.y = y;
result.z = z;
return _math.Vector3.normalize(result, result);
return result.normalize();
}
}, {
key: "geodeticSurfaceNormal",
value: function geodeticSurfaceNormal(cartesian, result) {
if (!defined(result)) {
result = new _math.Vector3();
}
result = _math.Vector3.multiplyComponents(cartesian, this._oneOverRadiiSquared, result);
return _math.Vector3.normalize(result, result);
value: function geodeticSurfaceNormal(cartesian) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _math.Vector3();
vec3.multiply(result, cartesian, this._oneOverRadiiSquared);
return vec3.normalize(result, result);
}

@@ -148,41 +140,36 @@ }, {

var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _math.Vector3();
var n = cartographicToCartesianNormal;
var k = cartographicToCartesianK;
this.geodeticSurfaceNormalCartographic(cartographic, n);
_math.Vector3.multiplyComponents(this._radiiSquared, n, k);
var _cartographic = (0, _slicedToArray2["default"])(cartographic, 3),
height = _cartographic[2];
var gamma = Math.sqrt(_math.Vector3.dot(n, k));
_math.Vector3.divideByScalar(k, gamma, k);
_math.Vector3.multiplyByScalar(n, cartographic.height, n);
return _math.Vector3.add(k, n, result);
var normal = cartographicToCartesianNormal;
var k = cartographicToCartesianK;
this.geodeticSurfaceNormalCartographic(cartographic, normal);
k.copy(this._radiiSquared).scale(normal);
var gamma = Math.sqrt(vec3.dot(normal, k));
k.scale(1 / gamma);
normal.scale(height);
k.add(normal);
vec3.copy(result, k);
return result;
}
}, {
key: "cartesianToCartographic",
value: function cartesianToCartographic(cartesian, result) {
var p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
value: function cartesianToCartographic(cartesian) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _math.Vector3();
var point = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
if (!defined(p)) {
if (!point) {
return undefined;
}
var n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
var h = _math.Vector3.subtract(cartesian, p, cartesianToCartographicH);
var longitude = Math.atan2(n.y, n.x);
var latitude = Math.asin(n.z);
var height = CesiumMath.sign(_math.Vector3.dot(h, cartesian)) * _math.Vector3.magnitude(h);
if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
var normal = this.geodeticSurfaceNormal(point, cartesianToCartographicN);
var h = cartesianToCartographicH;
h.copy(cartesian).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);
result[0] = (0, _math.degrees)(longitude);
result[1] = (0, _math.degrees)(latitude);
result[2] = height;
return result;

@@ -193,3 +180,3 @@ }

value: function scaleToGeodeticSurface(cartesian, result) {
return (0, _scaleToGeodeticSurface2["default"])(cartesian, this._oneOverRadii, this._oneOverRadiiSquared, this._centerToleranceSquared, result);
return (0, _scaleToGeodeticSurface2["default"])(cartesian, this, result);
}

@@ -229,3 +216,3 @@ }, {

if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, CesiumMath.EPSILON15)) {
if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, _mathUtils["default"].EPSILON15)) {
throw new DeveloperError('Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)');

@@ -278,2 +265,7 @@ }

}, {
key: "centerToleranceSquared",
get: function get() {
return this._centerToleranceSquared;
}
}, {
key: "minimumRadius",

@@ -288,2 +280,12 @@ get: function get() {

}
}], [{
key: "fromVector3",
value: function fromVector3(_ref) {
var _ref2 = (0, _slicedToArray2["default"])(_ref, 3),
x = _ref2[0],
y = _ref2[1],
z = _ref2[2];
return new Ellipsoid(x, y, z);
}
}]);

@@ -290,0 +292,0 @@ return Ellipsoid;

"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

@@ -32,2 +34,14 @@

});
Object.defineProperty(exports, "MathUtils", {
enumerable: true,
get: function get() {
return _mathUtils["default"];
}
});
Object.defineProperty(exports, "withEpsilon", {
enumerable: true,
get: function get() {
return _mathUtils.withEpsilon;
}
});

@@ -41,2 +55,4 @@ var _cartographic = _interopRequireDefault(require("./cartographic"));

var _webMercatorProjection = _interopRequireDefault(require("./web-mercator-projection"));
var _mathUtils = _interopRequireWildcard(require("./helpers/math-utils"));
//# sourceMappingURL=index.js.map
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { Vector3, degrees as toDegrees, radians as toRadians } from 'math.gl';
import assert from '../utils/assert';
import { WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z } from './constants';
import scaleToGeodeticSurface from './scale-to-geodetic-surface';
const WGS84_RADII_SQUARED = [WGS84_RADIUS_X * WGS84_RADIUS_X, WGS84_RADIUS_Y * WGS84_RADIUS_Y, WGS84_RADIUS_Z * WGS84_RADIUS_Z];
const wgs84OneOverRadii = [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z];
const wgs84OneOverRadiiSquared = [1.0 / WGS84_RADIUS_X * WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y * WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z * WGS84_RADIUS_Z];
const wgs84CenterToleranceSquared = 1e-1;
export default class Cartographic {
degreesToVector3(longitude, latitude, height, ellipsoid, result) {
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
longitude = toRadians(longitude);
latitude = toRadians(latitude);
return Vector3.fromRadians(longitude, latitude, height, ellipsoid, result);
import scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
import getEllipsoidProperties from './helpers/get-ellipsoid-properties';
const scratchN = new Vector3();
const scratchK = new Vector3();
export default class Cartographic extends Vector3 {
get longitude() {
return this[0];
}
radiansToVector3(_ref, ellipsoid, result) {
set longitude(value) {
this[0] = value;
return value;
}
get latitude() {
return this[1];
}
set latitude(value) {
this[1] = value;
return value;
}
get height() {
return this[2];
}
set height(value) {
this[2] = value;
return value;
}
static toRadians(_ref) {
let _ref2 = _slicedToArray(_ref, 3),

@@ -24,7 +41,41 @@ longitude = _ref2[0],

_ref2$ = _ref2[2],
height = _ref2$ === void 0 ? 0 : _ref2$;
z = _ref2$ === void 0 ? 0 : _ref2$;
let result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
const radiiSquared = ellipsoid ? ellipsoid.radiiSquared : WGS84_RADII_SQUARED;
result[0] = toRadians(longitude);
result[1] = toRadians(latitude);
result[2] = z;
return result;
}
static toDegrees(_ref3) {
let _ref4 = _slicedToArray(_ref3, 3),
longitude = _ref4[0],
latitude = _ref4[1],
_ref4$ = _ref4[2],
z = _ref4$ === void 0 ? 0 : _ref4$;
let result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
result[0] = toDegrees(longitude);
result[1] = toDegrees(latitude);
result[2] = z;
}
static toCartesian(_ref5, ellipsoid, result) {
let _ref6 = _slicedToArray(_ref5, 3),
longitude = _ref6[0],
latitude = _ref6[1],
_ref6$ = _ref6[2],
z = _ref6$ === void 0 ? 0 : _ref6$;
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
const _getEllipsoidProperti = getEllipsoidProperties(ellipsoid),
radiiSquared = _getEllipsoidProperti.radiiSquared;
const cosLatitude = Math.cos(latitude);

@@ -34,27 +85,19 @@ scratchN.x = cosLatitude * Math.cos(longitude);

scratchN.z = Math.sin(latitude);
scratchN = Vector3.normalize(scratchN, scratchN);
Vector3.multiplyComponents(radiiSquared, scratchN, scratchK);
const gamma = Math.sqrt(Vector3.dot(scratchN, scratchK));
scratchK = Vector3.divideByScalar(scratchK, gamma, scratchK);
scratchN = Vector3.multiplyByScalar(scratchN, height, scratchN);
scratchN.normalize();
scratchK.set(scratchN).scale(radiiSquared);
const gamma = Math.sqrt(scratchN.dot(scratchK));
scratchK.scale(1 / gamma);
scratchN.scale = height;
return scratchN.add(scratchK);
}
if (!defined(result)) {
result = new Vector3();
}
static fromCartesian(cartesian) {
let ellipsoid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : WSG84;
let result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
return Vector3.add(scratchK, scratchN, result);
}
const _getEllipsoidFields = getEllipsoidFields(ellipsoid),
oneOverRadii = _getEllipsoidFields.oneOverRadii,
oneOverRadiiSquared = _getEllipsoidFields.oneOverRadiiSquared,
centerToleranceSquared = _getEllipsoidFields.centerToleranceSquared;
vector3ToDegrees(cartesian, ellipsoid) {
let result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Vector3();
Cartographic.vector3(vector, ellipsoid, result);
result[0] = toDegrees(result[0]);
result[1] = toDegrees(result[1]);
}
vector3ToRadians(cartesian, ellipsoid) {
let result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Vector3();
const oneOverRadii = ellipsoid ? ellipsoid.oneOverRadii : wgs84OneOverRadii;
const oneOverRadiiSquared = ellipsoid ? ellipsoid.oneOverRadiiSquared : wgs84OneOverRadiiSquared;
const centerToleranceSquared = ellipsoid ? ellipsoid._centerToleranceSquared : wgs84CenterToleranceSquared;
const p = scaleToGeodeticSurface(cartesian, oneOverRadii, oneOverRadiiSquared, centerToleranceSquared, cartesianToCartographicP);

@@ -72,10 +115,5 @@

const height = sign(Vector3.dot(h, cartesian)) * Vector3.magnitude(h);
if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
result[0] = longitude;
result[1] = latitude;
result[2] = height;
return result;

@@ -82,0 +120,0 @@ }

@@ -1,10 +0,14 @@

import { Vector3 } from 'math.gl';
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { Vector3, radians as toRadians, degrees as toDegrees } from 'math.gl';
import * as vec3 from 'gl-matrix/vec3';
import assert from '../utils/assert';
import { WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z } from './constants';
import scaleToGeodeticSurface from './scale-to-geodetic-surface';
import scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
import MathUtils from './helpers/math-utils';
const LUNAR_RADIUS = 1737400.0;
var cartographicToCartesianNormal = new Vector3();
var cartographicToCartesianK = new Vector3();
var cartesianToCartographicN = new Vector3();
var cartesianToCartographicP = new Vector3();
var cartesianToCartographicH = new Vector3();
const cartographicToCartesianNormal = new Vector3();
const cartographicToCartesianK = new Vector3();
const cartesianToCartographicN = new Vector3();
const cartesianToCartographicP = new Vector3();
const cartesianToCartographicH = new Vector3();
export default class Ellipsoid {

@@ -36,9 +40,9 @@ static get WGS84() {

initialize(ellipsoid, x, y, z) {
x = defaultValue(x, 0.0);
y = defaultValue(y, 0.0);
z = defaultValue(z, 0.0);
Check.typeOf.number.greaterThanOrEquals('x', x, 0.0);
Check.typeOf.number.greaterThanOrEquals('y', y, 0.0);
Check.typeOf.number.greaterThanOrEquals('z', z, 0.0);
initialize(ellipsoid) {
let x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
let y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.0;
let z = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.0;
assert(x >= 0.0);
assert(y >= 0.0);
assert(z >= 0.0);
ellipsoid._radii = new Vector3(x, y, z);

@@ -51,3 +55,3 @@ ellipsoid._radiiSquared = new Vector3(x * x, y * y, z * z);

ellipsoid._maximumRadius = Math.max(x, y, z);
ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;
ellipsoid._centerToleranceSquared = MathUtils.EPSILON1;

@@ -59,9 +63,9 @@ if (ellipsoid._radiiSquared.z !== 0) {

fromVector3(cartesian) {
if (!defined(cartesian)) {
return result;
}
static fromVector3(_ref) {
let _ref2 = _slicedToArray(_ref, 3),
x = _ref2[0],
y = _ref2[1],
z = _ref2[2];
initialize(result, cartesian.x, cartesian.y, cartesian.z);
return result;
return new Ellipsoid(x, y, z);
}

@@ -89,2 +93,6 @@

get centerToleranceSquared() {
return this._centerToleranceSquared;
}
get minimumRadius() {

@@ -111,6 +119,6 @@ return this._minimumRadius;

geodeticSurfaceNormalCartographic(cartographic, result) {
Check.typeOf.object('cartographic', cartographic);
var longitude = cartographic.longitude;
var latitude = cartographic.latitude;
geodeticSurfaceNormalCartographic(cartographic) {
let result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
const longitude = toRadians(cartographic[0]);
const latitude = toRadians(cartographic[1]);
var cosLatitude = Math.cos(latitude);

@@ -120,20 +128,12 @@ var x = cosLatitude * Math.cos(longitude);

var z = Math.sin(latitude);
if (!defined(result)) {
result = new Vector3();
}
result.x = x;
result.y = y;
result.z = z;
return Vector3.normalize(result, result);
return result.normalize();
}
geodeticSurfaceNormal(cartesian, result) {
if (!defined(result)) {
result = new Vector3();
}
result = Vector3.multiplyComponents(cartesian, this._oneOverRadiiSquared, result);
return Vector3.normalize(result, result);
geodeticSurfaceNormal(cartesian) {
let result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
vec3.multiply(result, cartesian, this._oneOverRadiiSquared);
return vec3.normalize(result, result);
}

@@ -143,32 +143,35 @@

let result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
var n = cartographicToCartesianNormal;
const _cartographic = _slicedToArray(cartographic, 3),
height = _cartographic[2];
var normal = cartographicToCartesianNormal;
var k = cartographicToCartesianK;
this.geodeticSurfaceNormalCartographic(cartographic, n);
Vector3.multiplyComponents(this._radiiSquared, n, k);
var gamma = Math.sqrt(Vector3.dot(n, k));
Vector3.divideByScalar(k, gamma, k);
Vector3.multiplyByScalar(n, cartographic.height, n);
return Vector3.add(k, n, result);
this.geodeticSurfaceNormalCartographic(cartographic, normal);
k.copy(this._radiiSquared).scale(normal);
var gamma = Math.sqrt(vec3.dot(normal, k));
k.scale(1 / gamma);
normal.scale(height);
k.add(normal);
vec3.copy(result, k);
return result;
}
cartesianToCartographic(cartesian, result) {
var p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
cartesianToCartographic(cartesian) {
let result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
const point = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
if (!defined(p)) {
if (!point) {
return undefined;
}
var n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
var h = Vector3.subtract(cartesian, p, cartesianToCartographicH);
var longitude = Math.atan2(n.y, n.x);
var latitude = Math.asin(n.z);
var height = CesiumMath.sign(Vector3.dot(h, cartesian)) * Vector3.magnitude(h);
if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
const normal = this.geodeticSurfaceNormal(point, cartesianToCartographicN);
const h = cartesianToCartographicH;
h.copy(cartesian).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);
result[0] = toDegrees(longitude);
result[1] = toDegrees(latitude);
result[2] = height;
return result;

@@ -178,3 +181,3 @@ }

scaleToGeodeticSurface(cartesian, result) {
return scaleToGeodeticSurface(cartesian, this._oneOverRadii, this._oneOverRadiiSquared, this._centerToleranceSquared, result);
return scaleToGeodeticSurface(cartesian, this, result);
}

@@ -210,3 +213,3 @@

if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, CesiumMath.EPSILON15)) {
if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, MathUtils.EPSILON15)) {
throw new DeveloperError('Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)');

@@ -213,0 +216,0 @@ }

@@ -5,2 +5,3 @@ export { default as Cartographic } from './cartographic';

export { default as WebMercatorProjection } from './web-mercator-projection';
export { default as MathUtils, withEpsilon } from './helpers/math-utils';
//# sourceMappingURL=index.js.map
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import { Vector3, degrees as toDegrees, radians as toRadians } from 'math.gl';
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import { Vector3, degrees as _toDegrees, radians as _toRadians } from 'math.gl';
import assert from '../utils/assert';
import { WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z } from './constants';
import scaleToGeodeticSurface from './scale-to-geodetic-surface';
var WGS84_RADII_SQUARED = [WGS84_RADIUS_X * WGS84_RADIUS_X, WGS84_RADIUS_Y * WGS84_RADIUS_Y, WGS84_RADIUS_Z * WGS84_RADIUS_Z];
var wgs84OneOverRadii = [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z];
var wgs84OneOverRadiiSquared = [1.0 / WGS84_RADIUS_X * WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y * WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z * WGS84_RADIUS_Z];
var wgs84CenterToleranceSquared = 1e-1;
import scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
import getEllipsoidProperties from './helpers/get-ellipsoid-properties';
var scratchN = new Vector3();
var scratchK = new Vector3();
var Cartographic = function () {
var Cartographic = function (_Vector) {
_inherits(Cartographic, _Vector);
function Cartographic() {
_classCallCheck(this, Cartographic);
return _possibleConstructorReturn(this, _getPrototypeOf(Cartographic).apply(this, arguments));
}
_createClass(Cartographic, [{
key: "degreesToVector3",
value: function degreesToVector3(longitude, latitude, height, ellipsoid, result) {
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
longitude = toRadians(longitude);
latitude = toRadians(latitude);
return Vector3.fromRadians(longitude, latitude, height, ellipsoid, result);
key: "longitude",
get: function get() {
return this[0];
},
set: function set(value) {
this[0] = value;
return value;
}
}, {
key: "radiansToVector3",
value: function radiansToVector3(_ref, ellipsoid, result) {
key: "latitude",
get: function get() {
return this[1];
},
set: function set(value) {
this[1] = value;
return value;
}
}, {
key: "height",
get: function get() {
return this[2];
},
set: function set(value) {
this[2] = value;
return value;
}
}], [{
key: "toRadians",
value: function toRadians(_ref) {
var _ref2 = _slicedToArray(_ref, 3),

@@ -34,7 +57,43 @@ longitude = _ref2[0],

_ref2$ = _ref2[2],
height = _ref2$ === void 0 ? 0 : _ref2$;
z = _ref2$ === void 0 ? 0 : _ref2$;
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
var radiiSquared = ellipsoid ? ellipsoid.radiiSquared : WGS84_RADII_SQUARED;
result[0] = _toRadians(longitude);
result[1] = _toRadians(latitude);
result[2] = z;
return result;
}
}, {
key: "toDegrees",
value: function toDegrees(_ref3) {
var _ref4 = _slicedToArray(_ref3, 3),
longitude = _ref4[0],
latitude = _ref4[1],
_ref4$ = _ref4[2],
z = _ref4$ === void 0 ? 0 : _ref4$;
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
result[0] = _toDegrees(longitude);
result[1] = _toDegrees(latitude);
result[2] = z;
}
}, {
key: "toCartesian",
value: function toCartesian(_ref5, ellipsoid, result) {
var _ref6 = _slicedToArray(_ref5, 3),
longitude = _ref6[0],
latitude = _ref6[1],
_ref6$ = _ref6[2],
z = _ref6$ === void 0 ? 0 : _ref6$;
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
var _getEllipsoidProperti = getEllipsoidProperties(ellipsoid),
radiiSquared = _getEllipsoidProperti.radiiSquared;
var cosLatitude = Math.cos(latitude);

@@ -44,29 +103,20 @@ scratchN.x = cosLatitude * Math.cos(longitude);

scratchN.z = Math.sin(latitude);
scratchN = Vector3.normalize(scratchN, scratchN);
Vector3.multiplyComponents(radiiSquared, scratchN, scratchK);
var gamma = Math.sqrt(Vector3.dot(scratchN, scratchK));
scratchK = Vector3.divideByScalar(scratchK, gamma, scratchK);
scratchN = Vector3.multiplyByScalar(scratchN, height, scratchN);
scratchN.normalize();
scratchK.set(scratchN).scale(radiiSquared);
var gamma = Math.sqrt(scratchN.dot(scratchK));
scratchK.scale(1 / gamma);
scratchN.scale = height;
return scratchN.add(scratchK);
}
}, {
key: "fromCartesian",
value: function fromCartesian(cartesian) {
var ellipsoid = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : WSG84;
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
if (!defined(result)) {
result = new Vector3();
}
var _getEllipsoidFields = getEllipsoidFields(ellipsoid),
oneOverRadii = _getEllipsoidFields.oneOverRadii,
oneOverRadiiSquared = _getEllipsoidFields.oneOverRadiiSquared,
centerToleranceSquared = _getEllipsoidFields.centerToleranceSquared;
return Vector3.add(scratchK, scratchN, result);
}
}, {
key: "vector3ToDegrees",
value: function vector3ToDegrees(cartesian, ellipsoid) {
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Vector3();
Cartographic.vector3(vector, ellipsoid, result);
result[0] = toDegrees(result[0]);
result[1] = toDegrees(result[1]);
}
}, {
key: "vector3ToRadians",
value: function vector3ToRadians(cartesian, ellipsoid) {
var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Vector3();
var oneOverRadii = ellipsoid ? ellipsoid.oneOverRadii : wgs84OneOverRadii;
var oneOverRadiiSquared = ellipsoid ? ellipsoid.oneOverRadiiSquared : wgs84OneOverRadiiSquared;
var centerToleranceSquared = ellipsoid ? ellipsoid._centerToleranceSquared : wgs84CenterToleranceSquared;
var p = scaleToGeodeticSurface(cartesian, oneOverRadii, oneOverRadiiSquared, centerToleranceSquared, cartesianToCartographicP);

@@ -84,10 +134,5 @@

var height = sign(Vector3.dot(h, cartesian)) * Vector3.magnitude(h);
if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
result[0] = longitude;
result[1] = latitude;
result[2] = height;
return result;

@@ -98,5 +143,5 @@ }

return Cartographic;
}();
}(Vector3);
export { Cartographic as default };
//# sourceMappingURL=cartographic.js.map

@@ -0,6 +1,10 @@

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import { Vector3 } from 'math.gl';
import { Vector3, radians as toRadians, degrees as toDegrees } from 'math.gl';
import * as vec3 from 'gl-matrix/vec3';
import assert from '../utils/assert';
import { WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z } from './constants';
import _scaleToGeodeticSurface from './scale-to-geodetic-surface';
import _scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
import MathUtils from './helpers/math-utils';
var LUNAR_RADIUS = 1737400.0;

@@ -48,9 +52,9 @@ var cartographicToCartesianNormal = new Vector3();

key: "initialize",
value: function initialize(ellipsoid, x, y, z) {
x = defaultValue(x, 0.0);
y = defaultValue(y, 0.0);
z = defaultValue(z, 0.0);
Check.typeOf.number.greaterThanOrEquals('x', x, 0.0);
Check.typeOf.number.greaterThanOrEquals('y', y, 0.0);
Check.typeOf.number.greaterThanOrEquals('z', z, 0.0);
value: function initialize(ellipsoid) {
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
var y = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.0;
var z = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.0;
assert(x >= 0.0);
assert(y >= 0.0);
assert(z >= 0.0);
ellipsoid._radii = new Vector3(x, y, z);

@@ -63,3 +67,3 @@ ellipsoid._radiiSquared = new Vector3(x * x, y * y, z * z);

ellipsoid._maximumRadius = Math.max(x, y, z);
ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;
ellipsoid._centerToleranceSquared = MathUtils.EPSILON1;

@@ -71,12 +75,2 @@ if (ellipsoid._radiiSquared.z !== 0) {

}, {
key: "fromVector3",
value: function fromVector3(cartesian) {
if (!defined(cartesian)) {
return result;
}
initialize(result, cartesian.x, cartesian.y, cartesian.z);
return result;
}
}, {
key: "clone",

@@ -99,6 +93,6 @@ value: function clone(ellipsoid) {

key: "geodeticSurfaceNormalCartographic",
value: function geodeticSurfaceNormalCartographic(cartographic, result) {
Check.typeOf.object('cartographic', cartographic);
var longitude = cartographic.longitude;
var latitude = cartographic.latitude;
value: function geodeticSurfaceNormalCartographic(cartographic) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
var longitude = toRadians(cartographic[0]);
var latitude = toRadians(cartographic[1]);
var cosLatitude = Math.cos(latitude);

@@ -108,21 +102,13 @@ var x = cosLatitude * Math.cos(longitude);

var z = Math.sin(latitude);
if (!defined(result)) {
result = new Vector3();
}
result.x = x;
result.y = y;
result.z = z;
return Vector3.normalize(result, result);
return result.normalize();
}
}, {
key: "geodeticSurfaceNormal",
value: function geodeticSurfaceNormal(cartesian, result) {
if (!defined(result)) {
result = new Vector3();
}
result = Vector3.multiplyComponents(cartesian, this._oneOverRadiiSquared, result);
return Vector3.normalize(result, result);
value: function geodeticSurfaceNormal(cartesian) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
vec3.multiply(result, cartesian, this._oneOverRadiiSquared);
return vec3.normalize(result, result);
}

@@ -133,33 +119,36 @@ }, {

var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
var n = cartographicToCartesianNormal;
var _cartographic = _slicedToArray(cartographic, 3),
height = _cartographic[2];
var normal = cartographicToCartesianNormal;
var k = cartographicToCartesianK;
this.geodeticSurfaceNormalCartographic(cartographic, n);
Vector3.multiplyComponents(this._radiiSquared, n, k);
var gamma = Math.sqrt(Vector3.dot(n, k));
Vector3.divideByScalar(k, gamma, k);
Vector3.multiplyByScalar(n, cartographic.height, n);
return Vector3.add(k, n, result);
this.geodeticSurfaceNormalCartographic(cartographic, normal);
k.copy(this._radiiSquared).scale(normal);
var gamma = Math.sqrt(vec3.dot(normal, k));
k.scale(1 / gamma);
normal.scale(height);
k.add(normal);
vec3.copy(result, k);
return result;
}
}, {
key: "cartesianToCartographic",
value: function cartesianToCartographic(cartesian, result) {
var p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
value: function cartesianToCartographic(cartesian) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3();
var point = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
if (!defined(p)) {
if (!point) {
return undefined;
}
var n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
var h = Vector3.subtract(cartesian, p, cartesianToCartographicH);
var longitude = Math.atan2(n.y, n.x);
var latitude = Math.asin(n.z);
var height = CesiumMath.sign(Vector3.dot(h, cartesian)) * Vector3.magnitude(h);
if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
var normal = this.geodeticSurfaceNormal(point, cartesianToCartographicN);
var h = cartesianToCartographicH;
h.copy(cartesian).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);
result[0] = toDegrees(longitude);
result[1] = toDegrees(latitude);
result[2] = height;
return result;

@@ -170,3 +159,3 @@ }

value: function scaleToGeodeticSurface(cartesian, result) {
return _scaleToGeodeticSurface(cartesian, this._oneOverRadii, this._oneOverRadiiSquared, this._centerToleranceSquared, result);
return _scaleToGeodeticSurface(cartesian, this, result);
}

@@ -206,3 +195,3 @@ }, {

if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, CesiumMath.EPSILON15)) {
if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, MathUtils.EPSILON15)) {
throw new DeveloperError('Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)');

@@ -255,2 +244,7 @@ }

}, {
key: "centerToleranceSquared",
get: function get() {
return this._centerToleranceSquared;
}
}, {
key: "minimumRadius",

@@ -265,2 +259,12 @@ get: function get() {

}
}], [{
key: "fromVector3",
value: function fromVector3(_ref) {
var _ref2 = _slicedToArray(_ref, 3),
x = _ref2[0],
y = _ref2[1],
z = _ref2[2];
return new Ellipsoid(x, y, z);
}
}]);

@@ -267,0 +271,0 @@

@@ -5,2 +5,3 @@ export { default as Cartographic } from './cartographic';

export { default as WebMercatorProjection } from './web-mercator-projection';
export { default as MathUtils, withEpsilon } from './helpers/math-utils';
//# sourceMappingURL=index.js.map
{
"name": "@loaders.gl/math",
"version": "1.1.0-alpha.1",
"version": "1.1.0-beta.1",
"description": "Experimental math classes for loaders.gl",

@@ -34,5 +34,5 @@ "license": "MIT",

"dependencies": {
"@loaders.gl/core": "1.1.0-alpha.1",
"@loaders.gl/images": "1.1.0-alpha.1"
"@loaders.gl/core": "1.1.0-beta.1",
"@loaders.gl/images": "1.1.0-beta.1"
}
}

@@ -13,2 +13,3 @@ /* eslint-disable */

// A culling volume defined by planes.
export default class CullingVolume {

@@ -33,11 +34,4 @@ // For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value

// {Cartesian4[]} [planes] An array of clipping planes.
/**
* The culling volume defined by planes.
*
* @alias CullingVolume
* @constructor
*
* @param {Cartesian4[]} [planes] An array of clipping planes.
*/
/**
* Each plane is represented by a Cartesian4 object, where the x, y, and z components

@@ -44,0 +38,0 @@ * define the unit vector normal to the plane, and the w component is the distance of the

/* eslint-disable */
import {Vector3, degrees as toDegrees, radians as toRadians} from 'math.gl';
import assert from '../utils/assert';
import {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from './constants';
import scaleToGeodeticSurface from './scale-to-geodetic-surface';
import scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
import getEllipsoidProperties from './helpers/get-ellipsoid-properties';
const WGS84_RADII_SQUARED = [
WGS84_RADIUS_X * WGS84_RADIUS_X,
WGS84_RADIUS_Y * WGS84_RADIUS_Y,
WGS84_RADIUS_Z * WGS84_RADIUS_Z
];
const wgs84OneOverRadii = [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z];
const wgs84OneOverRadiiSquared = [
(1.0 / WGS84_RADIUS_X) * WGS84_RADIUS_X,
(1.0 / WGS84_RADIUS_Y) * WGS84_RADIUS_Y,
(1.0 / WGS84_RADIUS_Z) * WGS84_RADIUS_Z
];
const wgs84CenterToleranceSquared = 1e-1; // EPSILON1;
const scratchN = new Vector3();
const scratchK = new Vector3();
// const scratchN = new Vector3();
// const scratchK = new Vector3();
// const cartesianToCartographicN = new Vector3();

@@ -27,44 +14,58 @@ // const cartesianToCartographicP = new Vector3();

export default class Cartographic {
/**
* Returns a Vector3 position from longitude and latitude values given in degrees.
*
* @param {Number} longitude The longitude, in degrees
* @param {Number} latitude The latitude, in degrees
* @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
* @param {Vector3} [result] The object onto which to store the result.
* @returns {Vector3} The position
*
* @example
* const position = Vector3.fromDegrees(-115.0, 37.0);
*/
degreesToVector3(longitude, latitude, height, ellipsoid, result) {
export default class Cartographic extends Vector3 {
get longitude() {
return this[0];
}
set longitude(value) {
this[0] = value;
return value;
}
get latitude() {
return this[1];
}
set latitude(value) {
this[1] = value;
return value;
}
get height() {
return this[2];
}
set height(value) {
this[2] = value;
return value;
}
// Returns longitude and latitude values in radians (from degrees)
static toRadians([longitude, latitude, z = 0], result = [0, 0, 0]) {
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
longitude = toRadians(longitude);
latitude = toRadians(latitude);
return Vector3.fromRadians(longitude, latitude, height, ellipsoid, result);
result[0] = toRadians(longitude);
result[1] = toRadians(latitude);
result[2] = z;
return result;
}
/**
* Returns a Vector3 position from longitude and latitude values given in radians.
*
* @param {Number} longitude The longitude, in radians
* @param {Number} latitude The latitude, in radians
* @param {Number} [height=0.0] The height, in meters, above the ellipsoid.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
* @param {Vector3} [result] The object onto which to store the result.
* @returns {Vector3} The position
*
* @example
* const position = Vector3.fromRadians(-2.007, 0.645);
*/
radiansToVector3([longitude, latitude, height = 0], ellipsoid, result) {
// Returns longitude and latitude values in degrees (from radians)
static toDegrees([longitude, latitude, z = 0], result = [0, 0, 0]) {
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
const radiiSquared = ellipsoid ? ellipsoid.radiiSquared : WGS84_RADII_SQUARED;
result[0] = toDegrees(longitude);
result[1] = toDegrees(latitude);
result[2] = z;
}
// Returns a cartesian position from longitude and latitude values given in radians.
static toCartesian([longitude, latitude, z = 0], ellipsoid, result) {
assert(Number.isFinite(longitude));
assert(Number.isFinite(latitude));
const {radiiSquared} = getEllipsoidProperties(ellipsoid);
const cosLatitude = Math.cos(latitude);

@@ -74,38 +75,18 @@ scratchN.x = cosLatitude * Math.cos(longitude);

scratchN.z = Math.sin(latitude);
scratchN = Vector3.normalize(scratchN, scratchN);
scratchN.normalize();
Vector3.multiplyComponents(radiiSquared, scratchN, scratchK);
const gamma = Math.sqrt(Vector3.dot(scratchN, scratchK));
scratchK = Vector3.divideByScalar(scratchK, gamma, scratchK);
scratchN = Vector3.multiplyByScalar(scratchN, height, scratchN);
scratchK.set(scratchN).scale(radiiSquared);
if (!defined(result)) {
result = new Vector3();
}
return Vector3.add(scratchK, scratchN, result);
}
const gamma = Math.sqrt(scratchN.dot(scratchK));
scratchK.scale(1 / gamma);
scratchN.scale = height;
vector3ToDegrees(cartesian, ellipsoid, result = new Vector3()) {
Cartographic.vector3(vector, ellipsoid, result);
result[0] = toDegrees(result[0]);
result[1] = toDegrees(result[1]);
return scratchN.add(scratchK);
}
/**
* Creates a new Cartographic instance from a Cartesian position. The values in the
* resulting object will be in radians.
*
* @param {Vector3} cartesian The Cartesian position to convert to cartographic representation.
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid on which the position lies.
* @param {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
*/
vector3ToRadians(cartesian, ellipsoid, result = new Vector3()) {
const oneOverRadii = ellipsoid ? ellipsoid.oneOverRadii : wgs84OneOverRadii;
const oneOverRadiiSquared = ellipsoid
? ellipsoid.oneOverRadiiSquared
: wgs84OneOverRadiiSquared;
const centerToleranceSquared = ellipsoid
? ellipsoid._centerToleranceSquared
: wgs84CenterToleranceSquared;
// Converts a Cartesian geodetic position to a longitude/latitude
static fromCartesian(cartesian, ellipsoid = WSG84, result = [0, 0, 0]) {
const {oneOverRadii, oneOverRadiiSquared, centerToleranceSquared} = getEllipsoidFields(
ellipsoid
);

@@ -133,10 +114,7 @@ const p = scaleToGeodeticSurface(

if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
result[0] = longitude;
result[1] = latitude;
result[2] = height;
return result;
}
}
/* eslint-disable */
import {Vector3} from 'math.gl';
import {Vector3, radians as toRadians, degrees as toDegrees} from 'math.gl';
import * as vec3 from 'gl-matrix/vec3';
import assert from '../utils/assert';
import {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from './constants';
import scaleToGeodeticSurface from './scale-to-geodetic-surface';
import scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
import MathUtils from './helpers/math-utils';
const LUNAR_RADIUS = 1737400.0;
var cartographicToCartesianNormal = new Vector3();
var cartographicToCartesianK = new Vector3();
const cartographicToCartesianNormal = new Vector3();
const cartographicToCartesianK = new Vector3();
var cartesianToCartographicN = new Vector3();
var cartesianToCartographicP = new Vector3();
var cartesianToCartographicH = new Vector3();
const cartesianToCartographicN = new Vector3();
const cartesianToCartographicP = new Vector3();
const cartesianToCartographicH = new Vector3();

@@ -73,13 +76,7 @@ /*

initialize(ellipsoid, x, y, z) {
x = defaultValue(x, 0.0);
y = defaultValue(y, 0.0);
z = defaultValue(z, 0.0);
initialize(ellipsoid, x = 0.0, y = 0.0, z = 0.0) {
assert(x >= 0.0);
assert(y >= 0.0);
assert(z >= 0.0);
//>>includeStart('debug', pragmas.debug);
Check.typeOf.number.greaterThanOrEquals('x', x, 0.0);
Check.typeOf.number.greaterThanOrEquals('y', y, 0.0);
Check.typeOf.number.greaterThanOrEquals('z', z, 0.0);
//>>includeEnd('debug');
ellipsoid._radii = new Vector3(x, y, z);

@@ -107,3 +104,3 @@

ellipsoid._centerToleranceSquared = CesiumMath.EPSILON1;
ellipsoid._centerToleranceSquared = MathUtils.EPSILON1;

@@ -128,9 +125,4 @@ if (ellipsoid._radiiSquared.z !== 0) {

*/
fromVector3(cartesian) {
if (!defined(cartesian)) {
return result;
}
initialize(result, cartesian.x, cartesian.y, cartesian.z);
return result;
static fromVector3([x, y, z]) {
return new Ellipsoid(x, y, z);
}

@@ -188,2 +180,6 @@

get centerToleranceSquared() {
return this._centerToleranceSquared;
}
/**

@@ -269,9 +265,9 @@ * Gets the minimum radius of the ellipsoid.

*/
geodeticSurfaceNormalCartographic(cartographic, result) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object('cartographic', cartographic);
//>>includeEnd('debug');
geodeticSurfaceNormalCartographic(cartographic, result = new Vector3()) {
// var longitude = cartographic.longitude;
// var latitude = cartographic.latitude;
var longitude = cartographic.longitude;
var latitude = cartographic.latitude;
const longitude = toRadians(cartographic[0]);
const latitude = toRadians(cartographic[1]);
var cosLatitude = Math.cos(latitude);

@@ -283,9 +279,7 @@

if (!defined(result)) {
result = new Vector3();
}
result.x = x;
result.y = y;
result.z = z;
return Vector3.normalize(result, result);
return result.normalize();
}

@@ -300,8 +294,5 @@

*/
geodeticSurfaceNormal(cartesian, result) {
if (!defined(result)) {
result = new Vector3();
}
result = Vector3.multiplyComponents(cartesian, this._oneOverRadiiSquared, result);
return Vector3.normalize(result, result);
geodeticSurfaceNormal(cartesian, result = new Vector3()) {
vec3.multiply(result, cartesian, this._oneOverRadiiSquared);
return vec3.normalize(result, result);
}

@@ -318,48 +309,45 @@

cartographicToCartesian(cartographic, result = new Vector3()) {
const [, , height] = cartographic;
//`cartographic is required` is thrown from geodeticSurfaceNormalCartographic.
var n = cartographicToCartesianNormal;
var normal = cartographicToCartesianNormal;
var k = cartographicToCartesianK;
this.geodeticSurfaceNormalCartographic(cartographic, n);
Vector3.multiplyComponents(this._radiiSquared, n, k);
var gamma = Math.sqrt(Vector3.dot(n, k));
Vector3.divideByScalar(k, gamma, k);
Vector3.multiplyByScalar(n, cartographic.height, n);
return Vector3.add(k, n, result);
this.geodeticSurfaceNormalCartographic(cartographic, normal);
k.copy(this._radiiSquared).scale(normal);
var gamma = Math.sqrt(vec3.dot(normal, k));
k.scale(1 / gamma);
normal.scale(height);
k.add(normal);
vec3.copy(result, k);
return result;
}
/**
* Converts the provided cartesian to cartographic representation.
* The cartesian is undefined at the center of the ellipsoid.
*
* @param {Vector3} cartesian The Cartesian position to convert to cartographic representation.
* @param {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
*
* @example
* //Create a Cartesian and determine it's Cartographic representation on a WGS84 ellipsoid.
* var position = new Cesium.Vector3(17832.12, 83234.52, 952313.73);
* var cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
*/
cartesianToCartographic(cartesian, result) {
//`cartesian is required.` is thrown from scaleToGeodeticSurface
var p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
// Converts the provided cartesian to cartographic (lng/lat/z) representation.
// The cartesian is undefined at the center of the ellipsoid.
cartesianToCartographic(cartesian, result = new Vector3()) {
const point = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
if (!defined(p)) {
if (!point) {
return undefined;
}
var n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
var h = Vector3.subtract(cartesian, p, cartesianToCartographicH);
const normal = this.geodeticSurfaceNormal(point, cartesianToCartographicN);
var longitude = Math.atan2(n.y, n.x);
var latitude = Math.asin(n.z);
var height = CesiumMath.sign(Vector3.dot(h, cartesian)) * Vector3.magnitude(h);
const h = cartesianToCartographicH;
h.copy(cartesian).subtract(point);
if (!defined(result)) {
return new Cartographic(longitude, latitude, height);
}
result.longitude = longitude;
result.latitude = latitude;
result.height = height;
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);
result[0] = toDegrees(longitude);
result[1] = toDegrees(latitude);
result[2] = height;
return result;

@@ -378,9 +366,3 @@ }

scaleToGeodeticSurface(cartesian, result) {
return scaleToGeodeticSurface(
cartesian,
this._oneOverRadii,
this._oneOverRadiiSquared,
this._centerToleranceSquared,
result
);
return scaleToGeodeticSurface(cartesian, this, result);
}

@@ -469,3 +451,3 @@

if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, CesiumMath.EPSILON15)) {
if (!CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, MathUtils.EPSILON15)) {
throw new DeveloperError('Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)');

@@ -472,0 +454,0 @@ }

@@ -5,1 +5,3 @@ export {default as Cartographic} from './cartographic';

export {default as WebMercatorProjection} from './web-mercator-projection';
export {default as MathUtils, withEpsilon} from './helpers/math-utils';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc