Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@math.gl/culling

Package Overview
Dependencies
Maintainers
4
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@math.gl/culling - npm Package Compare versions

Comparing version 3.2.0-alpha.2 to 3.2.0-alpha.3

14

dist/es5/algorithms/bounding-box-from-points.d.ts
import OrientedBoundingBox from '../lib/oriented-bounding-box';
import AxisAlignedBoundingBox from '../lib/axis-aligned-bounding-box';

@@ -9,5 +10,14 @@ /**

*/
export default function makeOrientedBoundingBoxfromPoints(
export function makeOrientedBoundingBoxFromPoints(
positions: number[][],
result
result?: OrientedBoundingBox
): OrientedBoundingBox;
/**
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
export function makeAxisAlignedBoundingBoxFromPoints(
positions: readonly number[][],
result?: AxisAlignedBoundingBox
): AxisAlignedBoundingBox;

@@ -8,3 +8,4 @@ "use strict";

});
exports["default"] = makeOrientedBoundingBoxfromPoints;
exports.makeOrientedBoundingBoxFromPoints = makeOrientedBoundingBoxFromPoints;
exports.makeAxisAlignedBoundingBoxFromPoints = makeAxisAlignedBoundingBoxFromPoints;

@@ -15,2 +16,6 @@ var _core = require("@math.gl/core");

var _orientedBoundingBox = _interopRequireDefault(require("../lib/oriented-bounding-box"));
var _axisAlignedBoundingBox = _interopRequireDefault(require("../lib/axis-aligned-bounding-box"));
var scratchVector2 = new _core.Vector3();

@@ -27,3 +32,5 @@ var scratchVector3 = new _core.Vector3();

function makeOrientedBoundingBoxfromPoints(positions, result) {
function makeOrientedBoundingBoxFromPoints(positions) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _orientedBoundingBox["default"]();
if (!positions || positions.length === 0) {

@@ -166,2 +173,58 @@ result.halfAxes = new _core.Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);

}
function makeAxisAlignedBoundingBoxFromPoints(positions) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _axisAlignedBoundingBox["default"]();
if (!positions || positions.length === 0) {
result.minimum.set(0, 0, 0);
result.maximum.set(0, 0, 0);
result.center.set(0, 0, 0);
result.halfDiagonal.set(0, 0, 0);
return result;
}
var minimumX = positions[0][0];
var minimumY = positions[0][1];
var minimumZ = positions[0][2];
var maximumX = positions[0][0];
var maximumY = positions[0][1];
var maximumZ = positions[0][2];
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = positions[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var p = _step4.value;
var x = p[0];
var y = p[1];
var z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
_iterator4["return"]();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
result.minimum.set(minimumX, minimumY, minimumZ);
result.maximum.set(maximumX, maximumY, maximumZ);
result.center.copy(result.minimum).add(result.maximum).scale(0.5);
result.halfDiagonal.copy(result.maximum).subtract(result.center);
return result;
}
//# sourceMappingURL=bounding-box-from-points.js.map

5

dist/es5/index.d.ts

@@ -7,4 +7,7 @@ export {default as AxisAlignedBoundingBox} from './lib/axis-aligned-bounding-box';

export {default as makeOrientedBoundingBoxfromPoints} from './algorithms/bounding-box-from-points';
export {default as makeBoundingSphereFromPoints} from './algorithms/bounding-sphere-from-points';
export {
makeAxisAlignedBoundingBoxFromPoints,
makeOrientedBoundingBoxFromPoints
} from './algorithms/bounding-box-from-points';
export {default as computeEigenDecomposition} from './algorithms/compute-eigen-decomposition';

@@ -11,0 +14,0 @@

@@ -74,6 +74,12 @@ "use strict";

});
Object.defineProperty(exports, "makeAxisAlignedBoundingBoxFromPoints", {
enumerable: true,
get: function get() {
return _boundingBoxFromPoints.makeAxisAlignedBoundingBoxFromPoints;
}
});
Object.defineProperty(exports, "makeOrientedBoundingBoxFromPoints", {
enumerable: true,
get: function get() {
return _boundingBoxFromPoints["default"];
return _boundingBoxFromPoints.makeOrientedBoundingBoxFromPoints;
}

@@ -106,5 +112,5 @@ });

var _boundingBoxFromPoints = _interopRequireDefault(require("./algorithms/bounding-box-from-points"));
var _boundingBoxFromPoints = require("./algorithms/bounding-box-from-points");
var _computeEigenDecomposition = _interopRequireDefault(require("./algorithms/compute-eigen-decomposition"));
//# sourceMappingURL=index.js.map

@@ -13,2 +13,3 @@ import {Vector3} from '@math.gl/core';

readonly center: Vector3;
readonly halfDiagonal: Vector3;

@@ -23,6 +24,2 @@ /**

/** Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
fromPoints(positions: readonly number[][]): AxisAlignedBoundingBox;
/** Duplicates a AxisAlignedBoundingBox instance. */

@@ -34,2 +31,7 @@ clone(): AxisAlignedBoundingBox;

intersectPlane(plane: Plane): INTERSECTION_ENUM;
// Computes the estimated distance from the closest point on a bounding box to a point.
distanceTo(point: readonly number[]): number;
// Computes the estimated distance squared from the closest point on a bounding box to a point.
distanceSquaredTo(point: readonly number[]): number;
}

@@ -28,61 +28,9 @@ "use strict";

center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);
this.center = new _core.Vector3(center);
this.halfDiagonal = new _core.Vector3(maximum).subtract(this.center);
this.minimum = new _core.Vector3(minimum);
this.maximum = new _core.Vector3(maximum);
this.center = new _core.Vector3(center);
}
(0, _createClass2["default"])(AxisAlignedBoundingBox, [{
key: "fromPoints",
value: function fromPoints(positions) {
if (!positions || positions.length === 0) {
this.minimum.set(0, 0, 0);
this.maximum.set(0, 0, 0);
this.center.set(0, 0, 0);
return this;
}
var minimumX = positions[0][0];
var minimumY = positions[0][1];
var minimumZ = positions[0][2];
var maximumX = positions[0][0];
var maximumY = positions[0][1];
var maximumZ = positions[0][2];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = positions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var p = _step.value;
var x = p[0];
var y = p[1];
var z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
this.minimum.set(minimumX, minimumY, minimumZ);
this.maximum.set(maximumX, maximumY, maximumZ);
this.center.copy(this.minimum).add(this.maximum).scale(0.5);
return this;
}
}, {
key: "clone",

@@ -95,3 +43,3 @@ value: function clone() {

value: function equals(right) {
return this === right || Boolean(right) && this.center.equals(right.center) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
}

@@ -101,5 +49,5 @@ }, {

value: function intersectPlane(plane) {
var h = scratchVector.copy(this.maximum).subtract(this.minimum).scale(0.5);
var halfDiagonal = this.halfDiagonal;
var normal = scratchNormal.from(plane.normal);
var e = h.x * Math.abs(normal.x) + h.y * Math.abs(normal.y) + h.z * Math.abs(normal.z);
var e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
var s = this.center.dot(normal) + plane.distance;

@@ -117,2 +65,34 @@

}
}, {
key: "distanceTo",
value: function distanceTo(point) {
return Math.sqrt(this.distanceSquaredTo(point));
}
}, {
key: "distanceSquaredTo",
value: function distanceSquaredTo(point) {
var offset = scratchVector.from(point).subtract(this.center);
var halfDiagonal = this.halfDiagonal;
var distanceSquared = 0.0;
var d;
d = Math.abs(offset.x) - halfDiagonal.x;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.y) - halfDiagonal.y;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.z) - halfDiagonal.z;
if (d > 0) {
distanceSquared += d * d;
}
return distanceSquared;
}
}]);

@@ -119,0 +99,0 @@ return AxisAlignedBoundingBox;

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

fromPoints(points: readonly number[][]): OrientedBoundingBox;
// Compares the provided OrientedBoundingBox componentwise and returns

@@ -27,0 +25,0 @@ equals(right: OrientedBoundingBox): boolean;

@@ -20,4 +20,2 @@ "use strict";

var _boundingBoxFromPoints = _interopRequireDefault(require("../algorithms/bounding-box-from-points"));
var scratchVector = new _core.Vector3();

@@ -28,3 +26,2 @@ var scratchOffset = new _core.Vector3();

var scratchVectorW = new _core.Vector3();
var scratchPPrime = new _core.Vector3();
var scratchCorner = new _core.Vector3();

@@ -62,8 +59,2 @@ var scratchToCenter = new _core.Vector3();

}, {
key: "fromPoints",
value: function fromPoints(points) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new OrientedBoundingBox();
return (0, _boundingBoxFromPoints["default"])(points, result);
}
}, {
key: "equals",

@@ -125,31 +116,20 @@ value: function equals(right) {

w.normalize();
var pPrime = scratchPPrime;
pPrime.x = offset.dot(u);
pPrime.y = offset.dot(v);
pPrime.z = offset.dot(w);
var distanceSquared = 0.0;
var d;
d = Math.abs(offset.dot(u)) - uHalf;
if (pPrime.x < -uHalf) {
d = pPrime.x + uHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.x > uHalf) {
d = pPrime.x - uHalf;
distanceSquared += d * d;
}
if (pPrime.y < -vHalf) {
d = pPrime.y + vHalf;
d = Math.abs(offset.dot(v)) - vHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.y > vHalf) {
d = pPrime.y - vHalf;
distanceSquared += d * d;
}
if (pPrime.z < -wHalf) {
d = pPrime.z + wHalf;
d = Math.abs(offset.dot(w)) - wHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.z > wHalf) {
d = pPrime.z - wHalf;
distanceSquared += d * d;
}

@@ -156,0 +136,0 @@

import OrientedBoundingBox from '../lib/oriented-bounding-box';
import AxisAlignedBoundingBox from '../lib/axis-aligned-bounding-box';

@@ -9,5 +10,14 @@ /**

*/
export default function makeOrientedBoundingBoxfromPoints(
export function makeOrientedBoundingBoxFromPoints(
positions: number[][],
result
result?: OrientedBoundingBox
): OrientedBoundingBox;
/**
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
export function makeAxisAlignedBoundingBoxFromPoints(
positions: readonly number[][],
result?: AxisAlignedBoundingBox
): AxisAlignedBoundingBox;
import { Vector3, Matrix3 } from '@math.gl/core';
import computeEigenDecomposition from './compute-eigen-decomposition';
import OrientedBoundingBox from '../lib/oriented-bounding-box';
import AxisAlignedBoundingBox from '../lib/axis-aligned-bounding-box';
const scratchVector2 = new Vector3();

@@ -13,3 +15,3 @@ const scratchVector3 = new Vector3();

};
export default function makeOrientedBoundingBoxfromPoints(positions, result) {
export function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
if (!positions || positions.length === 0) {

@@ -94,2 +96,36 @@ result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);

}
export function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAlignedBoundingBox()) {
if (!positions || positions.length === 0) {
result.minimum.set(0, 0, 0);
result.maximum.set(0, 0, 0);
result.center.set(0, 0, 0);
result.halfDiagonal.set(0, 0, 0);
return result;
}
let minimumX = positions[0][0];
let minimumY = positions[0][1];
let minimumZ = positions[0][2];
let maximumX = positions[0][0];
let maximumY = positions[0][1];
let maximumZ = positions[0][2];
for (const p of positions) {
const x = p[0];
const y = p[1];
const z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
result.minimum.set(minimumX, minimumY, minimumZ);
result.maximum.set(maximumX, maximumY, maximumZ);
result.center.copy(result.minimum).add(result.maximum).scale(0.5);
result.halfDiagonal.copy(result.maximum).subtract(result.center);
return result;
}
//# sourceMappingURL=bounding-box-from-points.js.map

@@ -7,4 +7,7 @@ export {default as AxisAlignedBoundingBox} from './lib/axis-aligned-bounding-box';

export {default as makeOrientedBoundingBoxfromPoints} from './algorithms/bounding-box-from-points';
export {default as makeBoundingSphereFromPoints} from './algorithms/bounding-sphere-from-points';
export {
makeAxisAlignedBoundingBoxFromPoints,
makeOrientedBoundingBoxFromPoints
} from './algorithms/bounding-box-from-points';
export {default as computeEigenDecomposition} from './algorithms/compute-eigen-decomposition';

@@ -11,0 +14,0 @@

@@ -10,3 +10,3 @@ export { INTERSECTION } from './constants';

export { default as makeBoundingSphereFromPoints } from './algorithms/bounding-sphere-from-points';
export { default as makeOrientedBoundingBoxFromPoints } from './algorithms/bounding-box-from-points';
export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from './algorithms/bounding-box-from-points';
export { default as computeEigenDecomposition } from './algorithms/compute-eigen-decomposition';

@@ -13,0 +13,0 @@ export { INTERSECTION as Intersect } from './constants';

@@ -13,2 +13,3 @@ import {Vector3} from '@math.gl/core';

readonly center: Vector3;
readonly halfDiagonal: Vector3;

@@ -23,6 +24,2 @@ /**

/** Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
fromPoints(positions: readonly number[][]): AxisAlignedBoundingBox;
/** Duplicates a AxisAlignedBoundingBox instance. */

@@ -34,2 +31,7 @@ clone(): AxisAlignedBoundingBox;

intersectPlane(plane: Plane): INTERSECTION_ENUM;
// Computes the estimated distance from the closest point on a bounding box to a point.
distanceTo(point: readonly number[]): number;
// Computes the estimated distance squared from the closest point on a bounding box to a point.
distanceSquaredTo(point: readonly number[]): number;
}

@@ -8,40 +8,8 @@ import { Vector3 } from '@math.gl/core';

center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);
this.center = new Vector3(center);
this.halfDiagonal = new Vector3(maximum).subtract(this.center);
this.minimum = new Vector3(minimum);
this.maximum = new Vector3(maximum);
this.center = new Vector3(center);
}
fromPoints(positions) {
if (!positions || positions.length === 0) {
this.minimum.set(0, 0, 0);
this.maximum.set(0, 0, 0);
this.center.set(0, 0, 0);
return this;
}
let minimumX = positions[0][0];
let minimumY = positions[0][1];
let minimumZ = positions[0][2];
let maximumX = positions[0][0];
let maximumY = positions[0][1];
let maximumZ = positions[0][2];
for (const p of positions) {
const x = p[0];
const y = p[1];
const z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
this.minimum.set(minimumX, minimumY, minimumZ);
this.maximum.set(maximumX, maximumY, maximumZ);
this.center.copy(this.minimum).add(this.maximum).scale(0.5);
return this;
}
clone() {

@@ -52,9 +20,11 @@ return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);

equals(right) {
return this === right || Boolean(right) && this.center.equals(right.center) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
}
intersectPlane(plane) {
const h = scratchVector.copy(this.maximum).subtract(this.minimum).scale(0.5);
const {
halfDiagonal
} = this;
const normal = scratchNormal.from(plane.normal);
const e = h.x * Math.abs(normal.x) + h.y * Math.abs(normal.y) + h.z * Math.abs(normal.z);
const e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
const s = this.center.dot(normal) + plane.distance;

@@ -73,3 +43,35 @@

distanceTo(point) {
return Math.sqrt(this.distanceSquaredTo(point));
}
distanceSquaredTo(point) {
const offset = scratchVector.from(point).subtract(this.center);
const {
halfDiagonal
} = this;
let distanceSquared = 0.0;
let d;
d = Math.abs(offset.x) - halfDiagonal.x;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.y) - halfDiagonal.y;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.z) - halfDiagonal.z;
if (d > 0) {
distanceSquared += d * d;
}
return distanceSquared;
}
}
//# sourceMappingURL=axis-aligned-bounding-box.js.map

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

fromPoints(points: readonly number[][]): OrientedBoundingBox;
// Compares the provided OrientedBoundingBox componentwise and returns

@@ -27,0 +25,0 @@ equals(right: OrientedBoundingBox): boolean;

import { Vector3, Matrix3 } from '@math.gl/core';
import BoundingSphere from './bounding-sphere';
import { INTERSECTION } from '../constants';
import makeOrientedBoundingBoxfromPoints from '../algorithms/bounding-box-from-points';
const scratchVector = new Vector3();

@@ -10,3 +9,2 @@ const scratchOffset = new Vector3();

const scratchVectorW = new Vector3();
const scratchPPrime = new Vector3();
const scratchCorner = new Vector3();

@@ -38,6 +36,2 @@ const scratchToCenter = new Vector3();

fromPoints(points, result = new OrientedBoundingBox()) {
return makeOrientedBoundingBoxfromPoints(points, result);
}
equals(right) {

@@ -93,31 +87,20 @@ return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes);

w.normalize();
const pPrime = scratchPPrime;
pPrime.x = offset.dot(u);
pPrime.y = offset.dot(v);
pPrime.z = offset.dot(w);
let distanceSquared = 0.0;
let d;
d = Math.abs(offset.dot(u)) - uHalf;
if (pPrime.x < -uHalf) {
d = pPrime.x + uHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.x > uHalf) {
d = pPrime.x - uHalf;
distanceSquared += d * d;
}
if (pPrime.y < -vHalf) {
d = pPrime.y + vHalf;
d = Math.abs(offset.dot(v)) - vHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.y > vHalf) {
d = pPrime.y - vHalf;
distanceSquared += d * d;
}
if (pPrime.z < -wHalf) {
d = pPrime.z + wHalf;
d = Math.abs(offset.dot(w)) - wHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.z > wHalf) {
d = pPrime.z - wHalf;
distanceSquared += d * d;
}

@@ -124,0 +107,0 @@

import OrientedBoundingBox from '../lib/oriented-bounding-box';
import AxisAlignedBoundingBox from '../lib/axis-aligned-bounding-box';

@@ -9,5 +10,14 @@ /**

*/
export default function makeOrientedBoundingBoxfromPoints(
export function makeOrientedBoundingBoxFromPoints(
positions: number[][],
result
result?: OrientedBoundingBox
): OrientedBoundingBox;
/**
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
export function makeAxisAlignedBoundingBoxFromPoints(
positions: readonly number[][],
result?: AxisAlignedBoundingBox
): AxisAlignedBoundingBox;
import { Vector3, Matrix3 } from '@math.gl/core';
import computeEigenDecomposition from './compute-eigen-decomposition';
import OrientedBoundingBox from '../lib/oriented-bounding-box';
import AxisAlignedBoundingBox from '../lib/axis-aligned-bounding-box';
var scratchVector2 = new Vector3();

@@ -13,3 +15,5 @@ var scratchVector3 = new Vector3();

};
export default function makeOrientedBoundingBoxfromPoints(positions, result) {
export function makeOrientedBoundingBoxFromPoints(positions) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new OrientedBoundingBox();
if (!positions || positions.length === 0) {

@@ -152,2 +156,57 @@ result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);

}
export function makeAxisAlignedBoundingBoxFromPoints(positions) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new AxisAlignedBoundingBox();
if (!positions || positions.length === 0) {
result.minimum.set(0, 0, 0);
result.maximum.set(0, 0, 0);
result.center.set(0, 0, 0);
result.halfDiagonal.set(0, 0, 0);
return result;
}
var minimumX = positions[0][0];
var minimumY = positions[0][1];
var minimumZ = positions[0][2];
var maximumX = positions[0][0];
var maximumY = positions[0][1];
var maximumZ = positions[0][2];
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = positions[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var p = _step4.value;
var x = p[0];
var y = p[1];
var z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) {
_iterator4["return"]();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
result.minimum.set(minimumX, minimumY, minimumZ);
result.maximum.set(maximumX, maximumY, maximumZ);
result.center.copy(result.minimum).add(result.maximum).scale(0.5);
result.halfDiagonal.copy(result.maximum).subtract(result.center);
return result;
}
//# sourceMappingURL=bounding-box-from-points.js.map

@@ -7,4 +7,7 @@ export {default as AxisAlignedBoundingBox} from './lib/axis-aligned-bounding-box';

export {default as makeOrientedBoundingBoxfromPoints} from './algorithms/bounding-box-from-points';
export {default as makeBoundingSphereFromPoints} from './algorithms/bounding-sphere-from-points';
export {
makeAxisAlignedBoundingBoxFromPoints,
makeOrientedBoundingBoxFromPoints
} from './algorithms/bounding-box-from-points';
export {default as computeEigenDecomposition} from './algorithms/compute-eigen-decomposition';

@@ -11,0 +14,0 @@

@@ -10,3 +10,3 @@ export { INTERSECTION } from './constants';

export { default as makeBoundingSphereFromPoints } from './algorithms/bounding-sphere-from-points';
export { default as makeOrientedBoundingBoxFromPoints } from './algorithms/bounding-box-from-points';
export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from './algorithms/bounding-box-from-points';
export { default as computeEigenDecomposition } from './algorithms/compute-eigen-decomposition';

@@ -13,0 +13,0 @@ export { INTERSECTION as Intersect } from './constants';

@@ -13,2 +13,3 @@ import {Vector3} from '@math.gl/core';

readonly center: Vector3;
readonly halfDiagonal: Vector3;

@@ -23,6 +24,2 @@ /**

/** Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
fromPoints(positions: readonly number[][]): AxisAlignedBoundingBox;
/** Duplicates a AxisAlignedBoundingBox instance. */

@@ -34,2 +31,7 @@ clone(): AxisAlignedBoundingBox;

intersectPlane(plane: Plane): INTERSECTION_ENUM;
// Computes the estimated distance from the closest point on a bounding box to a point.
distanceTo(point: readonly number[]): number;
// Computes the estimated distance squared from the closest point on a bounding box to a point.
distanceSquaredTo(point: readonly number[]): number;
}

@@ -17,61 +17,9 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";

center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);
this.center = new Vector3(center);
this.halfDiagonal = new Vector3(maximum).subtract(this.center);
this.minimum = new Vector3(minimum);
this.maximum = new Vector3(maximum);
this.center = new Vector3(center);
}
_createClass(AxisAlignedBoundingBox, [{
key: "fromPoints",
value: function fromPoints(positions) {
if (!positions || positions.length === 0) {
this.minimum.set(0, 0, 0);
this.maximum.set(0, 0, 0);
this.center.set(0, 0, 0);
return this;
}
var minimumX = positions[0][0];
var minimumY = positions[0][1];
var minimumZ = positions[0][2];
var maximumX = positions[0][0];
var maximumY = positions[0][1];
var maximumZ = positions[0][2];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = positions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var p = _step.value;
var x = p[0];
var y = p[1];
var z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
this.minimum.set(minimumX, minimumY, minimumZ);
this.maximum.set(maximumX, maximumY, maximumZ);
this.center.copy(this.minimum).add(this.maximum).scale(0.5);
return this;
}
}, {
key: "clone",

@@ -84,3 +32,3 @@ value: function clone() {

value: function equals(right) {
return this === right || Boolean(right) && this.center.equals(right.center) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
}

@@ -90,5 +38,5 @@ }, {

value: function intersectPlane(plane) {
var h = scratchVector.copy(this.maximum).subtract(this.minimum).scale(0.5);
var halfDiagonal = this.halfDiagonal;
var normal = scratchNormal.from(plane.normal);
var e = h.x * Math.abs(normal.x) + h.y * Math.abs(normal.y) + h.z * Math.abs(normal.z);
var e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
var s = this.center.dot(normal) + plane.distance;

@@ -106,2 +54,34 @@

}
}, {
key: "distanceTo",
value: function distanceTo(point) {
return Math.sqrt(this.distanceSquaredTo(point));
}
}, {
key: "distanceSquaredTo",
value: function distanceSquaredTo(point) {
var offset = scratchVector.from(point).subtract(this.center);
var halfDiagonal = this.halfDiagonal;
var distanceSquared = 0.0;
var d;
d = Math.abs(offset.x) - halfDiagonal.x;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.y) - halfDiagonal.y;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.z) - halfDiagonal.z;
if (d > 0) {
distanceSquared += d * d;
}
return distanceSquared;
}
}]);

@@ -108,0 +88,0 @@

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

fromPoints(points: readonly number[][]): OrientedBoundingBox;
// Compares the provided OrientedBoundingBox componentwise and returns

@@ -27,0 +25,0 @@ equals(right: OrientedBoundingBox): boolean;

@@ -6,3 +6,2 @@ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";

import { INTERSECTION } from '../constants';
import makeOrientedBoundingBoxfromPoints from '../algorithms/bounding-box-from-points';
var scratchVector = new Vector3();

@@ -13,3 +12,2 @@ var scratchOffset = new Vector3();

var scratchVectorW = new Vector3();
var scratchPPrime = new Vector3();
var scratchCorner = new Vector3();

@@ -49,8 +47,2 @@ var scratchToCenter = new Vector3();

}, {
key: "fromPoints",
value: function fromPoints(points) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new OrientedBoundingBox();
return makeOrientedBoundingBoxfromPoints(points, result);
}
}, {
key: "equals",

@@ -112,31 +104,20 @@ value: function equals(right) {

w.normalize();
var pPrime = scratchPPrime;
pPrime.x = offset.dot(u);
pPrime.y = offset.dot(v);
pPrime.z = offset.dot(w);
var distanceSquared = 0.0;
var d;
d = Math.abs(offset.dot(u)) - uHalf;
if (pPrime.x < -uHalf) {
d = pPrime.x + uHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.x > uHalf) {
d = pPrime.x - uHalf;
distanceSquared += d * d;
}
if (pPrime.y < -vHalf) {
d = pPrime.y + vHalf;
d = Math.abs(offset.dot(v)) - vHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.y > vHalf) {
d = pPrime.y - vHalf;
distanceSquared += d * d;
}
if (pPrime.z < -wHalf) {
d = pPrime.z + wHalf;
d = Math.abs(offset.dot(w)) - wHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.z > wHalf) {
d = pPrime.z - wHalf;
distanceSquared += d * d;
}

@@ -143,0 +124,0 @@

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

},
"version": "3.2.0-alpha.2",
"version": "3.2.0-alpha.3",
"keywords": [

@@ -40,6 +40,6 @@ "webgl",

"@babel/runtime": "^7.0.0",
"@math.gl/core": "3.2.0-alpha.2",
"@math.gl/core": "3.2.0-alpha.3",
"gl-matrix": "^3.0.0"
},
"gitHead": "127b2196b775281db912472e43f579a201000c88"
"gitHead": "d4dbf43e20c7d51108bcdb52a3bd2ee6846d05a7"
}
import OrientedBoundingBox from '../lib/oriented-bounding-box';
import AxisAlignedBoundingBox from '../lib/axis-aligned-bounding-box';

@@ -9,5 +10,14 @@ /**

*/
export default function makeOrientedBoundingBoxfromPoints(
export function makeOrientedBoundingBoxFromPoints(
positions: number[][],
result
result?: OrientedBoundingBox
): OrientedBoundingBox;
/**
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
export function makeAxisAlignedBoundingBoxFromPoints(
positions: readonly number[][],
result?: AxisAlignedBoundingBox
): AxisAlignedBoundingBox;

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

import computeEigenDecomposition from './compute-eigen-decomposition';
import OrientedBoundingBox from '../lib/oriented-bounding-box';
import AxisAlignedBoundingBox from '../lib/axis-aligned-bounding-box';

@@ -25,4 +27,4 @@ const scratchVector2 = new Vector3();

// eslint-disable-next-line max-statements
export default function makeOrientedBoundingBoxfromPoints(positions, result) {
/* eslint-disable max-statements */
export function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
if (!positions || positions.length === 0) {

@@ -115,1 +117,45 @@ result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);

}
export function makeAxisAlignedBoundingBoxFromPoints(
positions,
result = new AxisAlignedBoundingBox()
) {
if (!positions || positions.length === 0) {
result.minimum.set(0, 0, 0);
result.maximum.set(0, 0, 0);
result.center.set(0, 0, 0);
result.halfDiagonal.set(0, 0, 0);
return result;
}
let minimumX = positions[0][0];
let minimumY = positions[0][1];
let minimumZ = positions[0][2];
let maximumX = positions[0][0];
let maximumY = positions[0][1];
let maximumZ = positions[0][2];
for (const p of positions) {
const x = p[0];
const y = p[1];
const z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
result.minimum.set(minimumX, minimumY, minimumZ);
result.maximum.set(maximumX, maximumY, maximumZ);
result.center
.copy(result.minimum)
.add(result.maximum)
.scale(0.5);
result.halfDiagonal.copy(result.maximum).subtract(result.center);
return result;
}

@@ -7,4 +7,7 @@ export {default as AxisAlignedBoundingBox} from './lib/axis-aligned-bounding-box';

export {default as makeOrientedBoundingBoxfromPoints} from './algorithms/bounding-box-from-points';
export {default as makeBoundingSphereFromPoints} from './algorithms/bounding-sphere-from-points';
export {
makeAxisAlignedBoundingBoxFromPoints,
makeOrientedBoundingBoxFromPoints
} from './algorithms/bounding-box-from-points';
export {default as computeEigenDecomposition} from './algorithms/compute-eigen-decomposition';

@@ -11,0 +14,0 @@

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

export {default as makeBoundingSphereFromPoints} from './algorithms/bounding-sphere-from-points';
export {default as makeOrientedBoundingBoxFromPoints} from './algorithms/bounding-box-from-points';
export {
makeAxisAlignedBoundingBoxFromPoints,
makeOrientedBoundingBoxFromPoints
} from './algorithms/bounding-box-from-points';
export {default as computeEigenDecomposition} from './algorithms/compute-eigen-decomposition';

@@ -19,0 +22,0 @@

@@ -13,2 +13,3 @@ import {Vector3} from '@math.gl/core';

readonly center: Vector3;
readonly halfDiagonal: Vector3;

@@ -23,6 +24,2 @@ /**

/** Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*/
fromPoints(positions: readonly number[][]): AxisAlignedBoundingBox;
/** Duplicates a AxisAlignedBoundingBox instance. */

@@ -34,2 +31,7 @@ clone(): AxisAlignedBoundingBox;

intersectPlane(plane: Plane): INTERSECTION_ENUM;
// Computes the estimated distance from the closest point on a bounding box to a point.
distanceTo(point: readonly number[]): number;
// Computes the estimated distance squared from the closest point on a bounding box to a point.
distanceSquaredTo(point: readonly number[]): number;
}

@@ -16,2 +16,12 @@ import {Vector3} from '@math.gl/core';

.scale(0.5);
/**
* The center point of the bounding box.
* @type {Vector3}
*/
this.center = new Vector3(center);
/**
* The positive half diagonal of the bounding box.
* @type {Vector3}
*/
this.halfDiagonal = new Vector3(maximum).subtract(this.center);

@@ -31,62 +41,5 @@ /**

this.maximum = new Vector3(maximum);
/**
* The center point of the bounding box.
* @type {Vector3}
*/
this.center = new Vector3(center);
}
/**
* Computes an instance of an AxisAlignedBoundingBox. The box is determined by
* finding the points spaced the farthest apart on the x, y, and z axes.
*
* @param {Vector3[]} positions List of points that the bounding box will enclose. Each point must have a <code>x</code>, <code>y</code>, and <code>z</code> properties.
* @returns {AxisAlignedBoundingBox} The modified result parameter or a new AxisAlignedBoundingBox instance if one was not provided.
*
* @example
* // Compute an axis aligned bounding box enclosing two points.
* const box = Cesium.AxisAlignedBoundingBox.fromPoints([new Cesium.Vector3(2, 0, 0), new Cesium.Vector3(-2, 0, 0)]);
*/
// eslint-disable-next-line
fromPoints(positions) {
if (!positions || positions.length === 0) {
this.minimum.set(0, 0, 0);
this.maximum.set(0, 0, 0);
this.center.set(0, 0, 0);
return this;
}
let minimumX = positions[0][0];
let minimumY = positions[0][1];
let minimumZ = positions[0][2];
let maximumX = positions[0][0];
let maximumY = positions[0][1];
let maximumZ = positions[0][2];
for (const p of positions) {
const x = p[0];
const y = p[1];
const z = p[2];
minimumX = Math.min(x, minimumX);
maximumX = Math.max(x, maximumX);
minimumY = Math.min(y, minimumY);
maximumY = Math.max(y, maximumY);
minimumZ = Math.min(z, minimumZ);
maximumZ = Math.max(z, maximumZ);
}
this.minimum.set(minimumX, minimumY, minimumZ);
this.maximum.set(maximumX, maximumY, maximumZ);
this.center
.copy(this.minimum)
.add(this.maximum)
.scale(0.5);
return this;
}
/**
* Duplicates a AxisAlignedBoundingBox instance.

@@ -110,6 +63,3 @@ *

this === right ||
(Boolean(right) &&
this.center.equals(right.center) &&
this.minimum.equals(right.minimum) &&
this.maximum.equals(right.maximum))
(Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))
);

@@ -122,8 +72,8 @@ }

intersectPlane(plane) {
const h = scratchVector
.copy(this.maximum)
.subtract(this.minimum)
.scale(0.5); // The positive half diagonal
const {halfDiagonal} = this;
const normal = scratchNormal.from(plane.normal);
const e = h.x * Math.abs(normal.x) + h.y * Math.abs(normal.y) + h.z * Math.abs(normal.z);
const e =
halfDiagonal.x * Math.abs(normal.x) +
halfDiagonal.y * Math.abs(normal.y) +
halfDiagonal.z * Math.abs(normal.z);
const s = this.center.dot(normal) + plane.distance; // signed distance from center

@@ -142,2 +92,34 @@

}
// Computes the estimated distance from the closest point on a bounding box to a point.
distanceTo(point) {
return Math.sqrt(this.distanceSquaredTo(point));
}
// Computes the estimated distance squared from the closest point on a bounding box to a point.
// A simplified version of OrientedBoundingBox.distanceSquaredTo
distanceSquaredTo(point) {
const offset = scratchVector.from(point).subtract(this.center);
const {halfDiagonal} = this;
let distanceSquared = 0.0;
let d;
d = Math.abs(offset.x) - halfDiagonal.x;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.y) - halfDiagonal.y;
if (d > 0) {
distanceSquared += d * d;
}
d = Math.abs(offset.z) - halfDiagonal.z;
if (d > 0) {
distanceSquared += d * d;
}
return distanceSquared;
}
}

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

fromPoints(points: readonly number[][]): OrientedBoundingBox;
// Compares the provided OrientedBoundingBox componentwise and returns

@@ -27,0 +25,0 @@ equals(right: OrientedBoundingBox): boolean;

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

import {INTERSECTION} from '../constants';
import makeOrientedBoundingBoxfromPoints from '../algorithms/bounding-box-from-points';

@@ -15,3 +14,2 @@ const scratchVector = new Vector3();

const scratchVectorW = new Vector3();
const scratchPPrime = new Vector3();
const scratchCorner = new Vector3();

@@ -47,6 +45,2 @@ const scratchToCenter = new Vector3();

fromPoints(points, result = new OrientedBoundingBox()) {
return makeOrientedBoundingBoxfromPoints(points, result);
}
// Compares the provided OrientedBoundingBox componentwise and returns

@@ -151,32 +145,18 @@ equals(right) {

const pPrime = scratchPPrime;
pPrime.x = offset.dot(u);
pPrime.y = offset.dot(v);
pPrime.z = offset.dot(w);
let distanceSquared = 0.0;
let d;
if (pPrime.x < -uHalf) {
d = pPrime.x + uHalf;
d = Math.abs(offset.dot(u)) - uHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.x > uHalf) {
d = pPrime.x - uHalf;
distanceSquared += d * d;
}
if (pPrime.y < -vHalf) {
d = pPrime.y + vHalf;
d = Math.abs(offset.dot(v)) - vHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.y > vHalf) {
d = pPrime.y - vHalf;
distanceSquared += d * d;
}
if (pPrime.z < -wHalf) {
d = pPrime.z + wHalf;
d = Math.abs(offset.dot(w)) - wHalf;
if (d > 0) {
distanceSquared += d * d;
} else if (pPrime.z > wHalf) {
d = pPrime.z - wHalf;
distanceSquared += d * d;
}

@@ -183,0 +163,0 @@

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