@math.gl/culling 3.6.0-alpha.1 → 3.6.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 (27) hide show
  1. package/dist/es5/constants.js +1 -1
  2. package/dist/es5/index.js +12 -12
  3. package/dist/es5/lib/algorithms/bounding-box-from-points.js +123 -72
  4. package/dist/es5/lib/algorithms/bounding-box-from-points.js.map +1 -1
  5. package/dist/es5/lib/algorithms/bounding-sphere-from-points.js +109 -81
  6. package/dist/es5/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
  7. package/dist/es5/lib/algorithms/compute-eigen-decomposition.js +37 -36
  8. package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
  9. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js +75 -63
  10. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  11. package/dist/es5/lib/bounding-volumes/bounding-sphere.js +111 -90
  12. package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
  13. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js +212 -187
  14. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  15. package/dist/es5/lib/culling-volume.js +111 -74
  16. package/dist/es5/lib/culling-volume.js.map +1 -1
  17. package/dist/es5/lib/perspective-frustum.js +78 -57
  18. package/dist/es5/lib/perspective-frustum.js.map +1 -1
  19. package/dist/es5/lib/perspective-off-center-frustum.js +113 -98
  20. package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
  21. package/dist/es5/lib/plane.js +70 -52
  22. package/dist/es5/lib/plane.js.map +1 -1
  23. package/dist/esm/lib/algorithms/bounding-sphere-from-points.js.map +1 -1
  24. package/dist/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -1
  25. package/dist/lib/algorithms/bounding-sphere-from-points.js +0 -2
  26. package/package.json +4 -4
  27. package/src/lib/algorithms/bounding-sphere-from-points.ts +0 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/algorithms/bounding-sphere-from-points.ts"],"names":["fromPointsXMin","Vector3","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","volumeConstant","Math","PI","makeBoundingSphereFromPoints","positions","result","BoundingSphere","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","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":";;;;;;;;;AAGA;;AACA;;AAGA,MAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AACA,MAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AACA,MAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AACA,MAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AACA,MAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AACA,MAAMK,cAAc,GAAG,IAAIL,aAAJ,EAAvB;AACA,MAAMM,oBAAoB,GAAG,IAAIN,aAAJ,EAA7B;AACA,MAAMO,iBAAiB,GAAG,IAAIP,aAAJ,EAA1B;AACA,MAAMQ,sBAAsB,GAAG,IAAIR,aAAJ,EAA/B;AACA,MAAMS,kBAAkB,GAAG,IAAIT,aAAJ,EAA3B;AACA,MAAMU,kBAAkB,GAAG,IAAIV,aAAJ,EAA3B;AACA,MAAMW,4BAA4B,GAAG,IAAIX,aAAJ,EAArC;AACA,MAAMY,cAAc,GAAI,MAAM,GAAP,GAAcC,IAAI,CAACC,EAA1C;;AAae,SAASC,4BAAT,CACbC,SADa,EAEbC,MAAsB,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ICENSE.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();\nconst 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 // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\n result.radius = ritterRadius;\n } else {\n naiveCenter.to(result.center);\n // @ts-ignore TS2540: Cannot assign to 'radius' because it is a read-only property.\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":["fromPointsXMin","Vector3","fromPointsYMin","fromPointsZMin","fromPointsXMax","fromPointsYMax","fromPointsZMax","fromPointsCurrentPos","fromPointsScratch","fromPointsRitterCenter","fromPointsMinBoxPt","fromPointsMaxBoxPt","fromPointsNaiveCenterScratch","volumeConstant","Math","PI","makeBoundingSphereFromPoints","positions","result","BoundingSphere","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","sqrt","minBoxPt","maxBoxPt","naiveCenter","add","multiplyByScalar","naiveRadius","r","magnitude","oldCenterToPointSquared","oldCenterToPoint","oldToNew","to","center","radius"],"mappings":";;;;;;;;;AAGA;;AACA;;;;;;;;AAGA,IAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AACA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AACA,IAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AACA,IAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AACA,IAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AACA,IAAMK,cAAc,GAAG,IAAIL,aAAJ,EAAvB;AACA,IAAMM,oBAAoB,GAAG,IAAIN,aAAJ,EAA7B;AACA,IAAMO,iBAAiB,GAAG,IAAIP,aAAJ,EAA1B;AACA,IAAMQ,sBAAsB,GAAG,IAAIR,aAAJ,EAA/B;AACA,IAAMS,kBAAkB,GAAG,IAAIT,aAAJ,EAA3B;AACA,IAAMU,kBAAkB,GAAG,IAAIV,aAAJ,EAA3B;AACA,IAAMW,4BAA4B,GAAG,IAAIX,aAAJ,EAArC;AACA,IAAMY,cAAc,GAAI,MAAM,GAAP,GAAcC,IAAI,CAACC,EAA1C;;AAae,SAASC,4BAAT,CACbC,SADa,EAGG;AAAA,MADhBC,MACgB,uEADS,IAAIC,uBAAJ,EACT;;AAChB,MAAI,CAACF,SAAD,IAAcA,SAAS,CAACG,MAAV,KAAqB,CAAvC,EAA0C;AACxC,WAAOF,MAAM,CAACG,gBAAP,CAAwB,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAxB,EAAmC,CAAnC,CAAP;AACD;;AAED,MAAMC,UAAU,GAAGf,oBAAoB,CAACgB,IAArB,CAA0BN,SAAS,CAAC,CAAD,CAAnC,CAAnB;AAEA,MAAMO,IAAI,GAAGxB,cAAc,CAACuB,I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,CAAUS,uBAAV,CAAzB;AAEAV,QAAAA,YAAY,GAAG,CAACA,YAAY,GAAGW,gBAAhB,IAAoC,GAAnD;AACAZ,QAAAA,aAAa,GAAGC,YAAY,GAAGA,YAA/B;AAEA,YAAMY,QAAQ,GAAGD,gBAAgB,GAAGX,YAApC;AACAF,QAAAA,YAAY,CAACX,CAAb,GAAiB,CAACa,YAAY,GAAGF,YAAY,CAACX,CAA5B,GAAgCyB,QAAQ,GAAGlC,UAAU,CAACS,CAAvD,IAA4DwB,gBAA7E;AACAb,QAAAA,YAAY,CAACV,CAAb,GAAiB,CAACY,YAAY,GAAGF,YAAY,CAACV,CAA5B,GAAgCwB,QAAQ,GAAGlC,UAAU,CAACU,CAAvD,IAA4DuB,gBAA7E;AACAb,QAAAA,YAAY,CAACT,CAAb,GAAiB,CAACW,YAAY,GAAGF,YAAY,CAACT,CAA5B,GAAgCuB,QAAQ,GAAGlC,UAAU,CAACW,CAAvD,IAA4DsB,gBAA7E;AACD;AACF;AA1He;AAAA;AAAA;AAAA;AAAA;;AA4HhB,MAAIX,YAAY,GAAGO,WAAnB,EAAgC;AAC9BT,IAAAA,YAAY,CAACe,EAAb,CAAgBvC,MAAM,CAACwC,MAAvB;AACAxC,IAAAA,MAAM,CAACyC,MAAP,GAAgBf,YAAhB;AACD,GAHD,MAGO;AACLI,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();\nconst 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"}
@@ -7,22 +7,23 @@ exports.default = computeEigenDecomposition;
7
7
 
8
8
  var _core = require("@math.gl/core");
9
9
 
10
- const scratchMatrix = new _core.Matrix3();
11
- const scratchUnitary = new _core.Matrix3();
12
- const scratchDiagonal = new _core.Matrix3();
13
- const jMatrix = new _core.Matrix3();
14
- const jMatrixTranspose = new _core.Matrix3();
15
-
16
- function computeEigenDecomposition(matrix, result = {}) {
17
- const EIGEN_TOLERANCE = _core._MathUtils.EPSILON20;
18
- const EIGEN_MAX_SWEEPS = 10;
19
- let count = 0;
20
- let sweep = 0;
21
- const unitaryMatrix = scratchUnitary;
22
- const diagonalMatrix = scratchDiagonal;
10
+ var scratchMatrix = new _core.Matrix3();
11
+ var scratchUnitary = new _core.Matrix3();
12
+ var scratchDiagonal = new _core.Matrix3();
13
+ var jMatrix = new _core.Matrix3();
14
+ var jMatrixTranspose = new _core.Matrix3();
15
+
16
+ function computeEigenDecomposition(matrix) {
17
+ var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
18
+ var EIGEN_TOLERANCE = _core._MathUtils.EPSILON20;
19
+ var EIGEN_MAX_SWEEPS = 10;
20
+ var count = 0;
21
+ var sweep = 0;
22
+ var unitaryMatrix = scratchUnitary;
23
+ var diagonalMatrix = scratchDiagonal;
23
24
  unitaryMatrix.identity();
24
25
  diagonalMatrix.copy(matrix);
25
- const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);
26
+ var epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);
26
27
 
27
28
  while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {
28
29
  shurDecomposition(diagonalMatrix, jMatrix);
@@ -43,24 +44,24 @@ function computeEigenDecomposition(matrix, result = {}) {
43
44
  }
44
45
 
45
46
  function computeFrobeniusNorm(matrix) {
46
- let norm = 0.0;
47
+ var norm = 0.0;
47
48
 
48
- for (let i = 0; i < 9; ++i) {
49
- const temp = matrix[i];
49
+ for (var i = 0; i < 9; ++i) {
50
+ var temp = matrix[i];
50
51
  norm += temp * temp;
51
52
  }
52
53
 
53
54
  return Math.sqrt(norm);
54
55
  }
55
56
 
56
- const rowVal = [1, 0, 0];
57
- const colVal = [2, 2, 1];
57
+ var rowVal = [1, 0, 0];
58
+ var colVal = [2, 2, 1];
58
59
 
59
60
  function offDiagonalFrobeniusNorm(matrix) {
60
- let norm = 0.0;
61
+ var norm = 0.0;
61
62
 
62
- for (let i = 0; i < 3; ++i) {
63
- const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];
63
+ for (var i = 0; i < 3; ++i) {
64
+ var temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];
64
65
  norm += 2.0 * temp * temp;
65
66
  }
66
67
 
@@ -68,12 +69,12 @@ function offDiagonalFrobeniusNorm(matrix) {
68
69
  }
69
70
 
70
71
  function shurDecomposition(matrix, result) {
71
- const tolerance = _core._MathUtils.EPSILON15;
72
- let maxDiagonal = 0.0;
73
- let rotAxis = 1;
72
+ var tolerance = _core._MathUtils.EPSILON15;
73
+ var maxDiagonal = 0.0;
74
+ var rotAxis = 1;
74
75
 
75
- for (let i = 0; i < 3; ++i) {
76
- const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);
76
+ for (var i = 0; i < 3; ++i) {
77
+ var temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);
77
78
 
78
79
  if (temp > maxDiagonal) {
79
80
  rotAxis = i;
@@ -81,17 +82,17 @@ function shurDecomposition(matrix, result) {
81
82
  }
82
83
  }
83
84
 
84
- const p = rowVal[rotAxis];
85
- const q = colVal[rotAxis];
86
- let c = 1.0;
87
- let s = 0.0;
85
+ var p = rowVal[rotAxis];
86
+ var q = colVal[rotAxis];
87
+ var c = 1.0;
88
+ var s = 0.0;
88
89
 
89
90
  if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {
90
- const qq = matrix[scratchMatrix.getElementIndex(q, q)];
91
- const pp = matrix[scratchMatrix.getElementIndex(p, p)];
92
- const qp = matrix[scratchMatrix.getElementIndex(q, p)];
93
- const tau = (qq - pp) / 2.0 / qp;
94
- let t;
91
+ var qq = matrix[scratchMatrix.getElementIndex(q, q)];
92
+ var pp = matrix[scratchMatrix.getElementIndex(p, p)];
93
+ var qp = matrix[scratchMatrix.getElementIndex(q, p)];
94
+ var tau = (qq - pp) / 2.0 / qp;
95
+ var t;
95
96
 
96
97
  if (tau < 0.0) {
97
98
  t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/algorithms/compute-eigen-decomposition.ts"],"names":["scratchMatrix","Matrix3","scratchUnitary","scratchDiagonal","jMatrix","jMatrixTranspose","computeEigenDecomposition","matrix","result","EIGEN_TOLERANCE","_MathUtils","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;;AAEA,MAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,MAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AACA,MAAME,eAAe,GAAG,IAAIF,aAAJ,EAAxB;AAEA,MAAMG,OAAO,GAAG,IAAIH,aAAJ,EAAhB;AACA,MAAMI,gBAAgB,GAAG,IAAIJ,aAAJ,EAAzB;;AAqCe,SAASK,yBAAT,CACbC,MADa,EAGbC,MAA0B,GAAG,EAHhB,EAIO;AACpB,QAAMC,eAAe,GAAGC,iBAAWC,SAAnC;AACA,QAAMC,gBAAgB,GAAG,EAAzB;AAEA,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAK,GAAG,CAAZ;AAEA,QAAMC,aAAa,GAAGb,cAAtB;AACA,QAAMc,cAAc,GAAGb,eAAvB;AAEAY,EAAAA,aAAa,CAACE,QAAd;AACAD,EAAAA,cAAc,CAACE,IAAf,CAAoBX,MAApB;AAEA,QAAMY,OAAO,GAAGV,eAAe,GAAGW,oBAAoB,CAACJ,cAAD,CAAtD;;AAEA,SAAOF,KAAK,GAAGF,gBAAR,IAA4BS,wBAAwB,CAACL,cAAD,CAAxB,GAA2CG,OAA9E,EAAuF;AACrFG,IAAAA,iBAAiB,CAACN,cAAD,EAAiBZ,OAAjB,CAAjB;AAEAC,IAAAA,gBAAgB,CAACa,IAAjB,CAAsBd,OAAtB,EAA+BmB,SAA/B;AAEAP,IAAAA,cAAc,CAACQ,aAAf,CAA6BpB,OAA7B;AACAY,IAAAA,cAAc,CAACS,YAAf,CAA4BpB,gBAA5B;AACAU,IAAAA,aAAa,CAACS,aAAd,CAA4BpB,OAA5B;;AAEA,QAAI,EAAES,KAAF,GAA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,GAAV,EAAe;AACbC,MAAAA,CAAC,GAAG,CAAC,GAAD,IAAQ,CAACD,GAAD,GAAOjB,IAAI,CAACC,IAAL,CAAU,MAAMgB,GAAG,GAAGA,GAAtB,CAAf,CAAJ;AACD,KAFD,MAEO;AACLC,MAAAA,CAAC,GAAG,OAAOD,GAAG,GAAGjB,IAAI,CAACC,IAAL,CAAU,MAAMgB,GAAG,GAAGA,GAAtB,CAAb,CAAJ;AACD;;AAEDL,IAAAA,CAAC,GAAG,MAAMZ,IAAI,CAACC,IAAL,CAAU,MAAMiB,CAAC,GAAGA,CAApB,CAAV;AACAL,IAAAA,CAAC,GAAGK,CAAC,GAAGN,CAAR;AACD;;AAGD3C,gBAAQkD,QAAR,CAAiBC,EAAjB,CAAoB5C,MAApB;;AACAA,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BM,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8ClC,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BO,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CC,CAA5F;AACApC,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BO,CAA9B,EAAiCD,CAAjC,CAAD,CAAN,GAA8CG,CAA9C;AACArC,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BM,CAA9B,EAAiCC,CAAjC,CAAD,CAAN,GAA8C,CAACE,CAA/C;AAEA,SAAOrC,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) {\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) {\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, result) {\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":["scratchMatrix","Matrix3","scratchUnitary","scratchDiagonal","jMatrix","jMatrixTranspose","computeEigenDecomposition","matrix","result","EIGEN_TOLERANCE","_MathUtils","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;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,cAAc,GAAG,IAAID,aAAJ,EAAvB;AACA,IAAME,eAAe,GAAG,IAAIF,aAAJ,EAAxB;AAEA,IAAMG,OAAO,GAAG,IAAIH,aAAJ,EAAhB;AACA,IAAMI,gBAAgB,GAAG,IAAIJ,aAAJ,EAAzB;;AAqCe,SAASK,yBAAT,CACbC,MADa,EAIO;AAAA,MADpBC,MACoB,uEADS,EACT;AACpB,MAAMC,eAAe,GAAGC,iBAAWC,SAAnC;AACA,MAAMC,gBAAgB,GAAG,EAAzB;AA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AD,CAAN,GAA8ClC,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BO,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CC,CAA5F;AACApC,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BO,CAA9B,EAAiCD,CAAjC,CAAD,CAAN,GAA8CG,CAA9C;AACArC,EAAAA,MAAM,CAACR,aAAa,CAACoC,eAAd,CAA8BM,CAA9B,EAAiCC,CAAjC,CAAD,CAAN,GAA8C,CAACE,CAA/C;AAEA,SAAOrC,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) {\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) {\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, result) {\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"}
@@ -7,17 +7,25 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
10
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
15
 
12
16
  var _core = require("@math.gl/core");
13
17
 
14
18
  var _constants = require("../../constants");
15
19
 
16
- const scratchVector = new _core.Vector3();
17
- const scratchNormal = new _core.Vector3();
20
+ var scratchVector = new _core.Vector3();
21
+ var scratchNormal = new _core.Vector3();
18
22
 
19
- class AxisAlignedBoundingBox {
20
- constructor(minimum = [0, 0, 0], maximum = [0, 0, 0], center) {
23
+ var AxisAlignedBoundingBox = function () {
24
+ function AxisAlignedBoundingBox() {
25
+ var minimum = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0, 0];
26
+ var maximum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
27
+ var center = arguments.length > 2 ? arguments[2] : undefined;
28
+ (0, _classCallCheck2.default)(this, AxisAlignedBoundingBox);
21
29
  (0, _defineProperty2.default)(this, "center", void 0);
22
30
  (0, _defineProperty2.default)(this, "halfDiagonal", void 0);
23
31
  (0, _defineProperty2.default)(this, "minimum", void 0);
@@ -29,74 +37,78 @@ class AxisAlignedBoundingBox {
29
37
  this.maximum = new _core.Vector3(maximum);
30
38
  }
31
39
 
32
- clone() {
33
- return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);
34
- }
35
-
36
- equals(right) {
37
- return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
38
- }
39
-
40
- transform(transform) {
41
- this.center.transformAsPoint(transform);
42
- this.halfDiagonal.transform(transform);
43
- this.minimum.transform(transform);
44
- this.maximum.transform(transform);
45
- return this;
46
- }
47
-
48
- intersectPlane(plane) {
49
- const {
50
- halfDiagonal
51
- } = this;
52
- const normal = scratchNormal.from(plane.normal);
53
- const e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
54
- const s = this.center.dot(normal) + plane.distance;
55
-
56
- if (s - e > 0) {
57
- return _constants.INTERSECTION.INSIDE;
40
+ (0, _createClass2.default)(AxisAlignedBoundingBox, [{
41
+ key: "clone",
42
+ value: function clone() {
43
+ return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);
58
44
  }
59
-
60
- if (s + e < 0) {
61
- return _constants.INTERSECTION.OUTSIDE;
45
+ }, {
46
+ key: "equals",
47
+ value: function equals(right) {
48
+ return this === right || Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum);
62
49
  }
63
-
64
- return _constants.INTERSECTION.INTERSECTING;
65
- }
66
-
67
- distanceTo(point) {
68
- return Math.sqrt(this.distanceSquaredTo(point));
69
- }
70
-
71
- distanceSquaredTo(point) {
72
- const offset = scratchVector.from(point).subtract(this.center);
73
- const {
74
- halfDiagonal
75
- } = this;
76
- let distanceSquared = 0.0;
77
- let d;
78
- d = Math.abs(offset.x) - halfDiagonal.x;
79
-
80
- if (d > 0) {
81
- distanceSquared += d * d;
50
+ }, {
51
+ key: "transform",
52
+ value: function transform(_transform) {
53
+ this.center.transformAsPoint(_transform);
54
+ this.halfDiagonal.transform(_transform);
55
+ this.minimum.transform(_transform);
56
+ this.maximum.transform(_transform);
57
+ return this;
58
+ }
59
+ }, {
60
+ key: "intersectPlane",
61
+ value: function intersectPlane(plane) {
62
+ var halfDiagonal = this.halfDiagonal;
63
+ var normal = scratchNormal.from(plane.normal);
64
+ var e = halfDiagonal.x * Math.abs(normal.x) + halfDiagonal.y * Math.abs(normal.y) + halfDiagonal.z * Math.abs(normal.z);
65
+ var s = this.center.dot(normal) + plane.distance;
66
+
67
+ if (s - e > 0) {
68
+ return _constants.INTERSECTION.INSIDE;
69
+ }
70
+
71
+ if (s + e < 0) {
72
+ return _constants.INTERSECTION.OUTSIDE;
73
+ }
74
+
75
+ return _constants.INTERSECTION.INTERSECTING;
82
76
  }
77
+ }, {
78
+ key: "distanceTo",
79
+ value: function distanceTo(point) {
80
+ return Math.sqrt(this.distanceSquaredTo(point));
81
+ }
82
+ }, {
83
+ key: "distanceSquaredTo",
84
+ value: function distanceSquaredTo(point) {
85
+ var offset = scratchVector.from(point).subtract(this.center);
86
+ var halfDiagonal = this.halfDiagonal;
87
+ var distanceSquared = 0.0;
88
+ var d;
89
+ d = Math.abs(offset.x) - halfDiagonal.x;
83
90
 
84
- d = Math.abs(offset.y) - halfDiagonal.y;
91
+ if (d > 0) {
92
+ distanceSquared += d * d;
93
+ }
85
94
 
86
- if (d > 0) {
87
- distanceSquared += d * d;
88
- }
95
+ d = Math.abs(offset.y) - halfDiagonal.y;
89
96
 
90
- d = Math.abs(offset.z) - halfDiagonal.z;
97
+ if (d > 0) {
98
+ distanceSquared += d * d;
99
+ }
91
100
 
92
- if (d > 0) {
93
- distanceSquared += d * d;
94
- }
101
+ d = Math.abs(offset.z) - halfDiagonal.z;
95
102
 
96
- return distanceSquared;
97
- }
103
+ if (d > 0) {
104
+ distanceSquared += d * d;
105
+ }
98
106
 
99
- }
107
+ return distanceSquared;
108
+ }
109
+ }]);
110
+ return AxisAlignedBoundingBox;
111
+ }();
100
112
 
101
113
  exports.default = AxisAlignedBoundingBox;
102
114
  //# sourceMappingURL=axis-aligned-bounding-box.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","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","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AAEA,MAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,MAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;AAQe,MAAME,sBAAN,CAAuD;AAgBpEC,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,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGjB,IAAI,CAACC,GAAL,CAASc,MAAM,CAACb,CAAhB,IAAqBhB,YAAY,CAACgB,CAAtC;;AACA,QAAIe,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGjB,IAAI,CAACC,GAAL,CAASc,MAAM,CAACZ,CAAhB,IAAqBjB,YAAY,CAACiB,CAAtC;;AACA,QAAIc,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() {\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) {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): INTERSECTION {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","scratchNormal","AxisAlignedBoundingBox","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","right","Boolean","equals","transform","transformAsPoint","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAQqBE,sB;AAgBnB,oCAIE;AAAA,QAHAC,OAGA,uEAH6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAG7B;AAAA,QAFAC,OAEA,uEAF6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAE7B;AAAA,QADAC,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIN,aAAa,CAACO,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,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ACe,CAAtC;;AACA,UAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,aAAOD,eAAP;AACD","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone() {\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) {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): INTERSECTION {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}