@math.gl/culling 3.6.0-alpha.8 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/constants.d.ts +5 -5
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/es5/constants.js +5 -7
  4. package/dist/es5/constants.js.map +1 -1
  5. package/dist/es5/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  6. package/dist/es5/lib/bounding-volumes/bounding-sphere.js.map +1 -1
  7. package/dist/es5/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  8. package/dist/es5/lib/culling-volume.js.map +1 -1
  9. package/dist/esm/constants.js +5 -7
  10. package/dist/esm/constants.js.map +1 -1
  11. package/dist/esm/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
  12. package/dist/esm/lib/bounding-volumes/bounding-sphere.js.map +1 -1
  13. package/dist/esm/lib/bounding-volumes/oriented-bounding-box.js.map +1 -1
  14. package/dist/esm/lib/culling-volume.js.map +1 -1
  15. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +1 -2
  16. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
  17. package/dist/lib/bounding-volumes/bounding-sphere.d.ts +1 -2
  18. package/dist/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -1
  19. package/dist/lib/bounding-volumes/bounding-volume.d.ts +1 -2
  20. package/dist/lib/bounding-volumes/bounding-volume.d.ts.map +1 -1
  21. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts +1 -2
  22. package/dist/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -1
  23. package/dist/lib/culling-volume.d.ts +1 -2
  24. package/dist/lib/culling-volume.d.ts.map +1 -1
  25. package/package.json +3 -3
  26. package/src/constants.ts +5 -5
  27. package/src/lib/bounding-volumes/axis-aligned-bounding-box.ts +1 -1
  28. package/src/lib/bounding-volumes/bounding-sphere.ts +1 -1
  29. package/src/lib/bounding-volumes/bounding-volume.ts +1 -1
  30. package/src/lib/bounding-volumes/oriented-bounding-box.ts +1 -1
  31. package/src/lib/culling-volume.ts +2 -2
  32. package/dist/constants.js +0 -8
  33. package/dist/index.js +0 -13
  34. package/dist/lib/algorithms/bounding-box-from-points.js +0 -131
  35. package/dist/lib/algorithms/bounding-sphere-from-points.js +0 -140
  36. package/dist/lib/algorithms/compute-eigen-decomposition.js +0 -131
  37. package/dist/lib/bounding-volumes/axis-aligned-bounding-box.js +0 -111
  38. package/dist/lib/bounding-volumes/bounding-sphere.js +0 -118
  39. package/dist/lib/bounding-volumes/bounding-volume.js +0 -1
  40. package/dist/lib/bounding-volumes/oriented-bounding-box.js +0 -256
  41. package/dist/lib/culling-volume.js +0 -121
  42. package/dist/lib/perspective-frustum.js +0 -190
  43. package/dist/lib/perspective-off-center-frustum.js +0 -270
  44. package/dist/lib/plane.js +0 -63
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/culling-volume.ts"],"names":["Vector3","assert","INTERSECTION","Plane","faces","scratchPlaneCenter","scratchPlaneNormal","scratchPlane","CullingVolume","constructor","planes","fromBoundingSphere","boundingSphere","length","center","radius","planeIndex","faceNormal","plane0","plane1","plane0Center","copy","scale","add","plane0Distance","dot","fromPointNormal","plane1Center","negatedFaceNormal","negate","plane1Distance","computeVisibility","boundingVolume","intersect","INSIDE","plane","result","intersectPlane","OUTSIDE","INTERSECTING","computeVisibilityWithPlaneMask","parentPlaneMask","Number","isFinite","MASK_OUTSIDE","MASK_INSIDE","mask","k","flag"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,QAA8B,eAA9B;AACA,SAAQC,YAAR,QAA2B,cAA3B;AACA,OAAOC,KAAP,MAAkB,SAAlB;AAKA,MAAMC,KAAK,GAAG,CAAC,IAAIJ,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAD,EAAyB,IAAIA,OAAJ,CAAY,CAAC,CAA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,aAAa,CAACoC,YAAlC,IACAH,eAAe,KAAKjC,aAAa,CAACqC,WAFpC,EAGE;AAEA,aAAOJ,eAAP;AACD;;AAID,QAAIK,IAAI,GAAGtC,aAAa,CAACqC,WAAzB;AAEA,UAAMnC,MAAM,GAAG,KAAKA,MAApB;;AACA,SAAK,IAAIqC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,KAAKrC,MAAL,CAAYG,MAAhC,EAAwC,EAAEkC,CAA1C,EAA6C;AAE3C,YAAMC,IAAI,GAAGD,CAAC,GAAG,EAAJ,GAAS,KAAKA,CAAd,GAAkB,CAA/B;;AACA,UAAIA,CAAC,GAAG,EAAJ,IAAU,CAACN,eAAe,GAAGO,IAAnB,MAA6B,CAA3C,EAA8C;AAE5C;AACD;;AAED,YAAMb,KAAK,GAAGzB,MAAM,CAACqC,CAAD,CAApB;AACA,YAAMX,MAAM,GAAGJ,cAAc,CAACK,cAAf,CAA8BF,KAA9B,CAAf;;AACA,UAAIC,MAAM,KAAKlC,YAAY,CAACoC,OAA5B,EAAqC;AACnC,eAAO9B,aAAa,CAACoC,YAArB;AACD,OAFD,MAEO,IAAIR,MAAM,KAAKlC,YAAY,CAACqC,YAA5B,EAA0C;AAC/CO,QAAAA,IAAI,IAAIE,IAAR;AACD;AACF;;AAED,WAAOF,IAAP;AACD;;AAzIgC;;gBAAdtC,a,kBAKG,U;;gBALHA,a,iBAWE,U;;gBAXFA,a,wBAiBS,U","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Vector3, assert} from '@math.gl/core';\nimport {INTERSECTION} from '../constants';\nimport Plane from './plane';\nimport type {BoundingVolume} from './bounding-volumes/bounding-volume';\nimport type BoundingSphere from './bounding-volumes/bounding-sphere';\n\n// X, Y, Z Unit vectors\nconst faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];\n\nconst scratchPlaneCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\nconst scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);\n\n/** A culling volume defined by planes. */\nexport default class CullingVolume {\n /**\n * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value\n * represents the case where the object bounding volume is entirely outside the culling volume.\n */\n static MASK_OUTSIDE = 0xffffffff;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume is entirely inside the culling volume.\n */\n static MASK_INSIDE = 0x00000000;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume (may) intersect all planes of the culling volume.\n */\n static MASK_INDETERMINATE = 0x7fffffff;\n\n /** Array of clipping planes. */\n readonly planes: Plane[];\n\n /**\n * Create a new `CullingVolume` bounded by an array of clipping planed\n * @param planes Array of clipping planes.\n * */\n constructor(planes: Plane[] = []) {\n this.planes = planes;\n }\n\n /**\n * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.\n * The planes are aligned to the x, y, and z axes in world coordinates.\n */\n fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume {\n this.planes.length = 2 * faces.length;\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let planeIndex = 0;\n\n for (const faceNormal of faces) {\n let plane0 = this.planes[planeIndex];\n let plane1 = this.planes[planeIndex + 1];\n\n if (!plane0) {\n plane0 = this.planes[planeIndex] = new Plane();\n }\n if (!plane1) {\n plane1 = this.planes[planeIndex + 1] = new Plane();\n }\n\n const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);\n const plane0Distance = -faceNormal.dot(plane0Center);\n\n plane0.fromPointNormal(plane0Center, faceNormal);\n\n const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);\n\n const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();\n\n const plane1Distance = -negatedFaceNormal.dot(plane1Center);\n\n plane1.fromPointNormal(plane1Center, negatedFaceNormal);\n\n planeIndex += 2;\n }\n\n return this;\n }\n\n /** Determines whether a bounding volume intersects the culling volume. */\n computeVisibility(boundingVolume: BoundingVolume): INTERSECTION {\n // const planes = this.planes;\n let intersect = INTERSECTION.INSIDE;\n for (const plane of this.planes) {\n const result = boundingVolume.intersectPlane(plane);\n switch (result) {\n case INTERSECTION.OUTSIDE:\n // We are done\n return INTERSECTION.OUTSIDE;\n\n case INTERSECTION.INTERSECTING:\n // If no other intersection is outside, return INTERSECTING\n intersect = INTERSECTION.INTERSECTING;\n break;\n\n default:\n }\n }\n\n return intersect;\n }\n\n /**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling\n * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then\n * the parent (and therefore this) volume is completely inside plane[planeIndex]\n * and that plane check can be skipped.\n */\n computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number {\n assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');\n\n if (\n parentPlaneMask === CullingVolume.MASK_OUTSIDE ||\n parentPlaneMask === CullingVolume.MASK_INSIDE\n ) {\n // parent is completely outside or completely inside, so this child is as well.\n return parentPlaneMask;\n }\n\n // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.\n // (Because if there are fewer than 31 planes, the upper bits wont be changed.)\n let mask = CullingVolume.MASK_INSIDE;\n\n const planes = this.planes;\n for (let k = 0; k < this.planes.length; ++k) {\n // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.\n const flag = k < 31 ? 1 << k : 0;\n if (k < 31 && (parentPlaneMask & flag) === 0) {\n // boundingVolume is known to be INSIDE this plane.\n continue;\n }\n\n const plane = planes[k];\n const result = boundingVolume.intersectPlane(plane);\n if (result === INTERSECTION.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n } else if (result === INTERSECTION.INTERSECTING) {\n mask |= flag;\n }\n }\n\n return mask;\n }\n}\n"],"file":"culling-volume.js"}
1
+ {"version":3,"sources":["../../../src/lib/culling-volume.ts"],"names":["Vector3","assert","INTERSECTION","Plane","faces","scratchPlaneCenter","scratchPlaneNormal","scratchPlane","CullingVolume","constructor","planes","fromBoundingSphere","boundingSphere","length","center","radius","planeIndex","faceNormal","plane0","plane1","plane0Center","copy","scale","add","plane0Distance","dot","fromPointNormal","plane1Center","negatedFaceNormal","negate","plane1Distance","computeVisibility","boundingVolume","intersect","INSIDE","plane","result","intersectPlane","OUTSIDE","INTERSECTING","computeVisibilityWithPlaneMask","parentPlaneMask","Number","isFinite","MASK_OUTSIDE","MASK_INSIDE","mask","k","flag"],"mappings":";AAIA,SAAQA,OAAR,EAAiBC,MAAjB,QAA8B,eAA9B;AACA,SAAQC,YAAR,QAA2B,cAA3B;AACA,OAAOC,KAAP,MAAkB,SAAlB;AAKA,MAAMC,KAAK,GAAG,CAAC,IAAIJ,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAD,EAAyB,IAAIA,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAzB,EAAiD,IAAIA,OAAJ,CAAY,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAZ,CAAjD,CAAd;AAEA,MAAMK,kBAAkB,GAAG,IAAIL,OAAJ,EAA3B;AACA,MAAMM,kBAAkB,GAAG,IAAIN,OAAJ,EAA3B;AACA,MAAMO,YAAY,GAAG,IAAIJ,KAAJ,CAAU,IAAIH,OAAJ,CAAY,GAAZ,EAAiB,GAAjB,EAAsB,GAAtB,CAAV,EAAsC,GAAtC,CAArB;AAGA,eAAe,MAAMQ,aAAN,CAAoB;AA0BjCC,EAAAA,WAAW,CAACC,MAAe,GAAG,EAAnB,EAAuB;AAAA;;AAChC,SAAKA,MAAL,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5C;AACD;;AAED,YAAMb,KAAK,GAAGzB,MAAM,CAACqC,CAAD,CAApB;AACA,YAAMX,MAAM,GAAGJ,cAAc,CAACK,cAAf,CAA8BF,KAA9B,CAAf;;AACA,UAAIC,MAAM,KAAKlC,YAAY,CAACoC,OAA5B,EAAqC;AACnC,eAAO9B,aAAa,CAACoC,YAArB;AACD,OAFD,MAEO,IAAIR,MAAM,KAAKlC,YAAY,CAACqC,YAA5B,EAA0C;AAC/CO,QAAAA,IAAI,IAAIE,IAAR;AACD;AACF;;AAED,WAAOF,IAAP;AACD;;AAzIgC;;gBAAdtC,a,kBAKG,U;;gBALHA,a,iBAWE,U;;gBAXFA,a,wBAiBS,U","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Vector3, assert} from '@math.gl/core';\nimport {INTERSECTION} from '../constants';\nimport Plane from './plane';\nimport type {BoundingVolume} from './bounding-volumes/bounding-volume';\nimport type BoundingSphere from './bounding-volumes/bounding-sphere';\n\n// X, Y, Z Unit vectors\nconst faces = [new Vector3([1, 0, 0]), new Vector3([0, 1, 0]), new Vector3([0, 0, 1])];\n\nconst scratchPlaneCenter = new Vector3();\nconst scratchPlaneNormal = new Vector3();\nconst scratchPlane = new Plane(new Vector3(1.0, 0.0, 0.0), 0.0);\n\n/** A culling volume defined by planes. */\nexport default class CullingVolume {\n /**\n * For plane masks (as used in {@link CullingVolume#computeVisibilityWithPlaneMask}), this special value\n * represents the case where the object bounding volume is entirely outside the culling volume.\n */\n static MASK_OUTSIDE = 0xffffffff;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume is entirely inside the culling volume.\n */\n static MASK_INSIDE = 0x00000000;\n\n /**\n * For plane masks (as used in {@link CullingVolume.prototype.computeVisibilityWithPlaneMask}), this value\n * represents the case where the object bounding volume (may) intersect all planes of the culling volume.\n */\n static MASK_INDETERMINATE = 0x7fffffff;\n\n /** Array of clipping planes. */\n readonly planes: Plane[];\n\n /**\n * Create a new `CullingVolume` bounded by an array of clipping planed\n * @param planes Array of clipping planes.\n * */\n constructor(planes: Plane[] = []) {\n this.planes = planes;\n }\n\n /**\n * Constructs a culling volume from a bounding sphere. Creates six planes that create a box containing the sphere.\n * The planes are aligned to the x, y, and z axes in world coordinates.\n */\n fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume {\n this.planes.length = 2 * faces.length;\n\n const center = boundingSphere.center;\n const radius = boundingSphere.radius;\n\n let planeIndex = 0;\n\n for (const faceNormal of faces) {\n let plane0 = this.planes[planeIndex];\n let plane1 = this.planes[planeIndex + 1];\n\n if (!plane0) {\n plane0 = this.planes[planeIndex] = new Plane();\n }\n if (!plane1) {\n plane1 = this.planes[planeIndex + 1] = new Plane();\n }\n\n const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);\n const plane0Distance = -faceNormal.dot(plane0Center);\n\n plane0.fromPointNormal(plane0Center, faceNormal);\n\n const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);\n\n const negatedFaceNormal = scratchPlaneNormal.copy(faceNormal).negate();\n\n const plane1Distance = -negatedFaceNormal.dot(plane1Center);\n\n plane1.fromPointNormal(plane1Center, negatedFaceNormal);\n\n planeIndex += 2;\n }\n\n return this;\n }\n\n /** Determines whether a bounding volume intersects the culling volume. */\n computeVisibility(boundingVolume: BoundingVolume): number {\n // const planes = this.planes;\n let intersect: number = INTERSECTION.INSIDE;\n for (const plane of this.planes) {\n const result = boundingVolume.intersectPlane(plane);\n switch (result) {\n case INTERSECTION.OUTSIDE:\n // We are done\n return INTERSECTION.OUTSIDE;\n\n case INTERSECTION.INTERSECTING:\n // If no other intersection is outside, return INTERSECTING\n intersect = INTERSECTION.INTERSECTING;\n break;\n\n default:\n }\n }\n\n return intersect;\n }\n\n /**\n * Determines whether a bounding volume intersects the culling volume.\n *\n * @param parentPlaneMask A bit mask from the boundingVolume's parent's check against the same culling\n * volume, such that if (planeMask & (1 << planeIndex) === 0), for k < 31, then\n * the parent (and therefore this) volume is completely inside plane[planeIndex]\n * and that plane check can be skipped.\n */\n computeVisibilityWithPlaneMask(boundingVolume: BoundingVolume, parentPlaneMask: number): number {\n assert(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');\n\n if (\n parentPlaneMask === CullingVolume.MASK_OUTSIDE ||\n parentPlaneMask === CullingVolume.MASK_INSIDE\n ) {\n // parent is completely outside or completely inside, so this child is as well.\n return parentPlaneMask;\n }\n\n // Start with MASK_INSIDE (all zeros) so that after the loop, the return value can be compared with MASK_INSIDE.\n // (Because if there are fewer than 31 planes, the upper bits wont be changed.)\n let mask = CullingVolume.MASK_INSIDE;\n\n const planes = this.planes;\n for (let k = 0; k < this.planes.length; ++k) {\n // For k greater than 31 (since 31 is the maximum number of INSIDE/INTERSECTING bits we can store), skip the optimization.\n const flag = k < 31 ? 1 << k : 0;\n if (k < 31 && (parentPlaneMask & flag) === 0) {\n // boundingVolume is known to be INSIDE this plane.\n continue;\n }\n\n const plane = planes[k];\n const result = boundingVolume.intersectPlane(plane);\n if (result === INTERSECTION.OUTSIDE) {\n return CullingVolume.MASK_OUTSIDE;\n } else if (result === INTERSECTION.INTERSECTING) {\n mask |= flag;\n }\n }\n\n return mask;\n }\n}\n"],"file":"culling-volume.js"}
@@ -1,7 +1,6 @@
1
1
  import { BoundingVolume } from './bounding-volume';
2
2
  import { Vector3 } from '@math.gl/core';
3
3
  import Plane from '../plane';
4
- import { INTERSECTION } from '../../constants';
5
4
  /**
6
5
  * An axis aligned bounding box - aligned with coordinate axes
7
6
  * @see BoundingVolume
@@ -47,7 +46,7 @@ export default class AxisAlignedBoundingBox implements BoundingVolume {
47
46
  /**
48
47
  * Determines which side of a plane a box is located.
49
48
  */
50
- intersectPlane(plane: Plane): INTERSECTION;
49
+ intersectPlane(plane: Plane): number;
51
50
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
52
51
  distanceTo(point: readonly number[]): number;
53
52
  /** Computes the estimated distance squared from the closest point on a bounding box to a point. */
@@ -1 +1 @@
1
- {"version":3,"file":"axis-aligned-bounding-box.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,MAAM,UAAU,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAK7C;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,cAAc;IACnE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,sDAAsD;IACtD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;;;OAKG;gBAED,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE;IAsB5B;;;;OAIG;IACH,KAAK,IAAI,sBAAsB;IAI/B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO;IAO9C;;;;OAIG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAS7C;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,YAAY;IAqB1C,2FAA2F;IAC3F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAI5C,mGAAmG;IACnG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;CAwBpD"}
1
+ {"version":3,"file":"axis-aligned-bounding-box.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/axis-aligned-bounding-box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,MAAM,UAAU,CAAC;AAM7B;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAuB,YAAW,cAAc;IACnE,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,sDAAsD;IACtD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;;;OAKG;gBAED,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,OAAO,GAAE,SAAS,MAAM,EAAc,EACtC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE;IAsB5B;;;;OAIG;IACH,KAAK,IAAI,sBAAsB;IAI/B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO;IAO9C;;;;OAIG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAS7C;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IAqBpC,2FAA2F;IAC3F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAI5C,mGAAmG;IACnG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;CAwBpD"}
@@ -1,5 +1,4 @@
1
1
  import { NumericArray, Vector3 } from '@math.gl/core';
2
- import { INTERSECTION } from '../../constants';
3
2
  import { BoundingVolume } from './bounding-volume';
4
3
  import Plane from '../plane';
5
4
  /** A BoundingSphere */
@@ -35,6 +34,6 @@ export default class BoundingSphere implements BoundingVolume {
35
34
  /** Computes the estimated distance from the closest point on a bounding sphere to a point. */
36
35
  distanceTo(point: Readonly<NumericArray>): number;
37
36
  /** Determines which side of a plane a sphere is located. */
38
- intersectPlane(plane: Plane): INTERSECTION;
37
+ intersectPlane(plane: Plane): number;
39
38
  }
40
39
  //# sourceMappingURL=bounding-sphere.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-sphere.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/bounding-sphere.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,YAAY,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,MAAM,UAAU,CAAC;AAK7B,uBAAuB;AACvB,MAAM,CAAC,OAAO,OAAO,cAAe,YAAW,cAAc;IAC3D,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IAEf,gCAAgC;gBACpB,MAAM,GAAE,SAAS,MAAM,EAAc,EAAE,MAAM,GAAE,MAAY;IAMvE,2DAA2D;IAC3D,gBAAgB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAMjE;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAOpF,0DAA0D;IAC1D,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO;IAOtC,4CAA4C;IAC5C,KAAK,IAAI,cAAc;IAIvB,yFAAyF;IACzF,KAAK,CAAC,cAAc,EAAE,cAAc,GAAG,cAAc;IAkCrD,iGAAiG;IACjG,MAAM,CAAC,KAAK,EAAE,SAAS,MAAM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AAE,GAAG,IAAI;IAWtC;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAO7C,sGAAsG;IACtG,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM;IAKxD,8FAA8F;IAC9F,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,MAAM;IAMjD,4DAA4D;IAC5D,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;CAiBrC"}
@@ -1,4 +1,3 @@
1
- import { INTERSECTION } from '../../constants';
2
1
  import Plane from '../plane';
3
2
  /**
4
3
  * Common interface for BoundingVolumes
@@ -25,6 +24,6 @@ export interface BoundingVolume {
25
24
  * - `INTERSECTION.OUTSIDE` if the entire box is on the opposite side.
26
25
  * - `INTERSECTION.INTERSECTING` if the box intersects the plane.
27
26
  */
28
- intersectPlane(plane: Plane): INTERSECTION;
27
+ intersectPlane(plane: Plane): number;
29
28
  }
30
29
  //# sourceMappingURL=bounding-volume.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-volume.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/bounding-volume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,MAAM,UAAU,CAAC;AAE7B;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAE9C,sGAAsG;IACtG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IACpD,8FAA8F;IAC9F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IAE7C;;;;;;;;OAQG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,YAAY,CAAC;CAC5C"}
1
+ {"version":3,"file":"bounding-volume.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/bounding-volume.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,UAAU,CAAC;AAE7B;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,SAAS,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;IAE9C,sGAAsG;IACtG,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IACpD,8FAA8F;IAC9F,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IAE7C;;;;;;;;OAQG;IACH,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC;CACtC"}
@@ -2,7 +2,6 @@ import { Vector3, Matrix3, Matrix4, Quaternion } from '@math.gl/core';
2
2
  import type { BoundingVolume } from './bounding-volume';
3
3
  import BoundingSphere from './bounding-sphere';
4
4
  import type Plane from '../plane';
5
- import { INTERSECTION } from '../../constants';
6
5
  /**
7
6
  * An OrientedBoundingBox of some object is a closed and convex cuboid.
8
7
  * It can provide a tighter bounding volume than `BoundingSphere` or
@@ -32,7 +31,7 @@ export default class OrientedBoundingBox implements BoundingVolume {
32
31
  /** Computes a tight-fitting bounding sphere enclosing the provided oriented bounding box. */
33
32
  getBoundingSphere(result?: BoundingSphere): BoundingSphere;
34
33
  /** Determines which side of a plane the oriented bounding box is located. */
35
- intersectPlane(plane: Plane): INTERSECTION;
34
+ intersectPlane(plane: Plane): number;
36
35
  /** Computes the estimated distance from the closest point on a bounding box to a point. */
37
36
  distanceTo(point: readonly number[]): number;
38
37
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"oriented-bounding-box.d.ts","sourceRoot":"","sources":["../../../src/lib/bounding-volumes/oriented-bounding-box.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU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;IAI5C;;;;OAIG;IACH,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM;IAwCnD;;;;;;;;;;;;;OAaG;IAEH,qBAAqB,CACnB,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,SAAS,EAAE,OAAO,EAClB,MAAM,GAAE,MAAM,EAAa,GAC1B,MAAM,EAAE;IAwFX;;;;OAIG;IACH,SAAS,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI;IAgBlD,YAAY,IAAI,OAAO;CAKxB"}
@@ -1,4 +1,3 @@
1
- import { INTERSECTION } from '../constants';
2
1
  import Plane from './plane';
3
2
  import type { BoundingVolume } from './bounding-volumes/bounding-volume';
4
3
  import type BoundingSphere from './bounding-volumes/bounding-sphere';
@@ -32,7 +31,7 @@ export default class CullingVolume {
32
31
  */
33
32
  fromBoundingSphere(boundingSphere: BoundingSphere): CullingVolume;
34
33
  /** Determines whether a bounding volume intersects the culling volume. */
35
- computeVisibility(boundingVolume: BoundingVolume): INTERSECTION;
34
+ computeVisibility(boundingVolume: BoundingVolume): number;
36
35
  /**
37
36
  * Determines whether a bounding volume intersects the culling volume.
38
37
  *
@@ -1 +1 @@
1
- {"version":3,"file":"culling-volume.d.ts","sourceRoot":"","sources":["../../src/lib/culling-volume.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,cAAc,MAAM,oCAAoC,CAAC;AASrE,0CAA0C;AAC1C,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;OAGG;IACH,MAAM,CAAC,YAAY,SAAc;IAEjC;;;OAGG;IACH,MAAM,CAAC,WAAW,SAAc;IAEhC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,SAAc;IAEvC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IAEzB;;;SAGK;gBACO,MAAM,GAAE,KAAK,EAAO;IAIhC;;;OAGG;IACH,kBAAkB,CAAC,cAAc,EAAE,cAAc,GAAG,aAAa;IAsCjE,0EAA0E;IAC1E,iBAAiB,CAAC,cAAc,EAAE,cAAc,GAAG,YAAY;IAsB/D;;;;;;;OAOG;IACH,8BAA8B,CAAC,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM;CAmChG"}
1
+ {"version":3,"file":"culling-volume.d.ts","sourceRoot":"","sources":["../../src/lib/culling-volume.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,cAAc,MAAM,oCAAoC,CAAC;AASrE,0CAA0C;AAC1C,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC;;;OAGG;IACH,MAAM,CAAC,YAAY,SAAc;IAEjC;;;OAGG;IACH,MAAM,CAAC,WAAW,SAAc;IAEhC;;;OAGG;IACH,MAAM,CAAC,kBAAkB,SAAc;IAEvC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IAEzB;;;SAGK;gBACO,MAAM,GAAE,KAAK,EAAO;IAIhC;;;OAGG;IACH,kBAAkB,CAAC,cAAc,EAAE,cAAc,GAAG,aAAa;IAsCjE,0EAA0E;IAC1E,iBAAiB,CAAC,cAAc,EAAE,cAAc,GAAG,MAAM;IAsBzD;;;;;;;OAOG;IACH,8BAA8B,CAAC,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM;CAmChG"}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "3.6.0-alpha.8",
8
+ "version": "3.6.2",
9
9
  "keywords": [
10
10
  "webgl",
11
11
  "javascript",
@@ -35,8 +35,8 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@babel/runtime": "^7.12.0",
38
- "@math.gl/core": "3.6.0-alpha.8",
38
+ "@math.gl/core": "3.6.2",
39
39
  "gl-matrix": "^3.4.0"
40
40
  },
41
- "gitHead": "5354df2f3c4111d4e48f4a0508d8e8103dd5eaf4"
41
+ "gitHead": "517015873bbd7143bfc4bb761e70071c7a86771b"
42
42
  }
package/src/constants.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  // This file is derived from the Cesium math library under Apache 2 license
2
2
  // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
3
 
4
- export enum INTERSECTION {
5
- OUTSIDE = -1, // Represents that an object is not contained within the frustum.
6
- INTERSECTING = 0, // Represents that an object intersects one of the frustum's planes.
7
- INSIDE = 1 // Represents that an object is fully within the frustum.
8
- }
4
+ export const INTERSECTION = {
5
+ OUTSIDE: -1, // Represents that an object is not contained within the frustum.
6
+ INTERSECTING: 0, // Represents that an object intersects one of the frustum's planes.
7
+ INSIDE: 1 // Represents that an object is fully within the frustum.
8
+ } as const;
@@ -93,7 +93,7 @@ export default class AxisAlignedBoundingBox implements BoundingVolume {
93
93
  /**
94
94
  * Determines which side of a plane a box is located.
95
95
  */
96
- intersectPlane(plane: Plane): INTERSECTION {
96
+ intersectPlane(plane: Plane): number {
97
97
  const {halfDiagonal} = this;
98
98
  const normal = scratchNormal.from(plane.normal);
99
99
  const e =
@@ -127,7 +127,7 @@ export default class BoundingSphere implements BoundingVolume {
127
127
  }
128
128
 
129
129
  /** Determines which side of a plane a sphere is located. */
130
- intersectPlane(plane: Plane): INTERSECTION {
130
+ intersectPlane(plane: Plane): number {
131
131
  const center = this.center;
132
132
  const radius = this.radius;
133
133
  const normal = plane.normal;
@@ -28,5 +28,5 @@ export interface BoundingVolume {
28
28
  * - `INTERSECTION.OUTSIDE` if the entire box is on the opposite side.
29
29
  * - `INTERSECTION.INTERSECTING` if the box intersects the plane.
30
30
  */
31
- intersectPlane(plane: Plane): INTERSECTION;
31
+ intersectPlane(plane: Plane): number;
32
32
  }
@@ -120,7 +120,7 @@ export default class OrientedBoundingBox implements BoundingVolume {
120
120
  }
121
121
 
122
122
  /** Determines which side of a plane the oriented bounding box is located. */
123
- intersectPlane(plane: Plane): INTERSECTION {
123
+ intersectPlane(plane: Plane): number {
124
124
  const center = this.center;
125
125
  const normal = plane.normal;
126
126
  const halfAxes = this.halfAxes;
@@ -89,9 +89,9 @@ export default class CullingVolume {
89
89
  }
90
90
 
91
91
  /** Determines whether a bounding volume intersects the culling volume. */
92
- computeVisibility(boundingVolume: BoundingVolume): INTERSECTION {
92
+ computeVisibility(boundingVolume: BoundingVolume): number {
93
93
  // const planes = this.planes;
94
- let intersect = INTERSECTION.INSIDE;
94
+ let intersect: number = INTERSECTION.INSIDE;
95
95
  for (const plane of this.planes) {
96
96
  const result = boundingVolume.intersectPlane(plane);
97
97
  switch (result) {
package/dist/constants.js DELETED
@@ -1,8 +0,0 @@
1
- // This file is derived from the Cesium math library under Apache 2 license
2
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
- export var INTERSECTION;
4
- (function (INTERSECTION) {
5
- INTERSECTION[INTERSECTION["OUTSIDE"] = -1] = "OUTSIDE";
6
- INTERSECTION[INTERSECTION["INTERSECTING"] = 0] = "INTERSECTING";
7
- INTERSECTION[INTERSECTION["INSIDE"] = 1] = "INSIDE"; // Represents that an object is fully within the frustum.
8
- })(INTERSECTION || (INTERSECTION = {}));
package/dist/index.js DELETED
@@ -1,13 +0,0 @@
1
- // This file is derived from the Cesium math library under Apache 2 license
2
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
- export { INTERSECTION } from './constants';
4
- export { default as AxisAlignedBoundingBox } from './lib/bounding-volumes/axis-aligned-bounding-box';
5
- export { default as BoundingSphere } from './lib/bounding-volumes/bounding-sphere';
6
- export { default as OrientedBoundingBox } from './lib/bounding-volumes/oriented-bounding-box';
7
- export { default as CullingVolume } from './lib/culling-volume';
8
- export { default as Plane } from './lib/plane';
9
- export { default as _PerspectiveOffCenterFrustum } from './lib/perspective-off-center-frustum';
10
- export { default as _PerspectiveFrustum } from './lib/perspective-frustum';
11
- export { default as makeBoundingSphereFromPoints } from './lib/algorithms/bounding-sphere-from-points';
12
- export { makeAxisAlignedBoundingBoxFromPoints, makeOrientedBoundingBoxFromPoints } from './lib/algorithms/bounding-box-from-points';
13
- export { default as computeEigenDecomposition } from './lib/algorithms/compute-eigen-decomposition';
@@ -1,131 +0,0 @@
1
- // This file is derived from the Cesium math library under Apache 2 license
2
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
- import { Vector3, Matrix3 } from '@math.gl/core';
4
- import computeEigenDecomposition from './compute-eigen-decomposition';
5
- import OrientedBoundingBox from '../bounding-volumes/oriented-bounding-box';
6
- import AxisAlignedBoundingBox from '../bounding-volumes/axis-aligned-bounding-box';
7
- const scratchVector2 = new Vector3();
8
- const scratchVector3 = new Vector3();
9
- const scratchVector4 = new Vector3();
10
- const scratchVector5 = new Vector3();
11
- const scratchVector6 = new Vector3();
12
- const scratchCovarianceResult = new Matrix3();
13
- const scratchEigenResult = {
14
- diagonal: new Matrix3(),
15
- unitary: new Matrix3()
16
- };
17
- /**
18
- * Computes an instance of an OrientedBoundingBox of the given positions.
19
- *
20
- * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).
21
- * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf
22
- */
23
- /* eslint-disable max-statements */
24
- export function makeOrientedBoundingBoxFromPoints(positions, result = new OrientedBoundingBox()) {
25
- if (!positions || positions.length === 0) {
26
- result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
27
- result.center = new Vector3();
28
- return result;
29
- }
30
- const length = positions.length;
31
- const meanPoint = new Vector3(0, 0, 0);
32
- for (const position of positions) {
33
- meanPoint.add(position);
34
- }
35
- const invLength = 1.0 / length;
36
- meanPoint.multiplyByScalar(invLength);
37
- let exx = 0.0;
38
- let exy = 0.0;
39
- let exz = 0.0;
40
- let eyy = 0.0;
41
- let eyz = 0.0;
42
- let ezz = 0.0;
43
- for (const position of positions) {
44
- const p = scratchVector2.copy(position).subtract(meanPoint);
45
- exx += p.x * p.x;
46
- exy += p.x * p.y;
47
- exz += p.x * p.z;
48
- eyy += p.y * p.y;
49
- eyz += p.y * p.z;
50
- ezz += p.z * p.z;
51
- }
52
- exx *= invLength;
53
- exy *= invLength;
54
- exz *= invLength;
55
- eyy *= invLength;
56
- eyz *= invLength;
57
- ezz *= invLength;
58
- const covarianceMatrix = scratchCovarianceResult;
59
- covarianceMatrix[0] = exx;
60
- covarianceMatrix[1] = exy;
61
- covarianceMatrix[2] = exz;
62
- covarianceMatrix[3] = exy;
63
- covarianceMatrix[4] = eyy;
64
- covarianceMatrix[5] = eyz;
65
- covarianceMatrix[6] = exz;
66
- covarianceMatrix[7] = eyz;
67
- covarianceMatrix[8] = ezz;
68
- const { unitary } = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);
69
- const rotation = result.halfAxes.copy(unitary);
70
- let v1 = rotation.getColumn(0, scratchVector4);
71
- let v2 = rotation.getColumn(1, scratchVector5);
72
- let v3 = rotation.getColumn(2, scratchVector6);
73
- let u1 = -Number.MAX_VALUE;
74
- let u2 = -Number.MAX_VALUE;
75
- let u3 = -Number.MAX_VALUE;
76
- let l1 = Number.MAX_VALUE;
77
- let l2 = Number.MAX_VALUE;
78
- let l3 = Number.MAX_VALUE;
79
- for (const position of positions) {
80
- scratchVector2.copy(position);
81
- u1 = Math.max(scratchVector2.dot(v1), u1);
82
- u2 = Math.max(scratchVector2.dot(v2), u2);
83
- u3 = Math.max(scratchVector2.dot(v3), u3);
84
- l1 = Math.min(scratchVector2.dot(v1), l1);
85
- l2 = Math.min(scratchVector2.dot(v2), l2);
86
- l3 = Math.min(scratchVector2.dot(v3), l3);
87
- }
88
- v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
89
- v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
90
- v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
91
- result.center.copy(v1).add(v2).add(v3);
92
- const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
93
- const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
94
- result.halfAxes.multiplyRight(scaleMatrix);
95
- return result;
96
- }
97
- /**
98
- * Computes an instance of an AxisAlignedBoundingBox. The box is determined by
99
- * finding the points spaced the farthest apart on the x, y, and z axes.
100
- */
101
- export function makeAxisAlignedBoundingBoxFromPoints(positions, result = new AxisAlignedBoundingBox()) {
102
- if (!positions || positions.length === 0) {
103
- result.minimum.set(0, 0, 0);
104
- result.maximum.set(0, 0, 0);
105
- result.center.set(0, 0, 0);
106
- result.halfDiagonal.set(0, 0, 0);
107
- return result;
108
- }
109
- let minimumX = positions[0][0];
110
- let minimumY = positions[0][1];
111
- let minimumZ = positions[0][2];
112
- let maximumX = positions[0][0];
113
- let maximumY = positions[0][1];
114
- let maximumZ = positions[0][2];
115
- for (const p of positions) {
116
- const x = p[0];
117
- const y = p[1];
118
- const z = p[2];
119
- minimumX = Math.min(x, minimumX);
120
- maximumX = Math.max(x, maximumX);
121
- minimumY = Math.min(y, minimumY);
122
- maximumY = Math.max(y, maximumY);
123
- minimumZ = Math.min(z, minimumZ);
124
- maximumZ = Math.max(z, maximumZ);
125
- }
126
- result.minimum.set(minimumX, minimumY, minimumZ);
127
- result.maximum.set(maximumX, maximumY, maximumZ);
128
- result.center.copy(result.minimum).add(result.maximum).scale(0.5);
129
- result.halfDiagonal.copy(result.maximum).subtract(result.center);
130
- return result;
131
- }
@@ -1,140 +0,0 @@
1
- // This file is derived from the Cesium math library under Apache 2 license
2
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
- import { Vector3 } from '@math.gl/core';
4
- import BoundingSphere from '../bounding-volumes/bounding-sphere';
5
- /* eslint-disable */
6
- const fromPointsXMin = new Vector3();
7
- const fromPointsYMin = new Vector3();
8
- const fromPointsZMin = new Vector3();
9
- const fromPointsXMax = new Vector3();
10
- const fromPointsYMax = new Vector3();
11
- const fromPointsZMax = new Vector3();
12
- const fromPointsCurrentPos = new Vector3();
13
- const fromPointsScratch = new Vector3();
14
- const fromPointsRitterCenter = new Vector3();
15
- const fromPointsMinBoxPt = new Vector3();
16
- const fromPointsMaxBoxPt = new Vector3();
17
- const fromPointsNaiveCenterScratch = new Vector3();
18
- const volumeConstant = (4.0 / 3.0) * Math.PI;
19
- /**
20
- * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
21
- *
22
- * The bounding sphere is computed by running two algorithms, a naive algorithm and
23
- * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
24
- * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding
25
- *
26
- * @param positions An array of points that the bounding sphere will enclose.
27
- * @param result Optional object onto which to store the result.
28
- * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
29
- */
30
- export default function makeBoundingSphereFromPoints(positions, result = new BoundingSphere()) {
31
- if (!positions || positions.length === 0) {
32
- return result.fromCenterRadius([0, 0, 0], 0);
33
- }
34
- const currentPos = fromPointsCurrentPos.copy(positions[0]);
35
- const xMin = fromPointsXMin.copy(currentPos);
36
- const yMin = fromPointsYMin.copy(currentPos);
37
- const zMin = fromPointsZMin.copy(currentPos);
38
- const xMax = fromPointsXMax.copy(currentPos);
39
- const yMax = fromPointsYMax.copy(currentPos);
40
- const zMax = fromPointsZMax.copy(currentPos);
41
- for (const position of positions) {
42
- currentPos.copy(position);
43
- const x = currentPos.x;
44
- const y = currentPos.y;
45
- const z = currentPos.z;
46
- // Store points containing the the smallest and largest components
47
- if (x < xMin.x) {
48
- xMin.copy(currentPos);
49
- }
50
- if (x > xMax.x) {
51
- xMax.copy(currentPos);
52
- }
53
- if (y < yMin.y) {
54
- yMin.copy(currentPos);
55
- }
56
- if (y > yMax.y) {
57
- yMax.copy(currentPos);
58
- }
59
- if (z < zMin.z) {
60
- zMin.copy(currentPos);
61
- }
62
- if (z > zMax.z) {
63
- zMax.copy(currentPos);
64
- }
65
- }
66
- // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
67
- const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
68
- const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
69
- const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
70
- // Set the diameter endpoints to the largest span.
71
- let diameter1 = xMin;
72
- let diameter2 = xMax;
73
- let maxSpan = xSpan;
74
- if (ySpan > maxSpan) {
75
- maxSpan = ySpan;
76
- diameter1 = yMin;
77
- diameter2 = yMax;
78
- }
79
- if (zSpan > maxSpan) {
80
- maxSpan = zSpan;
81
- diameter1 = zMin;
82
- diameter2 = zMax;
83
- }
84
- // Calculate the center of the initial sphere found by Ritter's algorithm
85
- const ritterCenter = fromPointsRitterCenter;
86
- ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
87
- ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
88
- ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
89
- // Calculate the radius of the initial sphere found by Ritter's algorithm
90
- let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
91
- let ritterRadius = Math.sqrt(radiusSquared);
92
- // Find the center of the sphere found using the Naive method.
93
- const minBoxPt = fromPointsMinBoxPt;
94
- minBoxPt.x = xMin.x;
95
- minBoxPt.y = yMin.y;
96
- minBoxPt.z = zMin.z;
97
- const maxBoxPt = fromPointsMaxBoxPt;
98
- maxBoxPt.x = xMax.x;
99
- maxBoxPt.y = yMax.y;
100
- maxBoxPt.z = zMax.z;
101
- const naiveCenter = fromPointsNaiveCenterScratch
102
- .copy(minBoxPt)
103
- .add(maxBoxPt)
104
- .multiplyByScalar(0.5);
105
- // Begin 2nd pass to find naive radius and modify the ritter sphere.
106
- let naiveRadius = 0;
107
- for (const position of positions) {
108
- currentPos.copy(position);
109
- // Find the furthest point from the naive center to calculate the naive radius.
110
- const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
111
- if (r > naiveRadius) {
112
- naiveRadius = r;
113
- }
114
- // Make adjustments to the Ritter Sphere to include all points.
115
- const oldCenterToPointSquared = fromPointsScratch
116
- .copy(currentPos)
117
- .subtract(ritterCenter)
118
- .magnitudeSquared();
119
- if (oldCenterToPointSquared > radiusSquared) {
120
- const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
121
- // Calculate new radius to include the point that lies outside
122
- ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
123
- radiusSquared = ritterRadius * ritterRadius;
124
- // Calculate center of new Ritter sphere
125
- const oldToNew = oldCenterToPoint - ritterRadius;
126
- ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
127
- ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
128
- ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
129
- }
130
- }
131
- if (ritterRadius < naiveRadius) {
132
- ritterCenter.to(result.center);
133
- result.radius = ritterRadius;
134
- }
135
- else {
136
- naiveCenter.to(result.center);
137
- result.radius = naiveRadius;
138
- }
139
- return result;
140
- }