@math.gl/geometry 5.0.0-alpha.18 → 5.0.0-alpha.19

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 (294) hide show
  1. package/README.md +7 -1
  2. package/dist/culling/constants.d.ts +3 -0
  3. package/dist/culling/constants.d.ts.map +1 -0
  4. package/dist/culling/constants.js +5 -0
  5. package/dist/culling/constants.js.map +1 -0
  6. package/dist/culling/index.cjs +2022 -0
  7. package/dist/culling/index.cjs.map +6 -0
  8. package/dist/culling/index.d.ts +28 -0
  9. package/dist/culling/index.d.ts.map +1 -0
  10. package/dist/culling/index.js +22 -0
  11. package/dist/culling/index.js.map +1 -0
  12. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts +15 -0
  13. package/dist/culling/lib/algorithms/bounding-box-from-points.d.ts.map +1 -0
  14. package/dist/culling/lib/algorithms/bounding-box-from-points.js +137 -0
  15. package/dist/culling/lib/algorithms/bounding-box-from-points.js.map +1 -0
  16. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts +14 -0
  17. package/dist/culling/lib/algorithms/bounding-sphere-from-points.d.ts.map +1 -0
  18. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js +146 -0
  19. package/dist/culling/lib/algorithms/bounding-sphere-from-points.js.map +1 -0
  20. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts +37 -0
  21. package/dist/culling/lib/algorithms/compute-eigen-decomposition.d.ts.map +1 -0
  22. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js +137 -0
  23. package/dist/culling/lib/algorithms/compute-eigen-decomposition.js.map +1 -0
  24. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +56 -0
  25. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -0
  26. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +116 -0
  27. package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -0
  28. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts +40 -0
  29. package/dist/culling/lib/bounding-volumes/bounding-sphere.d.ts.map +1 -0
  30. package/dist/culling/lib/bounding-volumes/bounding-sphere.js +123 -0
  31. package/dist/culling/lib/bounding-volumes/bounding-sphere.js.map +1 -0
  32. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts +30 -0
  33. package/dist/culling/lib/bounding-volumes/bounding-volume.d.ts.map +1 -0
  34. package/dist/culling/lib/bounding-volumes/bounding-volume.js +7 -0
  35. package/dist/culling/lib/bounding-volumes/bounding-volume.js.map +1 -0
  36. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts +68 -0
  37. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.d.ts.map +1 -0
  38. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js +259 -0
  39. package/dist/culling/lib/bounding-volumes/oriented-bounding-box.js.map +1 -0
  40. package/dist/culling/lib/culling-volume.d.ts +46 -0
  41. package/dist/culling/lib/culling-volume.d.ts.map +1 -0
  42. package/dist/culling/lib/culling-volume.js +126 -0
  43. package/dist/culling/lib/culling-volume.js.map +1 -0
  44. package/dist/culling/lib/perspective-frustum.d.ts +153 -0
  45. package/dist/culling/lib/perspective-frustum.d.ts.map +1 -0
  46. package/dist/culling/lib/perspective-frustum.js +191 -0
  47. package/dist/culling/lib/perspective-frustum.js.map +1 -0
  48. package/dist/culling/lib/perspective-off-center-frustum.d.ts +158 -0
  49. package/dist/culling/lib/perspective-off-center-frustum.d.ts.map +1 -0
  50. package/dist/culling/lib/perspective-off-center-frustum.js +276 -0
  51. package/dist/culling/lib/perspective-off-center-frustum.js.map +1 -0
  52. package/dist/culling/lib/plane.d.ts +35 -0
  53. package/dist/culling/lib/plane.d.ts.map +1 -0
  54. package/dist/culling/lib/plane.js +90 -0
  55. package/dist/culling/lib/plane.js.map +1 -0
  56. package/dist/culling/lib/ray.d.ts +13 -0
  57. package/dist/culling/lib/ray.d.ts.map +1 -0
  58. package/dist/culling/lib/ray.js +30 -0
  59. package/dist/culling/lib/ray.js.map +1 -0
  60. package/dist/culling/lib/shapes/box-shape.d.ts +19 -0
  61. package/dist/culling/lib/shapes/box-shape.d.ts.map +1 -0
  62. package/dist/culling/lib/shapes/box-shape.js +69 -0
  63. package/dist/culling/lib/shapes/box-shape.js.map +1 -0
  64. package/dist/culling/lib/shapes/capsule-shape.d.ts +23 -0
  65. package/dist/culling/lib/shapes/capsule-shape.d.ts.map +1 -0
  66. package/dist/culling/lib/shapes/capsule-shape.js +151 -0
  67. package/dist/culling/lib/shapes/capsule-shape.js.map +1 -0
  68. package/dist/culling/lib/shapes/cylinder-shape.d.ts +22 -0
  69. package/dist/culling/lib/shapes/cylinder-shape.d.ts.map +1 -0
  70. package/dist/culling/lib/shapes/cylinder-shape.js +99 -0
  71. package/dist/culling/lib/shapes/cylinder-shape.js.map +1 -0
  72. package/dist/culling/lib/shapes/implicit-shape.d.ts +56 -0
  73. package/dist/culling/lib/shapes/implicit-shape.d.ts.map +1 -0
  74. package/dist/culling/lib/shapes/implicit-shape.js +142 -0
  75. package/dist/culling/lib/shapes/implicit-shape.js.map +1 -0
  76. package/dist/culling/lib/shapes/plane-shape.d.ts +27 -0
  77. package/dist/culling/lib/shapes/plane-shape.d.ts.map +1 -0
  78. package/dist/culling/lib/shapes/plane-shape.js +71 -0
  79. package/dist/culling/lib/shapes/plane-shape.js.map +1 -0
  80. package/dist/culling/lib/shapes/sphere-shape.d.ts +18 -0
  81. package/dist/culling/lib/shapes/sphere-shape.d.ts.map +1 -0
  82. package/dist/culling/lib/shapes/sphere-shape.js +43 -0
  83. package/dist/culling/lib/shapes/sphere-shape.js.map +1 -0
  84. package/dist/culling/oriented-box-2d.cjs +73 -0
  85. package/dist/culling/oriented-box-2d.cjs.map +6 -0
  86. package/dist/culling/oriented-box-2d.d.ts +22 -0
  87. package/dist/culling/oriented-box-2d.d.ts.map +1 -0
  88. package/dist/culling/oriented-box-2d.js +86 -0
  89. package/dist/culling/oriented-box-2d.js.map +1 -0
  90. package/dist/culling/queries.cjs +161 -0
  91. package/dist/culling/queries.cjs.map +6 -0
  92. package/dist/culling/queries.d.ts +20 -0
  93. package/dist/culling/queries.d.ts.map +1 -0
  94. package/dist/culling/queries.js +139 -0
  95. package/dist/culling/queries.js.map +1 -0
  96. package/dist/curves/bezier-curves.d.ts +18 -0
  97. package/dist/curves/bezier-curves.d.ts.map +1 -0
  98. package/dist/curves/bezier-curves.js +54 -0
  99. package/dist/curves/bezier-curves.js.map +1 -0
  100. package/dist/curves/catmull-rom-curve.d.ts +15 -0
  101. package/dist/curves/catmull-rom-curve.d.ts.map +1 -0
  102. package/dist/curves/catmull-rom-curve.js +77 -0
  103. package/dist/curves/catmull-rom-curve.js.map +1 -0
  104. package/dist/curves/curve-arc-length.d.ts +17 -0
  105. package/dist/curves/curve-arc-length.d.ts.map +1 -0
  106. package/dist/curves/curve-arc-length.js +58 -0
  107. package/dist/curves/curve-arc-length.js.map +1 -0
  108. package/dist/curves/curve.d.ts +23 -0
  109. package/dist/curves/curve.d.ts.map +1 -0
  110. package/dist/curves/curve.js +77 -0
  111. package/dist/curves/curve.js.map +1 -0
  112. package/dist/curves/hermite-curve.d.ts +9 -0
  113. package/dist/curves/hermite-curve.d.ts.map +1 -0
  114. package/dist/curves/hermite-curve.js +24 -0
  115. package/dist/curves/hermite-curve.js.map +1 -0
  116. package/dist/curves/index.cjs +293 -0
  117. package/dist/curves/index.cjs.map +6 -0
  118. package/dist/curves/index.d.ts +8 -0
  119. package/dist/curves/index.d.ts.map +1 -0
  120. package/dist/curves/index.js +9 -0
  121. package/dist/curves/index.js.map +1 -0
  122. package/dist/lib/geometry.d.ts +1 -1
  123. package/dist/lib/geometry.d.ts.map +1 -1
  124. package/dist/polygon/cut-by-grid.d.ts +24 -0
  125. package/dist/polygon/cut-by-grid.d.ts.map +1 -0
  126. package/dist/polygon/cut-by-grid.js +221 -0
  127. package/dist/polygon/cut-by-grid.js.map +1 -0
  128. package/dist/polygon/cut-by-mercator-bounds.d.ts +17 -0
  129. package/dist/polygon/cut-by-mercator-bounds.d.ts.map +1 -0
  130. package/dist/polygon/cut-by-mercator-bounds.js +149 -0
  131. package/dist/polygon/cut-by-mercator-bounds.js.map +1 -0
  132. package/dist/polygon/earcut.d.ts +13 -0
  133. package/dist/polygon/earcut.d.ts.map +1 -0
  134. package/dist/polygon/earcut.js +627 -0
  135. package/dist/polygon/earcut.js.map +1 -0
  136. package/dist/polygon/index.cjs +1414 -0
  137. package/dist/polygon/index.cjs.map +6 -0
  138. package/dist/polygon/index.d.ts +12 -0
  139. package/dist/polygon/index.d.ts.map +1 -0
  140. package/dist/polygon/index.js +12 -0
  141. package/dist/polygon/index.js.map +1 -0
  142. package/dist/polygon/lineclip.d.ts +31 -0
  143. package/dist/polygon/lineclip.d.ts.map +1 -0
  144. package/dist/polygon/lineclip.js +184 -0
  145. package/dist/polygon/lineclip.js.map +1 -0
  146. package/dist/polygon/polygon-utils.d.ts +103 -0
  147. package/dist/polygon/polygon-utils.d.ts.map +1 -0
  148. package/dist/polygon/polygon-utils.js +155 -0
  149. package/dist/polygon/polygon-utils.js.map +1 -0
  150. package/dist/polygon/polygon.d.ts +41 -0
  151. package/dist/polygon/polygon.d.ts.map +1 -0
  152. package/dist/polygon/polygon.js +76 -0
  153. package/dist/polygon/polygon.js.map +1 -0
  154. package/dist/polygon/subdivide-polyline.d.ts +42 -0
  155. package/dist/polygon/subdivide-polyline.d.ts.map +1 -0
  156. package/dist/polygon/subdivide-polyline.js +109 -0
  157. package/dist/polygon/subdivide-polyline.js.map +1 -0
  158. package/dist/polygon/subdivide-triangle-mesh.d.ts +68 -0
  159. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -0
  160. package/dist/polygon/subdivide-triangle-mesh.js +228 -0
  161. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -0
  162. package/dist/polygon/utils.d.ts +5 -0
  163. package/dist/polygon/utils.d.ts.map +1 -0
  164. package/dist/polygon/utils.js +38 -0
  165. package/dist/polygon/utils.js.map +1 -0
  166. package/dist/spatial-index/box-index.cjs +328 -0
  167. package/dist/spatial-index/box-index.cjs.map +6 -0
  168. package/dist/spatial-index/box-index.d.ts +65 -0
  169. package/dist/spatial-index/box-index.d.ts.map +1 -0
  170. package/dist/spatial-index/box-index.js +263 -0
  171. package/dist/spatial-index/box-index.js.map +1 -0
  172. package/dist/spatial-index/index.cjs +494 -0
  173. package/dist/spatial-index/index.cjs.map +6 -0
  174. package/dist/spatial-index/index.d.ts +5 -0
  175. package/dist/spatial-index/index.d.ts.map +1 -0
  176. package/dist/spatial-index/index.js +6 -0
  177. package/dist/spatial-index/index.js.map +1 -0
  178. package/dist/spatial-index/triangle-bvh.d.ts +53 -0
  179. package/dist/spatial-index/triangle-bvh.d.ts.map +1 -0
  180. package/dist/spatial-index/triangle-bvh.js +102 -0
  181. package/dist/spatial-index/triangle-bvh.js.map +1 -0
  182. package/dist/utils/attribute-compression.d.ts +50 -0
  183. package/dist/utils/attribute-compression.d.ts.map +1 -0
  184. package/dist/utils/attribute-compression.js +186 -0
  185. package/dist/utils/attribute-compression.js.map +1 -0
  186. package/dist/utils/attribute-iterator.d.ts +8 -0
  187. package/dist/utils/attribute-iterator.d.ts.map +1 -0
  188. package/dist/utils/attribute-iterator.js +25 -0
  189. package/dist/utils/attribute-iterator.js.map +1 -0
  190. package/dist/utils/compute-vertex-normals.d.ts +4 -0
  191. package/dist/utils/compute-vertex-normals.d.ts.map +1 -0
  192. package/dist/utils/compute-vertex-normals.js +54 -0
  193. package/dist/utils/compute-vertex-normals.js.map +1 -0
  194. package/dist/utils/constants.d.ts +52 -0
  195. package/dist/utils/constants.d.ts.map +1 -0
  196. package/dist/utils/constants.js +39 -0
  197. package/dist/utils/constants.js.map +1 -0
  198. package/dist/utils/coordinates.d.ts +3 -0
  199. package/dist/utils/coordinates.d.ts.map +1 -0
  200. package/dist/utils/coordinates.js +8 -0
  201. package/dist/utils/coordinates.js.map +1 -0
  202. package/dist/utils/geometry.d.ts +20 -0
  203. package/dist/utils/geometry.d.ts.map +1 -0
  204. package/dist/utils/geometry.js +31 -0
  205. package/dist/utils/geometry.js.map +1 -0
  206. package/dist/utils/gl-type.d.ts +17 -0
  207. package/dist/utils/gl-type.d.ts.map +1 -0
  208. package/dist/utils/gl-type.js +69 -0
  209. package/dist/utils/gl-type.js.map +1 -0
  210. package/dist/utils/index.cjs +965 -0
  211. package/dist/utils/index.cjs.map +6 -0
  212. package/dist/utils/index.d.ts +18 -0
  213. package/dist/utils/index.d.ts.map +1 -0
  214. package/dist/utils/index.js +16 -0
  215. package/dist/utils/index.js.map +1 -0
  216. package/dist/utils/interpolate-packed-attributes.cjs +176 -0
  217. package/dist/utils/interpolate-packed-attributes.cjs.map +6 -0
  218. package/dist/utils/interpolate-packed-attributes.d.ts +43 -0
  219. package/dist/utils/interpolate-packed-attributes.d.ts.map +1 -0
  220. package/dist/utils/interpolate-packed-attributes.js +192 -0
  221. package/dist/utils/interpolate-packed-attributes.js.map +1 -0
  222. package/dist/utils/mesh-processing.d.ts +18 -0
  223. package/dist/utils/mesh-processing.d.ts.map +1 -0
  224. package/dist/utils/mesh-processing.js +300 -0
  225. package/dist/utils/mesh-processing.js.map +1 -0
  226. package/dist/utils/primitive-iterator.d.ts +21 -0
  227. package/dist/utils/primitive-iterator.d.ts.map +1 -0
  228. package/dist/utils/primitive-iterator.js +117 -0
  229. package/dist/utils/primitive-iterator.js.map +1 -0
  230. package/dist/utils/rgb565.d.ts +5 -0
  231. package/dist/utils/rgb565.d.ts.map +1 -0
  232. package/dist/utils/rgb565.js +24 -0
  233. package/dist/utils/rgb565.js.map +1 -0
  234. package/dist/utils/typed-array-utils.d.ts +3 -0
  235. package/dist/utils/typed-array-utils.d.ts.map +1 -0
  236. package/dist/utils/typed-array-utils.js +16 -0
  237. package/dist/utils/typed-array-utils.js.map +1 -0
  238. package/package.json +49 -3
  239. package/src/culling/constants.ts +6 -0
  240. package/src/culling/index.ts +40 -0
  241. package/src/culling/lib/algorithms/bounding-box-from-points.ts +174 -0
  242. package/src/culling/lib/algorithms/bounding-sphere-from-points.ts +175 -0
  243. package/src/culling/lib/algorithms/compute-eigen-decomposition.ts +171 -0
  244. package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +153 -0
  245. package/src/culling/lib/bounding-volumes/bounding-sphere.ts +154 -0
  246. package/src/culling/lib/bounding-volumes/bounding-volume.ts +38 -0
  247. package/src/culling/lib/bounding-volumes/oriented-bounding-box.ts +355 -0
  248. package/src/culling/lib/culling-volume.ts +163 -0
  249. package/src/culling/lib/perspective-frustum.ts +288 -0
  250. package/src/culling/lib/perspective-off-center-frustum.ts +381 -0
  251. package/src/culling/lib/plane.ts +118 -0
  252. package/src/culling/lib/ray.ts +33 -0
  253. package/src/culling/lib/shapes/box-shape.ts +78 -0
  254. package/src/culling/lib/shapes/capsule-shape.ts +232 -0
  255. package/src/culling/lib/shapes/cylinder-shape.ts +133 -0
  256. package/src/culling/lib/shapes/implicit-shape.ts +209 -0
  257. package/src/culling/lib/shapes/plane-shape.ts +78 -0
  258. package/src/culling/lib/shapes/sphere-shape.ts +60 -0
  259. package/src/culling/oriented-box-2d.ts +165 -0
  260. package/src/culling/queries.ts +155 -0
  261. package/src/curves/bezier-curves.ts +62 -0
  262. package/src/curves/catmull-rom-curve.ts +89 -0
  263. package/src/curves/curve-arc-length.ts +70 -0
  264. package/src/curves/curve.ts +96 -0
  265. package/src/curves/hermite-curve.ts +34 -0
  266. package/src/curves/index.ts +15 -0
  267. package/src/lib/geometry-utils.ts +1 -1
  268. package/src/lib/geometry.ts +1 -1
  269. package/src/polygon/cut-by-grid.ts +313 -0
  270. package/src/polygon/cut-by-mercator-bounds.ts +204 -0
  271. package/src/polygon/earcut.ts +798 -0
  272. package/src/polygon/index.ts +31 -0
  273. package/src/polygon/lineclip.ts +218 -0
  274. package/src/polygon/polygon-utils.ts +273 -0
  275. package/src/polygon/polygon.ts +105 -0
  276. package/src/polygon/subdivide-polyline.ts +160 -0
  277. package/src/polygon/subdivide-triangle-mesh.ts +322 -0
  278. package/src/polygon/utils.ts +50 -0
  279. package/src/spatial-index/box-index.ts +343 -0
  280. package/src/spatial-index/index.ts +18 -0
  281. package/src/spatial-index/triangle-bvh.ts +162 -0
  282. package/src/utils/attribute-compression.ts +234 -0
  283. package/src/utils/attribute-iterator.ts +28 -0
  284. package/src/utils/compute-vertex-normals.ts +63 -0
  285. package/src/utils/constants.ts +42 -0
  286. package/src/utils/coordinates.ts +8 -0
  287. package/src/utils/geometry.ts +49 -0
  288. package/src/utils/gl-type.ts +87 -0
  289. package/src/utils/index.ts +55 -0
  290. package/src/utils/interpolate-packed-attributes.ts +284 -0
  291. package/src/utils/mesh-processing.ts +377 -0
  292. package/src/utils/primitive-iterator.ts +145 -0
  293. package/src/utils/rgb565.ts +26 -0
  294. package/src/utils/typed-array-utils.ts +16 -0
@@ -0,0 +1,40 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export type {CullingResult} from './constants';
6
+
7
+ export {AxisAlignedBoundingBox} from './lib/bounding-volumes/axis-aligned-bounding-box';
8
+ export {BoundingSphere} from './lib/bounding-volumes/bounding-sphere';
9
+ export {OrientedBoundingBox} from './lib/bounding-volumes/oriented-bounding-box';
10
+ export {CullingVolume} from './lib/culling-volume';
11
+ export {Plane} from './lib/plane';
12
+ export {Ray} from './lib/ray';
13
+
14
+ export type {ImplicitShape, RayIntersection} from './lib/shapes/implicit-shape';
15
+ export {BoxShape} from './lib/shapes/box-shape';
16
+ export type {BoxShapeProps} from './lib/shapes/box-shape';
17
+ export {CapsuleShape} from './lib/shapes/capsule-shape';
18
+ export type {CapsuleShapeProps} from './lib/shapes/capsule-shape';
19
+ export {CylinderShape} from './lib/shapes/cylinder-shape';
20
+ export type {CylinderShapeProps} from './lib/shapes/cylinder-shape';
21
+ export {PlaneShape} from './lib/shapes/plane-shape';
22
+ export type {PlaneShapeProps} from './lib/shapes/plane-shape';
23
+ export {SphereShape} from './lib/shapes/sphere-shape';
24
+ export type {SphereShapeProps} from './lib/shapes/sphere-shape';
25
+
26
+ export {PerspectiveOffCenterFrustum as _PerspectiveOffCenterFrustum} from './lib/perspective-off-center-frustum';
27
+ export {PerspectiveFrustum as _PerspectiveFrustum} from './lib/perspective-frustum';
28
+
29
+ export {makeBoundingSphereFromPoints} from './lib/algorithms/bounding-sphere-from-points';
30
+ export {
31
+ makeAxisAlignedBoundingBoxFromPoints,
32
+ makeOrientedBoundingBoxFromPoints
33
+ } from './lib/algorithms/bounding-box-from-points';
34
+ export {computeEigenDecomposition} from './lib/algorithms/compute-eigen-decomposition';
35
+
36
+ export {intersectRayBounds, intersectRayTriangle, getClosestPointOnTriangle} from './queries';
37
+ export type {QueryPoint, TriangleRayHit} from './queries';
38
+
39
+ export {intersectOrientedBoxes2D} from './oriented-box-2d';
40
+ export type {OrientedBox2D} from './oriented-box-2d';
@@ -0,0 +1,174 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT AND Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
6
+
7
+ // This file is derived from the Cesium math library under Apache 2 license
8
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
9
+
10
+ import {Vector3, Matrix3} from '@math.gl/core';
11
+ import {computeEigenDecomposition} from './compute-eigen-decomposition';
12
+ import {OrientedBoundingBox} from '../bounding-volumes/oriented-bounding-box';
13
+ import {AxisAlignedBoundingBox} from '../bounding-volumes/axis-aligned-bounding-box';
14
+
15
+ const scratchVector2 = new Vector3();
16
+
17
+ const scratchVector3 = new Vector3();
18
+
19
+ const scratchVector4 = new Vector3();
20
+
21
+ const scratchVector5 = new Vector3();
22
+
23
+ const scratchVector6 = new Vector3();
24
+
25
+ const scratchCovarianceResult = new Matrix3();
26
+
27
+ const scratchEigenResult = {
28
+ diagonal: new Matrix3(),
29
+ unitary: new Matrix3()
30
+ };
31
+
32
+ /**
33
+ * Computes an instance of an OrientedBoundingBox of the given positions.
34
+ *
35
+ * This is an implementation of Stefan Gottschalk's Collision Queries using Oriented Bounding Boxes solution (PHD thesis).
36
+ * Reference: http://gamma.cs.unc.edu/users/gottschalk/main.pdf
37
+ */
38
+ /* eslint-disable max-statements */
39
+ export function makeOrientedBoundingBoxFromPoints(
40
+ positions: number[][],
41
+ result: OrientedBoundingBox = new OrientedBoundingBox()
42
+ ): OrientedBoundingBox {
43
+ if (!positions || positions.length === 0) {
44
+ result.halfAxes = new Matrix3([0, 0, 0, 0, 0, 0, 0, 0, 0]);
45
+ result.center = new Vector3();
46
+ return result;
47
+ }
48
+
49
+ const length = positions.length;
50
+ const meanPoint = new Vector3(0, 0, 0);
51
+ for (const position of positions) {
52
+ meanPoint.add(position);
53
+ }
54
+ const invLength = 1.0 / length;
55
+ meanPoint.multiplyByScalar(invLength);
56
+
57
+ let exx = 0.0;
58
+ let exy = 0.0;
59
+ let exz = 0.0;
60
+ let eyy = 0.0;
61
+ let eyz = 0.0;
62
+ let ezz = 0.0;
63
+
64
+ for (const position of positions) {
65
+ const p = scratchVector2.copy(position).subtract(meanPoint);
66
+ exx += p.x * p.x;
67
+ exy += p.x * p.y;
68
+ exz += p.x * p.z;
69
+ eyy += p.y * p.y;
70
+ eyz += p.y * p.z;
71
+ ezz += p.z * p.z;
72
+ }
73
+
74
+ exx *= invLength;
75
+ exy *= invLength;
76
+ exz *= invLength;
77
+ eyy *= invLength;
78
+ eyz *= invLength;
79
+ ezz *= invLength;
80
+
81
+ const covarianceMatrix = scratchCovarianceResult;
82
+ covarianceMatrix[0] = exx;
83
+ covarianceMatrix[1] = exy;
84
+ covarianceMatrix[2] = exz;
85
+ covarianceMatrix[3] = exy;
86
+ covarianceMatrix[4] = eyy;
87
+ covarianceMatrix[5] = eyz;
88
+ covarianceMatrix[6] = exz;
89
+ covarianceMatrix[7] = eyz;
90
+ covarianceMatrix[8] = ezz;
91
+
92
+ const {unitary} = computeEigenDecomposition(covarianceMatrix, scratchEigenResult);
93
+ const rotation = result.halfAxes.copy(unitary);
94
+
95
+ let v1 = rotation.getColumn(0, scratchVector4);
96
+ let v2 = rotation.getColumn(1, scratchVector5);
97
+ let v3 = rotation.getColumn(2, scratchVector6);
98
+
99
+ let u1 = -Number.MAX_VALUE;
100
+ let u2 = -Number.MAX_VALUE;
101
+ let u3 = -Number.MAX_VALUE;
102
+ let l1 = Number.MAX_VALUE;
103
+ let l2 = Number.MAX_VALUE;
104
+ let l3 = Number.MAX_VALUE;
105
+
106
+ for (const position of positions) {
107
+ scratchVector2.copy(position);
108
+
109
+ u1 = Math.max(scratchVector2.dot(v1), u1);
110
+ u2 = Math.max(scratchVector2.dot(v2), u2);
111
+ u3 = Math.max(scratchVector2.dot(v3), u3);
112
+
113
+ l1 = Math.min(scratchVector2.dot(v1), l1);
114
+ l2 = Math.min(scratchVector2.dot(v2), l2);
115
+ l3 = Math.min(scratchVector2.dot(v3), l3);
116
+ }
117
+
118
+ v1 = v1.multiplyByScalar(0.5 * (l1 + u1));
119
+ v2 = v2.multiplyByScalar(0.5 * (l2 + u2));
120
+ v3 = v3.multiplyByScalar(0.5 * (l3 + u3));
121
+
122
+ result.center.copy(v1).add(v2).add(v3);
123
+
124
+ const scale = scratchVector3.set(u1 - l1, u2 - l2, u3 - l3).multiplyByScalar(0.5);
125
+ const scaleMatrix = new Matrix3([scale[0], 0, 0, 0, scale[1], 0, 0, 0, scale[2]]);
126
+ result.halfAxes.multiplyRight(scaleMatrix);
127
+
128
+ return result;
129
+ }
130
+
131
+ /**
132
+ * Computes an instance of an AxisAlignedBoundingBox. The box is determined by
133
+ * finding the points spaced the farthest apart on the x, y, and z axes.
134
+ */
135
+ export function makeAxisAlignedBoundingBoxFromPoints(
136
+ positions: readonly number[][],
137
+ result: AxisAlignedBoundingBox = new AxisAlignedBoundingBox()
138
+ ): AxisAlignedBoundingBox {
139
+ if (!positions || positions.length === 0) {
140
+ result.minimum.set(0, 0, 0);
141
+ result.maximum.set(0, 0, 0);
142
+ result.center.set(0, 0, 0);
143
+ result.halfDiagonal.set(0, 0, 0);
144
+ return result;
145
+ }
146
+
147
+ let minimumX = positions[0][0];
148
+ let minimumY = positions[0][1];
149
+ let minimumZ = positions[0][2];
150
+
151
+ let maximumX = positions[0][0];
152
+ let maximumY = positions[0][1];
153
+ let maximumZ = positions[0][2];
154
+
155
+ for (const p of positions) {
156
+ const x = p[0];
157
+ const y = p[1];
158
+ const z = p[2];
159
+
160
+ minimumX = Math.min(x, minimumX);
161
+ maximumX = Math.max(x, maximumX);
162
+ minimumY = Math.min(y, minimumY);
163
+ maximumY = Math.max(y, maximumY);
164
+ minimumZ = Math.min(z, minimumZ);
165
+ maximumZ = Math.max(z, maximumZ);
166
+ }
167
+
168
+ result.minimum.set(minimumX, minimumY, minimumZ);
169
+ result.maximum.set(maximumX, maximumY, maximumZ);
170
+ result.center.copy(result.minimum).add(result.maximum).scale(0.5);
171
+ result.halfDiagonal.copy(result.maximum).subtract(result.center);
172
+
173
+ return result;
174
+ }
@@ -0,0 +1,175 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT AND Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
6
+
7
+ // This file is derived from the Cesium math library under Apache 2 license
8
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
9
+
10
+ import {Vector3} from '@math.gl/core';
11
+ import {BoundingSphere} from '../bounding-volumes/bounding-sphere';
12
+
13
+ /* eslint-disable */
14
+ const fromPointsXMin = new Vector3();
15
+ const fromPointsYMin = new Vector3();
16
+ const fromPointsZMin = new Vector3();
17
+ const fromPointsXMax = new Vector3();
18
+ const fromPointsYMax = new Vector3();
19
+ const fromPointsZMax = new Vector3();
20
+ const fromPointsCurrentPos = new Vector3();
21
+ const fromPointsScratch = new Vector3();
22
+ const fromPointsRitterCenter = new Vector3();
23
+ const fromPointsMinBoxPt = new Vector3();
24
+ const fromPointsMaxBoxPt = new Vector3();
25
+ const fromPointsNaiveCenterScratch = new Vector3();
26
+ // const volumeConstant = (4.0 / 3.0) * Math.PI;
27
+
28
+ /**
29
+ * Computes a tight-fitting bounding sphere enclosing a list of 3D Cartesian points.
30
+ *
31
+ * The bounding sphere is computed by running two algorithms, a naive algorithm and
32
+ * Ritter's algorithm. The smaller of the two spheres is used to ensure a tight fit.
33
+ * Bounding sphere computation article http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding
34
+ *
35
+ * @param positions An array of points that the bounding sphere will enclose.
36
+ * @param result Optional object onto which to store the result.
37
+ * @returns The modified result parameter or a new `BoundingSphere` instance if not provided.
38
+ */
39
+ export function makeBoundingSphereFromPoints(
40
+ positions: number[][],
41
+ result: BoundingSphere = new BoundingSphere()
42
+ ): BoundingSphere {
43
+ if (!positions || positions.length === 0) {
44
+ return result.fromCenterRadius([0, 0, 0], 0);
45
+ }
46
+
47
+ const currentPos = fromPointsCurrentPos.copy(positions[0]);
48
+
49
+ const xMin = fromPointsXMin.copy(currentPos);
50
+ const yMin = fromPointsYMin.copy(currentPos);
51
+ const zMin = fromPointsZMin.copy(currentPos);
52
+
53
+ const xMax = fromPointsXMax.copy(currentPos);
54
+ const yMax = fromPointsYMax.copy(currentPos);
55
+ const zMax = fromPointsZMax.copy(currentPos);
56
+
57
+ for (const position of positions) {
58
+ currentPos.copy(position);
59
+
60
+ const x = currentPos.x;
61
+ const y = currentPos.y;
62
+ const z = currentPos.z;
63
+
64
+ // Store points containing the the smallest and largest components
65
+ if (x < xMin.x) {
66
+ xMin.copy(currentPos);
67
+ }
68
+
69
+ if (x > xMax.x) {
70
+ xMax.copy(currentPos);
71
+ }
72
+
73
+ if (y < yMin.y) {
74
+ yMin.copy(currentPos);
75
+ }
76
+
77
+ if (y > yMax.y) {
78
+ yMax.copy(currentPos);
79
+ }
80
+
81
+ if (z < zMin.z) {
82
+ zMin.copy(currentPos);
83
+ }
84
+
85
+ if (z > zMax.z) {
86
+ zMax.copy(currentPos);
87
+ }
88
+ }
89
+
90
+ // Compute x-, y-, and z-spans (Squared distances b/n each component's min. and max.).
91
+ const xSpan = fromPointsScratch.copy(xMax).subtract(xMin).magnitudeSquared();
92
+ const ySpan = fromPointsScratch.copy(yMax).subtract(yMin).magnitudeSquared();
93
+ const zSpan = fromPointsScratch.copy(zMax).subtract(zMin).magnitudeSquared();
94
+
95
+ // Set the diameter endpoints to the largest span.
96
+ let diameter1 = xMin;
97
+ let diameter2 = xMax;
98
+ let maxSpan = xSpan;
99
+ if (ySpan > maxSpan) {
100
+ maxSpan = ySpan;
101
+ diameter1 = yMin;
102
+ diameter2 = yMax;
103
+ }
104
+ if (zSpan > maxSpan) {
105
+ maxSpan = zSpan;
106
+ diameter1 = zMin;
107
+ diameter2 = zMax;
108
+ }
109
+
110
+ // Calculate the center of the initial sphere found by Ritter's algorithm
111
+ const ritterCenter = fromPointsRitterCenter;
112
+ ritterCenter.x = (diameter1.x + diameter2.x) * 0.5;
113
+ ritterCenter.y = (diameter1.y + diameter2.y) * 0.5;
114
+ ritterCenter.z = (diameter1.z + diameter2.z) * 0.5;
115
+
116
+ // Calculate the radius of the initial sphere found by Ritter's algorithm
117
+ let radiusSquared = fromPointsScratch.copy(diameter2).subtract(ritterCenter).magnitudeSquared();
118
+ let ritterRadius = Math.sqrt(radiusSquared);
119
+
120
+ // Find the center of the sphere found using the Naive method.
121
+ const minBoxPt = fromPointsMinBoxPt;
122
+ minBoxPt.x = xMin.x;
123
+ minBoxPt.y = yMin.y;
124
+ minBoxPt.z = zMin.z;
125
+
126
+ const maxBoxPt = fromPointsMaxBoxPt;
127
+ maxBoxPt.x = xMax.x;
128
+ maxBoxPt.y = yMax.y;
129
+ maxBoxPt.z = zMax.z;
130
+
131
+ const naiveCenter = fromPointsNaiveCenterScratch
132
+ .copy(minBoxPt)
133
+ .add(maxBoxPt)
134
+ .multiplyByScalar(0.5);
135
+
136
+ // Begin 2nd pass to find naive radius and modify the ritter sphere.
137
+ let naiveRadius = 0;
138
+ for (const position of positions) {
139
+ currentPos.copy(position);
140
+
141
+ // Find the furthest point from the naive center to calculate the naive radius.
142
+ const r = fromPointsScratch.copy(currentPos).subtract(naiveCenter).magnitude();
143
+ if (r > naiveRadius) {
144
+ naiveRadius = r;
145
+ }
146
+
147
+ // Make adjustments to the Ritter Sphere to include all points.
148
+ const oldCenterToPointSquared = fromPointsScratch
149
+ .copy(currentPos)
150
+ .subtract(ritterCenter)
151
+ .magnitudeSquared();
152
+
153
+ if (oldCenterToPointSquared > radiusSquared) {
154
+ const oldCenterToPoint = Math.sqrt(oldCenterToPointSquared);
155
+ // Calculate new radius to include the point that lies outside
156
+ ritterRadius = (ritterRadius + oldCenterToPoint) * 0.5;
157
+ radiusSquared = ritterRadius * ritterRadius;
158
+ // Calculate center of new Ritter sphere
159
+ const oldToNew = oldCenterToPoint - ritterRadius;
160
+ ritterCenter.x = (ritterRadius * ritterCenter.x + oldToNew * currentPos.x) / oldCenterToPoint;
161
+ ritterCenter.y = (ritterRadius * ritterCenter.y + oldToNew * currentPos.y) / oldCenterToPoint;
162
+ ritterCenter.z = (ritterRadius * ritterCenter.z + oldToNew * currentPos.z) / oldCenterToPoint;
163
+ }
164
+ }
165
+
166
+ if (ritterRadius < naiveRadius) {
167
+ ritterCenter.to(result.center);
168
+ result.radius = ritterRadius;
169
+ } else {
170
+ naiveCenter.to(result.center);
171
+ result.radius = naiveRadius;
172
+ }
173
+
174
+ return result;
175
+ }
@@ -0,0 +1,171 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT AND Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright 2011-2018 CesiumJS Contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Derived from Cesium. See the repository LICENSE for upstream attribution and Apache-2.0 terms.
6
+
7
+ // This file is derived from the Cesium math library under Apache 2 license
8
+ // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
9
+
10
+ import {Matrix3, _MathUtils} from '@math.gl/core';
11
+
12
+ const scratchMatrix = new Matrix3();
13
+ const scratchUnitary = new Matrix3();
14
+ const scratchDiagonal = new Matrix3();
15
+
16
+ const jMatrix = new Matrix3();
17
+ const jMatrixTranspose = new Matrix3();
18
+
19
+ export type EigenDecomposition = {
20
+ unitary: Matrix3;
21
+ diagonal: Matrix3;
22
+ };
23
+
24
+ /**
25
+ * Computes the eigenvectors and eigenvalues of a symmetric matrix.
26
+ *
27
+ * - Returns a diagonal matrix and unitary matrix such that:
28
+ * `matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)`
29
+ * - The values along the diagonal of the diagonal matrix are the eigenvalues. The columns
30
+ * of the unitary matrix are the corresponding eigenvectors.
31
+ * - This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
32
+ * section 8.4.3 The Classical Jacobi Algorithm
33
+ *
34
+ * @param matrix The 3x3 matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.
35
+ * @param result Optional object with unitary and diagonal properties which are matrices onto which to store the result.
36
+ * @returns An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.
37
+ *
38
+ * @example
39
+ * const a = //... symmetric matrix
40
+ * const result = {
41
+ * unitary : new Matrix3(),
42
+ * diagonal : new Matrix3()
43
+ * };
44
+ * computeEigenDecomposition(a, result);
45
+ *
46
+ * const unitaryTranspose = Matrix3.transpose(result.unitary, new Matrix3());
47
+ * const b = Matrix3.multiply(result.unitary, result.diagonal, new Matrix3());
48
+ * Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a
49
+ *
50
+ * const lambda = result.diagonal.getColumn(0, new Vector3()).x; // first eigenvalue
51
+ * const v = result.unitary.getColumn(0, new Vector3()); // first eigenvector
52
+ * const c = v.multiplyByScalar(lambda); // equal to v.transformByMatrix3(a)
53
+ */
54
+ export function computeEigenDecomposition(
55
+ matrix: number[],
56
+ // @ts-expect-error accept empty object type
57
+ result: EigenDecomposition = {}
58
+ ): EigenDecomposition {
59
+ const EIGEN_TOLERANCE = _MathUtils.EPSILON20;
60
+ const EIGEN_MAX_SWEEPS = 10;
61
+
62
+ let count = 0;
63
+ let sweep = 0;
64
+
65
+ const unitaryMatrix = scratchUnitary;
66
+ const diagonalMatrix = scratchDiagonal;
67
+
68
+ unitaryMatrix.identity();
69
+ diagonalMatrix.copy(matrix);
70
+
71
+ const epsilon = EIGEN_TOLERANCE * computeFrobeniusNorm(diagonalMatrix);
72
+
73
+ while (sweep < EIGEN_MAX_SWEEPS && offDiagonalFrobeniusNorm(diagonalMatrix) > epsilon) {
74
+ shurDecomposition(diagonalMatrix, jMatrix);
75
+
76
+ jMatrixTranspose.copy(jMatrix).transpose();
77
+
78
+ diagonalMatrix.multiplyRight(jMatrix);
79
+ diagonalMatrix.multiplyLeft(jMatrixTranspose);
80
+ unitaryMatrix.multiplyRight(jMatrix);
81
+
82
+ if (++count > 2) {
83
+ ++sweep;
84
+ count = 0;
85
+ }
86
+ }
87
+
88
+ result.unitary = unitaryMatrix.toTarget(result.unitary);
89
+ result.diagonal = diagonalMatrix.toTarget(result.diagonal);
90
+
91
+ return result;
92
+ }
93
+
94
+ function computeFrobeniusNorm(matrix: Matrix3): number {
95
+ let norm = 0.0;
96
+ for (let i = 0; i < 9; ++i) {
97
+ const temp = matrix[i];
98
+ norm += temp * temp;
99
+ }
100
+ return Math.sqrt(norm);
101
+ }
102
+
103
+ const rowVal = [1, 0, 0];
104
+ const colVal = [2, 2, 1];
105
+
106
+ // Computes the "off-diagonal" Frobenius norm.
107
+ // Assumes matrix is symmetric.
108
+ function offDiagonalFrobeniusNorm(matrix: Matrix3): number {
109
+ let norm = 0.0;
110
+ for (let i = 0; i < 3; ++i) {
111
+ const temp = matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])];
112
+ norm += 2.0 * temp * temp;
113
+ }
114
+ return Math.sqrt(norm);
115
+ }
116
+
117
+ // The routine takes a matrix, which is assumed to be symmetric, and
118
+ // finds the largest off-diagonal term, and then creates
119
+ // a matrix (result) which can be used to help reduce it
120
+ //
121
+ // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
122
+ // section 8.4.2 The 2by2 Symmetric Schur Decomposition.
123
+ //
124
+ // eslint-disable-next-line max-statements
125
+ function shurDecomposition(matrix: Matrix3, result: Matrix3): Matrix3 {
126
+ const tolerance = _MathUtils.EPSILON15;
127
+
128
+ let maxDiagonal = 0.0;
129
+ let rotAxis = 1;
130
+
131
+ // find pivot (rotAxis) based on max diagonal of matrix
132
+ for (let i = 0; i < 3; ++i) {
133
+ const temp = Math.abs(matrix[scratchMatrix.getElementIndex(colVal[i], rowVal[i])]);
134
+ if (temp > maxDiagonal) {
135
+ rotAxis = i;
136
+ maxDiagonal = temp;
137
+ }
138
+ }
139
+
140
+ const p = rowVal[rotAxis];
141
+ const q = colVal[rotAxis];
142
+
143
+ let c = 1.0;
144
+ let s = 0.0;
145
+
146
+ if (Math.abs(matrix[scratchMatrix.getElementIndex(q, p)]) > tolerance) {
147
+ const qq = matrix[scratchMatrix.getElementIndex(q, q)];
148
+ const pp = matrix[scratchMatrix.getElementIndex(p, p)];
149
+ const qp = matrix[scratchMatrix.getElementIndex(q, p)];
150
+
151
+ const tau = (qq - pp) / 2.0 / qp;
152
+ let t;
153
+
154
+ if (tau < 0.0) {
155
+ t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
156
+ } else {
157
+ t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));
158
+ }
159
+
160
+ c = 1.0 / Math.sqrt(1.0 + t * t);
161
+ s = t * c;
162
+ }
163
+
164
+ // Copy into result
165
+ Matrix3.IDENTITY.to(result);
166
+ result[scratchMatrix.getElementIndex(p, p)] = result[scratchMatrix.getElementIndex(q, q)] = c;
167
+ result[scratchMatrix.getElementIndex(q, p)] = s;
168
+ result[scratchMatrix.getElementIndex(p, q)] = -s;
169
+
170
+ return result;
171
+ }