@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/perspective-off-center-frustum.ts"],"names":["scratchPlaneUpVector","Vector3","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","options","CullingVolume","Plane","Matrix4","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","other","update","_perspectiveMatrix","_infinitePerspective","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x","y","frustum","Infinity"],"mappings":";;;;;;;;;;;;;;;AASA;;AACA;;AACA;;;;;;AAEA,IAAMA,oBAAoB,GAAG,IAAIC,aAAJ,EAA7B;AACA,IAAMC,uBAAuB,GAAG,IAAID,aAAJ,EAAhC;AACA,IAAME,sBAAsB,GAAG,IAAIF,aAAJ,EAA/B;AACA,IAAMG,qBAAqB,GAAG,IAAIH,aAAJ,EAA9B;AACA,IAAMI,kBAAkB,GAAG,IAAIJ,aAAJ,EAA3B;;IAEqBK,2B;AAqDnB,yCAA+C;AAAA,QAAnCC,OAAmC,uEAAJ,EAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0DAxC9B,IAAIC,sBAAJ,CAAkB,CACjC,IAAIC,cAAJ,EADiC,EAE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jDP,MAAAA,IAAI,EAAJA,IALiD;AAMjDC,MAAAA,GAAG,EAAHA;AANiD,KAAtB,CAA7B;AAQA4C,IAAAA,OAAO,CAAC7B,oBAAR,GAA+B,IAAIjB,aAAJ,GAAc8C,OAAd,CAAsB;AACnD3C,MAAAA,IAAI,EAAJA,IADmD;AAEnDG,MAAAA,KAAK,EAALA,KAFmD;AAGnDI,MAAAA,MAAM,EAANA,MAHmD;AAInDF,MAAAA,GAAG,EAAHA,GAJmD;AAKnDP,MAAAA,IAAI,EAAJA,IALmD;AAMnDC,MAAAA,GAAG,EAAE6C;AAN8C,KAAtB,CAA/B;AAQD;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 {Vector3, Matrix4, assert} from '@math.gl/core';\nimport CullingVolume from './culling-volume';\nimport Plane from './plane';\n\nconst scratchPlaneUpVector = new Vector3();\nconst scratchPlaneRightVector = new Vector3();\nconst scratchPlaneNearCenter = new Vector3();\nconst scratchPlaneFarCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n\nexport default class PerspectiveOffCenterFrustum {\n left;\n _left;\n right;\n _right;\n top;\n _top;\n bottom;\n _bottom;\n near;\n _near;\n far;\n _far;\n _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n _perspectiveMatrix = new Matrix4();\n _infinitePerspective = new Matrix4();\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 PerspectiveOffCenterFrustum\n * @constructor\n *\n * @param {Object} [options] An object with the following properties:\n * @param {Number} [options.left] The left clipping plane distance.\n * @param {Number} [options.right] The right clipping plane distance.\n * @param {Number} [options.top] The top clipping plane distance.\n * @param {Number} [options.bottom] The bottom clipping plane distance.\n * @param {Number} [options.near=1.0] The near clipping plane distance.\n * @param {Number} [options.far=500000000.0] The far clipping plane distance.\n *\n * @example\n * const frustum = new PerspectiveOffCenterFrustum({\n * left : -1.0,\n * right : 1.0,\n * top : 1.0,\n * bottom : -1.0,\n * near : 1.0,\n * far : 100.0\n * });\n *\n * @see PerspectiveFrustum\n */\n constructor(options: Record<string, any> = {}) {\n options = {near: 1.0, far: 500000000.0, ...options};\n\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.left = options.left;\n this._left = undefined;\n\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.right = options.right;\n this._right = undefined;\n\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.top = options.top;\n this._top = undefined;\n\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n this.near = options.near;\n this._near = this.near;\n\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n this.far = options.far;\n this._far = this.far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone() {\n return new PerspectiveOffCenterFrustum({\n right: this.right,\n left: this.left,\n top: this.top,\n bottom: this.bottom,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveOffCenterFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {PerspectiveOffCenterFrustum} [other] The right hand side PerspectiveOffCenterFrustum.\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other) {\n return (\n other &&\n other instanceof PerspectiveOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix() {\n update(this);\n return this._perspectiveMatrix;\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix() {\n update(this);\n return this._infinitePerspective;\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 * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\n computeCullingVolume(position, direction, up) {\n assert(position, 'position is required.');\n assert(direction, 'direction is required.');\n assert(up, 'up is required.');\n\n const planes = this._cullingVolume.planes;\n\n up = scratchPlaneUpVector.copy(up).normalize();\n const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();\n\n const nearCenter = scratchPlaneNearCenter\n .copy(direction)\n .multiplyByScalar(this.near)\n .add(position);\n\n const farCenter = scratchPlaneFarCenter\n .copy(direction)\n .multiplyByScalar(this.far)\n .add(position);\n\n let normal = scratchPlaneNormal;\n\n // Left plane computation\n normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);\n\n planes[0].fromPointNormal(position, normal);\n\n // Right plane computation\n normal\n .copy(right)\n .multiplyByScalar(this.right)\n .add(nearCenter)\n .subtract(position)\n .cross(up)\n .negate();\n\n planes[1].fromPointNormal(position, normal);\n\n // Bottom plane computation\n normal\n .copy(up)\n .multiplyByScalar(this.bottom)\n .add(nearCenter)\n .subtract(position)\n .cross(right)\n .negate();\n\n planes[2].fromPointNormal(position, normal);\n\n // Top plane computation\n normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);\n\n planes[3].fromPointNormal(position, normal);\n\n normal = new Vector3().copy(direction);\n\n // Near plane computation\n planes[4].fromPointNormal(nearCenter, normal);\n\n // Far plane computation\n normal.negate();\n\n planes[5].fromPointNormal(farCenter, normal);\n\n return this._cullingVolume;\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 * const 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 * const position = camera.position;\n * const direction = camera.direction;\n * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * const distance = Vector3.magnitude(toCenterProj);\n * const pixelSize = camera.frustum.getPixelDimensions(scene.drawingBufferWidth, scene.drawingBufferHeight, distance, new Vector2());\n */\n getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {\n update(this);\n\n assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));\n // 'Both drawingBufferWidth and drawingBufferHeight are required.'\n assert(drawingBufferWidth > 0);\n // 'drawingBufferWidth must be greater than zero.'\n assert(drawingBufferHeight > 0);\n // 'drawingBufferHeight must be greater than zero.'\n assert(distance > 0);\n // 'distance is required.');\n assert(result);\n // 'A result object is required.');\n\n const inverseNear = 1.0 / this.near;\n let tanTheta = this.top * inverseNear;\n const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;\n tanTheta = this.right * inverseNear;\n const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n }\n}\n\n// eslint-disable-next-line complexity, max-statements\nfunction update(frustum) {\n assert(\n Number.isFinite(frustum.right) &&\n Number.isFinite(frustum.left) &&\n Number.isFinite(frustum.top) &&\n Number.isFinite(frustum.bottom) &&\n Number.isFinite(frustum.near) &&\n Number.isFinite(frustum.far)\n );\n // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');\n\n const {top, bottom, right, left, near, far} = frustum;\n\n if (\n top !== frustum._top ||\n bottom !== frustum._bottom ||\n left !== frustum._left ||\n right !== frustum._right ||\n near !== frustum._near ||\n far !== frustum._far\n ) {\n assert(\n frustum.near > 0 && frustum.near < frustum.far,\n 'near must be greater than zero and less than far.'\n );\n\n frustum._left = left;\n frustum._right = right;\n frustum._top = top;\n frustum._bottom = bottom;\n frustum._near = near;\n frustum._far = far;\n frustum._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n frustum._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
1
+ {"version":3,"sources":["../../../src/lib/perspective-off-center-frustum.ts"],"names":["scratchPlaneUpVector","Vector3","scratchPlaneRightVector","scratchPlaneNearCenter","scratchPlaneFarCenter","scratchPlaneNormal","PerspectiveOffCenterFrustum","options","CullingVolume","Plane","Matrix4","near","far","left","_left","undefined","right","_right","top","_top","bottom","_bottom","_near","_far","other","_update","_perspectiveMatrix","_infinitePerspective","position","direction","up","planes","_cullingVolume","copy","normalize","cross","nearCenter","multiplyByScalar","add","farCenter","normal","subtract","fromPointNormal","negate","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","inverseNear","tanTheta","pixelHeight","pixelWidth","x","y","frustum","Infinity"],"mappings":";;;;;;;;;;;;;;;AAOA;;AACA;;AACA;;AAEA,IAAMA,oBAAoB,GAAG,IAAIC,aAAJ,EAA7B;AACA,IAAMC,uBAAuB,GAAG,IAAID,aAAJ,EAAhC;AACA,IAAME,sBAAsB,GAAG,IAAIF,aAAJ,EAA/B;AACA,IAAMG,qBAAqB,GAAG,IAAIH,aAAJ,EAA9B;AACA,IAAMI,kBAAkB,GAAG,IAAIJ,aAAJ,EAA3B;;IAWqBK,2B;AA2EnB,yCAA8D;AAAA,QAAlDC,OAAkD,uEAAJ,EAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0DA/BrC,IAAIC,sBAAJ,CAAkB,CACzC,IAAIC,cAAJ,EADyC,EAEzC,IAAIA,cAAJ,EAFyC,EAGzC,IAAIA,cAAJ,EAHyC,EAIzC,IAAIA,cAAJ,EAJyC,EAKzC,IAAIA,cAAJ,EALyC,EAMzC,IAAIA,cAAJ,EANyC,CAAlB,CA+BqC;AAAA,8DAvBjC,IAAIC,aAAJ,EAuBiC;AAAA,gEAtB/B,IAAIA,aAAJ,EAsB+B;AAC5D,wBAAwCH,OAAxC,CAAOI,IAAP;AAAA,QAAOA,IAAP,8BAAc,GAAd;AAAA,uBAAwCJ,OAAxC,CAAmBK,GAAnB;AAAA,QAAmBA,GAAnB,6BAAyB,WAAzB;AAEA,SAAKC,IAAL,GAAYN,OAAO,CAACM,IAApB;AACA,SAAKC,KAAL,GAAaC,SAAb;AAEA,SAAKC,KAAL,GAAaT,OAAO,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A,aAAKI,MAAL,GAAcD,KAAd;AACA,aAAKG,IAAL,GAAYD,GAAZ;AACA,aAAKG,OAAL,GAAeD,MAAf;AACA,aAAKE,KAAL,GAAaX,IAAb;AACA,aAAKY,IAAL,GAAYX,GAAZ;AACA,aAAKc,kBAAL,GAA0B,IAAIhB,aAAJ,GAAc8C,OAAd,CAAsB;AAC9C3C,UAAAA,IAAI,EAAJA,IAD8C;AAE9CG,UAAAA,KAAK,EAALA,KAF8C;AAG9CI,UAAAA,MAAM,EAANA,MAH8C;AAI9CF,UAAAA,GAAG,EAAHA,GAJ8C;AAK9CP,UAAAA,IAAI,EAAJA,IAL8C;AAM9CC,UAAAA,GAAG,EAAHA;AAN8C,SAAtB,CAA1B;AAQA,aAAKe,oBAAL,GAA4B,IAAIjB,aAAJ,GAAc8C,OAAd,CAAsB;AAChD3C,UAAAA,IAAI,EAAJA,IADgD;AAEhDG,UAAAA,KAAK,EAALA,KAFgD;AAGhDI,UAAAA,MAAM,EAANA,MAHgD;AAIhDF,UAAAA,GAAG,EAAHA,GAJgD;AAKhDP,UAAAA,IAAI,EAAJA,IALgD;AAMhDC,UAAAA,GAAG,EAAE6C;AAN2C,SAAtB,CAA5B;AAQD;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 {Vector3, Vector2, Matrix4, assert, NumericArray} from '@math.gl/core';\nimport CullingVolume from './culling-volume';\nimport Plane from './plane';\n\nconst scratchPlaneUpVector = new Vector3();\nconst scratchPlaneRightVector = new Vector3();\nconst scratchPlaneNearCenter = new Vector3();\nconst scratchPlaneFarCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\n\ntype PerspectiveOffCenterFrustumOptions = {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n near?: number;\n far?: number;\n};\n\nexport default class PerspectiveOffCenterFrustum {\n /**\n * Defines the left clipping plane.\n * @type {Number}\n * @default undefined\n */\n left?: number;\n private _left?: number;\n /**\n * Defines the right clipping plane.\n * @type {Number}\n * @default undefined\n */\n right?: number;\n private _right?: number;\n /**\n * Defines the top clipping plane.\n * @type {Number}\n * @default undefined\n */\n top?: number;\n private _top?: number;\n /**\n * Defines the bottom clipping plane.\n * @type {Number}\n * @default undefined\n */\n bottom?: number;\n private _bottom?: number;\n /**\n * The distance of the near plane.\n * @type {Number}\n * @default 1.0\n */\n near: number;\n private _near: number;\n /**\n * The distance of the far plane.\n * @type {Number}\n * @default 500000000.0\n */\n far: number;\n private _far: number;\n\n private _cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n ]);\n private _perspectiveMatrix = new Matrix4();\n private _infinitePerspective = new Matrix4();\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 PerspectiveOffCenterFrustum\n *\n * @example\n * const frustum = new PerspectiveOffCenterFrustum({\n * left : -1.0,\n * right : 1.0,\n * top : 1.0,\n * bottom : -1.0,\n * near : 1.0,\n * far : 100.0\n * });\n *\n * @see PerspectiveFrustum\n */\n constructor(options: PerspectiveOffCenterFrustumOptions = {}) {\n const {near = 1.0, far = 500000000.0} = options;\n\n this.left = options.left;\n this._left = undefined;\n\n this.right = options.right;\n this._right = undefined;\n\n this.top = options.top;\n this._top = undefined;\n\n this.bottom = options.bottom;\n this._bottom = undefined;\n\n this.near = near;\n this._near = near;\n\n this.far = far;\n this._far = far;\n }\n\n /**\n * Returns a duplicate of a PerspectiveOffCenterFrustum instance.\n * @returns {PerspectiveOffCenterFrustum} A new PerspectiveFrustum instance.\n * */\n clone(): PerspectiveOffCenterFrustum {\n return new PerspectiveOffCenterFrustum({\n right: this.right,\n left: this.left,\n top: this.top,\n bottom: this.bottom,\n near: this.near,\n far: this.far\n });\n }\n\n /**\n * Compares the provided PerspectiveOffCenterFrustum componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.\n */\n equals(other: PerspectiveOffCenterFrustum): boolean {\n return (\n other &&\n other instanceof PerspectiveOffCenterFrustum &&\n this.right === other.right &&\n this.left === other.left &&\n this.top === other.top &&\n this.bottom === other.bottom &&\n this.near === other.near &&\n this.far === other.far\n );\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#infiniteProjectionMatrix\n */\n get projectionMatrix(): Matrix4 {\n this._update();\n return this._perspectiveMatrix;\n }\n\n /**\n * Gets the perspective projection matrix computed from the view frustum with an infinite far plane.\n * @memberof PerspectiveOffCenterFrustum.prototype\n * @type {Matrix4}\n *\n * @see PerspectiveOffCenterFrustum#projectionMatrix\n */\n get infiniteProjectionMatrix(): Matrix4 {\n this._update();\n return this._infinitePerspective;\n }\n\n /**\n * Creates a culling volume for this frustum.\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 * const cullingVolume = frustum.computeCullingVolume(cameraPosition, cameraDirection, cameraUp);\n * const intersect = cullingVolume.computeVisibility(boundingVolume);\n */\n // eslint-disable-next-line complexity, max-statements\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 assert(position, 'position is required.');\n assert(direction, 'direction is required.');\n assert(up, 'up is required.');\n\n const planes = this._cullingVolume.planes;\n\n up = scratchPlaneUpVector.copy(up).normalize();\n const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();\n\n const nearCenter = scratchPlaneNearCenter\n .copy(direction)\n .multiplyByScalar(this.near)\n .add(position);\n\n const farCenter = scratchPlaneFarCenter\n .copy(direction)\n .multiplyByScalar(this.far)\n .add(position);\n\n let normal = scratchPlaneNormal;\n\n // Left plane computation\n normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);\n\n planes[0].fromPointNormal(position, normal);\n\n // Right plane computation\n normal\n .copy(right)\n .multiplyByScalar(this.right)\n .add(nearCenter)\n .subtract(position)\n .cross(up)\n .negate();\n\n planes[1].fromPointNormal(position, normal);\n\n // Bottom plane computation\n normal\n .copy(up)\n .multiplyByScalar(this.bottom)\n .add(nearCenter)\n .subtract(position)\n .cross(right)\n .negate();\n\n planes[2].fromPointNormal(position, normal);\n\n // Top plane computation\n normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);\n\n planes[3].fromPointNormal(position, normal);\n\n normal = new Vector3().copy(direction);\n\n // Near plane computation\n planes[4].fromPointNormal(nearCenter, normal);\n\n // Far plane computation\n normal.negate();\n\n planes[5].fromPointNormal(farCenter, normal);\n\n return this._cullingVolume;\n }\n\n /**\n * Returns the pixel's width and height in meters.\n *\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 * const 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 * const position = camera.position;\n * const direction = camera.direction;\n * const toCenter = Vector3.subtract(primitive.boundingVolume.center, position, new Vector3()); // vector from camera to a primitive\n * const toCenterProj = Vector3.multiplyByScalar(direction, Vector3.dot(direction, toCenter), new Vector3()); // project vector onto camera direction vector\n * const distance = Vector3.magnitude(toCenterProj);\n * const pixelSize = camera.frustum.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\n assert(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));\n // 'Both drawingBufferWidth and drawingBufferHeight are required.'\n assert(drawingBufferWidth > 0);\n // 'drawingBufferWidth must be greater than zero.'\n assert(drawingBufferHeight > 0);\n // 'drawingBufferHeight must be greater than zero.'\n assert(distance > 0);\n // 'distance is required.');\n assert(result);\n // 'A result object is required.');\n\n const inverseNear = 1.0 / this.near;\n let tanTheta = this.top * inverseNear;\n const pixelHeight = (2.0 * distance * tanTheta) / drawingBufferHeight;\n tanTheta = this.right * inverseNear;\n const pixelWidth = (2.0 * distance * tanTheta) / drawingBufferWidth;\n\n result.x = pixelWidth;\n result.y = pixelHeight;\n return result;\n }\n\n // eslint-disable-next-line complexity, max-statements\n private _update() {\n assert(\n Number.isFinite(this.right) &&\n Number.isFinite(this.left) &&\n Number.isFinite(this.top) &&\n Number.isFinite(this.bottom) &&\n Number.isFinite(this.near) &&\n Number.isFinite(this.far)\n );\n // throw new DeveloperError('right, left, top, bottom, near, or far parameters are not set.');\n\n const {top, bottom, right, left, near, far} = this;\n\n if (\n top !== this._top ||\n bottom !== this._bottom ||\n left !== this._left ||\n right !== this._right ||\n near !== this._near ||\n far !== this._far\n ) {\n assert(\n this.near > 0 && this.near < this.far,\n 'near must be greater than zero and less than far.'\n );\n\n this._left = left;\n this._right = right;\n this._top = top;\n this._bottom = bottom;\n this._near = near;\n this._far = far;\n this._perspectiveMatrix = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far\n });\n this._infinitePerspective = new Matrix4().frustum({\n left,\n right,\n bottom,\n top,\n near,\n far: Infinity\n });\n }\n }\n}\n"],"file":"perspective-off-center-frustum.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/plane.ts"],"names":["scratchPosition","Vector3","scratchNormal","Plane","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","point","dot","a","b","c","d","set","len","right","matrix4","copy","transformAsVector","scale","transform","fromPointNormal","result","pointDistance","getPointDistance","scaledNormal","subtract","to"],"mappings":";;;;;;;;;;;;;;;AAIA;;AAEA,IAAMA,eAAe,GAAG,IAAIC,aAAJ,EAAxB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAGqBE,K;AAInB,mBAAyE;AAAA,QAA7DC,MAA6D,uEAAjC,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAiC;AAAA,QAAtBC,QAAsB,uEAAH,CAAG;AAAA;AAAA;AAAA;AACvE,SAAKD,MAAL,GAAc,IAAIH,aAAJ,EAAd;AACA,SAAKI,QAAL,GAAgB,CAAC,CAAjB;AACA,SAAKC,kBAAL,CAAwBF,MAAxB,EAAgCC,QAAhC;AACD;;;;WAGD,4BAAmBD,MAAnB,EAA8CC,QAA9C,EAAsE;AACpE,wBAAOE,MAAM,CAACC,QAAP,CAAgBH,QAAhB,CAAP;AACA,WAAKD,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAAyBM,SAAzB;AACA,WAAKL,QAAL,GAAgBA,QAAhB;AACA,aAAO,IAAP;AACD;;;WAGD,yBAAgBM,KAAhB,EAA0CP,MAA1C,EAA2E;AACzEO,MAAAA,KAAK,GAAGX,eAAe,CAACS,IAAhB,CAAqBE,KAArB,CAAR;AACA,WAAKP,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAAyBM,SAAzB;AACA,UAAML,QAAQ,GAAG,CAAC,KAAKD,MAAL,CAAYQ,GAAZ,CAAgBD,KAAhB,CAAlB;AACA,WAAKN,QAAL,GAAgBA,QAAhB;AACA,a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,CAAsBjB,KAAtB,CAAtB;AACA,UAAMkB,YAAY,GAAG3B,aAAa,CAACmB,IAAd,CAAmB,KAAKjB,MAAxB,EAAgCmB,KAAhC,CAAsCI,aAAtC,CAArB;AAEA,aAAOhB,KAAK,CAACmB,QAAN,CAAeD,YAAf,EAA6BE,EAA7B,CAAgCL,MAAhC,CAAP;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\n/* eslint-disable */\nimport {Vector3, equals, assert} from '@math.gl/core';\n\nconst scratchPosition = new Vector3();\nconst scratchNormal = new Vector3();\n\n// A plane in Hessian Normal Form\nexport default class Plane {\n readonly normal: Vector3;\n distance: number;\n\n constructor(normal: readonly number[] = [0, 0, 1], distance: number = 0) {\n this.normal = new Vector3();\n this.distance = -0;\n this.fromNormalDistance(normal, distance);\n }\n\n /** Creates a plane from a normal and a distance from the origin. */\n fromNormalDistance(normal: readonly number[], distance: number): this {\n assert(Number.isFinite(distance));\n this.normal.from(normal).normalize();\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from a normal and a point on the plane. */\n fromPointNormal(point: readonly number[], normal: readonly number[]): this {\n point = scratchPosition.from(point);\n this.normal.from(normal).normalize();\n const distance = -this.normal.dot(point);\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from the general equation */\n fromCoefficients(a: number, b: number, c: number, d: number): this {\n this.normal.set(a, b, c);\n assert(equals(this.normal.len(), 1));\n this.distance = d;\n return this;\n }\n\n /** Duplicates a Plane instance. */\n clone(): Plane {\n return new Plane(this.normal, this.distance);\n }\n\n /** Compares the provided Planes by normal and distance */\n equals(right: Plane): boolean {\n return equals(this.distance, right.distance) && equals(this.normal, right.normal);\n }\n\n /** Computes the signed shortest distance of a point to a plane.\n * The sign of the distance determines which side of the plane the point is on.\n */\n getPointDistance(point: readonly number[]): number {\n return this.normal.dot(point) + this.distance;\n }\n\n /** Transforms the plane by the given transformation matrix. */\n transform(matrix4: readonly number[]): this {\n const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();\n const point = this.normal.scale(-this.distance).transform(matrix4);\n return this.fromPointNormal(point, normal);\n }\n\n /** Projects a point onto the plane. */\n projectPointOntoPlane(point: readonly number[], result: Vector3): Vector3;\n projectPointOntoPlane(point: readonly number[], result?: readonly number[]): readonly number[];\n\n projectPointOntoPlane(point, result = [0, 0, 0]) {\n point = scratchPosition.from(point);\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = this.getPointDistance(point);\n const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);\n\n return point.subtract(scaledNormal).to(result);\n }\n}\n"],"file":"plane.js"}
1
+ {"version":3,"sources":["../../../src/lib/plane.ts"],"names":["scratchPosition","Vector3","scratchNormal","Plane","normal","distance","fromNormalDistance","Number","isFinite","from","normalize","point","dot","a","b","c","d","set","len","right","matrix4","copy","transformAsVector","scale","transform","fromPointNormal","result","pointDistance","getPointDistance","scaledNormal","subtract","to"],"mappings":";;;;;;;;;;;;;;;AAIA;;AAEA,IAAMA,eAAe,GAAG,IAAIC,aAAJ,EAAxB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;;IAGqBE,K;AAInB,mBAA8E;AAAA,QAAlEC,MAAkE,uEAAjC,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAiC;AAAA,QAAtBC,QAAsB,uEAAH,CAAG;AAAA;AAAA;AAAA;AAC5E,SAAKD,MAAL,GAAc,IAAIH,aAAJ,EAAd;AACA,SAAKI,QAAL,GAAgB,CAAC,CAAjB;AACA,SAAKC,kBAAL,CAAwBF,MAAxB,EAAgCC,QAAhC;AACD;;;;WAGD,4BAAmBD,MAAnB,EAAmDC,QAAnD,EAA2E;AACzE,wBAAOE,MAAM,CAACC,QAAP,CAAgBH,QAAhB,CAAP;AACA,WAAKD,MAAL,CAAYK,IAAZ,CAAiBL,MAAjB,EAAyBM,SAAzB;AACA,WAAKL,QAAL,G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AC,KAAKlB,QAAxB,EAAkCmB,SAAlC,CAA4CJ,OAA5C,CAAd;AACA,aAAO,KAAKK,eAAL,CAAqBd,KAArB,EAA4BP,MAA5B,CAAP;AACD;;;WASD,+BAAsBO,KAAtB,EAAiD;AAAA,UAApBe,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAC/Cf,MAAAA,KAAK,GAAGX,eAAe,CAACS,IAAhB,CAAqBE,KAArB,CAAR;AAEA,UAAMgB,aAAa,GAAG,KAAKC,gBAAL,CAAsBjB,KAAtB,CAAtB;AACA,UAAMkB,YAAY,GAAG3B,aAAa,CAACmB,IAAd,CAAmB,KAAKjB,MAAxB,EAAgCmB,KAAhC,CAAsCI,aAAtC,CAArB;AAEA,aAAOhB,KAAK,CAACmB,QAAN,CAAeD,YAAf,EAA6BE,EAA7B,CAAgCL,MAAhC,CAAP;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\n/* eslint-disable */\nimport {Vector3, equals, assert, NumericArray} from '@math.gl/core';\n\nconst scratchPosition = new Vector3();\nconst scratchNormal = new Vector3();\n\n// A plane in Hessian Normal Form\nexport default class Plane {\n readonly normal: Vector3;\n distance: number;\n\n constructor(normal: Readonly<NumericArray> = [0, 0, 1], distance: number = 0) {\n this.normal = new Vector3();\n this.distance = -0;\n this.fromNormalDistance(normal, distance);\n }\n\n /** Creates a plane from a normal and a distance from the origin. */\n fromNormalDistance(normal: Readonly<NumericArray>, distance: number): this {\n assert(Number.isFinite(distance));\n this.normal.from(normal).normalize();\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from a normal and a point on the plane. */\n fromPointNormal(point: Readonly<NumericArray>, normal: Readonly<NumericArray>): this {\n point = scratchPosition.from(point);\n this.normal.from(normal).normalize();\n const distance = -this.normal.dot(point);\n this.distance = distance;\n return this;\n }\n\n /** Creates a plane from the general equation */\n fromCoefficients(a: number, b: number, c: number, d: number): this {\n this.normal.set(a, b, c);\n assert(equals(this.normal.len(), 1));\n this.distance = d;\n return this;\n }\n\n /** Duplicates a Plane instance. */\n clone(): Plane {\n return new Plane(this.normal, this.distance);\n }\n\n /** Compares the provided Planes by normal and distance */\n equals(right: Plane): boolean {\n return equals(this.distance, right.distance) && equals(this.normal, right.normal);\n }\n\n /** Computes the signed shortest distance of a point to a plane.\n * The sign of the distance determines which side of the plane the point is on.\n */\n getPointDistance(point: Readonly<NumericArray>): number {\n return this.normal.dot(point) + this.distance;\n }\n\n /** Transforms the plane by the given transformation matrix. */\n transform(matrix4: Readonly<NumericArray>): this {\n const normal = scratchNormal.copy(this.normal).transformAsVector(matrix4).normalize();\n const point = this.normal.scale(-this.distance).transform(matrix4);\n return this.fromPointNormal(point, normal);\n }\n\n /** Projects a point onto the plane. */\n projectPointOntoPlane(point: Readonly<NumericArray>, result: Vector3): Vector3;\n projectPointOntoPlane(\n point: Readonly<NumericArray>,\n result?: readonly number[]\n ): readonly number[];\n\n projectPointOntoPlane(point, result = [0, 0, 0]) {\n point = scratchPosition.from(point);\n // projectedPoint = point - (normal.point + scale) * normal\n const pointDistance = this.getPointDistance(point);\n const scaledNormal = scratchNormal.copy(this.normal).scale(pointDistance);\n\n return point.subtract(scaledNormal).to(result);\n }\n}\n"],"file":"plane.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/algorithms/compute-eigen-decomposition.ts"],"names":["Matrix3","_MathUtils","scratchMatrix","scratchUnitary","scratchDiagonal","jMatrix","jMatrixTranspose","computeEigenDecomposition","matrix","result","EIGEN_TOLERANCE","EPSILON20","EIGEN_MAX_SWEEPS","count","sweep","unitaryMatrix","diagonalMatrix","identity","copy","epsilon","computeFrobeniusNorm","offDiagonalFrobeniusNorm","shurDecomposition","transpose","multiplyRight","multiplyLeft","unitary","toTarget","diagonal","norm","i","temp","Math","sqrt","rowVal","colVal","getElementIndex","tolerance","EPSILON15","maxDiagonal","rotAx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,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;;AAGD5C,EAAAA,OAAO,CAACmD,QAAR,CAAiBC,EAAjB,CAAoB3C,MAApB;AACAA,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BM,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CjC,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BO,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CC,CAA5F;AACAnC,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BO,CAA9B,EAAiCD,CAAjC,CAAD,CAAN,GAA8CG,CAA9C;AACApC,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BM,CAA9B,EAAiCC,CAAjC,CAAD,CAAN,GAA8C,CAACE,CAA/C;AAEA,SAAOpC,MAAP;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Matrix3, _MathUtils} from '@math.gl/core';\n\nconst scratchMatrix = new Matrix3();\nconst scratchUnitary = new Matrix3();\nconst scratchDiagonal = new Matrix3();\n\nconst jMatrix = new Matrix3();\nconst jMatrixTranspose = new Matrix3();\n\nexport type EigenDecomposition = {\n unitary: Matrix3;\n diagonal: Matrix3;\n};\n\n/**\n * Computes the eigenvectors and eigenvalues of a symmetric matrix.\n *\n * - Returns a diagonal matrix and unitary matrix such that:\n * `matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)`\n * - The values along the diagonal of the diagonal matrix are the eigenvalues. The columns\n * of the unitary matrix are the corresponding eigenvectors.\n * - This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n * section 8.4.3 The Classical Jacobi Algorithm\n *\n * @param matrix The 3x3 matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.\n * @param result Optional object with unitary and diagonal properties which are matrices onto which to store the result.\n * @returns An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.\n *\n * @example\n * const a = //... symmetric matrix\n * const result = {\n * unitary : new Matrix3(),\n * diagonal : new Matrix3()\n * };\n * computeEigenDecomposition(a, result);\n *\n * const unitaryTranspose = Matrix3.transpose(result.unitary, new Matrix3());\n * const b = Matrix3.multiply(result.unitary, result.diagonal, new Matrix3());\n * Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a\n *\n * const lambda = result.diagonal.getColumn(0, new Vector3()).x; // first eigenvalue\n * const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector\n * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)\n */\nexport default function computeEigenDecomposition(\n matrix: number[],\n // @ts-expect-error accept empty object type\n result: EigenDecomposition = {}\n): EigenDecomposition {\n const EIGEN_TOLERANCE = _MathUtils.EPSILON20;\n const EIGEN_MAX_SWEEPS = 10;\n\n let count = 0;\n let sweep = 0;\n\n const unitaryMatrix = scratchUnitary;\n const diagonalMatrix = scratchDiagonal;\n\n unitaryMatrix.identity();\n diagonalMatrix.copy(matrix);\n\n const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);\n\n while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {\n shurDecomposition(diagonalMatrix, jMatrix);\n\n jMatrixTranspose.copy(jMatrix).transpose();\n\n diagonalMatrix.multiplyRight(jMatrix);\n diagonalMatrix.multiplyLeft(jMatrixTranspose);\n unitaryMatrix.multiplyRight(jMatrix);\n\n if (++count > 2) {\n ++sweep;\n count = 0;\n }\n }\n\n result.unitary = unitaryMatrix.toTarget(result.unitary);\n result.diagonal = diagonalMatrix.toTarget(result.diagonal);\n\n return result;\n}\n\nfunction computeFrobeniusNorm(matrix) {\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":["Matrix3","_MathUtils","scratchMatrix","scratchUnitary","scratchDiagonal","jMatrix","jMatrixTranspose","computeEigenDecomposition","matrix","result","EIGEN_TOLERANCE","EPSILON20","EIGEN_MAX_SWEEPS","count","sweep","unitaryMatrix","diagonalMatrix","identity","copy","epsilon","computeFrobeniusNorm","offDiagonalFrobeniusNorm","shurDecomposition","transpose","multiplyRight","multiplyLeft","unitary","toTarget","diagonal","norm","i","temp","Math","sqrt","rowVal","colVal","getElementIndex","tolerance","EPSILON15","maxDiagonal","rotAxis","abs","p","q","c","s","qq","pp","qp","tau","t","IDENTITY","to"],"mappings":"AAGA,SAAQA,OAAR,EAAiBC,UAAjB,QAAkC,eAAlC;AAEA,MAAMC,aAAa,GAAG,IAAIF,OAAJ,EAAtB;AACA,MAAMG,cAAc,GAAG,IAAIH,OAAJ,EAAvB;AACA,MAAMI,eAAe,GAAG,IAAIJ,OAAJ,EAAxB;AAEA,MAAMK,OAAO,GAAG,IAAIL,OAAJ,EAAhB;AACA,MAAMM,gBAAgB,GAAG,IAAIN,OAAJ,EAAzB;AAqCA,eAAe,SAASO,yBAAT,CACbC,MADa,EAGbC,MAA0B,GAAG,EAHhB,EAIO;AACpB,QAAMC,eAAe,GAAGT,UAAU,CAACU,SAAnC;AACA,QAAMC,gBAAgB,GAAG,EAAzB;AAEA,MAAI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CAAjC,CAAD,CAAN,GAA8CjC,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BO,CAA9B,EAAiCA,CAAjC,CAAD,CAAN,GAA8CC,CAA5F;AACAnC,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BO,CAA9B,EAAiCD,CAAjC,CAAD,CAAN,GAA8CG,CAA9C;AACApC,EAAAA,MAAM,CAACP,aAAa,CAACkC,eAAd,CAA8BM,CAA9B,EAAiCC,CAAjC,CAAD,CAAN,GAA8C,CAACE,CAA/C;AAEA,SAAOpC,MAAP;AACD","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Matrix3, _MathUtils} from '@math.gl/core';\n\nconst scratchMatrix = new Matrix3();\nconst scratchUnitary = new Matrix3();\nconst scratchDiagonal = new Matrix3();\n\nconst jMatrix = new Matrix3();\nconst jMatrixTranspose = new Matrix3();\n\nexport type EigenDecomposition = {\n unitary: Matrix3;\n diagonal: Matrix3;\n};\n\n/**\n * Computes the eigenvectors and eigenvalues of a symmetric matrix.\n *\n * - Returns a diagonal matrix and unitary matrix such that:\n * `matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)`\n * - The values along the diagonal of the diagonal matrix are the eigenvalues. The columns\n * of the unitary matrix are the corresponding eigenvectors.\n * - This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n * section 8.4.3 The Classical Jacobi Algorithm\n *\n * @param matrix The 3x3 matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.\n * @param result Optional object with unitary and diagonal properties which are matrices onto which to store the result.\n * @returns An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.\n *\n * @example\n * const a = //... symmetric matrix\n * const result = {\n * unitary : new Matrix3(),\n * diagonal : new Matrix3()\n * };\n * computeEigenDecomposition(a, result);\n *\n * const unitaryTranspose = Matrix3.transpose(result.unitary, new Matrix3());\n * const b = Matrix3.multiply(result.unitary, result.diagonal, new Matrix3());\n * Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a\n *\n * const lambda = result.diagonal.getColumn(0, new Vector3()).x; // first eigenvalue\n * const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector\n * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)\n */\nexport default function computeEigenDecomposition(\n matrix: number[],\n // @ts-expect-error accept empty object type\n result: EigenDecomposition = {}\n): EigenDecomposition {\n const EIGEN_TOLERANCE = _MathUtils.EPSILON20;\n const EIGEN_MAX_SWEEPS = 10;\n\n let count = 0;\n let sweep = 0;\n\n const unitaryMatrix = scratchUnitary;\n const diagonalMatrix = scratchDiagonal;\n\n unitaryMatrix.identity();\n diagonalMatrix.copy(matrix);\n\n const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);\n\n while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {\n shurDecomposition(diagonalMatrix, jMatrix);\n\n jMatrixTranspose.copy(jMatrix).transpose();\n\n diagonalMatrix.multiplyRight(jMatrix);\n diagonalMatrix.multiplyLeft(jMatrixTranspose);\n unitaryMatrix.multiplyRight(jMatrix);\n\n if (++count > 2) {\n ++sweep;\n count = 0;\n }\n }\n\n result.unitary = unitaryMatrix.toTarget(result.unitary);\n result.diagonal = diagonalMatrix.toTarget(result.diagonal);\n\n return result;\n}\n\nfunction computeFrobeniusNorm(matrix: Matrix3): number {\n let norm = 0.0;\n for (let i = 0; i < 9; ++i) {\n const temp = matrix[i];\n norm += temp * temp;\n }\n return Math.sqrt(norm);\n}\n\nconst rowVal = [1, 0, 0];\nconst colVal = [2, 2, 1];\n\n// Computes the \"off-diagonal\" Frobenius norm.\n// Assumes matrix is symmetric.\nfunction offDiagonalFrobeniusNorm(matrix: Matrix3): number {\n let norm = 0.0;\n for (let i = 0; i < 3; ++i) {\n const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];\n norm += 2.0 * temp * temp;\n }\n return Math.sqrt(norm);\n}\n\n// The routine takes a matrix, which is assumed to be symmetric, and\n// finds the largest off-diagonal term, and then creates\n// a matrix (result) which can be used to help reduce it\n//\n// This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,\n// section 8.4.2 The 2by2 Symmetric Schur Decomposition.\n//\n// eslint-disable-next-line max-statements\nfunction shurDecomposition(matrix: Matrix3, result: Matrix3): Matrix3 {\n const tolerance = _MathUtils.EPSILON15;\n\n let maxDiagonal = 0.0;\n let rotAxis = 1;\n\n // find pivot (rotAxis) based on max diagonal of matrix\n for (let i = 0; i < 3; ++i) {\n const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);\n if (temp > maxDiagonal) {\n rotAxis = i;\n maxDiagonal = temp;\n }\n }\n\n const p = rowVal[rotAxis];\n const q = colVal[rotAxis];\n\n let c = 1.0;\n let s = 0.0;\n\n if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {\n const qq = matrix[scratchMatrix.getElementIndex(q, q)];\n const pp = matrix[scratchMatrix.getElementIndex(p, p)];\n const qp = matrix[scratchMatrix.getElementIndex(q, p)];\n\n const tau = (qq - pp) / 2.0 / qp;\n let t;\n\n if (tau < 0.0) {\n t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));\n } else {\n t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));\n }\n\n c = 1.0 / Math.sqrt(1.0 + t * t);\n s = t * c;\n }\n\n // Copy into result\n Matrix3.IDENTITY.to(result);\n result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;\n result[scratchMatrix.getElementIndex(q, p)] = s;\n result[scratchMatrix.getElementIndex(p, q)] = -s;\n\n return result;\n}\n"],"file":"compute-eigen-decomposition.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":["Vector3","INTERSECTION","scratchVector","scratchNormal","AxisAlignedBoundingBox","constructor","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","clone","equals","right","Boolean","transform","transformAsPoint","intersectPlane","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INSIDE","OUTSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","distanceSquared","d"],"mappings":";AACA,SAAQA,OAAR,QAAsB,eAAtB;AAEA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,MAAMC,aAAa,GAAG,IAAIF,OAAJ,EAAtB;AACA,MAAMG,aAAa,GAAG,IAAIH,OAAJ,EAAtB;AAQA,eAAe,MAAMI,sBAAN,CAAuD;AAgBpEC,EAAAA,WAAW,CACTC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CADpB,EAETC,OAA0B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAFpB,EAGTC,MAHS,EAIT;AAAA;;AAAA;;AAAA;;AAAA;;AAEAA,IAAAA,MAAM,GAAGA,MAAM,IAAIN,aAAa,CAACO,IAAd,CAAmBH,OAAnB,EAA4BI,GAA5B,CAAgCH,OAAhC,EAAyCI,KAAzC,CAA+C,GAA/C,CAAnB;AACA,SAAKH,MAAL,GAAc,IAAIR,OAAJ,CAAYQ,MAAZ,CAAd;AACA,SAAKI,YAAL,GAAoB,IAAIZ,OAAJ,CAAYO,OAAZ,EAAqBM,QAArB,CAA8B,KAAKL,MAAnC,CAApB;AAOA,SAAKF,OAAL,GAAe,IAAIN,OAAJ,CAAYM,OAAZ,CAAf;AAOA,SAAKC,OAAL,GAAe,IAAIP,OAAJ,CAAYO,OAAZ,CAAf;AACD;;AAODO,EAAAA,KAAK,GAAG;AACN,WAAO,IAAIV,sBAAJ,CAA2B,KAAKE,OAAhC,EAAyC,KAAKC,OAA9C,EAAuD,KAAKC,MAA5D,CAAP;AACD;;AASDO,EAAAA,MAAM,CAACC,KAAD,EAAQ;AACZ,WACE,SAASA,KAAT,IACCC,OAAO,C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,IAAI,CAACY,IAAL,CAAU,KAAKC,iBAAL,CAAuBF,KAAvB,CAAV,CAAP;AACD;;AAGDE,EAAAA,iBAAiB,CAACF,KAAD,EAAmC;AAClD,UAAMG,MAAM,GAAGtC,aAAa,CAACqB,IAAd,CAAmBc,KAAnB,EAA0BxB,QAA1B,CAAmC,KAAKL,MAAxC,CAAf;AACA,UAAM;AAACI,MAAAA;AAAD,QAAiB,IAAvB;AAEA,QAAI6B,eAAe,GAAG,GAAtB;AACA,QAAIC,CAAJ;AAEAA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACf,CAAhB,IAAqBb,YAAY,CAACa,CAAtC;;AACA,QAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBhB,YAAY,CAACgB,CAAtC;;AACA,QAAIc,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACX,CAAhB,IAAqBjB,YAAY,CAACiB,CAAtC;;AACA,QAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,WAAOD,eAAP;AACD;;AAnImE","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone() {\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":["Vector3","INTERSECTION","scratchVector","scratchNormal","AxisAlignedBoundingBox","constructor","minimum","maximum","center","copy","add","scale","halfDiagonal","subtract","clone","equals","right","Boolean","transform","transformAsPoint","intersectPlane","plane","normal","from","e","x","Math","abs","y","z","s","dot","distance","INSIDE","OUTSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","distanceSquared","d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AAmC,KAAKL,MAAxC,CAAf;AACA,UAAM;AAACI,MAAAA;AAAD,QAAiB,IAAvB;AAEA,QAAI6B,eAAe,GAAG,GAAtB;AACA,QAAIC,CAAJ;AAEAA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACf,CAAhB,IAAqBb,YAAY,CAACa,CAAtC;;AACA,QAAIiB,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACZ,CAAhB,IAAqBhB,YAAY,CAACgB,CAAtC;;AACA,QAAIc,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAEDA,IAAAA,CAAC,GAAGhB,IAAI,CAACC,GAAL,CAASa,MAAM,CAACX,CAAhB,IAAqBjB,YAAY,CAACiB,CAAtC;;AACA,QAAIa,CAAC,GAAG,CAAR,EAAW;AACTD,MAAAA,eAAe,IAAIC,CAAC,GAAGA,CAAvB;AACD;;AAED,WAAOD,eAAP;AACD;;AAnImE","sourcesContent":["import {BoundingVolume} from './bounding-volume';\nimport {Vector3} from '@math.gl/core';\nimport Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\n\n/**\n * An axis aligned bounding box - aligned with coordinate axes\n * @see BoundingVolume\n * @see BoundingRectangle\n * @see OrientedBoundingBox\n */\nexport default class AxisAlignedBoundingBox implements BoundingVolume {\n /** The center point of the bounding box. */\n readonly center: Vector3;\n /** The positive half diagonal of the bounding box. */\n readonly halfDiagonal: Vector3;\n /** The minimum point defining the bounding box. [0, 0, 0] for empty box */\n readonly minimum: Vector3;\n /** The maximum point defining the bounding box. [0, 0, 0] for empty box */\n readonly maximum: Vector3;\n\n /**\n * Creates an instance of an AxisAlignedBoundingBox from the minimum and maximum points along the x, y, and z axes.\n * @param minimum=[0, 0, 0] The minimum point along the x, y, and z axes.\n * @param maximum=[0, 0, 0] The maximum point along the x, y, and z axes.\n * @param center The center of the box; automatically computed if not supplied.\n */\n constructor(\n minimum: readonly number[] = [0, 0, 0],\n maximum: readonly number[] = [0, 0, 0],\n center?: readonly number[]\n ) {\n // If center was not defined, compute it.\n center = center || scratchVector.copy(minimum).add(maximum).scale(0.5);\n this.center = new Vector3(center);\n this.halfDiagonal = new Vector3(maximum).subtract(this.center);\n\n /**\n * The minimum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.minimum = new Vector3(minimum);\n\n /**\n * The maximum point defining the bounding box.\n * @type {Vector3}\n * @default {@link 0, 0, 0}\n */\n this.maximum = new Vector3(maximum);\n }\n\n /**\n * Duplicates a AxisAlignedBoundingBox instance.\n *\n * @returns {AxisAlignedBoundingBox} A new AxisAlignedBoundingBox instance.\n */\n clone(): AxisAlignedBoundingBox {\n return new AxisAlignedBoundingBox(this.minimum, this.maximum, this.center);\n }\n\n /**\n * Compares the provided AxisAlignedBoundingBox componentwise and returns\n * <code>true</code> if they are equal, <code>false</code> otherwise.\n *\n * @param {AxisAlignedBoundingBox} [right] The second AxisAlignedBoundingBox to compare with.\n * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.\n */\n equals(right: AxisAlignedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.minimum.equals(right.minimum) && this.maximum.equals(right.maximum))\n );\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transform: readonly number[]): this {\n this.center.transformAsPoint(transform);\n // TODO - this.halfDiagonal.transformAsVector(transform);\n this.halfDiagonal.transform(transform);\n this.minimum.transform(transform);\n this.maximum.transform(transform);\n return this;\n }\n\n /**\n * Determines which side of a plane a box is located.\n */\n intersectPlane(plane: Plane): 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":["Vector3","Matrix3","Quaternion","BoundingSphere","INTERSECTION","scratchVector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","constructor","center","halfAxes","from","halfSize","xAxis","getColumn","yAxis","zAxis","len","quaternion","normXAxis","normalize","normYAxis","normZAxis","fromMatrix3","fromCenterHalfSizeQuaternion","quaternionObject","directionsMatrix","fromQuaternion","clone","equals","right","Boolean","getBoundingSphere","result","u","v","w","cornerVector","copy","add","radius","magnitude","intersectPlane","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","OUTSIDE","INSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","computePlaneDistances","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transform","transformation","transformAsPoint","getTransform","Error"],"mappings":";AAGA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,UAA1B,QAAyD,eAAzD;AAEA,OAAOC,cAAP,MAA2B,mBAA3B;AAEA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,aAAa,GAAG,IAAIN,OAAJ,EAAtB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA,MAAMQ,cAAc,GAAG,IAAIR,OAAJ,EAAvB;AACA,MAAMS,cAAc,GAAG,IAAIT,OAAJ,EAAvB;AACA,MAAMU,aAAa,GAAG,IAAIV,OAAJ,EAAtB;AACA,MAAMW,eAAe,GAAG,IAAIX,OAAJ,EAAxB;AAEA,MAAMY,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;AAiBA,eAAe,MAAMC,mBAAN,CAAoD;AAUjEC,EAAAA,WAAW,CAACC,MAA8B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAA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A,KAAK,CAACyE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMtE,KAAK,GAAG,KAAKL,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BrB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACuE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMrE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BpB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACsE,gBAAN,CAAuBD,cAAvB;AAEA,SAAK3E,QAAL,GAAgB,IAAIxB,OAAJ,CAAY,CAAC,GAAG2B,KAAJ,EAAW,GAAGE,KAAd,EAAqB,GAAGC,KAAxB,CAAZ,CAAhB;AACA,WAAO,IAAP;AACD;;AAEDuE,EAAAA,YAAY,GAAG;AAGb,UAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;AACD;;AApTgE","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, 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":["Vector3","Matrix3","Quaternion","BoundingSphere","INTERSECTION","scratchVector3","scratchOffset","scratchVectorU","scratchVectorV","scratchVectorW","scratchCorner","scratchToCenter","MATRIX3","COLUMN0ROW0","COLUMN0ROW1","COLUMN0ROW2","COLUMN1ROW0","COLUMN1ROW1","COLUMN1ROW2","COLUMN2ROW0","COLUMN2ROW1","COLUMN2ROW2","OrientedBoundingBox","constructor","center","halfAxes","from","halfSize","xAxis","getColumn","yAxis","zAxis","len","quaternion","normXAxis","normalize","normYAxis","normZAxis","fromMatrix3","fromCenterHalfSizeQuaternion","quaternionObject","directionsMatrix","fromQuaternion","clone","equals","right","Boolean","getBoundingSphere","result","u","v","w","cornerVector","copy","add","radius","magnitude","intersectPlane","plane","normal","normalX","x","normalY","y","normalZ","z","radEffective","Math","abs","distanceToPlane","dot","distance","OUTSIDE","INSIDE","INTERSECTING","distanceTo","point","sqrt","distanceSquaredTo","offset","subtract","uHalf","vHalf","wHalf","distanceSquared","d","computePlaneDistances","position","direction","minDist","Number","POSITIVE_INFINITY","maxDist","NEGATIVE_INFINITY","corner","toCenter","mag","min","max","transform","transformation","transformAsPoint","getTransform","Error"],"mappings":";AAGA,SAAQA,OAAR,EAAiBC,OAAjB,EAAmCC,UAAnC,QAAkE,eAAlE;AAEA,OAAOC,cAAP,MAA2B,mBAA3B;AAEA,SAAQC,YAAR,QAA2B,iBAA3B;AAEA,MAAMC,cAAc,GAAG,IAAIL,OAAJ,EAAvB;AACA,MAAMM,aAAa,GAAG,IAAIN,OAAJ,EAAtB;AACA,MAAMO,cAAc,GAAG,IAAIP,OAAJ,EAAvB;AACA,MAAMQ,cAAc,GAAG,IAAIR,OAAJ,EAAvB;AACA,MAAMS,cAAc,GAAG,IAAIT,OAAJ,EAAvB;AACA,MAAMU,aAAa,GAAG,IAAIV,OAAJ,EAAtB;AACA,MAAMW,eAAe,GAAG,IAAIX,OAAJ,EAAxB;AAEA,MAAMY,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;AAiBA,eAAe,MAAMC,mBAAN,CAAoD;AAUjEC,EAAAA,WAAW,CAACC,MAA8B,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAlC,EAA6CC,QAAQ,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,C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wB,CAAxB,EAA2BrB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACuE,gBAAN,CAAuBD,cAAvB;AAEA,UAAMrE,KAAK,GAAG,KAAKN,QAAL,CAAcI,SAAd,CAAwB,CAAxB,EAA2BpB,cAA3B,CAAd;AACAsB,IAAAA,KAAK,CAACsE,gBAAN,CAAuBD,cAAvB;AAEA,SAAK3E,QAAL,GAAgB,IAAIxB,OAAJ,CAAY,CAAC,GAAG2B,KAAJ,EAAW,GAAGE,KAAd,EAAqB,GAAGC,KAAxB,CAAZ,CAAhB;AACA,WAAO,IAAP;AACD;;AAEDuE,EAAAA,YAAY,GAAY;AAGtB,UAAM,IAAIC,KAAJ,CAAU,iBAAV,CAAN;AACD;;AApTgE","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nimport {Vector3, Matrix3, Matrix4, Quaternion, NumericArray} from '@math.gl/core';\nimport type {BoundingVolume} from './bounding-volume';\nimport BoundingSphere from './bounding-sphere';\nimport type Plane from '../plane';\nimport {INTERSECTION} from '../../constants';\n\nconst scratchVector3 = new Vector3();\nconst scratchOffset = new Vector3();\nconst scratchVectorU = new Vector3();\nconst scratchVectorV = new Vector3();\nconst scratchVectorW = new Vector3();\nconst scratchCorner = new Vector3();\nconst scratchToCenter = new Vector3();\n\nconst MATRIX3 = {\n COLUMN0ROW0: 0,\n COLUMN0ROW1: 1,\n COLUMN0ROW2: 2,\n COLUMN1ROW0: 3,\n COLUMN1ROW1: 4,\n COLUMN1ROW2: 5,\n COLUMN2ROW0: 6,\n COLUMN2ROW1: 7,\n COLUMN2ROW2: 8\n};\n\n/**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than `BoundingSphere` or\n * `AxisAlignedBoundingBox` in many cases.\n */\nexport default class OrientedBoundingBox implements BoundingVolume {\n center: Vector3;\n halfAxes: Matrix3;\n\n /**\n * An OrientedBoundingBox of some object is a closed and convex cuboid.\n * It can provide a tighter bounding volume than\n * `BoundingSphere` or `AxisAlignedBoundingBox` in many cases.\n */\n constructor(center?: readonly number[], halfAxes?: readonly number[]);\n constructor(center: Readonly<NumericArray> = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {\n this.center = new Vector3().from(center);\n this.halfAxes = new Matrix3(halfAxes);\n }\n\n /** Returns an array with three halfSizes for the bounding box */\n get halfSize(): number[] {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n return [new Vector3(xAxis).len(), new Vector3(yAxis).len(), new Vector3(zAxis).len()];\n }\n\n /** Returns a quaternion describing the orientation of the bounding box */\n get quaternion(): Quaternion {\n const xAxis = this.halfAxes.getColumn(0);\n const yAxis = this.halfAxes.getColumn(1);\n const zAxis = this.halfAxes.getColumn(2);\n const normXAxis = new Vector3(xAxis).normalize();\n const normYAxis = new Vector3(yAxis).normalize();\n const normZAxis = new Vector3(zAxis).normalize();\n return new Quaternion().fromMatrix3(new Matrix3([...normXAxis, ...normYAxis, ...normZAxis]));\n }\n\n /**\n * Create OrientedBoundingBox from quaternion based OBB,\n */\n fromCenterHalfSizeQuaternion(\n center: number[],\n halfSize: number[],\n quaternion: number[]\n ): OrientedBoundingBox {\n const quaternionObject = new Quaternion(quaternion);\n const directionsMatrix = new Matrix3().fromQuaternion(quaternionObject);\n directionsMatrix[0] = directionsMatrix[0] * halfSize[0];\n directionsMatrix[1] = directionsMatrix[1] * halfSize[0];\n directionsMatrix[2] = directionsMatrix[2] * halfSize[0];\n directionsMatrix[3] = directionsMatrix[3] * halfSize[1];\n directionsMatrix[4] = directionsMatrix[4] * halfSize[1];\n directionsMatrix[5] = directionsMatrix[5] * halfSize[1];\n directionsMatrix[6] = directionsMatrix[6] * halfSize[2];\n directionsMatrix[7] = directionsMatrix[7] * halfSize[2];\n directionsMatrix[8] = directionsMatrix[8] * halfSize[2];\n this.center = new Vector3().from(center);\n this.halfAxes = directionsMatrix;\n return this;\n }\n\n /** Duplicates a OrientedBoundingBox instance. */\n clone(): OrientedBoundingBox {\n return new OrientedBoundingBox(this.center, this.halfAxes);\n }\n\n /** Compares the provided OrientedBoundingBox component wise and returns */\n equals(right: OrientedBoundingBox): boolean {\n return (\n this === right ||\n (Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes))\n );\n }\n\n /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */\n getBoundingSphere(result = new BoundingSphere()): BoundingSphere {\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // Calculate \"corner\" vector\n const cornerVector = scratchVector3.copy(u).add(v).add(w);\n\n result.center.copy(this.center);\n result.radius = cornerVector.magnitude();\n\n return result;\n }\n\n /** Determines which side of a plane the oriented bounding box is located. */\n intersectPlane(plane: Plane): INTERSECTION {\n const center = this.center;\n const normal = plane.normal;\n const halfAxes = this.halfAxes;\n\n const normalX = normal.x;\n const normalY = normal.y;\n const normalZ = normal.z;\n\n // Plane is used as if it is its normal; the first three components are assumed to be normalized\n const radEffective =\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN0ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN0ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN0ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN1ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN1ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN1ROW2]\n ) +\n Math.abs(\n normalX * halfAxes[MATRIX3.COLUMN2ROW0] +\n normalY * halfAxes[MATRIX3.COLUMN2ROW1] +\n normalZ * halfAxes[MATRIX3.COLUMN2ROW2]\n );\n const distanceToPlane = normal.dot(center) + plane.distance;\n\n if (distanceToPlane <= -radEffective) {\n // The entire box is on the negative side of the plane normal\n return INTERSECTION.OUTSIDE;\n } else if (distanceToPlane >= radEffective) {\n // The entire box is on the positive side of the plane normal\n return INTERSECTION.INSIDE;\n }\n return INTERSECTION.INTERSECTING;\n }\n\n /** Computes the estimated distance from the closest point on a bounding box to a point. */\n distanceTo(point: readonly number[]): number {\n return Math.sqrt(this.distanceSquaredTo(point));\n }\n\n /**\n * Computes the estimated distance squared from the closest point\n * on a bounding box to a point.\n * See Geometric Tools for Computer Graphics 10.4.2\n */\n distanceSquaredTo(point: readonly number[]): number {\n // Computes the estimated distance squared from the\n // closest point on a bounding box to a point.\n // See Geometric Tools for Computer Graphics 10.4.2\n const offset = scratchOffset.from(point).subtract(this.center);\n\n const halfAxes = this.halfAxes;\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n const uHalf = u.magnitude();\n const vHalf = v.magnitude();\n const wHalf = w.magnitude();\n\n u.normalize();\n v.normalize();\n w.normalize();\n\n let distanceSquared = 0.0;\n let d;\n\n d = Math.abs(offset.dot(u)) - uHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(v)) - vHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n d = Math.abs(offset.dot(w)) - wHalf;\n if (d > 0) {\n distanceSquared += d * d;\n }\n\n return distanceSquared;\n }\n\n /**\n * The distances calculated by the vector from the center of the bounding box\n * to position projected onto direction.\n *\n * - If you imagine the infinite number of planes with normal direction,\n * this computes the smallest distance to the closest and farthest planes\n * from `position` that intersect the bounding box.\n *\n * @param position The position to calculate the distance from.\n * @param direction The direction from position.\n * @param result An Interval (array of length 2) to store the nearest and farthest distances.\n * @returns Interval (array of length 2) with nearest and farthest distances\n * on the bounding box from position in direction.\n */\n // eslint-disable-next-line max-statements\n computePlaneDistances(\n position: readonly number[],\n direction: Vector3,\n result: number[] = [-0, -0]\n ): number[] {\n let minDist = Number.POSITIVE_INFINITY;\n let maxDist = Number.NEGATIVE_INFINITY;\n\n const center = this.center;\n const halfAxes = this.halfAxes;\n\n const u = halfAxes.getColumn(0, scratchVectorU);\n const v = halfAxes.getColumn(1, scratchVectorV);\n const w = halfAxes.getColumn(2, scratchVectorW);\n\n // project first corner\n const corner = scratchCorner.copy(u).add(v).add(w).add(center);\n\n const toCenter = scratchToCenter.copy(corner).subtract(position);\n let mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project second corner\n corner.copy(center).add(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project third corner\n corner.copy(center).add(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fourth corner\n corner.copy(center).add(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project fifth corner\n center.copy(corner).subtract(u).add(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project sixth corner\n center.copy(corner).subtract(u).add(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project seventh corner\n center.copy(corner).subtract(u).subtract(v).add(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n // project eighth corner\n center.copy(corner).subtract(u).subtract(v).subtract(w);\n\n toCenter.copy(corner).subtract(position);\n mag = direction.dot(toCenter);\n\n minDist = Math.min(mag, minDist);\n maxDist = Math.max(mag, maxDist);\n\n result[0] = minDist;\n result[1] = maxDist;\n return result;\n }\n\n /**\n * Applies a 4x4 affine transformation matrix to a bounding sphere.\n * @param transform The transformation matrix to apply to the bounding sphere.\n * @returns itself, i.e. the modified BoundingVolume.\n */\n transform(transformation: readonly number[]): this {\n this.center.transformAsPoint(transformation);\n\n const xAxis = this.halfAxes.getColumn(0, scratchVectorU);\n xAxis.transformAsPoint(transformation);\n\n const yAxis = this.halfAxes.getColumn(1, scratchVectorV);\n yAxis.transformAsPoint(transformation);\n\n const zAxis = this.halfAxes.getColumn(2, scratchVectorW);\n zAxis.transformAsPoint(transformation);\n\n this.halfAxes = new Matrix3([...xAxis, ...yAxis, ...zAxis]);\n return this;\n }\n\n getTransform(): Matrix4 {\n // const modelMatrix = Matrix4.fromRotationTranslation(this.boundingVolume.halfAxes, this.boundingVolume.center);\n // return modelMatrix;\n throw new Error('not implemented');\n }\n}\n"],"file":"oriented-bounding-box.js"}
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- import { assert } from '@math.gl/core';
2
+ import { assert, Vector2 } from '@math.gl/core';
3
3
  import PerspectiveOffCenterFrustum from './perspective-off-center-frustum';
4
4
 
5
5
  const defined = val => val !== null && typeof val !== 'undefined';
@@ -36,23 +36,20 @@ export default class PerspectiveFrustum {
36
36
 
37
37
  _defineProperty(this, "_yOffset", void 0);
38
38
 
39
- options = {
40
- near: 1.0,
41
- far: 500000000.0,
42
- xOffset: 0.0,
43
- yOffset: 0.0,
44
- ...options
45
- };
46
- this.fov = options.fov;
47
- this.aspectRatio = options.aspectRatio;
48
- this.near = options.near;
49
- this._near = this.near;
50
- this.far = options.far;
51
- this._far = this.far;
52
- this.xOffset = options.xOffset;
53
- this._xOffset = this.xOffset;
54
- this.yOffset = options.yOffset;
55
- this._yOffset = this.yOffset;
39
+ const {
40
+ fov,
41
+ aspectRatio,
42
+ near = 1.0,
43
+ far = 500000000.0,
44
+ xOffset = 0.0,
45
+ yOffset = 0.0
46
+ } = options;
47
+ this.fov = fov;
48
+ this.aspectRatio = aspectRatio;
49
+ this.near = near;
50
+ this.far = far;
51
+ this.xOffset = xOffset;
52
+ this.yOffset = yOffset;
56
53
  }
57
54
 
58
55
  clone() {
@@ -69,69 +66,77 @@ export default class PerspectiveFrustum {
69
66
  return false;
70
67
  }
71
68
 
72
- update(this);
73
- update(other);
69
+ this._update();
70
+
71
+ other._update();
72
+
74
73
  return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum);
75
74
  }
76
75
 
77
76
  get projectionMatrix() {
78
- update(this);
77
+ this._update();
78
+
79
79
  return this._offCenterFrustum.projectionMatrix;
80
80
  }
81
81
 
82
82
  get infiniteProjectionMatrix() {
83
- update(this);
83
+ this._update();
84
+
84
85
  return this._offCenterFrustum.infiniteProjectionMatrix;
85
86
  }
86
87
 
87
88
  get fovy() {
88
- update(this);
89
+ this._update();
90
+
89
91
  return this._fovy;
90
92
  }
91
93
 
92
94
  get sseDenominator() {
93
- update(this);
95
+ this._update();
96
+
94
97
  return this._sseDenominator;
95
98
  }
96
99
 
97
100
  computeCullingVolume(position, direction, up) {
98
- update(this);
101
+ this._update();
102
+
99
103
  return this._offCenterFrustum.computeCullingVolume(position, direction, up);
100
104
  }
101
105
 
102
106
  getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
103
- update(this);
104
- return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result);
105
- }
107
+ this._update();
106
108
 
107
- }
109
+ return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result || new Vector2());
110
+ }
108
111
 
109
- function update(frustum) {
110
- assert(Number.isFinite(frustum.fov) && Number.isFinite(frustum.aspectRatio) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far));
111
- const f = frustum._offCenterFrustum;
112
-
113
- 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) {
114
- assert(frustum.fov >= 0 && frustum.fov < Math.PI);
115
- assert(frustum.aspectRatio > 0);
116
- assert(frustum.near >= 0 && frustum.near < frustum.far);
117
- frustum._aspectRatio = frustum.aspectRatio;
118
- frustum._fov = frustum.fov;
119
- frustum._fovy = frustum.aspectRatio <= 1 ? frustum.fov : Math.atan(Math.tan(frustum.fov * 0.5) / frustum.aspectRatio) * 2.0;
120
- frustum._near = frustum.near;
121
- frustum._far = frustum.far;
122
- frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);
123
- frustum._xOffset = frustum.xOffset;
124
- frustum._yOffset = frustum.yOffset;
125
- f.top = frustum.near * Math.tan(0.5 * frustum._fovy);
126
- f.bottom = -f.top;
127
- f.right = frustum.aspectRatio * f.top;
128
- f.left = -f.right;
129
- f.near = frustum.near;
130
- f.far = frustum.far;
131
- f.right += frustum.xOffset;
132
- f.left += frustum.xOffset;
133
- f.top += frustum.yOffset;
134
- f.bottom += frustum.yOffset;
112
+ _update() {
113
+ assert(Number.isFinite(this.fov) && Number.isFinite(this.aspectRatio) && Number.isFinite(this.near) && Number.isFinite(this.far));
114
+ const f = this._offCenterFrustum;
115
+
116
+ 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) {
117
+ assert(this.fov >= 0 && this.fov < Math.PI);
118
+ assert(this.aspectRatio > 0);
119
+ assert(this.near >= 0 && this.near < this.far);
120
+ this._aspectRatio = this.aspectRatio;
121
+ this._fov = this.fov;
122
+ this._fovy = this.aspectRatio <= 1 ? this.fov : Math.atan(Math.tan(this.fov * 0.5) / this.aspectRatio) * 2.0;
123
+ this._near = this.near;
124
+ this._far = this.far;
125
+ this._sseDenominator = 2.0 * Math.tan(0.5 * this._fovy);
126
+ this._xOffset = this.xOffset;
127
+ this._yOffset = this.yOffset;
128
+ f.top = this.near * Math.tan(0.5 * this._fovy);
129
+ f.bottom = -f.top;
130
+ f.right = this.aspectRatio * f.top;
131
+ f.left = -f.right;
132
+ f.near = this.near;
133
+ f.far = this.far;
134
+ f.right += this.xOffset;
135
+ f.left += this.xOffset;
136
+ f.top += this.yOffset;
137
+ f.bottom += this.yOffset;
138
+ }
135
139
  }
140
+
136
141
  }
137
142
  //# sourceMappingURL=perspective-frustum.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/perspective-frustum.ts"],"names":["assert","PerspectiveOffCenterFrustum","defined","val","PerspectiveFrustum","constructor","options","near","far","xOffset","yOffset","fov","aspectRatio","_near","_far","_xOffset","_yOffset","clone","equals","other","update","_offCenterFrustum","projectionMatrix","infiniteProjectionMatrix","fovy","_fovy","sseDenominator","_sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","frustum","Number","isFinite","f","_fov","_aspectRatio","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";AASA,SAAQA,MAAR,QAA8B,eAA9B;AACA,OAAOC,2BAAP,MAAwC,kCAAxC;;AAEA,MAAMC,OAAO,GAAIC,GAAD,IAASA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAxD;;AA6BA,eAAe,MAAMC,kBAAN,CAAyB;AAyCtCC,EAAAA,WAAW,CAACC,OAA4B,GAAG,EAAhC,EAAoC;AAAA,+CAxC3B,IAAIL,2BAAJ,EAwC2B;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAC7CK,IAAAA,OAAO,GAAG;AACRC,MAAAA,IAAI,EAAE,GADE;AAERC,MAAAA,GAAG,EAAE,WAFG;AAGRC,MAAAA,OAAO,EAAE,GAHD;AAIRC,MAAAA,OAAO,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B,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACZ,KAAvB,CAAhC;AACAY,IAAAA,OAAO,CAACtB,QAAR,GAAmBsB,OAAO,CAAC5B,OAA3B;AACA4B,IAAAA,OAAO,CAACrB,QAAR,GAAmBqB,OAAO,CAAC3B,OAA3B;AAEA8B,IAAAA,CAAC,CAACO,GAAF,GAAQV,OAAO,CAAC9B,IAAR,GAAeoC,IAAI,CAACG,GAAL,CAAS,MAAMT,OAAO,CAACZ,KAAvB,CAAvB;AACAe,IAAAA,CAAC,CAACQ,MAAF,GAAW,CAACR,CAAC,CAACO,GAAd;AACAP,IAAAA,CAAC,CAACS,KAAF,GAAUZ,OAAO,CAACzB,WAAR,GAAsB4B,CAAC,CAACO,GAAlC;AACAP,IAAAA,CAAC,CAACU,IAAF,GAAS,CAACV,CAAC,CAACS,KAAZ;AACAT,IAAAA,CAAC,CAACjC,IAAF,GAAS8B,OAAO,CAAC9B,IAAjB;AACAiC,IAAAA,CAAC,CAAChC,GAAF,GAAQ6B,OAAO,CAAC7B,GAAhB;AAEAgC,IAAAA,CAAC,CAACS,KAAF,IAAWZ,OAAO,CAAC5B,OAAnB;AACA+B,IAAAA,CAAC,CAACU,IAAF,IAAUb,OAAO,CAAC5B,OAAlB;AACA+B,IAAAA,CAAC,CAACO,GAAF,IAASV,OAAO,CAAC3B,OAAjB;AACA8B,IAAAA,CAAC,CAACQ,MAAF,IAAYX,OAAO,CAAC3B,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":["assert","Vector2","PerspectiveOffCenterFrustum","defined","val","PerspectiveFrustum","constructor","options","fov","aspectRatio","near","far","xOffset","yOffset","clone","equals","other","_update","_offCenterFrustum","projectionMatrix","infiniteProjectionMatrix","fovy","_fovy","sseDenominator","_sseDenominator","computeCullingVolume","position","direction","up","getPixelDimensions","drawingBufferWidth","drawingBufferHeight","distance","result","Number","isFinite","f","_fov","_aspectRatio","_near","_far","_xOffset","_yOffset","Math","PI","atan","tan","top","bottom","right","left"],"mappings":";AAOA,SAAQA,MAAR,EAAuCC,OAAvC,QAAqD,eAArD;AACA,OAAOC,2BAAP,MAAwC,kCAAxC;;AAGA,MAAMC,OAAO,GAAIC,GAAD,IAASA,GAAG,KAAK,IAAR,IAAgB,OAAOA,GAAP,KAAe,WAAxD;;AAmCA,eAAe,MAAMC,kBAAN,CAAyB;AAyCtCC,EAAAA,WAAW,CAACC,OAAkC,GAAG,EAAtC,EAA0C;AAAA,+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IAAF,GAAS,CAACd,CAAC,CAACa,KAAZ;AACAb,MAAAA,CAAC,CAAC1B,IAAF,GAAS,KAAKA,IAAd;AACA0B,MAAAA,CAAC,CAACzB,GAAF,GAAQ,KAAKA,GAAb;AAEAyB,MAAAA,CAAC,CAACa,KAAF,IAAW,KAAKrC,OAAhB;AACAwB,MAAAA,CAAC,CAACc,IAAF,IAAU,KAAKtC,OAAf;AACAwB,MAAAA,CAAC,CAACW,GAAF,IAAS,KAAKlC,OAAd;AACAuB,MAAAA,CAAC,CAACY,MAAF,IAAY,KAAKnC,OAAjB;AACD;AACF;;AAzOqC","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"}