@math.gl/culling 3.6.1 → 3.6.2

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.
Files changed (44) hide show
  1. package/dist/constants.d.ts +5 -5
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/es5/constants.js +5 -7
  4. package/dist/es5/constants.js.map +1 -1
  5. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  6. package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
  7. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  8. package/dist/es5/lib/culling-volume.js.map +1 -1
  9. package/dist/esm/constants.js +5 -7
  10. package/dist/esm/constants.js.map +1 -1
  11. package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  12. package/dist/esm/lib/bounding-volumes/bounding-sphere.js.map +1 -1
  13. package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  14. package/dist/esm/lib/culling-volume.js.map +1 -1
  15. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +1 -2
  16. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  17. package/dist/lib/bounding-volumes/bounding-sphere.d.ts +1 -2
  18. package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -1
  19. package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -2
  20. package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -1
  21. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +1 -2
  22. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
  23. package/dist/lib/culling-volume.d.ts +1 -2
  24. package/dist/lib/culling-volume.d.ts.map +1 -1
  25. package/package.json +3 -3
  26. package/src/constants.ts +5 -5
  27. package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +1 -1
  28. package/src/lib/bounding-volumes/bounding-sphere.ts +1 -1
  29. package/src/lib/bounding-volumes/bounding-volume.ts +1 -1
  30. package/src/lib/bounding-volumes/oriented-bounding-box.ts +1 -1
  31. package/src/lib/culling-volume.ts +2 -2
  32. package/dist/constants.js +0 -8
  33. package/dist/index.js +0 -13
  34. package/dist/lib/algorithms/bounding-box-from-points.js +0 -131
  35. package/dist/lib/algorithms/bounding-sphere-from-points.js +0 -140
  36. package/dist/lib/algorithms/compute-eigen-decomposition.js +0 -131
  37. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +0 -111
  38. package/dist/lib/bounding-volumes/bounding-sphere.js +0 -118
  39. package/dist/lib/bounding-volumes/bounding-volume.js +0 -1
  40. package/dist/lib/bounding-volumes/oriented-bounding-box.js +0 -256
  41. package/dist/lib/culling-volume.js +0 -121
  42. package/dist/lib/perspective-frustum.js +0 -190
  43. package/dist/lib/perspective-off-center-frustum.js +0 -270
  44. package/dist/lib/plane.js +0 -63
@@ -1,6 +1,6 @@
1
- export declare enum INTERSECTION {
2
- OUTSIDE = -1,
3
- INTERSECTING = 0,
4
- INSIDE = 1
5
- }
1
+ export declare const INTERSECTION: {
2
+ readonly OUTSIDE: -1;
3
+ readonly INTERSECTING: 0;
4
+ readonly INSIDE: 1;
5
+ };
6
6
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,oBAAY,YAAY;IACtB,OAAO,KAAK;IACZ,YAAY,IAAI;IAChB,MAAM,IAAI;CACX"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;CAIf,CAAC"}
@@ -4,12 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.INTERSECTION = void 0;
7
- var INTERSECTION;
7
+ var INTERSECTION = {
8
+ OUTSIDE: -1,
9
+ INTERSECTING: 0,
10
+ INSIDE: 1
11
+ };
8
12
  exports.INTERSECTION = INTERSECTION;
9
-
10
- (function (INTERSECTION) {
11
- INTERSECTION[INTERSECTION["OUTSIDE"] = -1] = "OUTSIDE";
12
- INTERSECTION[INTERSECTION["INTERSECTING"] = 0] = "INTERSECTING";
13
- INTERSECTION[INTERSECTION["INSIDE"] = 1] = "INSIDE";
14
- })(INTERSECTION || (exports.INTERSECTION = INTERSECTION = {}));
15
13
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/constants.ts"],"names":["INTERSECTION"],"mappings":";;;;;;IAGYA,Y;;;WAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;GAAAA,Y,4BAAAA,Y","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\nexport enum INTERSECTION {\n OUTSIDE = -1, // Represents that an object is not contained within the frustum.\n INTERSECTING = 0, // Represents that an object intersects one of the frustum's planes.\n INSIDE = 1 // Represents that an object is fully within the frustum.\n}\n"],"file":"constants.js"}
1
+ {"version":3,"sources":["../../src/constants.ts"],"names":["INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";;;;;;AAGO,IAAMA,YAAY,GAAG;AAC1BC,EAAAA,OAAO,EAAE,CAAC,CADgB;AAE1BC,EAAAA,YAAY,EAAE,CAFY;AAG1BC,EAAAA,MAAM,EAAE;AAHkB,CAArB","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\nexport const INTERSECTION = {\n OUTSIDE: -1, // Represents that an object is not contained within the frustum.\n INTERSECTING: 0, // Represents that an object intersects one of the frustum's planes.\n INSIDE: 1 // Represents that an object is fully within the frustum.\n} as const;\n"],"file":"constants.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","scratchNormal","AxisAlignedBoundingBox","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","right","Boolean","equals","transform","transformAsPoint","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAQqBE,sB;AAgBnB,oCAIE;AAAA,QAHAC,OAGA,uEAH6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAG7B;AAAA,QAFAC,OAEA,uEAF6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAE7B;AAAA,QADAC,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIN,aAAa,CAACO,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,EAAyCI,KAAzC,CAA+C,GAA/C,CAAnB;AACA,SAAKH,MAAL,GAAc,IAAIL,aAAJ,CAAYK,MAAZ,CAAd;AACA,SAAKI,YAAL,GAAoB,IAAIT,aAAJ,CAAYI,OAAZ,EAAqBM,QAArB,CAA8B,KAAKL,MAAnC,CAApB;AAOA,SAAKF,OAAL,GAAe,IAAIH,aAAJ,CAAYG,OAAZ,CAAf;AAOA,SAAKC,OAAL,GAAe,IAAIJ,aAAJ,CAAYI,OAAZ,CAAf;AACD;;;;WAOD,iBAAgC;AAC9B,aAAO,IAAIF,sBAAJ,CAA2B,KAAKC,OAAhC,EAAyC,KAAKC,OAA9C,EAAuD,KAAKC,MAA5D,CAAP;AACD;;;WASD,gBAAOM,KAAP,EAA+C;AAC7C,aACE,SAASA,KAAT,IACCC,OAAO,CAACD,KAAD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AAP;AACD;;;WAGD,2BAAkBA,KAAlB,EAAoD;AAClD,UAAMG,MAAM,GAAGpC,aAAa,CAACmB,IAAd,CAAmBc,KAAnB,EAA0BtB,QAA1B,CAAmC,KAAKL,MAAxC,CAAf;AACA,UAAOI,YAAP,GAAuB,IAAvB,CAAOA,YAAP;AAEA,UAAI2B,eAAe,GAAG,GAAtB;AACA,UAAIC,CAAJ;AAEAA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACf,CAAhB,IAAqBX,YAAY,CAACW,CAAtC;;AACA,UAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBd,YAAY,CAACc,CAAtC;;AACA,UAAIc,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACX,CAAhB,IAAqBf,YAAY,CAACe,CAAtC;;AACA,UAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,aAAOD,eAAP;AACD","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone(): AxisAlignedBoundingBox {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right: AxisAlignedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): INTERSECTION {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","scratchNormal","AxisAlignedBoundingBox","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","right","Boolean","equals","transform","transformAsPoint","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,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AAY,CAACW,CAAtC;;AACA,UAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBd,YAAY,CAACc,CAAtC;;AACA,UAAIc,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACX,CAAhB,IAAqBf,YAAY,CAACe,CAAtC;;AACA,UAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,aAAOD,eAAP;AACD","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone(): AxisAlignedBoundingBox {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right: AxisAlignedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): number {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["scratchVector","Vector3","scratchVector2","BoundingSphere","center","radius","fromCenterRadius","from","corner","oppositeCorner","add","scale","distance","right","Boolean","equals","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","clone","halfDistanceBetweenTangentPoints","point","scratchPoint","transform","mat4","getScaling","Math","max","d","distanceTo","delta","len","plane","normal","distanceToPlane","dot","INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;;;;;AAIA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;;IAGqBE,c;AAKnB,4BAAyE;AAAA,QAA7DC,MAA6D,uEAAjC,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAiC;AAAA,QAAtBC,MAAsB,uEAAL,GAAK;AAAA;AAAA;AAAA;AACvE,SAAKA,MAAL,GAAc,CA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AAO,IAAP;AACD;;;WAGD,2BAAkBuB,KAAlB,EAAyD;AACvD,UAAMO,CAAC,GAAG,KAAKC,UAAL,CAAgBR,KAAhB,CAAV;AACA,aAAOO,CAAC,GAAGA,CAAX;AACD;;;WAGD,oBAAWP,KAAX,EAAkD;AAChD,UAAMC,YAAY,GAAG7B,aAAa,CAACO,IAAd,CAAmBqB,KAAnB,CAArB;AACA,UAAMS,KAAK,GAAGR,YAAY,CAACN,QAAb,CAAsB,KAAKnB,MAA3B,CAAd;AACA,aAAO6B,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYG,KAAK,CAACC,GAAN,KAAc,KAAKjC,MAA/B,CAAP;AACD;;;WAGD,wBAAekC,KAAf,EAA2C;AACzC,UAAMnC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMmC,MAAM,GAAGD,KAAK,CAACC,MAArB;AACA,UAAMC,eAAe,GAAGD,MAAM,CAACE,GAAP,CAAWtC,MAAX,IAAqBmC,KAAK,CAAC3B,QAAnD;;AAGA,UAAI6B,eAAe,GAAG,CAACpC,MAAvB,EAA+B;AAC7B,eAAOsC,wBAAaC,OAApB;AACD;;AAED,UAAIH,eAAe,GAAGpC,MAAtB,EAA8B;AAC5B,eAAOsC,wBAAaE,YAApB;AACD;;AAED,aAAOF,wBAAaG,MAApB;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {NumericArray, Vector3} from '@math.gl/core';\nimport * as mat4 from 'gl-matrix/mat4';\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 default 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): INTERSECTION {\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":["scratchVector","Vector3","scratchVector2","BoundingSphere","center","radius","fromCenterRadius","from","corner","oppositeCorner","add","scale","distance","right","Boolean","equals","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","clone","halfDistanceBetweenTangentPoints","point","scratchPoint","transform","mat4","getScaling","Math","max","d","distanceTo","delta","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AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {NumericArray, Vector3} from '@math.gl/core';\nimport * as mat4 from 'gl-matrix/mat4';\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 default 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 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["scratchVector3","Vector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","center","halfAxes","from","Matrix3","xAxis","getColumn","yAxis","zAxis","len","normXAxis","normalize","normYAxis","normZAxis","Quaternion","fromMatrix3","halfSize","quaternion","quaternionObject","directionsMatrix","fromQuaternion","right","Boolean","equals","result","BoundingSphere","u","v","w","cornerVector","copy","add","radius","magnitude","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","INTERSECTION","OUTSIDE","INSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transformation","transformAsPoint","Error"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAEA;;AAEA;;AAEA,IAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AACA,IAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AACA,IAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AACA,IAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AACA,IAAMK,aAAa,GAAG,IAAIL,aAAJ,EAAtB;AACA,IAAMM,eAAe,GAAG,IAAIN,aAAJ,EAAxB;AAEA,IAAMO,OAAO,GAAG;AACdC,EAAAA,WAAW,EAAE,CADC;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3C,MAAP;AACD;;;WAOD,mBAAUkD,cAAV,EAAmD;AACjD,WAAKzE,MAAL,CAAY0E,gBAAZ,CAA6BD,cAA7B;AAEA,UAAMrE,KAAK,GAAG,KAAKH,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BrB,cAA3B,CAAd;AACAoB,MAAAA,KAAK,CAACsE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMnE,KAAK,GAAG,KAAKL,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BpB,cAA3B,CAAd;AACAqB,MAAAA,KAAK,CAACoE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMlE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BnB,cAA3B,CAAd;AACAqB,MAAAA,KAAK,CAACmE,gBAAN,CAAuBD,cAAvB;AAEA,WAAKxE,QAAL,GAAgB,IAAIE,aAAJ,4CAAgBC,KAAhB,oCAA0BE,KAA1B,oCAAoCC,KAApC,GAAhB;AACA,aAAO,IAAP;AACD;;;WAED,wBAAwB;AAGtB,YAAM,IAAIoE,KAAJ,CAAU,iBAAV,CAAN;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): INTERSECTION {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["scratchVector3","Vector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","center","halfAxes","from","Matrix3","xAxis","getColumn","yAxis","zAxis","len","normXAxis","normalize","normYAxis","normZAxis","Quaternion","fromMatrix3","halfSize","quaternion","quaternionObject","directionsMatrix","fromQuaternion","right","Boolean","equals","result","BoundingSphere","u","v","w","cornerVector","copy","add","radius","magnitude","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","INTERSECTION","OUTSIDE","INSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transformation","transformAsPoint","Error"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAEA;;AAEA;;AAEA,IAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AACA,IAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AACA,IAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AACA,IAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AACA,IAAMK,aAAa,GAAG,IAAIL,aAAJ,EAAtB;AACA,IAAMM,eAAe,GAAG,IAAIN,aAAJ,EAAxB;AAEA,IAAMO,OAAO,GAAG;AACdC,EAAAA,WAAW,EAAE,CADC;AAEdC,EAAAA,WAAW,EAAE,CAFC;AAGdC,EAAAA,WAAW,EAAE,CAHC;AAIdC,EAAAA,WAAW,EAAE,CAJC;AAKdC,EAAAA,WAAW,EAAE,CALC;AAMdC,EAAAA,WAAW,EAAE,CANC;AAOdC,EAAAA,WAAW,EAAE,CAPC;AAQdC,EAAAA,WAAW,EAAE,CARC;AASdC,EAAAA,WAAW,EAAE;AATC,CAAhB;;IAiBqBC,mB;AAUnB,iCAAgG;AAAA,QAApFC,MAAoF,uEAAnD,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAmD;AAAA,QAAxCC,QAAwC,uEAA7B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAm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B,MAAAA,KAAK,CAACmE,gBAAN,CAAuBD,cAAvB;AAEA,WAAKxE,QAAL,GAAgB,IAAIE,aAAJ,4CAAgBC,KAAhB,oCAA0BE,KAA1B,oCAAoCC,KAApC,GAAhB;AACA,aAAO,IAAP;AACD;;;WAED,wBAAwB;AAGtB,YAAM,IAAIoE,KAAJ,CAAU,iBAAV,CAAN;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/culling-volume.ts"],"names":["faces","Vector3","scratchPlaneCenter","scratchPlaneNormal","scratchPlane","Plane","CullingVolume","planes","boundingSphere","length","center","radius","planeIndex","faceNormal","plane0","plane1","plane0Center","copy","scale","add","plane0Distance","dot","fromPointNormal","plane1Center","negatedFaceNormal","negate","plane1Distance","boundingVolume","intersect","INTERSECTION","INSIDE","plane","result","intersectPlane","OUTSIDE","INTERSECTING","parentPlaneMask","Number","isFinite","MASK_OUTSIDE","MASK_INSIDE","mask","k","flag"],"mappings":";;;;;;;;;;;;;;;AAIA;;AACA;;AACA;;;;;;;;AAKA,IAAMA,KAAK,GAAG,CAAC,IAAIC,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAD,EAAyB,IAAIA,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAzB,EAAiD,IAAIA,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAjD,CAAd;AAEA,IAAMC,kBAAkB,GAAG,IAAID,aAAJ,EAA3B;AACA,IAAME,kBAAkB,GAAG,IAAIF,aAAJ,EAA3B;AACA,IAAMG,YAAY,GAAG,IAAIC,cAAJ,CAAU,IAAIJ,aAAJ,CAAY,GAAZ,EAAiB,GA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1C,EAA6C;AAE3C,YAAMC,IAAI,GAAGD,CAAC,GAAG,EAAJ,GAAS,KAAKA,CAAd,GAAkB,CAA/B;;AACA,YAAIA,CAAC,GAAG,EAAJ,IAAU,CAACN,eAAe,GAAGO,IAAnB,MAA6B,CAA3C,EAA8C;AAE5C;AACD;;AAED,YAAMZ,KAAK,GAAGxB,MAAM,CAACmC,CAAD,CAApB;AACA,YAAMV,MAAM,GAAGL,cAAc,CAACM,cAAf,CAA8BF,KAA9B,CAAf;;AACA,YAAIC,MAAM,KAAKH,wBAAaK,OAA5B,EAAqC;AACnC,iBAAO5B,aAAa,CAACiC,YAArB;AACD,SAFD,MAEO,IAAIP,MAAM,KAAKH,wBAAaM,YAA5B,EAA0C;AAC/CM,UAAAA,IAAI,IAAIE,IAAR;AACD;AACF;;AAED,aAAOF,IAAP;AACD;;;;;;8BAzIkBnC,a,kBAKG,U;8BALHA,a,iBAWE,U;8BAXFA,a,wBAiBS,U","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Vector3, assert} from '@math.gl/core';\nimport {INTERSECTION} from '../constants';\nimport Plane from './plane';\nimport type {BoundingVolume} from './bounding-volumes/bounding-volume';\nimport type BoundingSphere from './bounding-volumes/bounding-sphere';\n\n// X, Y, Z Unit vectors\nconst faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];\n\nconst scratchPlaneCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\nconst scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);\n\n/** A culling volume defined by planes. */\nexport default class CullingVolume {\n /**\n * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value\n * represents the case where the object bounding volume is entirely outside the culling volume.\n */\n static MASK_OUTSIDE = 0xffffffff;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume is entirely inside the culling volume.\n */\n static MASK_INSIDE = 0x00000000;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume (may) intersect all planes of the culling volume.\n */\n static MASK_INDETERMINATE = 0x7fffffff;\n\n /** Array of clipping planes. */\n readonly planes: Plane[];\n\n /**\n * Create a new `CullingVolume` bounded by an array of clipping planed\n * @param planes Array of clipping planes.\n * */\n constructor(planes: Plane[] = []) {\n this.planes = planes;\n }\n\n /**\n * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.\n * The planes are aligned to the x, y, and z axes in world coordinates.\n */\n fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume {\n this.planes.length = 2 * faces.length;\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let planeIndex = 0;\n\n for (const faceNormal of faces) {\n let plane0 = this.planes[planeIndex];\n let plane1 = this.planes[planeIndex + 1];\n\n if (!plane0) {\n plane0 = this.planes[planeIndex] = new Plane();\n }\n if (!plane1) {\n plane1 = this.planes[planeIndex + 1] = new Plane();\n }\n\n const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);\n const plane0Distance = -faceNormal.dot(plane0Center);\n\n plane0.fromPointNormal(plane0Center, faceNormal);\n\n const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);\n\n const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();\n\n const plane1Distance = -negatedFaceNormal.dot(plane1Center);\n\n plane1.fromPointNormal(plane1Center, negatedFaceNormal);\n\n planeIndex += 2;\n }\n\n return this;\n }\n\n /** Determines whether a bounding volume intersects the culling volume. */\n computeVisibility(boundingVolume: BoundingVolume): INTERSECTION {\n // const planes = this.planes;\n let intersect = INTERSECTION.INSIDE;\n for (const plane of this.planes) {\n const result = boundingVolume.intersectPlane(plane);\n switch (result) {\n case INTERSECTION.OUTSIDE:\n // We are done\n return INTERSECTION.OUTSIDE;\n\n case INTERSECTION.INTERSECTING:\n // If no other intersection is outside, return INTERSECTING\n intersect = INTERSECTION.INTERSECTING;\n break;\n\n default:\n }\n }\n\n return intersect;\n }\n\n /**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling\n * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then\n * the parent (and therefore this) volume is completely inside plane[planeIndex]\n * and that plane check can be skipped.\n */\n computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number {\n assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');\n\n if (\n parentPlaneMask === CullingVolume.MASK_OUTSIDE ||\n parentPlaneMask === CullingVolume.MASK_INSIDE\n ) {\n // parent is completely outside or completely inside, so this child is as well.\n return parentPlaneMask;\n }\n\n // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.\n // (Because if there are fewer than 31 planes, the upper bits wont be changed.)\n let mask = CullingVolume.MASK_INSIDE;\n\n const planes = this.planes;\n for (let k = 0; k < this.planes.length; ++k) {\n // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.\n const flag = k < 31 ? 1 << k : 0;\n if (k < 31 && (parentPlaneMask & flag) === 0) {\n // boundingVolume is known to be INSIDE this plane.\n continue;\n }\n\n const plane = planes[k];\n const result = boundingVolume.intersectPlane(plane);\n if (result === INTERSECTION.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n } else if (result === INTERSECTION.INTERSECTING) {\n mask |= flag;\n }\n }\n\n return mask;\n }\n}\n"],"file":"culling-volume.js"}
1
+ {"version":3,"sources":["../../../src/lib/culling-volume.ts"],"names":["faces","Vector3","scratchPlaneCenter","scratchPlaneNormal","scratchPlane","Plane","CullingVolume","planes","boundingSphere","length","center","radius","planeIndex","faceNormal","plane0","plane1","plane0Center","copy","scale","add","plane0Distance","dot","fromPointNormal","plane1Center","negatedFaceNormal","negate","plane1Distance","boundingVolume","intersect","INTERSECTION","INSIDE","plane","result","intersectPlane","OUTSIDE","INTERSECTING","parentPlaneMask","Number","isFinite","MASK_OUTSIDE","MASK_INSIDE","mask","k","flag"],"mappings":";;;;;;;;;;;;;;;AAIA;;AACA;;AACA;;;;;;;;AAKA,IAAMA,KAAK,GAAG,CAAC,IAAIC,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAD,EAAyB,IAAIA,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAzB,EAAiD,IAAIA,aAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAjD,CAAd;AAEA,IAAMC,kBAAkB,GAAG,IAAID,aAAJ,EAA3B;AACA,IAAME,kBAAkB,GAAG,IAAIF,aAAJ,EAA3B;AACA,IAAMG,YAAY,GAAG,IAAIC,cAAJ,CAAU,IAAIJ,aAAJ,CAAY,GAAZ,EAAiB,GAAjB,EAAsB,GAAtB,CAAV,EAAsC,GAAtC,CAArB;;IAGqBK,a;AA0BnB,2BAAkC;AAAA,QAAtBC,MAAsB,uEAAJ,EAAI;AAAA;AAAA;AAChC,SAAKA,MAAL,GAAcA,MAAd;AACD;;;;WAMD,4BAAmBC,cAAnB,EAAkE;AAChE,WAAKD,MAAL,CAAYE,MAAZ,GAAqB,IAAIT,KAAK,CAACS,MAA/B;AAEA,UAAMC,MAAM,GAAGF,cAAc,CAACE,MAA9B;AACA,UAAMC,MAAM,GAAGH,cAAc,CAACG,MAA9B;AAEA,UAAIC,UAAU,GAAG,CAAjB;;AANgE,iDAQvCZ,KARuC;AAAA;;AAAA;AAQhE,4DAAgC;AAAA,cAArBa,UAAqB;AAC9B,cAAIC,MAAM,GAAG,KAAKP,MAAL,CAAYK,UAAZ,CAAb;AACA,cAAIG,MAAM,GAAG,KAAKR,MAAL,CAAYK,UAAU,GAAG,CAAzB,CAAb;;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,U","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Vector3, assert} from '@math.gl/core';\nimport {INTERSECTION} from '../constants';\nimport Plane from './plane';\nimport type {BoundingVolume} from './bounding-volumes/bounding-volume';\nimport type BoundingSphere from './bounding-volumes/bounding-sphere';\n\n// X, Y, Z Unit vectors\nconst faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];\n\nconst scratchPlaneCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\nconst scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);\n\n/** A culling volume defined by planes. */\nexport default class CullingVolume {\n /**\n * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value\n * represents the case where the object bounding volume is entirely outside the culling volume.\n */\n static MASK_OUTSIDE = 0xffffffff;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume is entirely inside the culling volume.\n */\n static MASK_INSIDE = 0x00000000;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume (may) intersect all planes of the culling volume.\n */\n static MASK_INDETERMINATE = 0x7fffffff;\n\n /** Array of clipping planes. */\n readonly planes: Plane[];\n\n /**\n * Create a new `CullingVolume` bounded by an array of clipping planed\n * @param planes Array of clipping planes.\n * */\n constructor(planes: Plane[] = []) {\n this.planes = planes;\n }\n\n /**\n * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.\n * The planes are aligned to the x, y, and z axes in world coordinates.\n */\n fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume {\n this.planes.length = 2 * faces.length;\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let planeIndex = 0;\n\n for (const faceNormal of faces) {\n let plane0 = this.planes[planeIndex];\n let plane1 = this.planes[planeIndex + 1];\n\n if (!plane0) {\n plane0 = this.planes[planeIndex] = new Plane();\n }\n if (!plane1) {\n plane1 = this.planes[planeIndex + 1] = new Plane();\n }\n\n const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);\n const plane0Distance = -faceNormal.dot(plane0Center);\n\n plane0.fromPointNormal(plane0Center, faceNormal);\n\n const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);\n\n const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();\n\n const plane1Distance = -negatedFaceNormal.dot(plane1Center);\n\n plane1.fromPointNormal(plane1Center, negatedFaceNormal);\n\n planeIndex += 2;\n }\n\n return this;\n }\n\n /** Determines whether a bounding volume intersects the culling volume. */\n computeVisibility(boundingVolume: BoundingVolume): number {\n // const planes = this.planes;\n let intersect: number = INTERSECTION.INSIDE;\n for (const plane of this.planes) {\n const result = boundingVolume.intersectPlane(plane);\n switch (result) {\n case INTERSECTION.OUTSIDE:\n // We are done\n return INTERSECTION.OUTSIDE;\n\n case INTERSECTION.INTERSECTING:\n // If no other intersection is outside, return INTERSECTING\n intersect = INTERSECTION.INTERSECTING;\n break;\n\n default:\n }\n }\n\n return intersect;\n }\n\n /**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling\n * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then\n * the parent (and therefore this) volume is completely inside plane[planeIndex]\n * and that plane check can be skipped.\n */\n computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number {\n assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');\n\n if (\n parentPlaneMask === CullingVolume.MASK_OUTSIDE ||\n parentPlaneMask === CullingVolume.MASK_INSIDE\n ) {\n // parent is completely outside or completely inside, so this child is as well.\n return parentPlaneMask;\n }\n\n // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.\n // (Because if there are fewer than 31 planes, the upper bits wont be changed.)\n let mask = CullingVolume.MASK_INSIDE;\n\n const planes = this.planes;\n for (let k = 0; k < this.planes.length; ++k) {\n // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.\n const flag = k < 31 ? 1 << k : 0;\n if (k < 31 && (parentPlaneMask & flag) === 0) {\n // boundingVolume is known to be INSIDE this plane.\n continue;\n }\n\n const plane = planes[k];\n const result = boundingVolume.intersectPlane(plane);\n if (result === INTERSECTION.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n } else if (result === INTERSECTION.INTERSECTING) {\n mask |= flag;\n }\n }\n\n return mask;\n }\n}\n"],"file":"culling-volume.js"}
@@ -1,8 +1,6 @@
1
- export let INTERSECTION;
2
-
3
- (function (INTERSECTION) {
4
- INTERSECTION[INTERSECTION["OUTSIDE"] = -1] = "OUTSIDE";
5
- INTERSECTION[INTERSECTION["INTERSECTING"] = 0] = "INTERSECTING";
6
- INTERSECTION[INTERSECTION["INSIDE"] = 1] = "INSIDE";
7
- })(INTERSECTION || (INTERSECTION = {}));
1
+ export const INTERSECTION = {
2
+ OUTSIDE: -1,
3
+ INTERSECTING: 0,
4
+ INSIDE: 1
5
+ };
8
6
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/constants.ts"],"names":["INTERSECTION"],"mappings":"AAGA,WAAYA,YAAZ;;WAAYA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;GAAAA,Y,KAAAA,Y","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\nexport enum INTERSECTION {\n OUTSIDE = -1, // Represents that an object is not contained within the frustum.\n INTERSECTING = 0, // Represents that an object intersects one of the frustum's planes.\n INSIDE = 1 // Represents that an object is fully within the frustum.\n}\n"],"file":"constants.js"}
1
+ {"version":3,"sources":["../../src/constants.ts"],"names":["INTERSECTION","OUTSIDE","INTERSECTING","INSIDE"],"mappings":"AAGA,OAAO,MAAMA,YAAY,GAAG;AAC1BC,EAAAA,OAAO,EAAE,CAAC,CADgB;AAE1BC,EAAAA,YAAY,EAAE,CAFY;AAG1BC,EAAAA,MAAM,EAAE;AAHkB,CAArB","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\nexport const INTERSECTION = {\n OUTSIDE: -1, // Represents that an object is not contained within the frustum.\n INTERSECTING: 0, // Represents that an object intersects one of the frustum's planes.\n INSIDE: 1 // Represents that an object is fully within the frustum.\n} as const;\n"],"file":"constants.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["Vector3","INTERSECTION","scratchVector","scratchNormal","AxisAlignedBoundingBox","constructor","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","clone","equals","right","Boolean","transform","transformAsPoint","intersectPlane","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INSIDE","OUTSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";AACA,SAAQA,OAAR,QAAsB,eAAtB;AAEA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,MAAMC,aAAa,GAAG,IAAIF,OAAJ,EAAtB;AACA,MAAMG,aAAa,GAAG,IAAIH,OAAJ,EAAtB;AAQA,eAAe,MAAMI,sBAAN,CAAuD;AAgBpEC,EAAAA,WAAW,CACTC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CADpB,EAETC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAFpB,EAGTC,MAHS,EAIT;AAAA;;AAAA;;AAAA;;AAAA;;AAEAA,IAAAA,MAAM,GAAGA,MAAM,I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C,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACX,CAAhB,IAAqBjB,YAAY,CAACiB,CAAtC;;AACA,QAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,WAAOD,eAAP;AACD;;AAnImE","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone(): AxisAlignedBoundingBox {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right: AxisAlignedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): INTERSECTION {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["Vector3","INTERSECTION","scratchVector","scratchNormal","AxisAlignedBoundingBox","constructor","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","clone","equals","right","Boolean","transform","transformAsPoint","intersectPlane","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INSIDE","OUTSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";AACA,SAAQA,OAAR,QAAsB,eAAtB;AAEA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,MAAMC,aAAa,GAAG,IAAIF,OAAJ,EAAtB;AACA,MAAMG,aAAa,GAAG,IAAIH,OAAJ,EAAtB;AAQA,eAAe,MAAMI,sBAAN,CAAuD;AAgBpEC,EAAAA,WAAW,CACTC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CADpB,EAETC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAFpB,EAGTC,MAHS,EAIT;AAAA;;AAAA;;AAAA;;AAAA;;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIN,aAAa,CAACO,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,EAAyCI,KAAzC,CAA+C,GAA/C,CAAnB;AACA,SAAKH,MAAL,GAAc,IAAIR,OAAJ,CAAYQ,MAA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Y,CAACiB,CAAtC;;AACA,QAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,WAAOD,eAAP;AACD;;AAnImE","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone(): AxisAlignedBoundingBox {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right: AxisAlignedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): number {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
@@ -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;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AAIA,MAAMC,aAAa,GAAG,IAAIH,OAAJ,EAAtB;AACA,MAAMI,cAAc,GAAG,IAAIJ,OAAJ,EAAvB;AAGA,eAAe,MAAMK,cAAN,CAA+C;AAK5DC,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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A,UAAU,CAACR,KAAD,EAAwC;AAChD,UAAMC,YAAY,GAAGhC,aAAa,CAACO,IAAd,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,EAA6B;AACzC,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;;AApI2D","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';\nimport * as mat4 from 'gl-matrix/mat4';\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 default 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): INTERSECTION {\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,S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Y,CAACgD,OAApB;AACD;;AAED,QAAIF,eAAe,GAAGxC,MAAtB,EAA8B;AAC5B,aAAON,YAAY,CAACiD,YAApB;AACD;;AAED,WAAOjD,YAAY,CAACkD,MAApB;AACD;;AApI2D","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';\nimport * as mat4 from 'gl-matrix/mat4';\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 default 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 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["Vector3","Matrix3","Quaternion","BoundingSphere","INTERSECTION","scratchVector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","constructor","center","halfAxes","from","halfSize","xAxis","getColumn","yAxis","zAxis","len","quaternion","normXAxis","normalize","normYAxis","normZAxis","fromMatrix3","fromCenterHalfSizeQuaternion","quaternionObject","directionsMatrix","fromQuaternion","clone","equals","right","Boolean","getBoundingSphere","result","u","v","w","cornerVector","copy","add","radius","magnitude","intersectPlane","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","OUTSIDE","INSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","computePlaneDistances","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transform","transformation","transformAsPoint","getTransform","Error"],"mappings":";AAGA,SAAQA,OAAR,EAAiBC,OAAjB,EAAmCC,UAAnC,QAAkE,eAAlE;AAEA,OAAOC,cAAP,MAA2B,mBAA3B;AAEA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,aAAa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AN;AACD;;AApTgE","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 {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): INTERSECTION {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["Vector3","Matrix3","Quaternion","BoundingSphere","INTERSECTION","scratchVector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","constructor","center","halfAxes","from","halfSize","xAxis","getColumn","yAxis","zAxis","len","quaternion","normXAxis","normalize","normYAxis","normZAxis","fromMatrix3","fromCenterHalfSizeQuaternion","quaternionObject","directionsMatrix","fromQuaternion","clone","equals","right","Boolean","getBoundingSphere","result","u","v","w","cornerVector","copy","add","radius","magnitude","intersectPlane","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","OUTSIDE","INSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","computePlaneDistances","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transform","transformation","transformAsPoint","getTransform","Error"],"mappings":";AAGA,SAAQA,OAAR,EAAiBC,OAAjB,EAAmCC,UAAnC,QAAkE,eAAlE;AAEA,OAAOC,cAAP,MAA2B,mBAA3B;AAEA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,aAAa,GAAG,IAAIN,OAAJ,EAAtB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA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C1C,IAAT,CAAcyC,MAAd,EAAsBd,QAAtB,CAA+BO,QAA/B;AACAS,IAAAA,GAAG,GAAGR,SAAS,CAAClB,GAAV,CAAcyB,QAAd,CAAN;AAEAN,IAAAA,OAAO,GAAGtB,IAAI,CAAC8B,GAAL,CAASD,GAAT,EAAcP,OAAd,CAAV;AACAG,IAAAA,OAAO,GAAGzB,IAAI,CAAC+B,GAAL,CAASF,GAAT,EAAcJ,OAAd,CAAV;AAEA5C,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAYyC,OAAZ;AACAzC,IAAAA,MAAM,CAAC,CAAD,CAAN,GAAY4C,OAAZ;AACA,WAAO5C,MAAP;AACD;;AAODmD,EAAAA,SAAS,CAACC,cAAD,EAA0C;AACjD,SAAK5E,MAAL,CAAY6E,gBAAZ,CAA6BD,cAA7B;AAEA,UAAMxE,KAAK,GAAG,KAAKH,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BtB,cAA3B,CAAd;AACAqB,IAAAA,KAAK,CAACyE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMtE,KAAK,GAAG,KAAKL,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BrB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACuE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMrE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BpB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACsE,gBAAN,CAAuBD,cAAvB;AAEA,SAAK3E,QAAL,GAAgB,IAAIxB,OAAJ,CAAY,CAAC,GAAG2B,KAAJ,EAAW,GAAGE,KAAd,EAAqB,GAAGC,KAAxB,CAAZ,CAAhB;AACA,WAAO,IAAP;AACD;;AAEDuE,EAAAA,YAAY,GAAY;AAGtB,UAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;AACD;;AApTgE","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 {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}