@math.gl/culling 4.0.0-alpha.4 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,10 +14,6 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
18
 
25
19
  // src/index.ts
@@ -111,7 +105,6 @@ var AxisAlignedBoundingBox = class {
111
105
 
112
106
  // src/lib/bounding-volumes/bounding-sphere.ts
113
107
  var import_core2 = require("@math.gl/core");
114
- var mat4 = __toESM(require("gl-matrix/mat4"), 1);
115
108
  var scratchVector2 = new import_core2.Vector3();
116
109
  var scratchVector22 = new import_core2.Vector3();
117
110
  var BoundingSphere = class {
@@ -166,7 +159,7 @@ var BoundingSphere = class {
166
159
  }
167
160
  transform(transform) {
168
161
  this.center.transform(transform);
169
- const scale = mat4.getScaling(scratchVector2, transform);
162
+ const scale = import_core2.mat4.getScaling(scratchVector2, transform);
170
163
  this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
171
164
  return this;
172
165
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-sphere.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":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 'gl-matrix/mat4';
2
+ import { Vector3, mat4 } from '@math.gl/core';
4
3
  import { INTERSECTION } from "../../constants.js";
5
4
  const scratchVector = new Vector3();
6
5
  const scratchVector2 = new Vector3();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["Vector3","mat4","INTERSECTION","scratchVector","scratchVector2","BoundingSphere","constructor","center","radius","fromCenterRadius","from","fromCornerPoints","corner","oppositeCorner","add","scale","distance","equals","right","Boolean","clone","union","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","halfDistanceBetweenTangentPoints","expand","point","scratchPoint","transform","getScaling","Math","max","distanceSquaredTo","d","distanceTo","delta","len","intersectPlane","plane","normal","distanceToPlane","dot","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";AAGA,SAAsBA,OAAtB,QAAoC,eAApC;AAEA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;SAEQC,Y;AAIR,MAAMC,aAAa,GAAG,IAAIH,OAAJ,EAAtB;AACA,MAAMI,cAAc,GAAG,IAAIJ,OAAJ,EAAvB;AAGA,OAAO,MAAMK,cAAN,CAA+C;AAKpDC,EAAAA,WAAW,CAACC,MAAyB,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA7B,EAAwCC,MAAc,GAAG,GAAzD,EAA8D;AAAA;;AAAA;;AACvE,SAAKA,MAAL,GAAc,CAAC,CAAf;AACA,SAAKD,MAAL,GAAc,IAAIP,OAAJ,EAAd;AACA,SAAKS,gBAAL,CAAsBF,MAAtB,EAA8BC,MAA9B;AACD;;AAGDC,EAAAA,gBAAgB,CAACF,MAAD,EAA4BC,MAA5B,EAAkD;AAChE,SAAKD,MAAL,CAAYG,IAAZ,CAAiBH,MAAjB;AACA,SAAKC,MAAL,GAAcA,MAAd;AACA,WAAO,IAAP;AACD;;AAMDG,EAAAA,gBAAgB,CAACC,MAAD,EAA4BC,cAA5B,EAA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CAAmBwB,KAAnB,CAArB;AACA,UAAMS,KAAK,GAAGR,YAAY,CAACN,QAAb,CAAsB,KAAKtB,MAA3B,CAAd;AACA,WAAO+B,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYI,KAAK,CAACC,GAAN,KAAc,KAAKpC,MAA/B,CAAP;AACD;;AAGDqC,EAAAA,cAAc,CAACC,KAAD,EAAuB;AACnC,UAAMvC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMuC,MAAM,GAAGD,KAAK,CAACC,MAArB;AACA,UAAMC,eAAe,GAAGD,MAAM,CAACE,GAAP,CAAW1C,MAAX,IAAqBuC,KAAK,CAAC9B,QAAnD;;AAGA,QAAIgC,eAAe,GAAG,CAACxC,MAAvB,EAA+B;AAC7B,aAAON,YAAY,CAACgD,OAApB;AACD;;AAED,QAAIF,eAAe,GAAGxC,MAAtB,EAA8B;AAC5B,aAAON,YAAY,CAACiD,YAApB;AACD;;AAED,WAAOjD,YAAY,CAACkD,MAApB;AACD;;AApImD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {NumericArray, Vector3} from '@math.gl/core';\n// @ts-ignore gl-matrix typings...\nimport * as mat4 from 'gl-matrix/mat4';\n\nimport {INTERSECTION} from '../../constants';\nimport {BoundingVolume} from './bounding-volume';\nimport {Plane} from '../plane';\n\nconst scratchVector = new Vector3();\nconst scratchVector2 = new Vector3();\n\n/** A BoundingSphere */\nexport class BoundingSphere implements BoundingVolume {\n center: Vector3;\n radius: number;\n\n /** Creates a bounding sphere */\n constructor(center: readonly number[] = [0, 0, 0], radius: number = 0.0) {\n this.radius = -0;\n this.center = new Vector3();\n this.fromCenterRadius(center, radius);\n }\n\n /** Sets the bounding sphere from `center` and `radius`. */\n fromCenterRadius(center: readonly number[], radius: number): this {\n this.center.from(center);\n this.radius = radius;\n return this;\n }\n\n /**\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\n * tightly and fully encompasses the box.\n */\n fromCornerPoints(corner: readonly number[], oppositeCorner: readonly number[]): this {\n oppositeCorner = scratchVector.from(oppositeCorner);\n this.center = new Vector3().from(corner).add(oppositeCorner).scale(0.5);\n this.radius = this.center.distance(oppositeCorner);\n return this;\n }\n\n /** Compares the provided BoundingSphere component wise */\n equals(right: BoundingSphere): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.radius === right.radius)\n );\n }\n\n /** Duplicates a BoundingSphere instance. */\n clone(): BoundingSphere {\n return new BoundingSphere(this.center, this.radius);\n }\n\n /** Computes a bounding sphere that contains both the left and right bounding spheres. */\n union(boundingSphere: BoundingSphere): BoundingSphere {\n const leftCenter = this.center;\n const leftRadius = this.radius;\n const rightCenter = boundingSphere.center;\n const rightRadius = boundingSphere.radius;\n\n const toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);\n const centerSeparation = toRightCenter.magnitude();\n\n if (leftRadius >= centerSeparation + rightRadius) {\n // Left sphere wins.\n return this.clone();\n }\n\n if (rightRadius >= centerSeparation + leftRadius) {\n // Right sphere wins.\n return boundingSphere.clone();\n }\n\n // There are two tangent points, one on far side of each sphere.\n const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;\n\n // Compute the center point halfway between the two tangent points.\n scratchVector2\n .copy(toRightCenter)\n .scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation)\n .add(leftCenter);\n\n this.center.copy(scratchVector2);\n this.radius = halfDistanceBetweenTangentPoints;\n\n return this;\n }\n\n /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */\n expand(point: readonly number[]): this {\n const scratchPoint = scratchVector.from(point);\n const radius = scratchPoint.subtract(this.center).magnitude();\n if (radius > this.radius) {\n this.radius = radius;\n }\n return this;\n }\n\n // BoundingVolume interface\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param sphere The bounding sphere to apply the transformation to.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns self.\n */\n transform(transform: readonly number[]): this {\n this.center.transform(transform);\n const scale = mat4.getScaling(scratchVector, transform);\n this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;\n return this;\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */\n distanceSquaredTo(point: Readonly<NumericArray>): number {\n const d = this.distanceTo(point);\n return d * d;\n }\n\n /** Computes the estimated distance from the closest point on a bounding sphere to a point. */\n distanceTo(point: Readonly<NumericArray>): number {\n const scratchPoint = scratchVector.from(point);\n const delta = scratchPoint.subtract(this.center);\n return Math.max(0, delta.len() - this.radius);\n }\n\n /** Determines which side of a plane a sphere is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const radius = this.radius;\n const normal = plane.normal;\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n // The center point is negative side of the plane normal\n if (distanceToPlane < -radius) {\n return INTERSECTION.OUTSIDE;\n }\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\n if (distanceToPlane < radius) {\n return INTERSECTION.INTERSECTING;\n }\n // The center point and radius is positive side of the plane\n return INTERSECTION.INSIDE;\n }\n}\n"],"file":"bounding-sphere.js"}
1
+ {"version":3,"sources":["../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["Vector3","mat4","INTERSECTION","scratchVector","scratchVector2","BoundingSphere","constructor","center","radius","fromCenterRadius","from","fromCornerPoints","corner","oppositeCorner","add","scale","distance","equals","right","Boolean","clone","union","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","halfDistanceBetweenTangentPoints","expand","point","scratchPoint","transform","getScaling","Math","max","distanceSquaredTo","d","distanceTo","delta","len","intersectPlane","plane","normal","distanceToPlane","dot","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";AAGA,SAAsBA,OAAtB,EAA+BC,IAA/B,QAA0C,eAA1C;SAEQC,Y;A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ED,WAAOjD,YAAY,CAACkD,MAApB;AACD;;AApImD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {NumericArray, Vector3, mat4} from '@math.gl/core';\n\nimport {INTERSECTION} from '../../constants';\nimport {BoundingVolume} from './bounding-volume';\nimport {Plane} from '../plane';\n\nconst scratchVector = new Vector3();\nconst scratchVector2 = new Vector3();\n\n/** A BoundingSphere */\nexport class BoundingSphere implements BoundingVolume {\n center: Vector3;\n radius: number;\n\n /** Creates a bounding sphere */\n constructor(center: readonly number[] = [0, 0, 0], radius: number = 0.0) {\n this.radius = -0;\n this.center = new Vector3();\n this.fromCenterRadius(center, radius);\n }\n\n /** Sets the bounding sphere from `center` and `radius`. */\n fromCenterRadius(center: readonly number[], radius: number): this {\n this.center.from(center);\n this.radius = radius;\n return this;\n }\n\n /**\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\n * tightly and fully encompasses the box.\n */\n fromCornerPoints(corner: readonly number[], oppositeCorner: readonly number[]): this {\n oppositeCorner = scratchVector.from(oppositeCorner);\n this.center = new Vector3().from(corner).add(oppositeCorner).scale(0.5);\n this.radius = this.center.distance(oppositeCorner);\n return this;\n }\n\n /** Compares the provided BoundingSphere component wise */\n equals(right: BoundingSphere): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.radius === right.radius)\n );\n }\n\n /** Duplicates a BoundingSphere instance. */\n clone(): BoundingSphere {\n return new BoundingSphere(this.center, this.radius);\n }\n\n /** Computes a bounding sphere that contains both the left and right bounding spheres. */\n union(boundingSphere: BoundingSphere): BoundingSphere {\n const leftCenter = this.center;\n const leftRadius = this.radius;\n const rightCenter = boundingSphere.center;\n const rightRadius = boundingSphere.radius;\n\n const toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);\n const centerSeparation = toRightCenter.magnitude();\n\n if (leftRadius >= centerSeparation + rightRadius) {\n // Left sphere wins.\n return this.clone();\n }\n\n if (rightRadius >= centerSeparation + leftRadius) {\n // Right sphere wins.\n return boundingSphere.clone();\n }\n\n // There are two tangent points, one on far side of each sphere.\n const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;\n\n // Compute the center point halfway between the two tangent points.\n scratchVector2\n .copy(toRightCenter)\n .scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation)\n .add(leftCenter);\n\n this.center.copy(scratchVector2);\n this.radius = halfDistanceBetweenTangentPoints;\n\n return this;\n }\n\n /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */\n expand(point: readonly number[]): this {\n const scratchPoint = scratchVector.from(point);\n const radius = scratchPoint.subtract(this.center).magnitude();\n if (radius > this.radius) {\n this.radius = radius;\n }\n return this;\n }\n\n // BoundingVolume interface\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param sphere The bounding sphere to apply the transformation to.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns self.\n */\n transform(transform: readonly number[]): this {\n this.center.transform(transform);\n const scale = mat4.getScaling(scratchVector, transform);\n this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;\n return this;\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */\n distanceSquaredTo(point: Readonly<NumericArray>): number {\n const d = this.distanceTo(point);\n return d * d;\n }\n\n /** Computes the estimated distance from the closest point on a bounding sphere to a point. */\n distanceTo(point: Readonly<NumericArray>): number {\n const scratchPoint = scratchVector.from(point);\n const delta = scratchPoint.subtract(this.center);\n return Math.max(0, delta.len() - this.radius);\n }\n\n /** Determines which side of a plane a sphere is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const radius = this.radius;\n const normal = plane.normal;\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n // The center point is negative side of the plane normal\n if (distanceToPlane < -radius) {\n return INTERSECTION.OUTSIDE;\n }\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\n if (distanceToPlane < radius) {\n return INTERSECTION.INTERSECTING;\n }\n // The center point and radius is positive side of the plane\n return INTERSECTION.INSIDE;\n }\n}\n"],"file":"bounding-sphere.js"}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
- "version": "4.0.0-alpha.4",
9
+ "version": "4.0.0",
10
10
  "keywords": [
11
11
  "webgl",
12
12
  "javascript",
@@ -43,8 +43,7 @@
43
43
  ],
44
44
  "dependencies": {
45
45
  "@babel/runtime": "^7.12.0",
46
- "@math.gl/core": "4.0.0-alpha.4",
47
- "gl-matrix": "^3.4.3"
46
+ "@math.gl/core": "4.0.0"
48
47
  },
49
- "gitHead": "c58e63bfb9c25cd5a4fb2599b2b52c272ed55c67"
48
+ "gitHead": "b7af99a25965af5112307552084fbaf5d4d53b7d"
50
49
  }
@@ -1,9 +1,7 @@
1
1
  // This file is derived from the Cesium math library under Apache 2 license
2
2
  // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
3
 
4
- import {NumericArray, Vector3} from '@math.gl/core';
5
- // @ts-ignore gl-matrix typings...
6
- import * as mat4 from 'gl-matrix/mat4';
4
+ import {NumericArray, Vector3, mat4} from '@math.gl/core';
7
5
 
8
6
  import {INTERSECTION} from '../../constants';
9
7
  import {BoundingVolume} from './bounding-volume';