@math.gl/culling 4.0.0-alpha.1 → 4.0.0-alpha.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 (59) hide show
  1. package/dist/index.d.ts +9 -9
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +9 -9
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/algorithms/bounding-box-from-points.d.ts +2 -2
  6. package/dist/lib/algorithms/bounding-box-from-points.d.ts.map +1 -1
  7. package/dist/lib/algorithms/bounding-box-from-points.js +3 -3
  8. package/dist/lib/algorithms/bounding-box-from-points.js.map +1 -1
  9. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts +2 -2
  10. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
  11. package/dist/lib/algorithms/bounding-sphere-from-points.js +2 -2
  12. package/dist/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
  13. package/dist/lib/algorithms/compute-eigen-decomposition.d.ts +2 -2
  14. package/dist/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -1
  15. package/dist/lib/algorithms/compute-eigen-decomposition.js +1 -1
  16. package/dist/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
  17. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +2 -2
  18. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  19. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +1 -1
  20. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  21. package/dist/lib/bounding-volumes/bounding-sphere.d.ts +2 -2
  22. package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -1
  23. package/dist/lib/bounding-volumes/bounding-sphere.js +1 -1
  24. package/dist/lib/bounding-volumes/bounding-sphere.js.map +1 -1
  25. package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -1
  26. package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -1
  27. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +3 -3
  28. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
  29. package/dist/lib/bounding-volumes/oriented-bounding-box.js +2 -2
  30. package/dist/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  31. package/dist/lib/culling-volume.d.ts +3 -3
  32. package/dist/lib/culling-volume.d.ts.map +1 -1
  33. package/dist/lib/culling-volume.js +2 -2
  34. package/dist/lib/culling-volume.js.map +1 -1
  35. package/dist/lib/perspective-frustum.d.ts +3 -3
  36. package/dist/lib/perspective-frustum.d.ts.map +1 -1
  37. package/dist/lib/perspective-frustum.js +2 -2
  38. package/dist/lib/perspective-frustum.js.map +1 -1
  39. package/dist/lib/perspective-off-center-frustum.d.ts +3 -3
  40. package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
  41. package/dist/lib/perspective-off-center-frustum.js +3 -3
  42. package/dist/lib/perspective-off-center-frustum.js.map +1 -1
  43. package/dist/lib/plane.d.ts +1 -1
  44. package/dist/lib/plane.d.ts.map +1 -1
  45. package/dist/lib/plane.js +1 -1
  46. package/dist/lib/plane.js.map +1 -1
  47. package/package.json +3 -3
  48. package/src/index.ts +9 -9
  49. package/src/lib/algorithms/bounding-box-from-points.ts +3 -3
  50. package/src/lib/algorithms/bounding-sphere-from-points.ts +2 -2
  51. package/src/lib/algorithms/compute-eigen-decomposition.ts +1 -1
  52. package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +2 -2
  53. package/src/lib/bounding-volumes/bounding-sphere.ts +2 -2
  54. package/src/lib/bounding-volumes/bounding-volume.ts +1 -1
  55. package/src/lib/bounding-volumes/oriented-bounding-box.ts +3 -3
  56. package/src/lib/culling-volume.ts +3 -3
  57. package/src/lib/perspective-frustum.ts +3 -3
  58. package/src/lib/perspective-off-center-frustum.ts +3 -3
  59. package/src/lib/plane.ts +1 -1
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { INTERSECTION } from './constants';
2
- export { default as AxisAlignedBoundingBox } from './lib/bounding-volumes/axis-aligned-bounding-box';
3
- export { default as BoundingSphere } from './lib/bounding-volumes/bounding-sphere';
4
- export { default as OrientedBoundingBox } from './lib/bounding-volumes/oriented-bounding-box';
5
- export { default as CullingVolume } from './lib/culling-volume';
6
- export { default as Plane } from './lib/plane';
7
- export { default as _PerspectiveOffCenterFrustum } from './lib/perspective-off-center-frustum';
8
- export { default as _PerspectiveFrustum } from './lib/perspective-frustum';
9
- export { default as makeBoundingSphereFromPoints } from './lib/algorithms/bounding-sphere-from-points';
2
+ export { AxisAlignedBoundingBox } from './lib/bounding-volumes/axis-aligned-bounding-box';
3
+ export { BoundingSphere } from './lib/bounding-volumes/bounding-sphere';
4
+ export { OrientedBoundingBox } from './lib/bounding-volumes/oriented-bounding-box';
5
+ export { CullingVolume } from './lib/culling-volume';
6
+ export { Plane } from './lib/plane';
7
+ export { PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum } from './lib/perspective-off-center-frustum';
8
+ export { PerspectiveFrustum as _PerspectiveFrustum } from './lib/perspective-frustum';
9
+ export { makeBoundingSphereFromPoints } from './lib/algorithms/bounding-sphere-from-points';
10
10
  export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from './lib/algorithms/bounding-box-from-points';
11
- export { default as computeEigenDecomposition } from './lib/algorithms/compute-eigen-decomposition';
11
+ export { computeEigenDecomposition } from './lib/algorithms/compute-eigen-decomposition';
12
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,kDAAkD,CAAC;AACnG,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAC,OAAO,IAAI,KAAK,EAAC,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,sCAAsC,CAAC;AAC7F,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAEzE,OAAO,EAAC,OAAO,IAAI,4BAA4B,EAAC,MAAM,8CAA8C,CAAC;AACrG,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EAClC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAC,OAAO,IAAI,yBAAyB,EAAC,MAAM,8CAA8C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAC,sBAAsB,EAAC,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAC,cAAc,EAAC,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAC,mBAAmB,EAAC,MAAM,8CAA8C,CAAC;AACjF,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAC;AAElC,OAAO,EAAC,2BAA2B,IAAI,4BAA4B,EAAC,MAAM,sCAAsC,CAAC;AACjH,OAAO,EAAC,kBAAkB,IAAI,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAEpF,OAAO,EAAC,4BAA4B,EAAC,MAAM,8CAA8C,CAAC;AAC1F,OAAO,EACL,oCAAoC,EACpC,iCAAiC,EAClC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAC,yBAAyB,EAAC,MAAM,8CAA8C,CAAC"}
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  export { INTERSECTION } from "./constants.js";
2
- export { default as AxisAlignedBoundingBox } from "./lib/bounding-volumes/axis-aligned-bounding-box.js";
3
- export { default as BoundingSphere } from "./lib/bounding-volumes/bounding-sphere.js";
4
- export { default as OrientedBoundingBox } from "./lib/bounding-volumes/oriented-bounding-box.js";
5
- export { default as CullingVolume } from "./lib/culling-volume.js";
6
- export { default as Plane } from "./lib/plane.js";
7
- export { default as _PerspectiveOffCenterFrustum } from "./lib/perspective-off-center-frustum.js";
8
- export { default as _PerspectiveFrustum } from "./lib/perspective-frustum.js";
9
- export { default as makeBoundingSphereFromPoints } from "./lib/algorithms/bounding-sphere-from-points.js";
2
+ export { AxisAlignedBoundingBox } from "./lib/bounding-volumes/axis-aligned-bounding-box.js";
3
+ export { BoundingSphere } from "./lib/bounding-volumes/bounding-sphere.js";
4
+ export { OrientedBoundingBox } from "./lib/bounding-volumes/oriented-bounding-box.js";
5
+ export { CullingVolume } from "./lib/culling-volume.js";
6
+ export { Plane } from "./lib/plane.js";
7
+ export { PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum } from "./lib/perspective-off-center-frustum.js";
8
+ export { PerspectiveFrustum as _PerspectiveFrustum } from "./lib/perspective-frustum.js";
9
+ export { makeBoundingSphereFromPoints } from "./lib/algorithms/bounding-sphere-from-points.js";
10
10
  export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from "./lib/algorithms/bounding-box-from-points.js";
11
- export { default as computeEigenDecomposition } from "./lib/algorithms/compute-eigen-decomposition.js";
11
+ export { computeEigenDecomposition } from "./lib/algorithms/compute-eigen-decomposition.js";
12
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["INTERSECTION","default","AxisAlignedBoundingBox","BoundingSphere","OrientedBoundingBox","CullingVolume","Plane","_PerspectiveOffCenterFrustum","_PerspectiveFrustum","makeBoundingSphereFromPoints","makeAxisAlignedBoundingBoxFromPoints","makeOrientedBoundingBoxFromPoints","computeEigenDecomposition"],"mappings":"SAGQA,Y;SAEAC,OAAO,IAAIC,sB;SACXD,OAAO,IAAIE,c;SACXF,OAAO,IAAIG,mB;SACXH,OAAO,IAAII,a;SACXJ,OAAO,IAAIK,K;SAEXL,OAAO,IAAIM,4B;SACXN,OAAO,IAAIO,mB;SAEXP,OAAO,IAAIQ,4B;SAEjBC,oC,EACAC,iC;SAEMV,OAAO,IAAIW,yB","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 {INTERSECTION} from './constants';\n\nexport {default as AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';\nexport {default as BoundingSphere} from './lib/bounding-volumes/bounding-sphere';\nexport {default as OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';\nexport {default as CullingVolume} from './lib/culling-volume';\nexport {default as Plane} from './lib/plane';\n\nexport {default as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';\nexport {default as _PerspectiveFrustum} from './lib/perspective-frustum';\n\nexport {default as makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';\nexport {\n makeAxisAlignedBoundingBoxFromPoints,\n makeOrientedBoundingBoxFromPoints\n} from './lib/algorithms/bounding-box-from-points';\nexport {default as computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["INTERSECTION","AxisAlignedBoundingBox","BoundingSphere","OrientedBoundingBox","CullingVolume","Plane","PerspectiveOffCenterFrustum","_PerspectiveOffCenterFrustum","PerspectiveFrustum","_PerspectiveFrustum","makeBoundingSphereFromPoints","makeAxisAlignedBoundingBoxFromPoints","makeOrientedBoundingBoxFromPoints","computeEigenDecomposition"],"mappings":"SAGQA,Y;SAEAC,sB;SACAC,c;SACAC,mB;SACAC,a;SACAC,K;SAEAC,2BAA2B,IAAIC,4B;SAC/BC,kBAAkB,IAAIC,mB;SAEtBC,4B;SAENC,oC,EACAC,iC;SAEMC,yB","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 {INTERSECTION} from './constants';\n\nexport {AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';\nexport {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';\nexport {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';\nexport {CullingVolume} from './lib/culling-volume';\nexport {Plane} from './lib/plane';\n\nexport {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';\nexport {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';\n\nexport {makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';\nexport {\n makeAxisAlignedBoundingBoxFromPoints,\n makeOrientedBoundingBoxFromPoints\n} from './lib/algorithms/bounding-box-from-points';\nexport {computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';\n"],"file":"index.js"}
@@ -1,5 +1,5 @@
1
- import OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';
2
- import AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';
1
+ import { OrientedBoundingBox } from '../bounding-volumes/oriented-bounding-box';
2
+ import { AxisAlignedBoundingBox } from '../bounding-volumes/axis-aligned-bounding-box';
3
3
  /**
4
4
  * Computes an instance of an OrientedBoundingBox of the given positions.
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-box-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":[],"mappings":"AAKA,OAAO,mBAAmB,MAAM,2CAA2C,CAAC;AAC5E,OAAO,sBAAsB,MAAM,+CAA+C,CAAC;AAmBnF;;;;;GAKG;AAEH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,mBAA+C,GACtD,mBAAmB,CAuFrB;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,SAAS,MAAM,EAAE,EAAE,EAC9B,MAAM,GAAE,sBAAqD,GAC5D,sBAAsB,CAoCxB"}
1
+ {"version":3,"file":"bounding-box-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,mBAAmB,EAAC,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAC,sBAAsB,EAAC,MAAM,+CAA+C,CAAC;AAmBrF;;;;;GAKG;AAEH,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,mBAA+C,GACtD,mBAAmB,CAuFrB;AAED;;;GAGG;AACH,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,SAAS,MAAM,EAAE,EAAE,EAC9B,MAAM,GAAE,sBAAqD,GAC5D,sBAAsB,CAoCxB"}
@@ -1,7 +1,7 @@
1
1
  import { Vector3, Matrix3 } from '@math.gl/core';
2
- import computeEigenDecomposition from "./compute-eigen-decomposition.js";
3
- import OrientedBoundingBox from "../bounding-volumes/oriented-bounding-box.js";
4
- import AxisAlignedBoundingBox from "../bounding-volumes/axis-aligned-bounding-box.js";
2
+ import { computeEigenDecomposition } from "./compute-eigen-decomposition.js";
3
+ import { OrientedBoundingBox } from "../bounding-volumes/oriented-bounding-box.js";
4
+ import { AxisAlignedBoundingBox } from "../bounding-volumes/axis-aligned-bounding-box.js";
5
5
  const scratchVector2 = new Vector3();
6
6
  const scratchVector3 = new Vector3();
7
7
  const scratchVector4 = new Vector3();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":["Vector3","Matrix3","computeEigenDecomposition","OrientedBoundingBox","AxisAlignedBoundingBox","scratchVector2","scratchVector3","scratchVector4","scratchVector5","scratchVector6","scratchCovarianceResult","scratchEigenResult","diagonal","unitary","makeOrientedBoundingBoxFromPoints","positions","result","length","halfAxes","center","meanPoint","position","add","invLength","multiplyByScalar","exx","exy","exz","eyy","eyz","ezz","p","copy","subtract","x","y","z","covarianceMatrix","rotation","v1","getColumn","v2","v3","u1","Number","MAX_VALUE","u2","u3","l1","l2","l3","Math","max","dot","min","scale","set","scaleMatrix","multiplyRight","makeAxisAlignedBoundingBoxFromPoints","minimum","maximum","halfDiagonal","minimumX","minimumY","minimumZ","maximumX","maximumY","maximumZ"],"mappings":"AAGA,SAAQA,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;OACOC,yB;OACAC,mB;OACAC,sB;AAEP,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AAEA,MAAMM,cAAc,GAAG,IAAIN,OAAJ,EAAvB;AAEA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AAEA,MAAMQ,cAAc,GAAG,IAAIR,OAAJ,EAAvB;AAEA,MAAMS,cAAc,GAAG,IAAIT,OAAJ,EAAvB;AAEA,MAAMU,uBAAuB,GAAG,IAAIT,OAAJ,EAAhC;AAEA,MAAMU,kBAAkB,GAAG;AACzBC,EAAAA,QAAQ,EAAE,IAAIX,OAAJ,EADe;AAEzBY,EAAAA,OAAO,EAAE,IAAIZ,OAAJ;AAFgB,CAA3B;AAYA,OAAO,SAASa,iCAAT,CACLC,SADK,EAELC,MAA2B,GAAG,IAAIb,mBAAJ,EAFzB,EAGgB;AACrB,MAAI,CAACY,SAAD,IAAcA,SAAS,CAACE,MAAV,KAAqB,CAAvC,EAA0C;AACxCD,IAAAA,MAAM,CAACE,QAAP,GAAkB,IAAIjB,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAAZ,CAAlB;AACAe,IAAAA,MAAM,CAACG,MAAP,GAAgB,IAAInB,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vC;AACApD,EAAAA,MAAM,CAACG,MAAP,CAAca,IAAd,CAAmBhB,MAAM,CAAC4C,OAA1B,EAAmCtC,GAAnC,CAAuCN,MAAM,CAAC6C,OAA9C,EAAuDN,KAAvD,CAA6D,GAA7D;AACAvC,EAAAA,MAAM,CAAC8C,YAAP,CAAoB9B,IAApB,CAAyBhB,MAAM,CAAC6C,OAAhC,EAAyC5B,QAAzC,CAAkDjB,MAAM,CAACG,MAAzD;AAEA,SAAOH,MAAP;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} from '@math.gl/core';\nimport computeEigenDecomposition from './compute-eigen-decomposition';\nimport OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';\nimport AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';\n\nconst scratchVector2 = new Vector3();\n\nconst scratchVector3 = new Vector3();\n\nconst scratchVector4 = new Vector3();\n\nconst scratchVector5 = new Vector3();\n\nconst scratchVector6 = new Vector3();\n\nconst scratchCovarianceResult = new Matrix3();\n\nconst scratchEigenResult = {\n diagonal: new Matrix3(),\n unitary: new Matrix3()\n};\n\n/**\n * Computes an instance of an OrientedBoundingBox of the given positions.\n *\n * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).\n * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf\n */\n/* eslint-disable max-statements */\nexport function makeOrientedBoundingBoxFromPoints(\n positions: number[][],\n result: OrientedBoundingBox = new OrientedBoundingBox()\n): OrientedBoundingBox {\n if (!positions || positions.length === 0) {\n result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);\n result.center = new Vector3();\n return result;\n }\n\n const length = positions.length;\n const meanPoint = new Vector3(0, 0, 0);\n for (const position of positions) {\n meanPoint.add(position);\n }\n const invLength = 1.0 / length;\n meanPoint.multiplyByScalar(invLength);\n\n let exx = 0.0;\n let exy = 0.0;\n let exz = 0.0;\n let eyy = 0.0;\n let eyz = 0.0;\n let ezz = 0.0;\n\n for (const position of positions) {\n const p = scratchVector2.copy(position).subtract(meanPoint);\n exx += p.x * p.x;\n exy += p.x * p.y;\n exz += p.x * p.z;\n eyy += p.y * p.y;\n eyz += p.y * p.z;\n ezz += p.z * p.z;\n }\n\n exx *= invLength;\n exy *= invLength;\n exz *= invLength;\n eyy *= invLength;\n eyz *= invLength;\n ezz *= invLength;\n\n const covarianceMatrix = scratchCovarianceResult;\n covarianceMatrix[0] = exx;\n covarianceMatrix[1] = exy;\n covarianceMatrix[2] = exz;\n covarianceMatrix[3] = exy;\n covarianceMatrix[4] = eyy;\n covarianceMatrix[5] = eyz;\n covarianceMatrix[6] = exz;\n covarianceMatrix[7] = eyz;\n covarianceMatrix[8] = ezz;\n\n const {unitary} = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);\n const rotation = result.halfAxes.copy(unitary);\n\n let v1 = rotation.getColumn(0, scratchVector4);\n let v2 = rotation.getColumn(1, scratchVector5);\n let v3 = rotation.getColumn(2, scratchVector6);\n\n let u1 = -Number.MAX_VALUE;\n let u2 = -Number.MAX_VALUE;\n let u3 = -Number.MAX_VALUE;\n let l1 = Number.MAX_VALUE;\n let l2 = Number.MAX_VALUE;\n let l3 = Number.MAX_VALUE;\n\n for (const position of positions) {\n scratchVector2.copy(position);\n\n u1 = Math.max(scratchVector2.dot(v1), u1);\n u2 = Math.max(scratchVector2.dot(v2), u2);\n u3 = Math.max(scratchVector2.dot(v3), u3);\n\n l1 = Math.min(scratchVector2.dot(v1), l1);\n l2 = Math.min(scratchVector2.dot(v2), l2);\n l3 = Math.min(scratchVector2.dot(v3), l3);\n }\n\n v1 = v1.multiplyByScalar(0.5 * (l1 + u1));\n v2 = v2.multiplyByScalar(0.5 * (l2 + u2));\n v3 = v3.multiplyByScalar(0.5 * (l3 + u3));\n\n result.center.copy(v1).add(v2).add(v3);\n\n const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);\n const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);\n result.halfAxes.multiplyRight(scaleMatrix);\n\n return result;\n}\n\n/**\n * Computes an instance of an AxisAlignedBoundingBox. The box is determined by\n * finding the points spaced the farthest apart on the x, y, and z axes.\n */\nexport function makeAxisAlignedBoundingBoxFromPoints(\n positions: readonly number[][],\n result: AxisAlignedBoundingBox = new AxisAlignedBoundingBox()\n): AxisAlignedBoundingBox {\n if (!positions || positions.length === 0) {\n result.minimum.set(0, 0, 0);\n result.maximum.set(0, 0, 0);\n result.center.set(0, 0, 0);\n result.halfDiagonal.set(0, 0, 0);\n return result;\n }\n\n let minimumX = positions[0][0];\n let minimumY = positions[0][1];\n let minimumZ = positions[0][2];\n\n let maximumX = positions[0][0];\n let maximumY = positions[0][1];\n let maximumZ = positions[0][2];\n\n for (const p of positions) {\n const x = p[0];\n const y = p[1];\n const z = p[2];\n\n minimumX = Math.min(x, minimumX);\n maximumX = Math.max(x, maximumX);\n minimumY = Math.min(y, minimumY);\n maximumY = Math.max(y, maximumY);\n minimumZ = Math.min(z, minimumZ);\n maximumZ = Math.max(z, maximumZ);\n }\n\n result.minimum.set(minimumX, minimumY, minimumZ);\n result.maximum.set(maximumX, maximumY, maximumZ);\n result.center.copy(result.minimum).add(result.maximum).scale(0.5);\n result.halfDiagonal.copy(result.maximum).subtract(result.center);\n\n return result;\n}\n"],"file":"bounding-box-from-points.js"}
1
+ {"version":3,"sources":["../../../src/lib/algorithms/bounding-box-from-points.ts"],"names":["Vector3","Matrix3","computeEigenDecomposition","OrientedBoundingBox","AxisAlignedBoundingBox","scratchVector2","scratchVector3","scratchVector4","scratchVector5","scratchVector6","scratchCovarianceResult","scratchEigenResult","diagonal","unitary","makeOrientedBoundingBoxFromPoints","positions","result","length","halfAxes","center","meanPoint","position","add","invLength","multiplyByScalar","exx","exy","exz","eyy","eyz","ezz","p","copy","subtract","x","y","z","covarianceMatrix","rotation","v1","getColumn","v2","v3","u1","Number","MAX_VALUE","u2","u3","l1","l2","l3","Math","max","dot","min","scale","set","scaleMatrix","multiplyRight","makeAxisAlignedBoundingBoxFromPoints","minimum","maximum","halfDiagonal","minimumX","minimumY","minimumZ","maximumX","maximumY","maximumZ"],"mappings":"AAGA,SAAQA,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;SACQC,yB;SACAC,mB;SACAC,sB;AAER,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AAEA,MAAMM,cAAc,GAAG,IAAIN,OAAJ,EAAvB;AAEA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AAEA,MAAMQ,cAAc,GAAG,IAAIR,OAAJ,EAAvB;AAEA,MAAMS,cAAc,GAAG,IAAIT,OAAJ,EAAvB;AAEA,MAAMU,uBAAuB,GAAG,IAAIT,OAAJ,EAAhC;AAEA,MAAMU,kBAAkB,GAAG;AACzBC,EAAAA,QAAQ,EAAE,IAAIX,OAAJ,EADe;AAEzBY,EAAAA,OAAO,EAAE,IAAIZ,OAAJ;AAFgB,CAA3B;AAYA,OAAO,SAASa,iCAAT,CACLC,SADK,EAELC,MAA2B,GAAG,IAAIb,mBAAJ,EAFzB,EAGgB;AACrB,MAAI,CAACY,SAAD,IAAcA,SAAS,CAACE,MAAV,KAAqB,CAAvC,EAA0C;AACxCD,IAAAA,MAAM,CAACE,QAAP,GAAkB,IAAIjB,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,CAAZ,CAAlB;AACAe,IAAAA,MAAM,CAACG,MAAP,GAAgB,IAAInB,OAAJ,EAAhB;AACA,WAAOgB,MAAP;AACD;;AAED,QAAMC,MAAM,GAAGF,SAAS,CAACE,MAAzB;AACA,QAAMG,SAAS,GAAG,IAAIpB,OAAJ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9C,EAAuDN,KAAvD,CAA6D,GAA7D;AACAvC,EAAAA,MAAM,CAAC8C,YAAP,CAAoB9B,IAApB,CAAyBhB,MAAM,CAAC6C,OAAhC,EAAyC5B,QAAzC,CAAkDjB,MAAM,CAACG,MAAzD;AAEA,SAAOH,MAAP;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} from '@math.gl/core';\nimport {computeEigenDecomposition} from './compute-eigen-decomposition';\nimport {OrientedBoundingBox} from '../bounding-volumes/oriented-bounding-box';\nimport {AxisAlignedBoundingBox} from '../bounding-volumes/axis-aligned-bounding-box';\n\nconst scratchVector2 = new Vector3();\n\nconst scratchVector3 = new Vector3();\n\nconst scratchVector4 = new Vector3();\n\nconst scratchVector5 = new Vector3();\n\nconst scratchVector6 = new Vector3();\n\nconst scratchCovarianceResult = new Matrix3();\n\nconst scratchEigenResult = {\n diagonal: new Matrix3(),\n unitary: new Matrix3()\n};\n\n/**\n * Computes an instance of an OrientedBoundingBox of the given positions.\n *\n * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).\n * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf\n */\n/* eslint-disable max-statements */\nexport function makeOrientedBoundingBoxFromPoints(\n positions: number[][],\n result: OrientedBoundingBox = new OrientedBoundingBox()\n): OrientedBoundingBox {\n if (!positions || positions.length === 0) {\n result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);\n result.center = new Vector3();\n return result;\n }\n\n const length = positions.length;\n const meanPoint = new Vector3(0, 0, 0);\n for (const position of positions) {\n meanPoint.add(position);\n }\n const invLength = 1.0 / length;\n meanPoint.multiplyByScalar(invLength);\n\n let exx = 0.0;\n let exy = 0.0;\n let exz = 0.0;\n let eyy = 0.0;\n let eyz = 0.0;\n let ezz = 0.0;\n\n for (const position of positions) {\n const p = scratchVector2.copy(position).subtract(meanPoint);\n exx += p.x * p.x;\n exy += p.x * p.y;\n exz += p.x * p.z;\n eyy += p.y * p.y;\n eyz += p.y * p.z;\n ezz += p.z * p.z;\n }\n\n exx *= invLength;\n exy *= invLength;\n exz *= invLength;\n eyy *= invLength;\n eyz *= invLength;\n ezz *= invLength;\n\n const covarianceMatrix = scratchCovarianceResult;\n covarianceMatrix[0] = exx;\n covarianceMatrix[1] = exy;\n covarianceMatrix[2] = exz;\n covarianceMatrix[3] = exy;\n covarianceMatrix[4] = eyy;\n covarianceMatrix[5] = eyz;\n covarianceMatrix[6] = exz;\n covarianceMatrix[7] = eyz;\n covarianceMatrix[8] = ezz;\n\n const {unitary} = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);\n const rotation = result.halfAxes.copy(unitary);\n\n let v1 = rotation.getColumn(0, scratchVector4);\n let v2 = rotation.getColumn(1, scratchVector5);\n let v3 = rotation.getColumn(2, scratchVector6);\n\n let u1 = -Number.MAX_VALUE;\n let u2 = -Number.MAX_VALUE;\n let u3 = -Number.MAX_VALUE;\n let l1 = Number.MAX_VALUE;\n let l2 = Number.MAX_VALUE;\n let l3 = Number.MAX_VALUE;\n\n for (const position of positions) {\n scratchVector2.copy(position);\n\n u1 = Math.max(scratchVector2.dot(v1), u1);\n u2 = Math.max(scratchVector2.dot(v2), u2);\n u3 = Math.max(scratchVector2.dot(v3), u3);\n\n l1 = Math.min(scratchVector2.dot(v1), l1);\n l2 = Math.min(scratchVector2.dot(v2), l2);\n l3 = Math.min(scratchVector2.dot(v3), l3);\n }\n\n v1 = v1.multiplyByScalar(0.5 * (l1 + u1));\n v2 = v2.multiplyByScalar(0.5 * (l2 + u2));\n v3 = v3.multiplyByScalar(0.5 * (l3 + u3));\n\n result.center.copy(v1).add(v2).add(v3);\n\n const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);\n const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);\n result.halfAxes.multiplyRight(scaleMatrix);\n\n return result;\n}\n\n/**\n * Computes an instance of an AxisAlignedBoundingBox. The box is determined by\n * finding the points spaced the farthest apart on the x, y, and z axes.\n */\nexport function makeAxisAlignedBoundingBoxFromPoints(\n positions: readonly number[][],\n result: AxisAlignedBoundingBox = new AxisAlignedBoundingBox()\n): AxisAlignedBoundingBox {\n if (!positions || positions.length === 0) {\n result.minimum.set(0, 0, 0);\n result.maximum.set(0, 0, 0);\n result.center.set(0, 0, 0);\n result.halfDiagonal.set(0, 0, 0);\n return result;\n }\n\n let minimumX = positions[0][0];\n let minimumY = positions[0][1];\n let minimumZ = positions[0][2];\n\n let maximumX = positions[0][0];\n let maximumY = positions[0][1];\n let maximumZ = positions[0][2];\n\n for (const p of positions) {\n const x = p[0];\n const y = p[1];\n const z = p[2];\n\n minimumX = Math.min(x, minimumX);\n maximumX = Math.max(x, maximumX);\n minimumY = Math.min(y, minimumY);\n maximumY = Math.max(y, maximumY);\n minimumZ = Math.min(z, minimumZ);\n maximumZ = Math.max(z, maximumZ);\n }\n\n result.minimum.set(minimumX, minimumY, minimumZ);\n result.maximum.set(maximumX, maximumY, maximumZ);\n result.center.copy(result.minimum).add(result.maximum).scale(0.5);\n result.halfDiagonal.copy(result.maximum).subtract(result.center);\n\n return result;\n}\n"],"file":"bounding-box-from-points.js"}
@@ -1,4 +1,4 @@
1
- import BoundingSphere from '../bounding-volumes/bounding-sphere';
1
+ import { BoundingSphere } from '../bounding-volumes/bounding-sphere';
2
2
  /**
3
3
  * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
4
4
  *
@@ -10,5 +10,5 @@ import BoundingSphere from '../bounding-volumes/bounding-sphere';
10
10
  * @param result Optional object onto which to store the result.
11
11
  * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
12
12
  */
13
- export default function makeBoundingSphereFromPoints(positions: number[][], result?: BoundingSphere): BoundingSphere;
13
+ export declare function makeBoundingSphereFromPoints(positions: number[][], result?: BoundingSphere): BoundingSphere;
14
14
  //# sourceMappingURL=bounding-sphere-from-points.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-sphere-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":[],"mappings":"AAIA,OAAO,cAAc,MAAM,qCAAqC,CAAC;AAiBjE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAClD,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,cAAqC,GAC5C,cAAc,CAqIhB"}
1
+ {"version":3,"file":"bounding-sphere-from-points.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,cAAc,EAAC,MAAM,qCAAqC,CAAC;AAiBnE;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EAAE,EAAE,EACrB,MAAM,GAAE,cAAqC,GAC5C,cAAc,CAqIhB"}
@@ -1,5 +1,5 @@
1
1
  import { Vector3 } from '@math.gl/core';
2
- import BoundingSphere from "../bounding-volumes/bounding-sphere.js";
2
+ import { BoundingSphere } from "../bounding-volumes/bounding-sphere.js";
3
3
  const fromPointsXMin = new Vector3();
4
4
  const fromPointsYMin = new Vector3();
5
5
  const fromPointsZMin = new Vector3();
@@ -12,7 +12,7 @@ const fromPointsRitterCenter = new Vector3();
12
12
  const fromPointsMinBoxPt = new Vector3();
13
13
  const fromPointsMaxBoxPt = new Vector3();
14
14
  const fromPointsNaiveCenterScratch = new Vector3();
15
- export default function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
15
+ export function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
16
16
  if (!positions || positions.length === 0) {
17
17
  return result.fromCenterRadius([0, 0, 0], 0);
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":["Vector3","BoundingSphere","fromPointsXMin","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","makeBoundingSphereFromPoints","positions","result","length","fromCenterRadius","currentPos","copy","xMin","yMin","zMin","xMax","yMax","zMax","position","x","y","z","xSpan","subtract","magnitudeSquared","ySpan","zSpan","diameter1","diameter2","maxSpan","ritterCenter","radiusSquared","ritterRadius","Math","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":"AAGA,SAAQA,OAAR,QAAsB,eAAtB;OACOC,c;AAGP,MAAMC,cAAc,GAAG,IAAIF,OAAJ,EAAvB;AACA,MAAMG,cAAc,GAAG,IAAIH,OAAJ,EAAvB;AACA,MAAMI,cAAc,GAAG,IAAIJ,OAAJ,EAAvB;AACA,MAAMK,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,cAAc,GAAG,IAAIN,OAAJ,EAAvB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA,MAAMQ,oBAAoB,GAAG,IAAIR,OAAJ,EAA7B;AACA,MAAMS,iBAAiB,GAAG,IAAIT,OAAJ,EAA1B;AACA,MAAMU,sBAAsB,GAAG,IAAIV,OAAJ,EAA/B;AACA,MAAMW,kBAAkB,GAAG,IAAIX,OAAJ,EAA3B;AACA,MAAMY,kBAAkB,GAAG,IAAIZ,OAAJ,EAA3B;AACA,MAAMa,4BAA4B,GAAG,IAAIb,OAAJ,EAArC;AAcA,eAAe,SAASc,4BAAT,CACbC,SADa,EAEbC,MAAsB,GAAG,IAAIf,cAAJ,EAFZ,EAGG;AAChB,MAAI,CAACc,SAAD,IAAcA,SAAS,CAACE,MAAV,KAAqB,CAAvC,EAA0C;AACxC,WAAOD,MAA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CAEpBO,YAFoB,EAG7BN,gBAH6B,EAAhC;;AAKA,QAAImB,uBAAuB,GAAGZ,aAA9B,EAA6C;AAC3C,YAAMa,gBAAgB,GAAGX,IAAI,CAACC,IAAL,CAAUS,uBAAV,CAAzB;AAEAX,MAAAA,YAAY,GAAG,CAACA,YAAY,GAAGY,gBAAhB,IAAoC,GAAnD;AACAb,MAAAA,aAAa,GAAGC,YAAY,GAAGA,YAA/B;AAEA,YAAMa,QAAQ,GAAGD,gBAAgB,GAAGZ,YAApC;AACAF,MAAAA,YAAY,CAACX,CAAb,GAAiB,CAACa,YAAY,GAAGF,YAAY,CAACX,CAA5B,GAAgC0B,QAAQ,GAAGnC,UAAU,CAACS,CAAvD,IAA4DyB,gBAA7E;AACAd,MAAAA,YAAY,CAACV,CAAb,GAAiB,CAACY,YAAY,GAAGF,YAAY,CAACV,CAA5B,GAAgCyB,QAAQ,GAAGnC,UAAU,CAACU,CAAvD,IAA4DwB,gBAA7E;AACAd,MAAAA,YAAY,CAACT,CAAb,GAAiB,CAACW,YAAY,GAAGF,YAAY,CAACT,CAA5B,GAAgCwB,QAAQ,GAAGnC,UAAU,CAACW,CAAvD,IAA4DuB,gBAA7E;AACD;AACF;;AAED,MAAIZ,YAAY,GAAGQ,WAAnB,EAAgC;AAC9BV,IAAAA,YAAY,CAACgB,EAAb,CAAgBvC,MAAM,CAACwC,MAAvB;AACAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBhB,YAAhB;AACD,GAHD,MAGO;AACLK,IAAAA,WAAW,CAACS,EAAZ,CAAevC,MAAM,CAACwC,MAAtB;AACAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBR,WAAhB;AACD;;AAED,SAAOjC,MAAP;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} from '@math.gl/core';\nimport BoundingSphere from '../bounding-volumes/bounding-sphere';\n\n/* eslint-disable */\nconst fromPointsXMin = new Vector3();\nconst fromPointsYMin = new Vector3();\nconst fromPointsZMin = new Vector3();\nconst fromPointsXMax = new Vector3();\nconst fromPointsYMax = new Vector3();\nconst fromPointsZMax = new Vector3();\nconst fromPointsCurrentPos = new Vector3();\nconst fromPointsScratch = new Vector3();\nconst fromPointsRitterCenter = new Vector3();\nconst fromPointsMinBoxPt = new Vector3();\nconst fromPointsMaxBoxPt = new Vector3();\nconst fromPointsNaiveCenterScratch = new Vector3();\n// const volumeConstant = (4.0 / 3.0) * Math.PI;\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\n *\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\n * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding\n *\n * @param positions An array of points that the bounding sphere will enclose.\n * @param result Optional object onto which to store the result.\n * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.\n */\nexport default function makeBoundingSphereFromPoints(\n positions: number[][],\n result: BoundingSphere = new BoundingSphere()\n): BoundingSphere {\n if (!positions || positions.length === 0) {\n return result.fromCenterRadius([0, 0, 0], 0);\n }\n\n const currentPos = fromPointsCurrentPos.copy(positions[0]);\n\n const xMin = fromPointsXMin.copy(currentPos);\n const yMin = fromPointsYMin.copy(currentPos);\n const zMin = fromPointsZMin.copy(currentPos);\n\n const xMax = fromPointsXMax.copy(currentPos);\n const yMax = fromPointsYMax.copy(currentPos);\n const zMax = fromPointsZMax.copy(currentPos);\n\n for (const position of positions) {\n currentPos.copy(position);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n xMin.copy(currentPos);\n }\n\n if (x > xMax.x) {\n xMax.copy(currentPos);\n }\n\n if (y < yMin.y) {\n yMin.copy(currentPos);\n }\n\n if (y > yMax.y) {\n yMax.copy(currentPos);\n }\n\n if (z < zMin.z) {\n zMin.copy(currentPos);\n }\n\n if (z > zMax.z) {\n zMax.copy(currentPos);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();\n const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();\n const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = fromPointsNaiveCenterScratch\n .copy(minBoxPt)\n .add(maxBoxPt)\n .multiplyByScalar(0.5);\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (const position of positions) {\n currentPos.copy(position);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = fromPointsScratch\n .copy(currentPos)\n .subtract(ritterCenter)\n .magnitudeSquared();\n\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;\n ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;\n ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n ritterCenter.to(result.center);\n result.radius = ritterRadius;\n } else {\n naiveCenter.to(result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n}\n"],"file":"bounding-sphere-from-points.js"}
1
+ {"version":3,"sources":["../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":["Vector3","BoundingSphere","fromPointsXMin","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","makeBoundingSphereFromPoints","positions","result","length","fromCenterRadius","currentPos","copy","xMin","yMin","zMin","xMax","yMax","zMax","position","x","y","z","xSpan","subtract","magnitudeSquared","ySpan","zSpan","diameter1","diameter2","maxSpan","ritterCenter","radiusSquared","ritterRadius","Math","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":"AAGA,SAAQA,OAAR,QAAsB,eAAtB;SACQC,c;A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iB,CAACY,YAAY,GAAGF,YAAY,CAACV,CAA5B,GAAgCyB,QAAQ,GAAGnC,UAAU,CAACU,CAAvD,IAA4DwB,gBAA7E;AACAd,MAAAA,YAAY,CAACT,CAAb,GAAiB,CAACW,YAAY,GAAGF,YAAY,CAACT,CAA5B,GAAgCwB,QAAQ,GAAGnC,UAAU,CAACW,CAAvD,IAA4DuB,gBAA7E;AACD;AACF;;AAED,MAAIZ,YAAY,GAAGQ,WAAnB,EAAgC;AAC9BV,IAAAA,YAAY,CAACgB,EAAb,CAAgBvC,MAAM,CAACwC,MAAvB;AACAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBhB,YAAhB;AACD,GAHD,MAGO;AACLK,IAAAA,WAAW,CAACS,EAAZ,CAAevC,MAAM,CAACwC,MAAtB;AACAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBR,WAAhB;AACD;;AAED,SAAOjC,MAAP;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} from '@math.gl/core';\nimport {BoundingSphere} from '../bounding-volumes/bounding-sphere';\n\n/* eslint-disable */\nconst fromPointsXMin = new Vector3();\nconst fromPointsYMin = new Vector3();\nconst fromPointsZMin = new Vector3();\nconst fromPointsXMax = new Vector3();\nconst fromPointsYMax = new Vector3();\nconst fromPointsZMax = new Vector3();\nconst fromPointsCurrentPos = new Vector3();\nconst fromPointsScratch = new Vector3();\nconst fromPointsRitterCenter = new Vector3();\nconst fromPointsMinBoxPt = new Vector3();\nconst fromPointsMaxBoxPt = new Vector3();\nconst fromPointsNaiveCenterScratch = new Vector3();\n// const volumeConstant = (4.0 / 3.0) * Math.PI;\n\n/**\n * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.\n *\n * The bounding sphere is computed by running two algorithms, a naive algorithm and\n * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.\n * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding\n *\n * @param positions An array of points that the bounding sphere will enclose.\n * @param result Optional object onto which to store the result.\n * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.\n */\nexport function makeBoundingSphereFromPoints(\n positions: number[][],\n result: BoundingSphere = new BoundingSphere()\n): BoundingSphere {\n if (!positions || positions.length === 0) {\n return result.fromCenterRadius([0, 0, 0], 0);\n }\n\n const currentPos = fromPointsCurrentPos.copy(positions[0]);\n\n const xMin = fromPointsXMin.copy(currentPos);\n const yMin = fromPointsYMin.copy(currentPos);\n const zMin = fromPointsZMin.copy(currentPos);\n\n const xMax = fromPointsXMax.copy(currentPos);\n const yMax = fromPointsYMax.copy(currentPos);\n const zMax = fromPointsZMax.copy(currentPos);\n\n for (const position of positions) {\n currentPos.copy(position);\n\n const x = currentPos.x;\n const y = currentPos.y;\n const z = currentPos.z;\n\n // Store points containing the the smallest and largest components\n if (x < xMin.x) {\n xMin.copy(currentPos);\n }\n\n if (x > xMax.x) {\n xMax.copy(currentPos);\n }\n\n if (y < yMin.y) {\n yMin.copy(currentPos);\n }\n\n if (y > yMax.y) {\n yMax.copy(currentPos);\n }\n\n if (z < zMin.z) {\n zMin.copy(currentPos);\n }\n\n if (z > zMax.z) {\n zMax.copy(currentPos);\n }\n }\n\n // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).\n const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();\n const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();\n const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();\n\n // Set the diameter endpoints to the largest span.\n let diameter1 = xMin;\n let diameter2 = xMax;\n let maxSpan = xSpan;\n if (ySpan > maxSpan) {\n maxSpan = ySpan;\n diameter1 = yMin;\n diameter2 = yMax;\n }\n if (zSpan > maxSpan) {\n maxSpan = zSpan;\n diameter1 = zMin;\n diameter2 = zMax;\n }\n\n // Calculate the center of the initial sphere found by Ritter's algorithm\n const ritterCenter = fromPointsRitterCenter;\n ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;\n ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;\n ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;\n\n // Calculate the radius of the initial sphere found by Ritter's algorithm\n let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();\n let ritterRadius = Math.sqrt(radiusSquared);\n\n // Find the center of the sphere found using the Naive method.\n const minBoxPt = fromPointsMinBoxPt;\n minBoxPt.x = xMin.x;\n minBoxPt.y = yMin.y;\n minBoxPt.z = zMin.z;\n\n const maxBoxPt = fromPointsMaxBoxPt;\n maxBoxPt.x = xMax.x;\n maxBoxPt.y = yMax.y;\n maxBoxPt.z = zMax.z;\n\n const naiveCenter = fromPointsNaiveCenterScratch\n .copy(minBoxPt)\n .add(maxBoxPt)\n .multiplyByScalar(0.5);\n\n // Begin 2nd pass to find naive radius and modify the ritter sphere.\n let naiveRadius = 0;\n for (const position of positions) {\n currentPos.copy(position);\n\n // Find the furthest point from the naive center to calculate the naive radius.\n const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();\n if (r > naiveRadius) {\n naiveRadius = r;\n }\n\n // Make adjustments to the Ritter Sphere to include all points.\n const oldCenterToPointSquared = fromPointsScratch\n .copy(currentPos)\n .subtract(ritterCenter)\n .magnitudeSquared();\n\n if (oldCenterToPointSquared > radiusSquared) {\n const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);\n // Calculate new radius to include the point that lies outside\n ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;\n radiusSquared = ritterRadius * ritterRadius;\n // Calculate center of new Ritter sphere\n const oldToNew = oldCenterToPoint - ritterRadius;\n ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;\n ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;\n ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;\n }\n }\n\n if (ritterRadius < naiveRadius) {\n ritterCenter.to(result.center);\n result.radius = ritterRadius;\n } else {\n naiveCenter.to(result.center);\n result.radius = naiveRadius;\n }\n\n return result;\n}\n"],"file":"bounding-sphere-from-points.js"}
@@ -1,5 +1,5 @@
1
1
  import { Matrix3 } from '@math.gl/core';
2
- export type EigenDecomposition = {
2
+ export declare type EigenDecomposition = {
3
3
  unitary: Matrix3;
4
4
  diagonal: Matrix3;
5
5
  };
@@ -33,5 +33,5 @@ export type EigenDecomposition = {
33
33
  * const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector
34
34
  * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)
35
35
  */
36
- export default function computeEigenDecomposition(matrix: number[], result?: EigenDecomposition): EigenDecomposition;
36
+ export declare function computeEigenDecomposition(matrix: number[], result?: EigenDecomposition): EigenDecomposition;
37
37
  //# sourceMappingURL=compute-eigen-decomposition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compute-eigen-decomposition.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/compute-eigen-decomposition.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,OAAO,EAAa,MAAM,eAAe,CAAC;AASlD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,MAAM,EAAE,MAAM,EAAE,EAEhB,MAAM,GAAE,kBAAuB,GAC9B,kBAAkB,CAkCpB"}
1
+ {"version":3,"file":"compute-eigen-decomposition.d.ts","sourceRoot":"","sources":["../../../src/lib/algorithms/compute-eigen-decomposition.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,OAAO,EAAa,MAAM,eAAe,CAAC;AASlD,oBAAY,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,MAAM,EAAE,EAEhB,MAAM,GAAE,kBAAuB,GAC9B,kBAAkB,CAkCpB"}
@@ -4,7 +4,7 @@ const scratchUnitary = new Matrix3();
4
4
  const scratchDiagonal = new Matrix3();
5
5
  const jMatrix = new Matrix3();
6
6
  const jMatrixTranspose = new Matrix3();
7
- export default function computeEigenDecomposition(matrix, result = {}) {
7
+ export function computeEigenDecomposition(matrix, result = {}) {
8
8
  const EIGEN_TOLERANCE = _MathUtils.EPSILON20;
9
9
  const EIGEN_MAX_SWEEPS = 10;
10
10
  let count = 0;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/algorithms/compute-eigen-decomposition.ts"],"names":["Matrix3","_MathUtils","scratchMatrix","scratchUnitary","scratchDiagonal","jMatrix","jMatrixTranspose","computeEigenDecomposition","matrix","result","EIGEN_TOLERANCE","EPSILON20","EIGEN_MAX_SWEEPS","count","sweep","unitaryMatrix","diagonalMatrix","identity","copy","epsilon","computeFrobeniusNorm","offDiagonalFrobeniusNorm","shurDecomposition","transpose","multiplyRight","multiplyLeft","unitary","toTarget","diagonal","norm","i","temp","Math","sqrt","rowVal","colVal","getElementIndex","tolerance","EPSILON15","maxDiagonal","rotAxis","abs","p","q","c","s","qq","pp","qp","tau","t","IDENTITY","to"],"mappings":"AAGA,SAAQA,OAAR,EAAiBC,UAAjB,QAAkC,eAAlC;AAEA,MAAMC,aAAa,GAAG,IAAIF,OAAJ,EAAtB;AACA,MAAMG,cAAc,GAAG,IAAIH,OAAJ,EAAvB;AACA,MAAMI,eAAe,GAAG,IAAIJ,OAAJ,EAAxB;AAEA,MAAMK,OAAO,GAAG,IAAIL,OAAJ,EAAhB;AACA,MAAMM,gBAAgB,GAAG,IAAIN,OAAJ,EAA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AGK,CAAC,GAAGN,CAAR;AACD;;AAGD5C,EAAAA,OAAO,CAACmD,QAAR,CAAiBC,EAAjB,CAAoB3C,MAApB;AACAA,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BM,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CjC,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BO,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CC,CAA5F;AACAnC,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BO,CAA9B,EAAiCD,CAAjC,CAAD,CAAN,GAA8CG,CAA9C;AACApC,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BM,CAA9B,EAAiCC,CAAjC,CAAD,CAAN,GAA8C,CAACE,CAA/C;AAEA,SAAOpC,MAAP;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 {Matrix3, _MathUtils} from '@math.gl/core';\n\nconst scratchMatrix = new Matrix3();\nconst scratchUnitary = new Matrix3();\nconst scratchDiagonal = new Matrix3();\n\nconst jMatrix = new Matrix3();\nconst jMatrixTranspose = new Matrix3();\n\nexport type EigenDecomposition = {\n unitary: Matrix3;\n diagonal: Matrix3;\n};\n\n/**\n * Computes the eigenvectors and eigenvalues of a symmetric matrix.\n *\n * - Returns a diagonal matrix and unitary matrix such that:\n * `matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)`\n * - The values along the diagonal of the diagonal matrix are the eigenvalues. The columns\n * of the unitary matrix are the corresponding eigenvectors.\n * - This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n * section 8.4.3 The Classical Jacobi Algorithm\n *\n * @param matrix The 3x3 matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.\n * @param result Optional object with unitary and diagonal properties which are matrices onto which to store the result.\n * @returns An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.\n *\n * @example\n * const a = //... symmetric matrix\n * const result = {\n * unitary : new Matrix3(),\n * diagonal : new Matrix3()\n * };\n * computeEigenDecomposition(a, result);\n *\n * const unitaryTranspose = Matrix3.transpose(result.unitary, new Matrix3());\n * const b = Matrix3.multiply(result.unitary, result.diagonal, new Matrix3());\n * Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a\n *\n * const lambda = result.diagonal.getColumn(0, new Vector3()).x; // first eigenvalue\n * const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector\n * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)\n */\nexport default function computeEigenDecomposition(\n matrix: number[],\n // @ts-expect-error accept empty object type\n result: EigenDecomposition = {}\n): EigenDecomposition {\n const EIGEN_TOLERANCE = _MathUtils.EPSILON20;\n const EIGEN_MAX_SWEEPS = 10;\n\n let count = 0;\n let sweep = 0;\n\n const unitaryMatrix = scratchUnitary;\n const diagonalMatrix = scratchDiagonal;\n\n unitaryMatrix.identity();\n diagonalMatrix.copy(matrix);\n\n const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);\n\n while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {\n shurDecomposition(diagonalMatrix, jMatrix);\n\n jMatrixTranspose.copy(jMatrix).transpose();\n\n diagonalMatrix.multiplyRight(jMatrix);\n diagonalMatrix.multiplyLeft(jMatrixTranspose);\n unitaryMatrix.multiplyRight(jMatrix);\n\n if (++count > 2) {\n ++sweep;\n count = 0;\n }\n }\n\n result.unitary = unitaryMatrix.toTarget(result.unitary);\n result.diagonal = diagonalMatrix.toTarget(result.diagonal);\n\n return result;\n}\n\nfunction computeFrobeniusNorm(matrix: Matrix3): number {\n let norm = 0.0;\n for (let i = 0; i < 9; ++i) {\n const temp = matrix[i];\n norm += temp * temp;\n }\n return Math.sqrt(norm);\n}\n\nconst rowVal = [1, 0, 0];\nconst colVal = [2, 2, 1];\n\n// Computes the \"off-diagonal\" Frobenius norm.\n// Assumes matrix is symmetric.\nfunction offDiagonalFrobeniusNorm(matrix: Matrix3): number {\n let norm = 0.0;\n for (let i = 0; i < 3; ++i) {\n const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];\n norm += 2.0 * temp * temp;\n }\n return Math.sqrt(norm);\n}\n\n// The routine takes a matrix, which is assumed to be symmetric, and\n// finds the largest off-diagonal term, and then creates\n// a matrix (result) which can be used to help reduce it\n//\n// This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n// section 8.4.2 The 2by2 Symmetric Schur Decomposition.\n//\n// eslint-disable-next-line max-statements\nfunction shurDecomposition(matrix: Matrix3, result: Matrix3): Matrix3 {\n const tolerance = _MathUtils.EPSILON15;\n\n let maxDiagonal = 0.0;\n let rotAxis = 1;\n\n // find pivot (rotAxis) based on max diagonal of matrix\n for (let i = 0; i < 3; ++i) {\n const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);\n if (temp > maxDiagonal) {\n rotAxis = i;\n maxDiagonal = temp;\n }\n }\n\n const p = rowVal[rotAxis];\n const q = colVal[rotAxis];\n\n let c = 1.0;\n let s = 0.0;\n\n if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {\n const qq = matrix[scratchMatrix.getElementIndex(q, q)];\n const pp = matrix[scratchMatrix.getElementIndex(p, p)];\n const qp = matrix[scratchMatrix.getElementIndex(q, p)];\n\n const tau = (qq - pp) / 2.0 / qp;\n let t;\n\n if (tau < 0.0) {\n t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));\n } else {\n t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));\n }\n\n c = 1.0 / Math.sqrt(1.0 + t * t);\n s = t * c;\n }\n\n // Copy into result\n Matrix3.IDENTITY.to(result);\n result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;\n result[scratchMatrix.getElementIndex(q, p)] = s;\n result[scratchMatrix.getElementIndex(p, q)] = -s;\n\n return result;\n}\n"],"file":"compute-eigen-decomposition.js"}
1
+ {"version":3,"sources":["../../../src/lib/algorithms/compute-eigen-decomposition.ts"],"names":["Matrix3","_MathUtils","scratchMatrix","scratchUnitary","scratchDiagonal","jMatrix","jMatrixTranspose","computeEigenDecomposition","matrix","result","EIGEN_TOLERANCE","EPSILON20","EIGEN_MAX_SWEEPS","count","sweep","unitaryMatrix","diagonalMatrix","identity","copy","epsilon","computeFrobeniusNorm","offDiagonalFrobeniusNorm","shurDecomposition","transpose","multiplyRight","multiplyLeft","unitary","toTarget","diagonal","norm","i","temp","Math","sqrt","rowVal","colVal","getElementIndex","tolerance","EPSILON15","maxDiagonal","rotAxis","abs","p","q","c","s","qq","pp","qp","tau","t","IDENTITY","to"],"mappings":"AAGA,SAAQA,OAAR,EAAiBC,UAAjB,QAAkC,eAAlC;AAEA,MAAMC,aAAa,GAAG,IAAIF,OAAJ,EAAtB;AACA,MAAMG,cAAc,GAAG,IAAIH,OAAJ,EAAvB;AACA,MAAMI,eAAe,GAAG,IAAIJ,OAAJ,EAAxB;AAEA,MAAMK,OAAO,GAAG,IAAIL,OAAJ,EAAhB;AACA,MAAMM,gBAAgB,GAAG,IAAIN,OAAJ,EAAzB;AAqCA,OAAO,SAASO,yBAAT,CACLC,MADK,EAGLC,MAA0B,GAAG,EAHxB,EAIe;AACpB,QAAMC,eAAe,GAAGT,UAAU,CAACU,SAAnC;AACA,QAAMC,gBAAgB,GAAG,EAAzB;AAEA,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAK,GAAG,CAAZ;AAEA,QAAMC,aAAa,GAAGZ,cAAtB;AACA,QAAMa,cAAc,GAAGZ,eAAvB;AAEAW,EAAAA,aAAa,CAACE,QAAd;AACAD,EAAAA,cAAc,CAACE,IAAf,CAAoBV,MAApB;AAEA,QAAMW,OAAO,GAAGT,eAAe,GAAGU,oBAAoB,CAACJ,cAAD,CAAtD;;AAEA,SAAOF,KAAK,GAAGF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AjC,CAAD,CAAN,GAA8C,CAACE,CAA/C;AAEA,SAAOpC,MAAP;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 {Matrix3, _MathUtils} from '@math.gl/core';\n\nconst scratchMatrix = new Matrix3();\nconst scratchUnitary = new Matrix3();\nconst scratchDiagonal = new Matrix3();\n\nconst jMatrix = new Matrix3();\nconst jMatrixTranspose = new Matrix3();\n\nexport type EigenDecomposition = {\n unitary: Matrix3;\n diagonal: Matrix3;\n};\n\n/**\n * Computes the eigenvectors and eigenvalues of a symmetric matrix.\n *\n * - Returns a diagonal matrix and unitary matrix such that:\n * `matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)`\n * - The values along the diagonal of the diagonal matrix are the eigenvalues. The columns\n * of the unitary matrix are the corresponding eigenvectors.\n * - This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n * section 8.4.3 The Classical Jacobi Algorithm\n *\n * @param matrix The 3x3 matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.\n * @param result Optional object with unitary and diagonal properties which are matrices onto which to store the result.\n * @returns An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.\n *\n * @example\n * const a = //... symmetric matrix\n * const result = {\n * unitary : new Matrix3(),\n * diagonal : new Matrix3()\n * };\n * computeEigenDecomposition(a, result);\n *\n * const unitaryTranspose = Matrix3.transpose(result.unitary, new Matrix3());\n * const b = Matrix3.multiply(result.unitary, result.diagonal, new Matrix3());\n * Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a\n *\n * const lambda = result.diagonal.getColumn(0, new Vector3()).x; // first eigenvalue\n * const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector\n * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)\n */\nexport function computeEigenDecomposition(\n matrix: number[],\n // @ts-expect-error accept empty object type\n result: EigenDecomposition = {}\n): EigenDecomposition {\n const EIGEN_TOLERANCE = _MathUtils.EPSILON20;\n const EIGEN_MAX_SWEEPS = 10;\n\n let count = 0;\n let sweep = 0;\n\n const unitaryMatrix = scratchUnitary;\n const diagonalMatrix = scratchDiagonal;\n\n unitaryMatrix.identity();\n diagonalMatrix.copy(matrix);\n\n const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);\n\n while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {\n shurDecomposition(diagonalMatrix, jMatrix);\n\n jMatrixTranspose.copy(jMatrix).transpose();\n\n diagonalMatrix.multiplyRight(jMatrix);\n diagonalMatrix.multiplyLeft(jMatrixTranspose);\n unitaryMatrix.multiplyRight(jMatrix);\n\n if (++count > 2) {\n ++sweep;\n count = 0;\n }\n }\n\n result.unitary = unitaryMatrix.toTarget(result.unitary);\n result.diagonal = diagonalMatrix.toTarget(result.diagonal);\n\n return result;\n}\n\nfunction computeFrobeniusNorm(matrix: Matrix3): number {\n let norm = 0.0;\n for (let i = 0; i < 9; ++i) {\n const temp = matrix[i];\n norm += temp * temp;\n }\n return Math.sqrt(norm);\n}\n\nconst rowVal = [1, 0, 0];\nconst colVal = [2, 2, 1];\n\n// Computes the \"off-diagonal\" Frobenius norm.\n// Assumes matrix is symmetric.\nfunction offDiagonalFrobeniusNorm(matrix: Matrix3): number {\n let norm = 0.0;\n for (let i = 0; i < 3; ++i) {\n const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];\n norm += 2.0 * temp * temp;\n }\n return Math.sqrt(norm);\n}\n\n// The routine takes a matrix, which is assumed to be symmetric, and\n// finds the largest off-diagonal term, and then creates\n// a matrix (result) which can be used to help reduce it\n//\n// This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n// section 8.4.2 The 2by2 Symmetric Schur Decomposition.\n//\n// eslint-disable-next-line max-statements\nfunction shurDecomposition(matrix: Matrix3, result: Matrix3): Matrix3 {\n const tolerance = _MathUtils.EPSILON15;\n\n let maxDiagonal = 0.0;\n let rotAxis = 1;\n\n // find pivot (rotAxis) based on max diagonal of matrix\n for (let i = 0; i < 3; ++i) {\n const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);\n if (temp > maxDiagonal) {\n rotAxis = i;\n maxDiagonal = temp;\n }\n }\n\n const p = rowVal[rotAxis];\n const q = colVal[rotAxis];\n\n let c = 1.0;\n let s = 0.0;\n\n if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {\n const qq = matrix[scratchMatrix.getElementIndex(q, q)];\n const pp = matrix[scratchMatrix.getElementIndex(p, p)];\n const qp = matrix[scratchMatrix.getElementIndex(q, p)];\n\n const tau = (qq - pp) / 2.0 / qp;\n let t;\n\n if (tau < 0.0) {\n t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));\n } else {\n t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));\n }\n\n c = 1.0 / Math.sqrt(1.0 + t * t);\n s = t * c;\n }\n\n // Copy into result\n Matrix3.IDENTITY.to(result);\n result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;\n result[scratchMatrix.getElementIndex(q, p)] = s;\n result[scratchMatrix.getElementIndex(p, q)] = -s;\n\n return result;\n}\n"],"file":"compute-eigen-decomposition.js"}
@@ -1,13 +1,13 @@
1
1
  import { BoundingVolume } from './bounding-volume';
2
2
  import { Vector3 } from '@math.gl/core';
3
- import Plane from '../plane';
3
+ import { Plane } from '../plane';
4
4
  /**
5
5
  * An axis aligned bounding box - aligned with coordinate axes
6
6
  * @see BoundingVolume
7
7
  * @see BoundingRectangle
8
8
  * @see OrientedBoundingBox
9
9
  */
10
- export default class AxisAlignedBoundingBox implements BoundingVolume {
10
+ export declare class AxisAlignedBoundingBox implements BoundingVolume {
11
11
  /** The center point of the bounding box. */
12
12
  readonly center: Vector3;
13
13
  /** The positive half diagonal of the bounding box. */
@@ -1 +1 @@
1
- {"version":3,"file":"axis-aligned-bounding-box.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,MAAM,UAAU,CAAC;AAM7B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,cAAc;IACnE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,sDAAsD;IACtD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;;;OAKG;gBAED,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE;IAsB5B;;;;OAIG;IACH,KAAK,IAAI,sBAAsB;IAI/B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO;IAO9C;;;;OAIG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAS7C;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAqBpC,2FAA2F;IAC3F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAI5C,mGAAmG;IACnG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;CAwBpD"}
1
+ {"version":3,"file":"axis-aligned-bounding-box.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAM/B;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,cAAc;IAC3D,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,sDAAsD;IACtD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;;;OAKG;gBAED,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE;IAsB5B;;;;OAIG;IACH,KAAK,IAAI,sBAAsB;IAI/B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO;IAO9C;;;;OAIG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAS7C;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAqBpC,2FAA2F;IAC3F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAI5C,mGAAmG;IACnG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;CAwBpD"}
@@ -3,7 +3,7 @@ import { Vector3 } from '@math.gl/core';
3
3
  import { INTERSECTION } from "../../constants.js";
4
4
  const scratchVector = new Vector3();
5
5
  const scratchNormal = new Vector3();
6
- export default class AxisAlignedBoundingBox {
6
+ export class AxisAlignedBoundingBox {
7
7
  constructor(minimum = [0, 0, 0], maximum = [0, 0, 0], center) {
8
8
  _defineProperty(this, "center", void 0);
9
9
 
@@ -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;SAEQC,Y;AAER,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,MAAZ,CAAd;AACA,SAAKI,YAAL,GAAoB,IAAIZ,OAAJ,CAAYO,OAAZ,EAAqBM,QAArB,CAA8B,KAAKL,MAAnC,CAApB;AAOA,SAAKF,OAAL,GAAe,IAAIN,OAAJ,CAAYM,OAAZ,CAAf;AAOA,SAAKC,OAAL,GAAe,IAAIP,OAAJ,CAAYO,OAAZ,CAAf;AACD;;AAODO,EAAAA,KAAK,GAA2B;AAC9B,WAAO,IAAIV,sBAAJ,CAA2B,KAAKE,OAAhC,EAAyC,KAAKC,OAA9C,EAAuD,KAAKC,MAA5D,CAAP;AACD;;AASDO,EAAAA,MAAM,CAACC,KAAD,E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AAA,UAAU,CAACC,KAAD,EAAmC;AAC3C,WAAOX,IAAI,CAACY,IAAL,CAAU,KAAKC,iBAAL,CAAuBF,KAAvB,CAAV,CAAP;AACD;;AAGDE,EAAAA,iBAAiB,CAACF,KAAD,EAAmC;AAClD,UAAMG,MAAM,GAAGtC,aAAa,CAACqB,IAAd,CAAmBc,KAAnB,EAA0BxB,QAA1B,CAAmC,KAAKL,MAAxC,CAAf;AACA,UAAM;AAACI,MAAAA;AAAD,QAAiB,IAAvB;AAEA,QAAI6B,eAAe,GAAG,GAAtB;AACA,QAAIC,CAAJ;AAEAA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACf,CAAhB,IAAqBb,YAAY,CAACa,CAAtC;;AACA,QAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBhB,YAAY,CAACgB,CAAtC;;AACA,QAAIc,CAAC,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): 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
+ {"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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CAACqB,IAAd,CAAmBc,KAAnB,EAA0BxB,QAA1B,CAAmC,KAAKL,MAAxC,CAAf;AACA,UAAM;AAACI,MAAAA;AAAD,QAAiB,IAAvB;AAEA,QAAI6B,eAAe,GAAG,GAAtB;AACA,QAAIC,CAAJ;AAEAA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACf,CAAhB,IAAqBb,YAAY,CAACa,CAAtC;;AACA,QAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBhB,YAAY,CAACgB,CAAtC;;AACA,QAAIc,CAAC,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;;AAnI2D","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 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,8 +1,8 @@
1
1
  import { NumericArray, Vector3 } from '@math.gl/core';
2
2
  import { BoundingVolume } from './bounding-volume';
3
- import Plane from '../plane';
3
+ import { Plane } from '../plane';
4
4
  /** A BoundingSphere */
5
- export default class BoundingSphere implements BoundingVolume {
5
+ export declare class BoundingSphere implements BoundingVolume {
6
6
  center: Vector3;
7
7
  radius: number;
8
8
  /** Creates a bounding sphere */
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-sphere.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAE,OAAO,EAAC,MAAM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AAe,CAAC;AAKpD,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAK/B,uBAAuB;AACvB,qBAAa,cAAe,YAAW,cAAc;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IAEf,gCAAgC;gBACpB,MAAM,GAAE,SAAS,MAAM,EAAc,EAAE,MAAM,GAAE,MAAY;IAMvE,2DAA2D;IAC3D,gBAAgB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAMjE;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAOpF,0DAA0D;IAC1D,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;IAOtC,4CAA4C;IAC5C,KAAK,IAAI,cAAc;IAIvB,yFAAyF;IACzF,KAAK,CAAC,cAAc,EAAE,cAAc,GAAG,cAAc;IAkCrD,iGAAiG;IACjG,MAAM,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAWtC;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAO7C,sGAAsG;IACtG,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM;IAKxD,8FAA8F;IAC9F,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM;IAMjD,4DAA4D;IAC5D,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;CAiBrC"}
@@ -4,7 +4,7 @@ import * as mat4 from 'gl-matrix/mat4';
4
4
  import { INTERSECTION } from "../../constants.js";
5
5
  const scratchVector = new Vector3();
6
6
  const scratchVector2 = new Vector3();
7
- export default class BoundingSphere {
7
+ export class BoundingSphere {
8
8
  constructor(center = [0, 0, 0], radius = 0.0) {
9
9
  _defineProperty(this, "center", void 0);
10
10
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["Vector3","mat4","INTERSECTION","scratchVector","scratchVector2","BoundingSphere","constructor","center","radius","fromCenterRadius","from","fromCornerPoints","corner","oppositeCorner","add","scale","distance","equals","right","Boolean","clone","union","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","halfDistanceBetweenTangentPoints","expand","point","scratchPoint","transform","getScaling","Math","max","distanceSquaredTo","d","distanceTo","delta","len","intersectPlane","plane","normal","distanceToPlane","dot","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";AAGA,SAAsBA,OAAtB,QAAoC,eAApC;AAEA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;SAEQC,Y;AAIR,MAAMC,aAAa,GAAG,IAAIH,OAAJ,EAAtB;AACA,MAAMI,cAAc,GAAG,IAAIJ,OAAJ,EAAvB;AAGA,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,WAAO,IAAP;AACD;;AAMDG,EAAAA,gBAAgB,CAACC,MAAD,EAA4BC,cAA5B,EAAqE;AACnFA,IAAAA,cAAc,GAAGV,aAAa,CAACO,IAAd,C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AY,CAACN,QAAb,CAAsB,KAAKtB,MAA3B,CAAd;AACA,WAAO+B,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYI,KAAK,CAACC,GAAN,KAAc,KAAKpC,MAA/B,CAAP;AACD;;AAGDqC,EAAAA,cAAc,CAACC,KAAD,EAAuB;AACnC,UAAMvC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMC,MAAM,GAAG,KAAKA,MAApB;AACA,UAAMuC,MAAM,GAAGD,KAAK,CAACC,MAArB;AACA,UAAMC,eAAe,GAAGD,MAAM,CAACE,GAAP,CAAW1C,MAAX,IAAqBuC,KAAK,CAAC9B,QAAnD;;AAGA,QAAIgC,eAAe,GAAG,CAACxC,MAAvB,EAA+B;AAC7B,aAAON,YAAY,CAACgD,OAApB;AACD;;AAED,QAAIF,eAAe,GAAGxC,MAAtB,EAA8B;AAC5B,aAAON,YAAY,CAACiD,YAApB;AACD;;AAED,WAAOjD,YAAY,CAACkD,MAApB;AACD;;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';\n// @ts-ignore gl-matrix typings...\nimport * as mat4 from 'gl-matrix/mat4';\n\nimport {INTERSECTION} from '../../constants';\nimport {BoundingVolume} from './bounding-volume';\nimport Plane from '../plane';\n\nconst scratchVector = new Vector3();\nconst scratchVector2 = new Vector3();\n\n/** A BoundingSphere */\nexport 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
+ {"version":3,"sources":["../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":["Vector3","mat4","INTERSECTION","scratchVector","scratchVector2","BoundingSphere","constructor","center","radius","fromCenterRadius","from","fromCornerPoints","corner","oppositeCorner","add","scale","distance","equals","right","Boolean","clone","union","boundingSphere","leftCenter","leftRadius","rightCenter","rightRadius","toRightCenter","copy","subtract","centerSeparation","magnitude","halfDistanceBetweenTangentPoints","expand","point","scratchPoint","transform","getScaling","Math","max","distanceSquaredTo","d","distanceTo","delta","len","intersectPlane","plane","normal","distanceToPlane","dot","OUTSIDE","INTERSECTING","INSIDE"],"mappings":";AAGA,SAAsBA,OAAtB,QAAoC,eAApC;AAEA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;SAEQC,Y;AAIR,MAAMC,aAAa,GAAG,I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AApB;AACD;;AApImD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {NumericArray, Vector3} from '@math.gl/core';\n// @ts-ignore gl-matrix typings...\nimport * as mat4 from 'gl-matrix/mat4';\n\nimport {INTERSECTION} from '../../constants';\nimport {BoundingVolume} from './bounding-volume';\nimport {Plane} from '../plane';\n\nconst scratchVector = new Vector3();\nconst scratchVector2 = new Vector3();\n\n/** A BoundingSphere */\nexport class BoundingSphere implements BoundingVolume {\n center: Vector3;\n radius: number;\n\n /** Creates a bounding sphere */\n constructor(center: readonly number[] = [0, 0, 0], radius: number = 0.0) {\n this.radius = -0;\n this.center = new Vector3();\n this.fromCenterRadius(center, radius);\n }\n\n /** Sets the bounding sphere from `center` and `radius`. */\n fromCenterRadius(center: readonly number[], radius: number): this {\n this.center.from(center);\n this.radius = radius;\n return this;\n }\n\n /**\n * Computes a bounding sphere from the corner points of an axis-aligned bounding box. The sphere\n * tightly and fully encompasses the box.\n */\n fromCornerPoints(corner: readonly number[], oppositeCorner: readonly number[]): this {\n oppositeCorner = scratchVector.from(oppositeCorner);\n this.center = new Vector3().from(corner).add(oppositeCorner).scale(0.5);\n this.radius = this.center.distance(oppositeCorner);\n return this;\n }\n\n /** Compares the provided BoundingSphere component wise */\n equals(right: BoundingSphere): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.radius === right.radius)\n );\n }\n\n /** Duplicates a BoundingSphere instance. */\n clone(): BoundingSphere {\n return new BoundingSphere(this.center, this.radius);\n }\n\n /** Computes a bounding sphere that contains both the left and right bounding spheres. */\n union(boundingSphere: BoundingSphere): BoundingSphere {\n const leftCenter = this.center;\n const leftRadius = this.radius;\n const rightCenter = boundingSphere.center;\n const rightRadius = boundingSphere.radius;\n\n const toRightCenter = scratchVector.copy(rightCenter).subtract(leftCenter);\n const centerSeparation = toRightCenter.magnitude();\n\n if (leftRadius >= centerSeparation + rightRadius) {\n // Left sphere wins.\n return this.clone();\n }\n\n if (rightRadius >= centerSeparation + leftRadius) {\n // Right sphere wins.\n return boundingSphere.clone();\n }\n\n // There are two tangent points, one on far side of each sphere.\n const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;\n\n // Compute the center point halfway between the two tangent points.\n scratchVector2\n .copy(toRightCenter)\n .scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation)\n .add(leftCenter);\n\n this.center.copy(scratchVector2);\n this.radius = halfDistanceBetweenTangentPoints;\n\n return this;\n }\n\n /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */\n expand(point: readonly number[]): this {\n const scratchPoint = scratchVector.from(point);\n const radius = scratchPoint.subtract(this.center).magnitude();\n if (radius > this.radius) {\n this.radius = radius;\n }\n return this;\n }\n\n // BoundingVolume interface\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param sphere The bounding sphere to apply the transformation to.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns self.\n */\n transform(transform: readonly number[]): this {\n this.center.transform(transform);\n const scale = mat4.getScaling(scratchVector, transform);\n this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;\n return this;\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding sphere to a point. */\n distanceSquaredTo(point: Readonly<NumericArray>): number {\n const d = this.distanceTo(point);\n return d * d;\n }\n\n /** Computes the estimated distance from the closest point on a bounding sphere to a point. */\n distanceTo(point: Readonly<NumericArray>): number {\n const scratchPoint = scratchVector.from(point);\n const delta = scratchPoint.subtract(this.center);\n return Math.max(0, delta.len() - this.radius);\n }\n\n /** Determines which side of a plane a sphere is located. */\n intersectPlane(plane: Plane): number {\n const center = this.center;\n const radius = this.radius;\n const normal = plane.normal;\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n // The center point is negative side of the plane normal\n if (distanceToPlane < -radius) {\n return INTERSECTION.OUTSIDE;\n }\n // The center point is positive side of the plane, but radius extends beyond it; partial overlap\n if (distanceToPlane < radius) {\n return INTERSECTION.INTERSECTING;\n }\n // The center point and radius is positive side of the plane\n return INTERSECTION.INSIDE;\n }\n}\n"],"file":"bounding-sphere.js"}
@@ -1,4 +1,4 @@
1
- import Plane from '../plane';
1
+ import { Plane } from '../plane';
2
2
  /**
3
3
  * Common interface for BoundingVolumes
4
4
  * including BoundingSphere, AxisAlignedBoundingBox and OrientedBoundingBox
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-volume.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/bounding-volume.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,UAAU,CAAC;AAE7B;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAE9C,sGAAsG;IACtG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IACpD,8FAA8F;IAC9F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IAE7C;;;;;;;;OAQG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACtC"}
1
+ {"version":3,"file":"bounding-volume.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/bounding-volume.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAE/B;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAE9C,sGAAsG;IACtG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IACpD,8FAA8F;IAC9F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IAE7C;;;;;;;;OAQG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACtC"}
@@ -1,13 +1,13 @@
1
1
  import { Vector3, Matrix3, Matrix4, Quaternion, NumericArray } from '@math.gl/core';
2
2
  import type { BoundingVolume } from './bounding-volume';
3
- import BoundingSphere from './bounding-sphere';
4
- import type Plane from '../plane';
3
+ import { BoundingSphere } from './bounding-sphere';
4
+ import type { Plane } from '../plane';
5
5
  /**
6
6
  * An OrientedBoundingBox of some object is a closed and convex cuboid.
7
7
  * It can provide a tighter bounding volume than `BoundingSphere` or
8
8
  * `AxisAlignedBoundingBox` in many cases.
9
9
  */
10
- export default class OrientedBoundingBox implements BoundingVolume {
10
+ export declare class OrientedBoundingBox implements BoundingVolume {
11
11
  center: Vector3;
12
12
  halfAxes: Matrix3;
13
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"oriented-bounding-box.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAClF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,UAAU,CAAC;AAuBlC;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,YAAW,cAAc;IAChE,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAElB;;;;OAIG;gBACS,MAAM,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC;IAS9E,iEAAiE;IACjE,IAAI,QAAQ,IAAI,MAAM,EAAE,CAKvB;IAED,0EAA0E;IAC1E,IAAI,UAAU,IAAI,UAAU,CAQ3B;IAED;;OAEG;IACH,4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,OAAO,CAAC;IAElB;;;;OAIG;gBACS,MAAM,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC;IAS9E,iEAAiE;IACjE,IAAI,QAAQ,IAAI,MAAM,EAAE,CAKvB;IAED,0EAA0E;IAC1E,IAAI,UAAU,IAAI,UAAU,CAQ3B;IAED;;OAEG;IACH,4BAA4B,CAC1B,MAAM,EAAE,MAAM,EAAE,EAChB,QAAQ,EAAE,MAAM,EAAE,EAClB,UAAU,EAAE,MAAM,EAAE,GACnB,mBAAmB;IAiBtB,iDAAiD;IACjD,KAAK,IAAI,mBAAmB;IAI5B,2EAA2E;IAC3E,MAAM,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO;IAO3C,6FAA6F;IAC7F,iBAAiB,CAAC,MAAM,iBAAuB,GAAG,cAAc;IAehE,6EAA6E;IAC7E,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAsCpC,2FAA2F;IAC3F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAI5C;;;;OAIG;IACH,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAwCnD;;;;;;;;;;;;;OAaG;IAEH,qBAAqB,CACnB,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,SAAS,EAAE,OAAO,EAClB,MAAM,GAAE,MAAM,EAAa,GAC1B,MAAM,EAAE;IAwFX;;;;OAIG;IACH,SAAS,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAgBlD,YAAY,IAAI,OAAO;CAKxB"}
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import { Vector3, Matrix3, Quaternion } from '@math.gl/core';
3
- import BoundingSphere from "./bounding-sphere.js";
3
+ import { BoundingSphere } from "./bounding-sphere.js";
4
4
  import { INTERSECTION } from "../../constants.js";
5
5
  const scratchVector3 = new Vector3();
6
6
  const scratchOffset = new Vector3();
@@ -20,7 +20,7 @@ const MATRIX3 = {
20
20
  COLUMN2ROW1: 7,
21
21
  COLUMN2ROW2: 8
22
22
  };
23
- export default class OrientedBoundingBox {
23
+ export class OrientedBoundingBox {
24
24
  constructor(center = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {
25
25
  _defineProperty(this, "center", void 0);
26
26