@math.gl/culling 3.6.0-alpha.3 → 3.6.0-alpha.6

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 (35) hide show
  1. package/dist/es5/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
  2. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  3. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  4. package/dist/es5/lib/perspective-frustum.js +63 -58
  5. package/dist/es5/lib/perspective-frustum.js.map +1 -1
  6. package/dist/es5/lib/perspective-off-center-frustum.js +51 -51
  7. package/dist/es5/lib/perspective-off-center-frustum.js.map +1 -1
  8. package/dist/es5/lib/plane.js.map +1 -1
  9. package/dist/esm/lib/algorithms/compute-eigen-decomposition.js.map +1 -1
  10. package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  11. package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  12. package/dist/esm/lib/perspective-frustum.js +60 -55
  13. package/dist/esm/lib/perspective-frustum.js.map +1 -1
  14. package/dist/esm/lib/perspective-off-center-frustum.js +48 -46
  15. package/dist/esm/lib/perspective-off-center-frustum.js.map +1 -1
  16. package/dist/esm/lib/plane.js.map +1 -1
  17. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +1 -1
  18. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  19. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +2 -2
  20. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
  21. package/dist/lib/perspective-frustum.d.ts +52 -40
  22. package/dist/lib/perspective-frustum.d.ts.map +1 -1
  23. package/dist/lib/perspective-frustum.js +81 -96
  24. package/dist/lib/perspective-off-center-frustum.d.ts +74 -38
  25. package/dist/lib/perspective-off-center-frustum.d.ts.map +1 -1
  26. package/dist/lib/perspective-off-center-frustum.js +64 -99
  27. package/dist/lib/plane.d.ts +8 -8
  28. package/dist/lib/plane.d.ts.map +1 -1
  29. package/package.json +3 -3
  30. package/src/lib/algorithms/compute-eigen-decomposition.ts +3 -3
  31. package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +2 -2
  32. package/src/lib/bounding-volumes/oriented-bounding-box.ts +2 -2
  33. package/src/lib/perspective-frustum.ts +115 -118
  34. package/src/lib/perspective-off-center-frustum.ts +137 -131
  35. package/src/lib/plane.ts +11 -8
@@ -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,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;AAEA,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAK,GAAG,CAAZ;AAEA,MAAMC,aAAa,GAAGb,cA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AN,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;AAEA,MAAIC,KAAK,GAAG,CAAZ;AACA,MAAIC,KAAK,GAAG,CAAZ;AAEA,MAAMC,aAAa,GAAGb,cAAtB;AACA,MAAMc,cAAc,GAAGb,eAAvB;AAEAY,EAAAA,aAAa,CAACE,QAAd;AACAD,EAAAA,cAAc,CAACE,IAAf,CAAoBX,MAApB;AAEA,MAAMY,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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AAEA,QAAID,GAAG,GAAG,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: 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 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","scratchNormal","AxisAlignedBoundingBox","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","right","Boolean","equals","transform","transformAsPoint","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAQqBE,sB;AAgBnB,oCAIE;AAAA,QAHAC,OAGA,uEAH6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAG7B;AAAA,QAFAC,OAEA,uEAF6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAE7B;AAAA,QADAC,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIN,aAAa,CAACO,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,EAAyCI,KAAzC,CAA+C,GAA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AC,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"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["scratchVector","Vector3","scratchNormal","AxisAlignedBoundingBox","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","right","Boolean","equals","transform","transformAsPoint","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INTERSECTION","INSIDE","OUTSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";;;;;;;;;;;;;;;AACA;;AAEA;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAQqBE,sB;AAgBnB,oCAIE;AAAA,QAHAC,OAGA,uEAH6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAG7B;AAAA,QAFAC,OAEA,uEAF6B,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAE7B;AAAA,QADAC,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIN,aAAa,CAACO,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,EAAyCI,KAAzC,CAA+C,GAA/C,CAAnB;AACA,SAAKH,MAAL,GAAc,IAAIL,aAAJ,CAAYK,MAAZ,CAAd;AACA,SAAKI,YAAL,GAAoB,IAAIT,aAAJ,CAAYI,OAAZ,EAAqBM,QAArB,CAA8B,KAAKL,MAAnC,CAApB;AAOA,SAAKF,OAAL,GAAe,IAAIH,aAAJ,CAAYG,OAAZ,CAAf;AAOA,SAAKC,OAAL,GAAe,IAAIJ,aAAJ,CAAYI,OAAZ,CAAf;AACD;;;;WAOD,iBAAgC;AAC9B,aAAO,IAAIF,sBAAJ,CAA2B,KAAKC,OAAhC,EAAyC,KAA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G,YAApB;AACD;;;WAGD,oBAAWC,KAAX,EAA6C;AAC3C,aAAOX,IAAI,CAACY,IAAL,CAAU,KAAKC,iBAAL,CAAuBF,KAAvB,CAAV,CAAP;AACD;;;WAGD,2BAAkBA,KAAlB,EAAoD;AAClD,UAAMG,MAAM,GAAGpC,aAAa,CAACmB,IAAd,CAAmBc,KAAnB,EAA0BtB,QAA1B,CAAmC,KAAKL,MAAxC,CAAf;AACA,UAAOI,YAAP,GAAuB,IAAvB,CAAOA,YAAP;AAEA,UAAI2B,eAAe,GAAG,GAAtB;AACA,UAAIC,CAAJ;AAEAA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACf,CAAhB,IAAqBX,YAAY,CAACW,CAAtC;;AACA,UAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBd,YAAY,CAACc,CAAtC;;AACA,UAAIc,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,MAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACX,CAAhB,IAAqBf,YAAY,CAACe,CAAtC;;AACA,UAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,QAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,aAAOD,eAAP;AACD","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone(): AxisAlignedBoundingBox {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right: AxisAlignedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): INTERSECTION {\n const {halfDiagonal} = this;\n const normal = scratchNormal.from(plane.normal);\n const e =\n halfDiagonal.x * Math.abs(normal.x) +\n halfDiagonal.y * Math.abs(normal.y) +\n halfDiagonal.z * Math.abs(normal.z);\n const s = this.center.dot(normal) + plane.distance; // signed distance from center\n\n if (s - e > 0) {\n return INTERSECTION.INSIDE;\n }\n\n if (s + e < 0) {\n // Not in front because normals point inward\n return INTERSECTION.OUTSIDE;\n }\n\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /** Computes the estimated distance squared from the closest point on a bounding box to a point. */\n distanceSquaredTo(point: readonly number[]): number {\n const offset = scratchVector.from(point).subtract(this.center);\n const {halfDiagonal} = this;\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.x) - halfDiagonal.x;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.y) - halfDiagonal.y;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.z) - halfDiagonal.z;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n}\n"],"file":"axis-aligned-bounding-box.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["scratchVector3","Vector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","center","halfAxes","from","Matrix3","xAxis","getColumn","yAxis","zAxis","len","normXAxis","normalize","normYAxis","normZAxis","Quaternion","fromMatrix3","halfSize","quaternion","quaternionObject","directionsMatrix","fromQuaternion","right","Boolean","equals","result","BoundingSphere","u","v","w","cornerVector","copy","add","radius","magnitude","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","INTERSECTION","OUTSIDE","INSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transformation","transformAsPoint","Error"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAEA;;AAEA;;AAEA,IAAMA,cAAc,GAAG,IAAIC,aAAJ,EAAvB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AACA,IAAME,cAAc,GAAG,IAAIF,aAAJ,EAAvB;AACA,IAAMG,cAAc,GAAG,IAAIH,aAAJ,EAAvB;AACA,IAAMI,cAAc,GAAG,IAAIJ,aAAJ,EAAvB;AACA,IAAMK,aAAa,GAAG,IAAIL,aAAJ,EAAtB;AACA,IAAMM,eAAe,GAAG,IAAIN,aAAJ,EAAxB;AAEA,IAAMO,OAAO,GAAG;AACdC,EAAAA,WAAW,EAAE,CADC;AAEdC,EAAAA,WAAW,EAAE,CAFC;AAGdC,EAAAA,WAAW,EAAE,CAHC;AAIdC,EAAAA,WAAW,EAAE,CAJC;AAKdC,EAAAA,WAAW,EAAE,CALC;AAMdC,EAAAA,WAAW,EAAE,CANC;AAOdC,EAAAA,WAAW,EAAE,CAPC;AAQdC,EAAAA,WAAW,EAAE,CARC;AASdC,EAAAA,WAAW,EAAE;AATC,CAAhB;;IAiBqBC,mB;AAUnB,iCAAgG;AAAA,QAApFC,MAAoF,uEAAnD,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3B,CAAd;AACAqB,MAAAA,KAAK,CAACoE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMlE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BnB,cAA3B,CAAd;AACAqB,MAAAA,KAAK,CAACmE,gBAAN,CAAuBD,cAAvB;AAEA,WAAKxE,QAAL,GAAgB,IAAIE,aAAJ,4CAAgBC,KAAhB,oCAA0BE,KAA1B,oCAAoCC,KAApC,GAAhB;AACA,aAAO,IAAP;AACD;;;WAED,wBAAe;AAGb,YAAM,IAAIoE,KAAJ,CAAU,iBAAV,CAAN;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): INTERSECTION {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform() {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
1
+ {"version":3,"sources":["../../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":["scratchVector3","Vector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","center","halfAxes","from","Matrix3","xAxis","getColumn","yAxis","zAxis","len","normXAxis","normalize","normYAxis","normZAxis","Quaternion","fromMatrix3","halfSize","quaternion","quaternionObject","directionsMatrix","fromQuaternion","right","Boolean","equals","result","BoundingSphere","u","v","w","cornerVector","copy","add","radius","magnitude","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","INTERSECTION","OUTSIDE","INSIDE","INTERSECTING","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transformation","transformAsPoint","Error"],"mappings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AAAA,QAAQ,CAACxC,IAAT,CAAcuC,MAAd,EAAsBb,QAAtB,CAA+BM,QAA/B;AACAS,MAAAA,GAAG,GAAGR,SAAS,CAACjB,GAAV,CAAcwB,QAAd,CAAN;AAEAN,MAAAA,OAAO,GAAGrB,IAAI,CAAC6B,GAAL,CAASD,GAAT,EAAcP,OAAd,CAAV;AACAG,MAAAA,OAAO,GAAGxB,IAAI,CAAC8B,GAAL,CAASF,GAAT,EAAcJ,OAAd,CAAV;AAEA3C,MAAAA,MAAM,CAAC,CAAD,CAAN,GAAYwC,OAAZ;AACAxC,MAAAA,MAAM,CAAC,CAAD,CAAN,GAAY2C,OAAZ;AACA,aAAO3C,MAAP;AACD;;;WAOD,mBAAUkD,cAAV,EAAmD;AACjD,WAAKzE,MAAL,CAAY0E,gBAAZ,CAA6BD,cAA7B;AAEA,UAAMrE,KAAK,GAAG,KAAKH,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BrB,cAA3B,CAAd;AACAoB,MAAAA,KAAK,CAACsE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMnE,KAAK,GAAG,KAAKL,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BpB,cAA3B,CAAd;AACAqB,MAAAA,KAAK,CAACoE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMlE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BnB,cAA3B,CAAd;AACAqB,MAAAA,KAAK,CAACmE,gBAAN,CAAuBD,cAAvB;AAEA,WAAKxE,QAAL,GAAgB,IAAIE,aAAJ,4CAAgBC,KAAhB,oCAA0BE,KAA1B,oCAAoCC,KAApC,GAAhB;AACA,aAAO,IAAP;AACD;;;WAED,wBAAwB;AAGtB,YAAM,IAAIoE,KAAJ,CAAU,iBAAV,CAAN;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): INTERSECTION {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
@@ -17,10 +17,6 @@ var _core = require("@math.gl/core");
17
17
 
18
18
  var _perspectiveOffCenterFrustum = _interopRequireDefault(require("./perspective-off-center-frustum"));
19
19
 
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
-
24
20
  var defined = function defined(val) {
25
21
  return val !== null && typeof val !== 'undefined';
26
22
  };
@@ -44,22 +40,22 @@ var PerspectiveFrustum = function () {
44
40
  (0, _defineProperty2.default)(this, "_xOffset", void 0);
45
41
  (0, _defineProperty2.default)(this, "yOffset", void 0);
46
42
  (0, _defineProperty2.default)(this, "_yOffset", void 0);
47
- options = _objectSpread({
48
- near: 1.0,
49
- far: 500000000.0,
50
- xOffset: 0.0,
51
- yOffset: 0.0
52
- }, options);
53
- this.fov = options.fov;
54
- this.aspectRatio = options.aspectRatio;
55
- this.near = options.near;
56
- this._near = this.near;
57
- this.far = options.far;
58
- this._far = this.far;
59
- this.xOffset = options.xOffset;
60
- this._xOffset = this.xOffset;
61
- this.yOffset = options.yOffset;
62
- this._yOffset = this.yOffset;
43
+ var fov = options.fov,
44
+ aspectRatio = options.aspectRatio,
45
+ _options$near = options.near,
46
+ near = _options$near === void 0 ? 1.0 : _options$near,
47
+ _options$far = options.far,
48
+ far = _options$far === void 0 ? 500000000.0 : _options$far,
49
+ _options$xOffset = options.xOffset,
50
+ xOffset = _options$xOffset === void 0 ? 0.0 : _options$xOffset,
51
+ _options$yOffset = options.yOffset,
52
+ yOffset = _options$yOffset === void 0 ? 0.0 : _options$yOffset;
53
+ this.fov = fov;
54
+ this.aspectRatio = aspectRatio;
55
+ this.near = near;
56
+ this.far = far;
57
+ this.xOffset = xOffset;
58
+ this.yOffset = yOffset;
63
59
  }
64
60
 
65
61
  (0, _createClass2.default)(PerspectiveFrustum, [{
@@ -79,78 +75,87 @@ var PerspectiveFrustum = function () {
79
75
  return false;
80
76
  }
81
77
 
82
- update(this);
83
- update(other);
78
+ this._update();
79
+
80
+ other._update();
81
+
84
82
  return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum);
85
83
  }
86
84
  }, {
87
85
  key: "projectionMatrix",
88
86
  get: function get() {
89
- update(this);
87
+ this._update();
88
+
90
89
  return this._offCenterFrustum.projectionMatrix;
91
90
  }
92
91
  }, {
93
92
  key: "infiniteProjectionMatrix",
94
93
  get: function get() {
95
- update(this);
94
+ this._update();
95
+
96
96
  return this._offCenterFrustum.infiniteProjectionMatrix;
97
97
  }
98
98
  }, {
99
99
  key: "fovy",
100
100
  get: function get() {
101
- update(this);
101
+ this._update();
102
+
102
103
  return this._fovy;
103
104
  }
104
105
  }, {
105
106
  key: "sseDenominator",
106
107
  get: function get() {
107
- update(this);
108
+ this._update();
109
+
108
110
  return this._sseDenominator;
109
111
  }
110
112
  }, {
111
113
  key: "computeCullingVolume",
112
114
  value: function computeCullingVolume(position, direction, up) {
113
- update(this);
115
+ this._update();
116
+
114
117
  return this._offCenterFrustum.computeCullingVolume(position, direction, up);
115
118
  }
116
119
  }, {
117
120
  key: "getPixelDimensions",
118
121
  value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
119
- update(this);
120
- return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result);
122
+ this._update();
123
+
124
+ return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new _core.Vector2());
125
+ }
126
+ }, {
127
+ key: "_update",
128
+ value: function _update() {
129
+ (0, _core.assert)(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
130
+ var f = this._offCenterFrustum;
131
+
132
+ if (this.fov !== this._fov || this.aspectRatio !== this._aspectRatio || this.near !== this._near || this.far !== this._far || this.xOffset !== this._xOffset || this.yOffset !== this._yOffset) {
133
+ (0, _core.assert)(this.fov >= 0 && this.fov < Math.PI);
134
+ (0, _core.assert)(this.aspectRatio > 0);
135
+ (0, _core.assert)(this.near >= 0 && this.near < this.far);
136
+ this._aspectRatio = this.aspectRatio;
137
+ this._fov = this.fov;
138
+ this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;
139
+ this._near = this.near;
140
+ this._far = this.far;
141
+ this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);
142
+ this._xOffset = this.xOffset;
143
+ this._yOffset = this.yOffset;
144
+ f.top = this.near * Math.tan(0.5 * this._fovy);
145
+ f.bottom = -f.top;
146
+ f.right = this.aspectRatio * f.top;
147
+ f.left = -f.right;
148
+ f.near = this.near;
149
+ f.far = this.far;
150
+ f.right += this.xOffset;
151
+ f.left += this.xOffset;
152
+ f.top += this.yOffset;
153
+ f.bottom += this.yOffset;
154
+ }
121
155
  }
122
156
  }]);
123
157
  return PerspectiveFrustum;
124
158
  }();
125
159
 
126
160
  exports.default = PerspectiveFrustum;
127
-
128
- function update(frustum) {
129
- (0, _core.assert)(Number.isFinite(frustum.fov) && Number.isFinite(frustum.aspectRatio) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far));
130
- var f = frustum._offCenterFrustum;
131
-
132
- if (frustum.fov !== frustum._fov || frustum.aspectRatio !== frustum._aspectRatio || frustum.near !== frustum._near || frustum.far !== frustum._far || frustum.xOffset !== frustum._xOffset || frustum.yOffset !== frustum._yOffset) {
133
- (0, _core.assert)(frustum.fov >= 0 && frustum.fov < Math.PI);
134
- (0, _core.assert)(frustum.aspectRatio > 0);
135
- (0, _core.assert)(frustum.near >= 0 && frustum.near < frustum.far);
136
- frustum._aspectRatio = frustum.aspectRatio;
137
- frustum._fov = frustum.fov;
138
- frustum._fovy = frustum.aspectRatio <= 1 ? frustum.fov : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;
139
- frustum._near = frustum.near;
140
- frustum._far = frustum.far;
141
- frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);
142
- frustum._xOffset = frustum.xOffset;
143
- frustum._yOffset = frustum.yOffset;
144
- f.top = frustum.near * Math.tan(0.5 * frustum._fovy);
145
- f.bottom = -f.top;
146
- f.right = frustum.aspectRatio * f.top;
147
- f.left = -f.right;
148
- f.near = frustum.near;
149
- f.far = frustum.far;
150
- f.right += frustum.xOffset;
151
- f.left += frustum.xOffset;
152
- f.top += frustum.yOffset;
153
- f.bottom += frustum.yOffset;
154
- }
155
- }
156
161
  //# sourceMappingURL=perspective-frustum.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/perspective-frustum.ts"],"names":["defined","val","PerspectiveFrustum","options","PerspectiveOffCenterFrustum","near","far","xOffset","yOffset","fov","aspectRatio","_near","_far","_xOffset","_yOffset","other","update","_offCenterFrustum","equals","projectionMatrix","infiniteProjectionMatrix","_fovy","_sseDenominator","position","direction","up","computeCullingVolume","drawingBufferWidth","drawingBufferHeight","distance","result","getPixelDimensions","frustum","Number","isFinite","f","_fov","_aspectRatio","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";;;;;;;;;;;;;;;AASA;;AACA;;;;;;AAEA,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,GAAD;AAAA,SAASA,GAAG,KAAK,IAAR,I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IAsB,IAAAA,OAAO,CAACrB,KAAR,GAAgBqB,OAAO,CAAC3B,IAAxB;AACA2B,IAAAA,OAAO,CAACpB,IAAR,GAAeoB,OAAO,CAAC1B,GAAvB;AACA0B,IAAAA,OAAO,CAACV,eAAR,GAA0B,MAAMgB,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACX,KAAvB,CAAhC;AACAW,IAAAA,OAAO,CAACnB,QAAR,GAAmBmB,OAAO,CAACzB,OAA3B;AACAyB,IAAAA,OAAO,CAAClB,QAAR,GAAmBkB,OAAO,CAACxB,OAA3B;AAEA2B,IAAAA,CAAC,CAACO,GAAF,GAAQV,OAAO,CAAC3B,IAAR,GAAeiC,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACX,KAAvB,CAAvB;AACAc,IAAAA,CAAC,CAACQ,MAAF,GAAW,CAACR,CAAC,CAACO,GAAd;AACAP,IAAAA,CAAC,CAACS,KAAF,GAAUZ,OAAO,CAACtB,WAAR,GAAsByB,CAAC,CAACO,GAAlC;AACAP,IAAAA,CAAC,CAACU,IAAF,GAAS,CAACV,CAAC,CAACS,KAAZ;AACAT,IAAAA,CAAC,CAAC9B,IAAF,GAAS2B,OAAO,CAAC3B,IAAjB;AACA8B,IAAAA,CAAC,CAAC7B,GAAF,GAAQ0B,OAAO,CAAC1B,GAAhB;AAEA6B,IAAAA,CAAC,CAACS,KAAF,IAAWZ,OAAO,CAACzB,OAAnB;AACA4B,IAAAA,CAAC,CAACU,IAAF,IAAUb,OAAO,CAACzB,OAAlB;AACA4B,IAAAA,CAAC,CAACO,GAAF,IAASV,OAAO,CAACxB,OAAjB;AACA2B,IAAAA,CAAC,CAACQ,MAAF,IAAYX,OAAO,CAACxB,OAApB;AACD;AACF","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\n// @ts-nocheck\n\nimport {assert, Matrix4} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\n\nconst defined = (val) => val !== null && typeof val !== 'undefined';\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.fov] The angle of the field of view (FOV), in radians.\n * @param {Number} [options.aspectRatio] The aspect ratio of the frustum's width to it's height.\n * @param {Number} [options.near=1.0] The distance of the near plane.\n * @param {Number} [options.far=500000000.0] The distance of the far plane.\n * @param {Number} [options.xOffset=0.0] The offset in the x direction.\n * @param {Number} [options.yOffset=0.0] The offset in the y direction.\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport default class PerspectiveFrustum {\n _offCenterFrustum = new PerspectiveOffCenterFrustum();\n /**\n * The angle of the field of view (FOV), in radians. This angle will be used\n * as the horizontal FOV if the width is greater than the height, otherwise\n * it will be the vertical FOV.\n */\n fov: number;\n _fov;\n _fovy;\n _sseDenominator;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio: number;\n _aspectRatio;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n _near;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n _far;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n _xOffset;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n _yOffset;\n\n constructor(options: Record<string, any> = {}) {\n options = {\n near: 1.0,\n far: 500000000.0,\n xOffset: 0.0,\n yOffset: 0.0,\n ...options\n };\n\n this.fov = options.fov;\n\n this.aspectRatio = options.aspectRatio;\n\n this.near = options.near;\n this._near = this.near;\n\n this.far = options.far;\n this._far = this.far;\n\n this.xOffset = options.xOffset;\n this._xOffset = this.xOffset;\n\n this.yOffset = options.yOffset;\n this._yOffset = this.yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n */\n clone(): PerspectiveFrustum {\n return new PerspectiveFrustum({\n aspectRatio: this.aspectRatio,\n fov: this.fov,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveFrustum): boolean {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n update(this);\n update(other);\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n */\n get projectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n */\n get infiniteProjectionMatrix(): Matrix4 {\n update(this);\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n */\n get fovy(): number {\n update(this);\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n update(this);\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this frustum.\n *\n * @param {Vector3} position The eye position.\n * @param {Vector3} direction The view direction.\n * @param {Vector3} up The up direction.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the frustum.\n * var cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(position, direction, up) {\n update(this);\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\n * @param {Number} drawingBufferWidth The width of the drawing buffer.\n * @param {Number} drawingBufferHeight The height of the drawing buffer.\n * @param {Number} distance The distance to the near plane in meters.\n * @param {Vector2} result The object onto which to store the result.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result\n );\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.fov) &&\n Number.isFinite(frustum.aspectRatio) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = frustum._offCenterFrustum;\n\n if (\n frustum.fov !== frustum._fov ||\n frustum.aspectRatio !== frustum._aspectRatio ||\n frustum.near !== frustum._near ||\n frustum.far !== frustum._far ||\n frustum.xOffset !== frustum._xOffset ||\n frustum.yOffset !== frustum._yOffset\n ) {\n assert(frustum.fov >= 0 && frustum.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(frustum.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(frustum.near >= 0 && frustum.near < frustum.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n frustum._aspectRatio = frustum.aspectRatio;\n frustum._fov = frustum.fov;\n frustum._fovy =\n frustum.aspectRatio <= 1\n ? frustum.fov\n : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;\n frustum._near = frustum.near;\n frustum._far = frustum.far;\n frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);\n frustum._xOffset = frustum.xOffset;\n frustum._yOffset = frustum.yOffset;\n\n f.top = frustum.near * Math.tan(0.5 * frustum._fovy);\n f.bottom = -f.top;\n f.right = frustum.aspectRatio * f.top;\n f.left = -f.right;\n f.near = frustum.near;\n f.far = frustum.far;\n\n f.right += frustum.xOffset;\n f.left += frustum.xOffset;\n f.top += frustum.yOffset;\n f.bottom += frustum.yOffset;\n }\n}\n"],"file":"perspective-frustum.js"}
1
+ {"version":3,"sources":["../../../src/lib/perspective-frustum.ts"],"names":["defined","val","PerspectiveFrustum","options","PerspectiveOffCenterFrustum","fov","aspectRatio","near","far","xOffset","yOffset","other","_update","_offCenterFrustum","equals","projectionMatrix","infiniteProjectionMatrix","_fovy","_sseDenominator","position","direction","up","computeCullingVolume","drawingBufferWidth","drawingBufferHeight","distance","result","getPixelDimensions","Vector2","Number","isFinite","f","_fov","_aspectRatio","_near","_far","_xOffset","_yOffset","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";;;;;;;;;;;;;;;AAOA;;AACA;;AAGA,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,GAAD;AAAA,SAASA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAA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AU,KAAKtC,WAAL,GAAmByB,CAAC,CAACW,GAA/B;AACAX,QAAAA,CAAC,CAACc,IAAF,GAAS,CAACd,CAAC,CAACa,KAAZ;AACAb,QAAAA,CAAC,CAACxB,IAAF,GAAS,KAAKA,IAAd;AACAwB,QAAAA,CAAC,CAACvB,GAAF,GAAQ,KAAKA,GAAb;AAEAuB,QAAAA,CAAC,CAACa,KAAF,IAAW,KAAKnC,OAAhB;AACAsB,QAAAA,CAAC,CAACc,IAAF,IAAU,KAAKpC,OAAf;AACAsB,QAAAA,CAAC,CAACW,GAAF,IAAS,KAAKhC,OAAd;AACAqB,QAAAA,CAAC,CAACY,MAAF,IAAY,KAAKjC,OAAjB;AACD;AACF","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// Note: This class is still an experimental export, mainly used by other test cases\n// - It has not been fully adapted to math.gl conventions\n// - Documentation has not been ported\n\nimport {assert, Matrix4, NumericArray, Vector2} from '@math.gl/core';\nimport PerspectiveOffCenterFrustum from './perspective-off-center-frustum';\nimport CullingVolume from './culling-volume';\n\nconst defined = (val) => val !== null && typeof val !== 'undefined';\n\ntype PerspectiveFrustumOptions = {\n /** The angle of the field of view (FOV), in radians. */\n fov?: number;\n /** The aspect ratio of the frustum's width to it's height. */\n aspectRatio?: number;\n /** The distance of the near plane. */\n near?: number;\n /** The distance of the far plane. */\n far?: number;\n /** The offset in the x direction. */\n xOffset?: number;\n /** The offset in the y direction. */\n yOffset?: number;\n};\n\n/**\n * The viewing frustum is defined by 6 planes.\n * Each plane is represented by a {@link Vector4} object, where the x, y, and z components\n * define the unit vector normal to the plane, and the w component is the distance of the\n * plane from the origin/camera position.\n *\n * @alias PerspectiveFrustum\n *\n * @example\n * var frustum = new PerspectiveFrustum({\n * fov : Math.PI_OVER_THREE,\n * aspectRatio : canvas.clientWidth / canvas.clientHeight\n * near : 1.0,\n * far : 1000.0\n * });\n *\n * @see PerspectiveOffCenterFrustum\n */\nexport default class PerspectiveFrustum {\n private _offCenterFrustum = new PerspectiveOffCenterFrustum();\n /**\n * The angle of the field of view (FOV), in radians. This angle will be used\n * as the horizontal FOV if the width is greater than the height, otherwise\n * it will be the vertical FOV.\n */\n fov?: number;\n private _fov: number;\n private _fovy: number;\n private _sseDenominator: number;\n /**\n * The aspect ratio of the frustum's width to it's height.\n */\n aspectRatio?: number;\n private _aspectRatio: number;\n /**\n * The distance of the near plane.\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n /**\n * Offsets the frustum in the x direction.\n * @default 0.0\n */\n xOffset: number;\n private _xOffset: number;\n /**\n * Offsets the frustum in the y direction.\n * @default 0.0\n */\n yOffset: number;\n private _yOffset: number;\n\n constructor(options: PerspectiveFrustumOptions = {}) {\n const {fov, aspectRatio, near = 1.0, far = 500000000.0, xOffset = 0.0, yOffset = 0.0} = options;\n\n this.fov = fov;\n this.aspectRatio = aspectRatio;\n this.near = near;\n this.far = far;\n this.xOffset = xOffset;\n this.yOffset = yOffset;\n }\n\n /**\n * Returns a duplicate of a PerspectiveFrustum instance.\n */\n clone(): PerspectiveFrustum {\n return new PerspectiveFrustum({\n aspectRatio: this.aspectRatio,\n fov: this.fov,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveFrustum): boolean {\n if (!defined(other) || !(other instanceof PerspectiveFrustum)) {\n return false;\n }\n\n this._update();\n other._update();\n\n return (\n this.fov === other.fov &&\n this.aspectRatio === other.aspectRatio &&\n this.near === other.near &&\n this.far === other.far &&\n this._offCenterFrustum.equals(other._offCenterFrustum)\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view this.\n */\n get projectionMatrix(): Matrix4 {\n this._update();\n return this._offCenterFrustum.projectionMatrix;\n }\n\n /**\n * The perspective projection matrix computed from the view frustum with an infinite far plane.\n */\n get infiniteProjectionMatrix(): Matrix4 {\n this._update();\n return this._offCenterFrustum.infiniteProjectionMatrix;\n }\n\n /**\n * Gets the angle of the vertical field of view, in radians.\n */\n get fovy(): number {\n this._update();\n return this._fovy;\n }\n\n /**\n * @private\n */\n get sseDenominator(): number {\n this._update();\n return this._sseDenominator;\n }\n\n /**\n * Creates a culling volume for this this.ion.\n * @returns {CullingVolume} A culling volume at the given position and orientation.\n *\n * @example\n * // Check if a bounding volume intersects the this.\n * var cullingVolume = this.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * var intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n computeCullingVolume(\n /** A Vector3 defines the eye position. */\n position: Readonly<NumericArray>,\n /** A Vector3 defines the view direction. */\n direction: Readonly<NumericArray>,\n /** A Vector3 defines the up direction. */\n up: Readonly<NumericArray>\n ): CullingVolume {\n this._update();\n return this._offCenterFrustum.computeCullingVolume(position, direction, up);\n }\n\n /**\n * Returns the pixel's width and height in meters.\n * @returns {Vector2} The modified result parameter or a new instance of {@link Vector2} with the pixel's width and height in the x and y properties, respectively.\n *\n * @exception {DeveloperError} drawingBufferWidth must be greater than zero.\n * @exception {DeveloperError} drawingBufferHeight must be greater than zero.\n *\n * @example\n * // Example 1\n * // Get the width and height of a pixel.\n * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, 1.0, new Vector2());\n *\n * @example\n * // Example 2\n * // Get the width and height of a pixel if the near plane was set to 'distance'.\n * // For example, get the size of a pixel of an image on a billboard.\n * var position = camera.position;\n * var direction = camera.direction;\n * var toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * var toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * var distance = Vector3.magnitude(toCenterProj);\n * var pixelSize = camera.this.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(\n /** The width of the drawing buffer. */\n drawingBufferWidth: number,\n /** The height of the drawing buffer. */\n drawingBufferHeight: number,\n /** The distance to the near plane in meters. */\n distance: number,\n /** The object onto which to store the result. */\n result?: Vector2\n ): Vector2 {\n this._update();\n return this._offCenterFrustum.getPixelDimensions(\n drawingBufferWidth,\n drawingBufferHeight,\n distance,\n result || new Vector2()\n );\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update(): void {\n assert(\n Number.isFinite(this.fov) &&\n Number.isFinite(this.aspectRatio) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // 'fov, aspectRatio, near, or far parameters are not set.'\n\n const f = this._offCenterFrustum;\n\n if (\n this.fov !== this._fov ||\n this.aspectRatio !== this._aspectRatio ||\n this.near !== this._near ||\n this.far !== this._far ||\n this.xOffset !== this._xOffset ||\n this.yOffset !== this._yOffset\n ) {\n assert(this.fov >= 0 && this.fov < Math.PI);\n // throw new DeveloperError('fov must be in the range [0, PI).');\n\n assert(this.aspectRatio > 0);\n // throw new DeveloperError('aspectRatio must be positive.');\n\n assert(this.near >= 0 && this.near < this.far);\n // throw new DeveloperError('near must be greater than zero and less than far.');\n\n this._aspectRatio = this.aspectRatio;\n this._fov = this.fov;\n this._fovy =\n this.aspectRatio <= 1\n ? this.fov\n : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;\n this._near = this.near;\n this._far = this.far;\n this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);\n this._xOffset = this.xOffset;\n this._yOffset = this.yOffset;\n\n f.top = this.near * Math.tan(0.5 * this._fovy);\n f.bottom = -f.top;\n f.right = this.aspectRatio * f.top;\n f.left = -f.right;\n f.near = this.near;\n f.far = this.far;\n\n f.right += this.xOffset;\n f.left += this.xOffset;\n f.top += this.yOffset;\n f.bottom += this.yOffset;\n }\n }\n}\n"],"file":"perspective-frustum.js"}
@@ -19,10 +19,6 @@ var _cullingVolume = _interopRequireDefault(require("./culling-volume"));
19
19
 
20
20
  var _plane = _interopRequireDefault(require("./plane"));
21
21
 
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
23
-
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
25
-
26
22
  var scratchPlaneUpVector = new _core.Vector3();
27
23
  var scratchPlaneRightVector = new _core.Vector3();
28
24
  var scratchPlaneNearCenter = new _core.Vector3();
@@ -48,10 +44,10 @@ var PerspectiveOffCenterFrustum = function () {
48
44
  (0, _defineProperty2.default)(this, "_cullingVolume", new _cullingVolume.default([new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default(), new _plane.default()]));
49
45
  (0, _defineProperty2.default)(this, "_perspectiveMatrix", new _core.Matrix4());
50
46
  (0, _defineProperty2.default)(this, "_infinitePerspective", new _core.Matrix4());
51
- options = _objectSpread({
52
- near: 1.0,
53
- far: 500000000.0
54
- }, options);
47
+ var _options$near = options.near,
48
+ near = _options$near === void 0 ? 1.0 : _options$near,
49
+ _options$far = options.far,
50
+ far = _options$far === void 0 ? 500000000.0 : _options$far;
55
51
  this.left = options.left;
56
52
  this._left = undefined;
57
53
  this.right = options.right;
@@ -60,10 +56,10 @@ var PerspectiveOffCenterFrustum = function () {
60
56
  this._top = undefined;
61
57
  this.bottom = options.bottom;
62
58
  this._bottom = undefined;
63
- this.near = options.near;
64
- this._near = this.near;
65
- this.far = options.far;
66
- this._far = this.far;
59
+ this.near = near;
60
+ this._near = near;
61
+ this.far = far;
62
+ this._far = far;
67
63
  }
68
64
 
69
65
  (0, _createClass2.default)(PerspectiveOffCenterFrustum, [{
@@ -86,13 +82,15 @@ var PerspectiveOffCenterFrustum = function () {
86
82
  }, {
87
83
  key: "projectionMatrix",
88
84
  get: function get() {
89
- update(this);
85
+ this._update();
86
+
90
87
  return this._perspectiveMatrix;
91
88
  }
92
89
  }, {
93
90
  key: "infiniteProjectionMatrix",
94
91
  get: function get() {
95
- update(this);
92
+ this._update();
93
+
96
94
  return this._infinitePerspective;
97
95
  }
98
96
  }, {
@@ -124,7 +122,8 @@ var PerspectiveOffCenterFrustum = function () {
124
122
  }, {
125
123
  key: "getPixelDimensions",
126
124
  value: function getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
127
- update(this);
125
+ this._update();
126
+
128
127
  (0, _core.assert)(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
129
128
  (0, _core.assert)(drawingBufferWidth > 0);
130
129
  (0, _core.assert)(drawingBufferHeight > 0);
@@ -139,45 +138,46 @@ var PerspectiveOffCenterFrustum = function () {
139
138
  result.y = pixelHeight;
140
139
  return result;
141
140
  }
141
+ }, {
142
+ key: "_update",
143
+ value: function _update() {
144
+ (0, _core.assert)(Number.isFinite(this.right) && Number.isFinite(this.left) && Number.isFinite(this.top) && Number.isFinite(this.bottom) && Number.isFinite(this.near) && Number.isFinite(this.far));
145
+ var top = this.top,
146
+ bottom = this.bottom,
147
+ right = this.right,
148
+ left = this.left,
149
+ near = this.near,
150
+ far = this.far;
151
+
152
+ if (top !== this._top || bottom !== this._bottom || left !== this._left || right !== this._right || near !== this._near || far !== this._far) {
153
+ (0, _core.assert)(this.near > 0 && this.near < this.far, 'near must be greater than zero and less than far.');
154
+ this._left = left;
155
+ this._right = right;
156
+ this._top = top;
157
+ this._bottom = bottom;
158
+ this._near = near;
159
+ this._far = far;
160
+ this._perspectiveMatrix = new _core.Matrix4().frustum({
161
+ left: left,
162
+ right: right,
163
+ bottom: bottom,
164
+ top: top,
165
+ near: near,
166
+ far: far
167
+ });
168
+ this._infinitePerspective = new _core.Matrix4().frustum({
169
+ left: left,
170
+ right: right,
171
+ bottom: bottom,
172
+ top: top,
173
+ near: near,
174
+ far: Infinity
175
+ });
176
+ }
177
+ }
142
178
  }]);
143
179
  return PerspectiveOffCenterFrustum;
144
180
  }();
145
181
 
146
182
  exports.default = PerspectiveOffCenterFrustum;
147
-
148
- function update(frustum) {
149
- (0, _core.assert)(Number.isFinite(frustum.right) && Number.isFinite(frustum.left) && Number.isFinite(frustum.top) && Number.isFinite(frustum.bottom) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far));
150
- var top = frustum.top,
151
- bottom = frustum.bottom,
152
- right = frustum.right,
153
- left = frustum.left,
154
- near = frustum.near,
155
- far = frustum.far;
156
-
157
- if (top !== frustum._top || bottom !== frustum._bottom || left !== frustum._left || right !== frustum._right || near !== frustum._near || far !== frustum._far) {
158
- (0, _core.assert)(frustum.near > 0 && frustum.near < frustum.far, 'near must be greater than zero and less than far.');
159
- frustum._left = left;
160
- frustum._right = right;
161
- frustum._top = top;
162
- frustum._bottom = bottom;
163
- frustum._near = near;
164
- frustum._far = far;
165
- frustum._perspectiveMatrix = new _core.Matrix4().frustum({
166
- left: left,
167
- right: right,
168
- bottom: bottom,
169
- top: top,
170
- near: near,
171
- far: far
172
- });
173
- frustum._infinitePerspective = new _core.Matrix4().frustum({
174
- left: left,
175
- right: right,
176
- bottom: bottom,
177
- top: top,
178
- near: near,
179
- far: Infinity
180
- });
181
- }
182
- }
183
183
  //# sourceMappingURL=perspective-off-center-frustum.js.map