@cesium/engine 24.0.0 → 26.0.0

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 (362) hide show
  1. package/Build/Workers/{chunk-6WLHJFD3.js → chunk-3VFEWOBI.js} +59 -32
  2. package/Build/Workers/{chunk-UQU4RXLT.js → chunk-424RNO3D.js} +50 -45
  3. package/Build/Workers/chunk-4MGMYHOO.js +147 -0
  4. package/Build/Workers/{chunk-AMIHNSST.js → chunk-4S7IE3LB.js} +2 -2
  5. package/Build/Workers/{chunk-J6AW5YHS.js → chunk-52JDLOEM.js} +14 -14
  6. package/Build/Workers/{chunk-6RMS4S72.js → chunk-54I6Y66F.js} +6 -6
  7. package/Build/Workers/{chunk-C6P4IG5P.js → chunk-6YEE6JDR.js} +6 -6
  8. package/Build/Workers/{chunk-72VYSVEW.js → chunk-7J2HKPRH.js} +11 -10
  9. package/Build/Workers/{chunk-7O5XJTVE.js → chunk-7WM2PX4V.js} +5 -5
  10. package/Build/Workers/{chunk-5A2SW66E.js → chunk-ACXQXN46.js} +16 -16
  11. package/Build/Workers/{chunk-VLDEUTOP.js → chunk-AYKR4VBR.js} +2 -2
  12. package/Build/Workers/{chunk-YQFTYQMZ.js → chunk-C6J67V5A.js} +3 -2
  13. package/Build/Workers/{chunk-D4EJ2NXG.js → chunk-C6KNZ7T4.js} +17 -17
  14. package/Build/Workers/{chunk-7MDYBRYJ.js → chunk-CFQP6LYM.js} +4 -4
  15. package/Build/Workers/{chunk-YAOZMOFL.js → chunk-CXOYE2WM.js} +5 -5
  16. package/Build/Workers/{chunk-B6SCUUFP.js → chunk-CZEYZU4N.js} +10 -10
  17. package/Build/Workers/{chunk-NPF7SSHZ.js → chunk-DBOEKL43.js} +7 -7
  18. package/Build/Workers/{chunk-44EMEGKW.js → chunk-DDWSZVMY.js} +5 -5
  19. package/Build/Workers/{chunk-7X322WP2.js → chunk-DOBXCNC3.js} +13 -13
  20. package/Build/Workers/{chunk-JCI63T3K.js → chunk-E7VQ76KE.js} +6 -6
  21. package/Build/Workers/{chunk-7TYLCBGK.js → chunk-EBSIOBXY.js} +12 -10
  22. package/Build/Workers/{chunk-GQUNK2XC.js → chunk-EF2QYXGA.js} +14 -14
  23. package/Build/Workers/{chunk-BJD6QGXZ.js → chunk-EPYXRCDB.js} +12 -12
  24. package/Build/Workers/{chunk-63SIWPLS.js → chunk-F6QDY6HU.js} +13 -13
  25. package/Build/Workers/{chunk-XY6HMDGI.js → chunk-FRQZECAO.js} +5 -5
  26. package/Build/Workers/{chunk-VMVOUQ5J.js → chunk-G7PXZRVF.js} +7 -7
  27. package/Build/Workers/{chunk-N65BAKSH.js → chunk-INUEEEQA.js} +8 -8
  28. package/Build/Workers/{chunk-7QRFIKWQ.js → chunk-IRBKFCEJ.js} +2 -2
  29. package/Build/Workers/{chunk-UIGVOKKI.js → chunk-IYOUHCZB.js} +3 -2
  30. package/Build/Workers/{chunk-5GXYJQ2K.js → chunk-J6BWOHUF.js} +3 -3
  31. package/Build/Workers/{chunk-A47HVBC5.js → chunk-KFSTQKNM.js} +7 -7
  32. package/Build/Workers/{chunk-EV3VGO6Y.js → chunk-KKOSKAZB.js} +17 -17
  33. package/Build/Workers/{chunk-6MPGQEHA.js → chunk-KSSWJIZW.js} +2 -2
  34. package/Build/Workers/{chunk-DHKPFLSJ.js → chunk-M3B5JKSM.js} +3 -2
  35. package/Build/Workers/chunk-MPZHGZU6.js +2342 -0
  36. package/Build/Workers/{chunk-YJZGW74L.js → chunk-MYP774IS.js} +2213 -1349
  37. package/Build/Workers/{chunk-LIB2H534.js → chunk-O3EA5HS7.js} +12 -11
  38. package/Build/Workers/{chunk-ILMFADZA.js → chunk-P3CK7MCY.js} +27 -5
  39. package/Build/Workers/chunk-Q3PY526V.js +3201 -0
  40. package/Build/Workers/chunk-QN67VG36.js +973 -0
  41. package/Build/Workers/{chunk-XJRBB253.js → chunk-QRWGUWI6.js} +11 -11
  42. package/Build/Workers/{chunk-AF3MU2RL.js → chunk-S4MCOY6I.js} +7 -6
  43. package/Build/Workers/{chunk-Y7HNNPNK.js → chunk-SMQZZOW6.js} +10 -10
  44. package/Build/Workers/{chunk-PVV64VFW.js → chunk-TKKIREQ6.js} +3 -2
  45. package/Build/Workers/{chunk-MKM27KGV.js → chunk-U3ZA64U7.js} +2 -2
  46. package/Build/Workers/{chunk-2N4KDHS3.js → chunk-UA25D5MX.js} +12 -11
  47. package/Build/Workers/{chunk-RQNJD3O4.js → chunk-UOOIQ3KX.js} +12 -12
  48. package/Build/Workers/{chunk-GOQBUCXH.js → chunk-V7VQKN6N.js} +709 -431
  49. package/Build/Workers/{chunk-LXMCPFFS.js → chunk-VQYETPWC.js} +4 -4
  50. package/Build/Workers/{chunk-NKT5K3K3.js → chunk-VWV2IJRB.js} +13 -12
  51. package/Build/Workers/chunk-XZMBNNDX.js +1287 -0
  52. package/Build/Workers/{chunk-ISY4EZCA.js → chunk-Y57HREW5.js} +4 -4
  53. package/Build/Workers/{chunk-EDXL4W76.js → chunk-Y5BF6AFU.js} +2 -2
  54. package/Build/Workers/{chunk-Q3C6VQH6.js → chunk-YLY7NKAB.js} +4 -4
  55. package/Build/Workers/{chunk-4TIG36AW.js → chunk-ZK3CF7ZD.js} +12 -12
  56. package/Build/Workers/{chunk-AJLTU6PF.js → chunk-ZP7JMQV4.js} +4 -1
  57. package/Build/Workers/{chunk-HXJMS2ZI.js → chunk-ZZ46LWL6.js} +1 -1
  58. package/Build/Workers/combineGeometry.js +24 -24
  59. package/Build/Workers/createBoxGeometry.js +18 -18
  60. package/Build/Workers/createBoxOutlineGeometry.js +16 -16
  61. package/Build/Workers/createCircleGeometry.js +26 -26
  62. package/Build/Workers/createCircleOutlineGeometry.js +19 -19
  63. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -33
  64. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -31
  65. package/Build/Workers/createCorridorGeometry.js +29 -29
  66. package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
  67. package/Build/Workers/createCylinderGeometry.js +20 -20
  68. package/Build/Workers/createCylinderOutlineGeometry.js +18 -18
  69. package/Build/Workers/createEllipseGeometry.js +26 -26
  70. package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
  71. package/Build/Workers/createEllipsoidGeometry.js +19 -19
  72. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
  73. package/Build/Workers/createFrustumGeometry.js +18 -18
  74. package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
  75. package/Build/Workers/createGeometry.js +24 -24
  76. package/Build/Workers/createGroundPolylineGeometry.js +175 -118
  77. package/Build/Workers/createPlaneGeometry.js +16 -16
  78. package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
  79. package/Build/Workers/createPolygonGeometry.js +32 -32
  80. package/Build/Workers/createPolygonOutlineGeometry.js +30 -30
  81. package/Build/Workers/createPolylineGeometry.js +25 -25
  82. package/Build/Workers/createPolylineVolumeGeometry.js +31 -31
  83. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
  84. package/Build/Workers/createRectangleGeometry.js +27 -27
  85. package/Build/Workers/createRectangleOutlineGeometry.js +20 -20
  86. package/Build/Workers/createSimplePolylineGeometry.js +23 -23
  87. package/Build/Workers/createSphereGeometry.js +19 -19
  88. package/Build/Workers/createSphereOutlineGeometry.js +18 -18
  89. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  90. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  91. package/Build/Workers/createVectorTileGeometries.js +24 -24
  92. package/Build/Workers/createVectorTilePoints.js +13 -13
  93. package/Build/Workers/createVectorTilePolygons.js +22 -22
  94. package/Build/Workers/createVectorTilePolylines.js +14 -14
  95. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -25
  96. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +22 -22
  97. package/Build/Workers/createVerticesFromHeightmap.js +24 -23
  98. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +20 -20
  99. package/Build/Workers/createWallGeometry.js +24 -24
  100. package/Build/Workers/createWallOutlineGeometry.js +23 -23
  101. package/Build/Workers/decodeDraco.js +10 -10
  102. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  103. package/Build/Workers/decodeI3S.js +10 -10
  104. package/Build/Workers/gaussianSplatSorter.js +4 -4
  105. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  106. package/Build/Workers/incrementallyBuildTerrainPicker.js +10 -10
  107. package/Build/Workers/transcodeKTX2.js +12 -9
  108. package/Build/Workers/transferTypedArrayTest.js +1 -1
  109. package/Build/Workers/upsampleQuantizedTerrainMesh.js +22 -22
  110. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
  111. package/Source/Core/ArcType.js +6 -1
  112. package/Source/Core/ArticulationStageType.js +5 -1
  113. package/Source/Core/AssociativeArray.js +100 -94
  114. package/Source/Core/BoundingSphere.js +1296 -1300
  115. package/Source/Core/Cartesian2.js +1 -1
  116. package/Source/Core/Cartesian3.js +2 -3
  117. package/Source/Core/Cartesian4.js +1 -1
  118. package/Source/Core/Cartographic.js +257 -249
  119. package/Source/Core/ClockRange.js +6 -1
  120. package/Source/Core/ClockStep.js +6 -1
  121. package/Source/Core/Color.js +844 -835
  122. package/Source/Core/ComponentDatatype.js +39 -1
  123. package/Source/Core/CornerType.js +6 -1
  124. package/Source/Core/Credit.js +121 -124
  125. package/Source/Core/Ellipsoid.js +637 -660
  126. package/Source/Core/ExtrapolationType.js +6 -1
  127. package/Source/Core/GeocodeType.js +6 -1
  128. package/Source/Core/GeographicProjection.js +74 -74
  129. package/Source/Core/GeographicTilingScheme.js +179 -198
  130. package/Source/Core/GeometryOffsetAttribute.js +7 -1
  131. package/Source/Core/GeometryType.js +7 -1
  132. package/Source/Core/HeightmapEncoding.js +6 -1
  133. package/Source/Core/Iau2006XysData.js +24 -13
  134. package/Source/Core/IndexDatatype.js +3 -1
  135. package/Source/Core/InterpolationType.js +5 -1
  136. package/Source/Core/Intersect.js +6 -1
  137. package/Source/Core/Ion.js +1 -1
  138. package/Source/Core/IonGeocodeProviderType.js +5 -1
  139. package/Source/Core/JulianDate.js +850 -848
  140. package/Source/Core/KeyboardEventModifier.js +6 -1
  141. package/Source/Core/MapProjection.js +40 -44
  142. package/Source/Core/Matrix2.js +906 -893
  143. package/Source/Core/Matrix3.js +1643 -1575
  144. package/Source/Core/Matrix4.js +2903 -2872
  145. package/Source/Core/PixelFormat.js +3 -1
  146. package/Source/Core/PrimitiveType.js +11 -1
  147. package/Source/Core/Ray.js +62 -60
  148. package/Source/Core/Rectangle.js +913 -904
  149. package/Source/Core/ReferenceFrame.js +6 -1
  150. package/Source/Core/RequestScheduler.js +8 -3
  151. package/Source/Core/RequestState.js +6 -1
  152. package/Source/Core/RequestType.js +6 -1
  153. package/Source/Core/Resource.js +1 -1
  154. package/Source/Core/ScreenSpaceEventHandler.js +51 -41
  155. package/Source/Core/ScreenSpaceEventType.js +6 -1
  156. package/Source/Core/TerrainQuantization.js +6 -1
  157. package/Source/Core/TilingScheme.js +100 -98
  158. package/Source/Core/TimeConstants.js +6 -1
  159. package/Source/Core/TimeStandard.js +6 -1
  160. package/Source/Core/TrackingReferenceFrame.js +6 -1
  161. package/Source/Core/Visibility.js +6 -1
  162. package/Source/Core/VulkanConstants.js +6 -1
  163. package/Source/Core/WebGLConstants.js +6 -1
  164. package/Source/Core/WebMercatorProjection.js +108 -109
  165. package/Source/Core/WebMercatorTilingScheme.js +246 -242
  166. package/Source/Core/WindingOrder.js +3 -1
  167. package/Source/Core/createColorRamp.js +37 -0
  168. package/Source/Core/globalTypes.js +25 -0
  169. package/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js +1 -0
  170. package/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js +1 -0
  171. package/Source/DataSources/StripeOrientation.js +6 -1
  172. package/Source/Renderer/BufferUsage.js +20 -9
  173. package/Source/Renderer/Context.js +2 -29
  174. package/Source/Renderer/DrawCommand.js +435 -403
  175. package/Source/Renderer/MipmapHint.js +5 -1
  176. package/Source/Renderer/Pass.js +10 -3
  177. package/Source/Renderer/PickId.js +44 -0
  178. package/Source/Renderer/PixelDatatype.js +3 -1
  179. package/Source/Renderer/RenderbufferFormat.js +5 -1
  180. package/Source/Renderer/ShaderDestination.js +4 -1
  181. package/Source/Renderer/TextureMagnificationFilter.js +3 -1
  182. package/Source/Renderer/TextureMinificationFilter.js +3 -1
  183. package/Source/Renderer/TextureWrap.js +5 -1
  184. package/Source/Renderer/createUniform.js +346 -239
  185. package/Source/Renderer/createUniformArray.js +494 -381
  186. package/Source/Scene/AlphaMode.js +5 -1
  187. package/Source/Scene/ArcGisBaseMapType.js +6 -1
  188. package/Source/Scene/ArcGisMapService.js +1 -1
  189. package/Source/Scene/AttributeType.js +3 -1
  190. package/Source/Scene/Axis.js +3 -1
  191. package/Source/Scene/BingMapsStyle.js +6 -1
  192. package/Source/Scene/BlendEquation.js +6 -1
  193. package/Source/Scene/BlendFunction.js +6 -1
  194. package/Source/Scene/BlendOption.js +6 -1
  195. package/Source/Scene/BlendingState.js +6 -1
  196. package/Source/Scene/BufferLoader.js +0 -2
  197. package/Source/Scene/BufferPoint.js +1 -0
  198. package/Source/Scene/BufferPointCollection.js +17 -1
  199. package/Source/Scene/BufferPolygon.js +3 -2
  200. package/Source/Scene/BufferPolygonCollection.js +13 -1
  201. package/Source/Scene/BufferPolyline.js +1 -0
  202. package/Source/Scene/BufferPolylineCollection.js +5 -1
  203. package/Source/Scene/BufferPrimitiveCollection.js +210 -43
  204. package/Source/Scene/CameraEventAggregator.js +30 -18
  205. package/Source/Scene/CameraEventType.js +6 -1
  206. package/Source/Scene/Cesium3DTile.js +54 -1
  207. package/Source/Scene/Cesium3DTileColorBlendMode.js +6 -1
  208. package/Source/Scene/Cesium3DTileContent.js +195 -254
  209. package/Source/Scene/Cesium3DTileContentFactory.js +10 -2
  210. package/Source/Scene/Cesium3DTileContentState.js +6 -1
  211. package/Source/Scene/Cesium3DTileContentType.js +3 -1
  212. package/Source/Scene/Cesium3DTileFeature.js +289 -306
  213. package/Source/Scene/Cesium3DTileOptimizationHint.js +6 -1
  214. package/Source/Scene/Cesium3DTilePass.js +5 -1
  215. package/Source/Scene/Cesium3DTilePointFeature.js +433 -511
  216. package/Source/Scene/Cesium3DTileRefine.js +6 -1
  217. package/Source/Scene/Cesium3DTileVectorFeature.js +586 -0
  218. package/Source/Scene/Cesium3DTileset.js +46 -6
  219. package/Source/Scene/ClassificationType.js +3 -1
  220. package/Source/Scene/CloudType.js +3 -1
  221. package/Source/Scene/ColorBlendMode.js +4 -1
  222. package/Source/Scene/Composite3DTileContent.js +254 -292
  223. package/Source/Scene/CullFace.js +6 -1
  224. package/Source/Scene/DepthFunction.js +6 -1
  225. package/Source/Scene/DynamicAtmosphereLightingType.js +3 -1
  226. package/Source/Scene/EdgeDisplayMode.js +50 -0
  227. package/Source/Scene/Empty3DTileContent.js +100 -132
  228. package/Source/Scene/EquirectangularPanorama.js +1 -0
  229. package/Source/Scene/ExpressionNodeType.js +6 -1
  230. package/Source/Scene/GaussianSplat3DTileContent.js +436 -478
  231. package/Source/Scene/GeoJsonPrimitive.js +874 -0
  232. package/Source/Scene/Geometry3DTileContent.js +151 -185
  233. package/Source/Scene/GltfBufferViewLoader.js +0 -2
  234. package/Source/Scene/GltfDracoLoader.js +0 -2
  235. package/Source/Scene/GltfImageLoader.js +0 -3
  236. package/Source/Scene/GltfIndexBufferLoader.js +0 -4
  237. package/Source/Scene/GltfJsonLoader.js +0 -2
  238. package/Source/Scene/GltfLoader.js +109 -5
  239. package/Source/Scene/GltfLoaderUtil.js +14 -0
  240. package/Source/Scene/GltfSpzLoader.js +0 -2
  241. package/Source/Scene/GltfStructuralMetadataLoader.js +0 -2
  242. package/Source/Scene/GltfTextureLoader.js +0 -2
  243. package/Source/Scene/GltfVertexBufferLoader.js +0 -4
  244. package/Source/Scene/HeightReference.js +5 -1
  245. package/Source/Scene/HorizontalOrigin.js +6 -1
  246. package/Source/Scene/ImageryProvider.js +1 -1
  247. package/Source/Scene/ImageryState.js +6 -1
  248. package/Source/Scene/Implicit3DTileContent.js +179 -214
  249. package/Source/Scene/ImplicitSubdivisionScheme.js +3 -1
  250. package/Source/Scene/InstanceAttributeSemantic.js +3 -1
  251. package/Source/Scene/IonWorldImageryStyle.js +6 -1
  252. package/Source/Scene/JobType.js +6 -1
  253. package/Source/Scene/LabelStyle.js +6 -1
  254. package/Source/Scene/MVTDataProvider.js +147 -0
  255. package/Source/Scene/MapMode2D.js +6 -1
  256. package/Source/Scene/MetadataComponentType.js +3 -1
  257. package/Source/Scene/MetadataSchemaLoader.js +0 -2
  258. package/Source/Scene/MetadataSemantic.js +6 -2
  259. package/Source/Scene/MetadataType.js +3 -1
  260. package/Source/Scene/Model/B3dmLoader.js +0 -3
  261. package/Source/Scene/Model/CustomShaderMode.js +3 -1
  262. package/Source/Scene/Model/CustomShaderTranslucencyMode.js +5 -1
  263. package/Source/Scene/Model/EdgeVisibilityPipelineStage.js +78 -337
  264. package/Source/Scene/Model/Extensions/Gpm/PpeSource.js +5 -1
  265. package/Source/Scene/Model/Extensions/Gpm/StorageType.js +5 -1
  266. package/Source/Scene/Model/GeoJsonLoader.js +0 -2
  267. package/Source/Scene/Model/I3dmLoader.js +0 -3
  268. package/Source/Scene/Model/InstancingPipelineStage.js +1 -1
  269. package/Source/Scene/Model/LightingModel.js +5 -1
  270. package/Source/Scene/Model/MaterialPipelineStage.js +184 -3
  271. package/Source/Scene/Model/Model.js +34 -0
  272. package/Source/Scene/Model/Model3DTileContent.js +424 -458
  273. package/Source/Scene/Model/ModelDrawCommand.js +31 -3
  274. package/Source/Scene/Model/ModelReader.js +474 -3
  275. package/Source/Scene/Model/ModelRuntimePrimitive.js +2 -1
  276. package/Source/Scene/Model/ModelType.js +3 -1
  277. package/Source/Scene/Model/ModelUtility.js +4 -0
  278. package/Source/Scene/Model/PntsLoader.js +4 -3
  279. package/Source/Scene/Model/StyleCommandsNeeded.js +3 -1
  280. package/Source/Scene/Model/UniformType.js +5 -1
  281. package/Source/Scene/Model/VaryingType.js +5 -1
  282. package/Source/Scene/Model/createVectorTileBuffersFromModelComponents.js +500 -139
  283. package/Source/Scene/Model/pickModel.js +94 -299
  284. package/Source/Scene/ModelAnimationLoop.js +6 -1
  285. package/Source/Scene/ModelAnimationState.js +6 -1
  286. package/Source/Scene/ModelComponents.js +47 -2
  287. package/Source/Scene/Multiple3DTileContent.js +291 -334
  288. package/Source/Scene/PrimitiveState.js +7 -1
  289. package/Source/Scene/QuadtreeOccluders.js +20 -15
  290. package/Source/Scene/QuadtreeTile.js +547 -541
  291. package/Source/Scene/QuadtreeTileLoadState.js +6 -1
  292. package/Source/Scene/QuadtreeTileProvider.js +159 -175
  293. package/Source/Scene/ResourceLoader.js +0 -1
  294. package/Source/Scene/ResourceLoaderState.js +7 -1
  295. package/Source/Scene/Scene.js +26 -0
  296. package/Source/Scene/SceneMode.js +4 -1
  297. package/Source/Scene/ShadowMode.js +3 -1
  298. package/Source/Scene/SkyBox.js +1 -1
  299. package/Source/Scene/SplitDirection.js +6 -1
  300. package/Source/Scene/StencilFunction.js +6 -1
  301. package/Source/Scene/StencilOperation.js +6 -1
  302. package/Source/Scene/TerrainState.js +7 -1
  303. package/Source/Scene/TileState.js +7 -1
  304. package/Source/Scene/Tileset3DTileContent.js +113 -146
  305. package/Source/Scene/Tonemapper.js +5 -1
  306. package/Source/Scene/UrlTemplate3DTilesDataProvider.js +499 -0
  307. package/Source/Scene/Vector3DTileContent.js +205 -234
  308. package/Source/Scene/VectorGltf3DTileContent.js +131 -61
  309. package/Source/Scene/VertexAttributeSemantic.js +3 -1
  310. package/Source/Scene/VerticalOrigin.js +6 -1
  311. package/Source/Scene/VoxelBoxShape.js +12 -6
  312. package/Source/Scene/VoxelContent.js +2 -0
  313. package/Source/Scene/VoxelCylinderShape.js +39 -38
  314. package/Source/Scene/VoxelEllipsoidShape.js +46 -96
  315. package/Source/Scene/VoxelMetadataOrder.js +6 -1
  316. package/Source/Scene/VoxelPrimitive.js +159 -175
  317. package/Source/Scene/VoxelProvider.js +64 -90
  318. package/Source/Scene/VoxelShapeType.js +3 -1
  319. package/Source/Scene/buildVectorGltfFromMVT.js +1059 -0
  320. package/Source/Scene/buildVoxelCustomShader.js +199 -0
  321. package/Source/Scene/decodeMVT.js +634 -0
  322. package/Source/Scene/renderBufferPointCollection.js +124 -127
  323. package/Source/Scene/renderBufferPolygonCollection.js +122 -122
  324. package/Source/Scene/renderBufferPolylineCollection.js +386 -238
  325. package/Source/Shaders/BufferPointMaterialFS.glsl +1 -0
  326. package/Source/Shaders/BufferPointMaterialFS.js +1 -0
  327. package/Source/Shaders/BufferPointMaterialVS.glsl +19 -9
  328. package/Source/Shaders/BufferPointMaterialVS.js +20 -10
  329. package/Source/Shaders/BufferPolygonMaterialVS.glsl +13 -4
  330. package/Source/Shaders/BufferPolygonMaterialVS.js +14 -5
  331. package/Source/Shaders/BufferPolylineMaterialVS.glsl +16 -2
  332. package/Source/Shaders/BufferPolylineMaterialVS.js +17 -3
  333. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdgesDirect.glsl +9 -0
  334. package/Source/Shaders/Builtin/Constants/passCesium3DTileEdgesDirect.js +11 -0
  335. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  336. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  337. package/Source/Shaders/Builtin/CzmBuiltins.js +4 -0
  338. package/Source/Shaders/Builtin/Functions/computeTextureTransform.glsl +24 -0
  339. package/Source/Shaders/Builtin/Functions/computeTextureTransform.js +25 -0
  340. package/Source/Shaders/Model/ConstantLodStageFS.glsl +60 -0
  341. package/Source/Shaders/Model/ConstantLodStageFS.js +62 -0
  342. package/Source/Shaders/Model/ConstantLodStageVS.glsl +12 -0
  343. package/Source/Shaders/Model/ConstantLodStageVS.js +13 -0
  344. package/Source/Shaders/Model/EdgeVisibilityStageVS.glsl +0 -1
  345. package/Source/Shaders/Model/EdgeVisibilityStageVS.js +0 -1
  346. package/Source/Shaders/Model/MaterialStageFS.glsl +46 -20
  347. package/Source/Shaders/Model/MaterialStageFS.js +46 -20
  348. package/Source/Shaders/Voxels/convertLocalToBoxUv.glsl +0 -1
  349. package/Source/Shaders/Voxels/convertLocalToBoxUv.js +0 -1
  350. package/Source/Shaders/Voxels/convertLocalToCylinderUv.glsl +7 -9
  351. package/Source/Shaders/Voxels/convertLocalToCylinderUv.js +7 -9
  352. package/Source/Shaders/Voxels/convertLocalToEllipsoidUv.glsl +7 -17
  353. package/Source/Shaders/Voxels/convertLocalToEllipsoidUv.js +7 -17
  354. package/Source/Widget/CesiumWidget.js +11 -4
  355. package/index.d.ts +595 -343
  356. package/index.js +392 -378
  357. package/package.json +3 -3
  358. package/Build/Workers/chunk-DVB56LG7.js +0 -114
  359. package/Build/Workers/chunk-HKUES6UG.js +0 -2357
  360. package/Build/Workers/chunk-HRHRYFHS.js +0 -940
  361. package/Build/Workers/chunk-KLPGTXS3.js +0 -642
  362. package/Build/Workers/chunk-ZBZRTRJB.js +0 -1829
@@ -1,25 +1,25 @@
1
+ // @ts-check
2
+
1
3
  import Cartesian3 from "./Cartesian3.js";
2
4
  import Check from "./Check.js";
3
5
  import defined from "./defined.js";
4
6
  import DeveloperError from "./DeveloperError.js";
5
7
  import CesiumMath from "./Math.js";
6
8
 
9
+ /** @import Quaternion from "./Quaternion.js"; */
10
+ /** @import HeadingPitchRoll from "./HeadingPitchRoll.js"; */
11
+
12
+ /**
13
+ * @typedef {object} EigenDecompositionResult
14
+ * @property {Matrix3} [unitary]
15
+ * @property {Matrix3} [diagonal]
16
+ */
17
+
7
18
  /**
8
19
  * A 3x3 matrix, indexable as a column-major order array.
9
20
  * Constructor parameters are in row-major order for code readability.
10
- * @alias Matrix3
11
- * @constructor
12
- * @implements {ArrayLike<number>}
13
21
  *
14
- * @param {number} [column0Row0=0.0] The value for column 0, row 0.
15
- * @param {number} [column1Row0=0.0] The value for column 1, row 0.
16
- * @param {number} [column2Row0=0.0] The value for column 2, row 0.
17
- * @param {number} [column0Row1=0.0] The value for column 0, row 1.
18
- * @param {number} [column1Row1=0.0] The value for column 1, row 1.
19
- * @param {number} [column2Row1=0.0] The value for column 2, row 1.
20
- * @param {number} [column0Row2=0.0] The value for column 0, row 2.
21
- * @param {number} [column1Row2=0.0] The value for column 1, row 2.
22
- * @param {number} [column2Row2=0.0] The value for column 2, row 2.
22
+ * @implements {ArrayLike<number>}
23
23
  *
24
24
  * @see Matrix3.fromArray
25
25
  * @see Matrix3.fromColumnMajorArray
@@ -35,1635 +35,1662 @@ import CesiumMath from "./Math.js";
35
35
  * @see Matrix2
36
36
  * @see Matrix4
37
37
  */
38
- function Matrix3(
39
- column0Row0,
40
- column1Row0,
41
- column2Row0,
42
- column0Row1,
43
- column1Row1,
44
- column2Row1,
45
- column0Row2,
46
- column1Row2,
47
- column2Row2,
48
- ) {
49
- this[0] = column0Row0 ?? 0.0;
50
- this[1] = column0Row1 ?? 0.0;
51
- this[2] = column0Row2 ?? 0.0;
52
- this[3] = column1Row0 ?? 0.0;
53
- this[4] = column1Row1 ?? 0.0;
54
- this[5] = column1Row2 ?? 0.0;
55
- this[6] = column2Row0 ?? 0.0;
56
- this[7] = column2Row1 ?? 0.0;
57
- this[8] = column2Row2 ?? 0.0;
58
- }
59
-
60
- /**
61
- * The number of elements used to pack the object into an array.
62
- * @type {number}
63
- */
64
- Matrix3.packedLength = 9;
38
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
39
+ class Matrix3 {
40
+ /**
41
+ * @param {number} [column0Row0=0.0] The value for column 0, row 0.
42
+ * @param {number} [column1Row0=0.0] The value for column 1, row 0.
43
+ * @param {number} [column2Row0=0.0] The value for column 2, row 0.
44
+ * @param {number} [column0Row1=0.0] The value for column 0, row 1.
45
+ * @param {number} [column1Row1=0.0] The value for column 1, row 1.
46
+ * @param {number} [column2Row1=0.0] The value for column 2, row 1.
47
+ * @param {number} [column0Row2=0.0] The value for column 0, row 2.
48
+ * @param {number} [column1Row2=0.0] The value for column 1, row 2.
49
+ * @param {number} [column2Row2=0.0] The value for column 2, row 2.
50
+ */
51
+ constructor(
52
+ column0Row0,
53
+ column1Row0,
54
+ column2Row0,
55
+ column0Row1,
56
+ column1Row1,
57
+ column2Row1,
58
+ column0Row2,
59
+ column1Row2,
60
+ column2Row2,
61
+ ) {
62
+ this[0] = column0Row0 ?? 0.0;
63
+ this[1] = column0Row1 ?? 0.0;
64
+ this[2] = column0Row2 ?? 0.0;
65
+ this[3] = column1Row0 ?? 0.0;
66
+ this[4] = column1Row1 ?? 0.0;
67
+ this[5] = column1Row2 ?? 0.0;
68
+ this[6] = column2Row0 ?? 0.0;
69
+ this[7] = column2Row1 ?? 0.0;
70
+ this[8] = column2Row2 ?? 0.0;
71
+ }
65
72
 
66
- /**
67
- * Stores the provided instance into the provided array.
68
- *
69
- * @param {Matrix3} value The value to pack.
70
- * @param {number[]} array The array to pack into.
71
- * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
72
- *
73
- * @returns {number[]} The array that was packed into
74
- */
75
- Matrix3.pack = function (value, array, startingIndex) {
76
- //>>includeStart('debug', pragmas.debug);
77
- Check.typeOf.object("value", value);
78
- Check.defined("array", array);
79
- //>>includeEnd('debug');
80
-
81
- startingIndex = startingIndex ?? 0;
82
-
83
- array[startingIndex++] = value[0];
84
- array[startingIndex++] = value[1];
85
- array[startingIndex++] = value[2];
86
- array[startingIndex++] = value[3];
87
- array[startingIndex++] = value[4];
88
- array[startingIndex++] = value[5];
89
- array[startingIndex++] = value[6];
90
- array[startingIndex++] = value[7];
91
- array[startingIndex++] = value[8];
92
-
93
- return array;
94
- };
73
+ /**
74
+ * Stores the provided instance into the provided array.
75
+ *
76
+ * @param {Matrix3} value The value to pack.
77
+ * @param {number[]} array The array to pack into.
78
+ * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
79
+ *
80
+ * @returns {number[]} The array that was packed into
81
+ */
82
+ static pack(value, array, startingIndex) {
83
+ //>>includeStart('debug', pragmas.debug);
84
+ Check.typeOf.object("value", value);
85
+ Check.defined("array", array);
86
+ //>>includeEnd('debug');
95
87
 
96
- /**
97
- * Retrieves an instance from a packed array.
98
- *
99
- * @param {number[]} array The packed array.
100
- * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
101
- * @param {Matrix3} [result] The object into which to store the result.
102
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
103
- */
104
- Matrix3.unpack = function (array, startingIndex, result) {
105
- //>>includeStart('debug', pragmas.debug);
106
- Check.defined("array", array);
107
- //>>includeEnd('debug');
88
+ startingIndex = startingIndex ?? 0;
108
89
 
109
- startingIndex = startingIndex ?? 0;
90
+ array[startingIndex++] = value[0];
91
+ array[startingIndex++] = value[1];
92
+ array[startingIndex++] = value[2];
93
+ array[startingIndex++] = value[3];
94
+ array[startingIndex++] = value[4];
95
+ array[startingIndex++] = value[5];
96
+ array[startingIndex++] = value[6];
97
+ array[startingIndex++] = value[7];
98
+ array[startingIndex++] = value[8];
110
99
 
111
- if (!defined(result)) {
112
- result = new Matrix3();
100
+ return array;
113
101
  }
114
102
 
115
- result[0] = array[startingIndex++];
116
- result[1] = array[startingIndex++];
117
- result[2] = array[startingIndex++];
118
- result[3] = array[startingIndex++];
119
- result[4] = array[startingIndex++];
120
- result[5] = array[startingIndex++];
121
- result[6] = array[startingIndex++];
122
- result[7] = array[startingIndex++];
123
- result[8] = array[startingIndex++];
124
- return result;
125
- };
126
-
127
- /**
128
- * Flattens an array of Matrix3s into an array of components. The components
129
- * are stored in column-major order.
130
- *
131
- * @param {Matrix3[]} array The array of matrices to pack.
132
- * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 9 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 9) elements.
133
- * @returns {number[]} The packed array.
134
- */
135
- Matrix3.packArray = function (array, result) {
136
- //>>includeStart('debug', pragmas.debug);
137
- Check.defined("array", array);
138
- //>>includeEnd('debug');
139
-
140
- const length = array.length;
141
- const resultLength = length * 9;
142
- if (!defined(result)) {
143
- result = new Array(resultLength);
144
- } else if (!Array.isArray(result) && result.length !== resultLength) {
103
+ /**
104
+ * Retrieves an instance from a packed array.
105
+ *
106
+ * @param {number[]} array The packed array.
107
+ * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
108
+ * @param {Matrix3} [result] The object into which to store the result.
109
+ * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
110
+ */
111
+ static unpack(array, startingIndex, result) {
145
112
  //>>includeStart('debug', pragmas.debug);
146
- throw new DeveloperError(
147
- "If result is a typed array, it must have exactly array.length * 9 elements",
148
- );
113
+ Check.defined("array", array);
149
114
  //>>includeEnd('debug');
150
- } else if (result.length !== resultLength) {
151
- result.length = resultLength;
152
- }
153
115
 
154
- for (let i = 0; i < length; ++i) {
155
- Matrix3.pack(array[i], result, i * 9);
156
- }
157
- return result;
158
- };
116
+ startingIndex = startingIndex ?? 0;
159
117
 
160
- /**
161
- * Unpacks an array of column-major matrix components into an array of Matrix3s.
162
- *
163
- * @param {number[]} array The array of components to unpack.
164
- * @param {Matrix3[]} [result] The array onto which to store the result.
165
- * @returns {Matrix3[]} The unpacked array.
166
- */
167
- Matrix3.unpackArray = function (array, result) {
168
- //>>includeStart('debug', pragmas.debug);
169
- Check.defined("array", array);
170
- Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 9);
171
- if (array.length % 9 !== 0) {
172
- throw new DeveloperError("array length must be a multiple of 9.");
173
- }
174
- //>>includeEnd('debug');
118
+ if (!defined(result)) {
119
+ result = new Matrix3();
120
+ }
175
121
 
176
- const length = array.length;
177
- if (!defined(result)) {
178
- result = new Array(length / 9);
179
- } else {
180
- result.length = length / 9;
122
+ result[0] = array[startingIndex++];
123
+ result[1] = array[startingIndex++];
124
+ result[2] = array[startingIndex++];
125
+ result[3] = array[startingIndex++];
126
+ result[4] = array[startingIndex++];
127
+ result[5] = array[startingIndex++];
128
+ result[6] = array[startingIndex++];
129
+ result[7] = array[startingIndex++];
130
+ result[8] = array[startingIndex++];
131
+ return result;
181
132
  }
182
133
 
183
- for (let i = 0; i < length; i += 9) {
184
- const index = i / 9;
185
- result[index] = Matrix3.unpack(array, i, result[index]);
186
- }
187
- return result;
188
- };
134
+ /**
135
+ * Flattens an array of Matrix3s into an array of components. The components
136
+ * are stored in column-major order.
137
+ *
138
+ * @param {Matrix3[]} array The array of matrices to pack.
139
+ * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 9 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 9) elements.
140
+ * @returns {number[]} The packed array.
141
+ */
142
+ static packArray(array, result) {
143
+ //>>includeStart('debug', pragmas.debug);
144
+ Check.defined("array", array);
145
+ //>>includeEnd('debug');
189
146
 
190
- /**
191
- * Duplicates a Matrix3 instance.
192
- *
193
- * @param {Matrix3} matrix The matrix to duplicate.
194
- * @param {Matrix3} [result] The object onto which to store the result.
195
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)
196
- */
197
- Matrix3.clone = function (matrix, result) {
198
- if (!defined(matrix)) {
199
- return undefined;
200
- }
201
- if (!defined(result)) {
202
- return new Matrix3(
203
- matrix[0],
204
- matrix[3],
205
- matrix[6],
206
- matrix[1],
207
- matrix[4],
208
- matrix[7],
209
- matrix[2],
210
- matrix[5],
211
- matrix[8],
212
- );
147
+ const length = array.length;
148
+ const resultLength = length * 9;
149
+ if (!defined(result)) {
150
+ result = new Array(resultLength);
151
+ // @ts-expect-error TODO(tsd-jsdoc): Requires conditional TypedArray types.
152
+ } else if (!Array.isArray(result) && result.length !== resultLength) {
153
+ //>>includeStart('debug', pragmas.debug);
154
+ throw new DeveloperError(
155
+ "If result is a typed array, it must have exactly array.length * 9 elements",
156
+ );
157
+ //>>includeEnd('debug');
158
+ } else if (result.length !== resultLength) {
159
+ /** @type {number[]} */ (result).length = resultLength;
160
+ }
161
+
162
+ for (let i = 0; i < length; ++i) {
163
+ Matrix3.pack(array[i], result, i * 9);
164
+ }
165
+
166
+ return result;
213
167
  }
214
- result[0] = matrix[0];
215
- result[1] = matrix[1];
216
- result[2] = matrix[2];
217
- result[3] = matrix[3];
218
- result[4] = matrix[4];
219
- result[5] = matrix[5];
220
- result[6] = matrix[6];
221
- result[7] = matrix[7];
222
- result[8] = matrix[8];
223
- return result;
224
- };
225
168
 
226
- /**
227
- * Creates a Matrix3 from 9 consecutive elements in an array.
228
- *
229
- * @function
230
- * @param {number[]} array The array whose 9 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
231
- * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
232
- * @param {Matrix3} [result] The object onto which to store the result.
233
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
234
- *
235
- * @example
236
- * // Create the Matrix3:
237
- * // [1.0, 2.0, 3.0]
238
- * // [1.0, 2.0, 3.0]
239
- * // [1.0, 2.0, 3.0]
240
- *
241
- * const v = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
242
- * const m = Cesium.Matrix3.fromArray(v);
243
- *
244
- * // Create same Matrix3 with using an offset into an array
245
- * const v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
246
- * const m2 = Cesium.Matrix3.fromArray(v2, 2);
247
- */
248
- Matrix3.fromArray = Matrix3.unpack;
169
+ /**
170
+ * Unpacks an array of column-major matrix components into an array of Matrix3s.
171
+ *
172
+ * @param {number[]} array The array of components to unpack.
173
+ * @param {Matrix3[]} [result] The array onto which to store the result.
174
+ * @returns {Matrix3[]} The unpacked array.
175
+ */
176
+ static unpackArray(array, result) {
177
+ //>>includeStart('debug', pragmas.debug);
178
+ Check.defined("array", array);
179
+ Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 9);
180
+ if (array.length % 9 !== 0) {
181
+ throw new DeveloperError("array length must be a multiple of 9.");
182
+ }
183
+ //>>includeEnd('debug');
249
184
 
250
- /**
251
- * Creates a Matrix3 instance from a column-major order array.
252
- *
253
- * @param {number[]} values The column-major order array.
254
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
255
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
256
- */
257
- Matrix3.fromColumnMajorArray = function (values, result) {
258
- //>>includeStart('debug', pragmas.debug);
259
- Check.defined("values", values);
260
- //>>includeEnd('debug');
185
+ const length = array.length;
186
+ if (!defined(result)) {
187
+ result = new Array(length / 9);
188
+ } else {
189
+ result.length = length / 9;
190
+ }
261
191
 
262
- return Matrix3.clone(values, result);
263
- };
192
+ for (let i = 0; i < length; i += 9) {
193
+ const index = i / 9;
194
+ result[index] = Matrix3.unpack(array, i, result[index]);
195
+ }
196
+ return result;
197
+ }
264
198
 
265
- /**
266
- * Creates a Matrix3 instance from a row-major order array.
267
- * The resulting matrix will be in column-major order.
268
- *
269
- * @param {number[]} values The row-major order array.
270
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
271
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
272
- */
273
- Matrix3.fromRowMajorArray = function (values, result) {
274
- //>>includeStart('debug', pragmas.debug);
275
- Check.defined("values", values);
276
- //>>includeEnd('debug');
277
-
278
- if (!defined(result)) {
279
- return new Matrix3(
280
- values[0],
281
- values[1],
282
- values[2],
283
- values[3],
284
- values[4],
285
- values[5],
286
- values[6],
287
- values[7],
288
- values[8],
289
- );
199
+ /**
200
+ * Duplicates a Matrix3 instance.
201
+ *
202
+ * @param {Matrix3} matrix The matrix to duplicate.
203
+ * @param {Matrix3} [result] The object onto which to store the result.
204
+ * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided. (Returns undefined if matrix is undefined)
205
+ */
206
+ static clone(matrix, result) {
207
+ if (!defined(matrix)) {
208
+ return undefined;
209
+ }
210
+ if (!defined(result)) {
211
+ return new Matrix3(
212
+ matrix[0],
213
+ matrix[3],
214
+ matrix[6],
215
+ matrix[1],
216
+ matrix[4],
217
+ matrix[7],
218
+ matrix[2],
219
+ matrix[5],
220
+ matrix[8],
221
+ );
222
+ }
223
+ result[0] = matrix[0];
224
+ result[1] = matrix[1];
225
+ result[2] = matrix[2];
226
+ result[3] = matrix[3];
227
+ result[4] = matrix[4];
228
+ result[5] = matrix[5];
229
+ result[6] = matrix[6];
230
+ result[7] = matrix[7];
231
+ result[8] = matrix[8];
232
+ return result;
290
233
  }
291
- result[0] = values[0];
292
- result[1] = values[3];
293
- result[2] = values[6];
294
- result[3] = values[1];
295
- result[4] = values[4];
296
- result[5] = values[7];
297
- result[6] = values[2];
298
- result[7] = values[5];
299
- result[8] = values[8];
300
- return result;
301
- };
302
234
 
303
- /**
304
- * Computes a 3x3 rotation matrix from the provided quaternion.
305
- *
306
- * @param {Quaternion} quaternion the quaternion to use.
307
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
308
- * @returns {Matrix3} The 3x3 rotation matrix from this quaternion.
309
- */
310
- Matrix3.fromQuaternion = function (quaternion, result) {
311
- //>>includeStart('debug', pragmas.debug);
312
- Check.typeOf.object("quaternion", quaternion);
313
- //>>includeEnd('debug');
314
-
315
- const x2 = quaternion.x * quaternion.x;
316
- const xy = quaternion.x * quaternion.y;
317
- const xz = quaternion.x * quaternion.z;
318
- const xw = quaternion.x * quaternion.w;
319
- const y2 = quaternion.y * quaternion.y;
320
- const yz = quaternion.y * quaternion.z;
321
- const yw = quaternion.y * quaternion.w;
322
- const z2 = quaternion.z * quaternion.z;
323
- const zw = quaternion.z * quaternion.w;
324
- const w2 = quaternion.w * quaternion.w;
325
-
326
- const m00 = x2 - y2 - z2 + w2;
327
- const m01 = 2.0 * (xy - zw);
328
- const m02 = 2.0 * (xz + yw);
329
-
330
- const m10 = 2.0 * (xy + zw);
331
- const m11 = -x2 + y2 - z2 + w2;
332
- const m12 = 2.0 * (yz - xw);
333
-
334
- const m20 = 2.0 * (xz - yw);
335
- const m21 = 2.0 * (yz + xw);
336
- const m22 = -x2 - y2 + z2 + w2;
337
-
338
- if (!defined(result)) {
339
- return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
235
+ /**
236
+ * Creates a Matrix3 instance from a column-major order array.
237
+ *
238
+ * @param {number[]} values The column-major order array.
239
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
240
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
241
+ */
242
+ static fromColumnMajorArray(values, result) {
243
+ //>>includeStart('debug', pragmas.debug);
244
+ Check.defined("values", values);
245
+ //>>includeEnd('debug');
246
+
247
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
248
+ return Matrix3.clone(values, result);
340
249
  }
341
- result[0] = m00;
342
- result[1] = m10;
343
- result[2] = m20;
344
- result[3] = m01;
345
- result[4] = m11;
346
- result[5] = m21;
347
- result[6] = m02;
348
- result[7] = m12;
349
- result[8] = m22;
350
- return result;
351
- };
352
250
 
353
- /**
354
- * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
355
- *
356
- * @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.
357
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
358
- * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.
359
- */
360
- Matrix3.fromHeadingPitchRoll = function (headingPitchRoll, result) {
361
- //>>includeStart('debug', pragmas.debug);
362
- Check.typeOf.object("headingPitchRoll", headingPitchRoll);
363
- //>>includeEnd('debug');
364
-
365
- const cosTheta = Math.cos(-headingPitchRoll.pitch);
366
- const cosPsi = Math.cos(-headingPitchRoll.heading);
367
- const cosPhi = Math.cos(headingPitchRoll.roll);
368
- const sinTheta = Math.sin(-headingPitchRoll.pitch);
369
- const sinPsi = Math.sin(-headingPitchRoll.heading);
370
- const sinPhi = Math.sin(headingPitchRoll.roll);
371
-
372
- const m00 = cosTheta * cosPsi;
373
- const m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
374
- const m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;
375
-
376
- const m10 = cosTheta * sinPsi;
377
- const m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;
378
- const m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi;
379
-
380
- const m20 = -sinTheta;
381
- const m21 = sinPhi * cosTheta;
382
- const m22 = cosPhi * cosTheta;
383
-
384
- if (!defined(result)) {
385
- return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
251
+ /**
252
+ * Creates a Matrix3 instance from a row-major order array.
253
+ * The resulting matrix will be in column-major order.
254
+ *
255
+ * @param {number[]} values The row-major order array.
256
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
257
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
258
+ */
259
+ static fromRowMajorArray(values, result) {
260
+ //>>includeStart('debug', pragmas.debug);
261
+ Check.defined("values", values);
262
+ //>>includeEnd('debug');
263
+
264
+ if (!defined(result)) {
265
+ return new Matrix3(
266
+ values[0],
267
+ values[1],
268
+ values[2],
269
+ values[3],
270
+ values[4],
271
+ values[5],
272
+ values[6],
273
+ values[7],
274
+ values[8],
275
+ );
276
+ }
277
+ result[0] = values[0];
278
+ result[1] = values[3];
279
+ result[2] = values[6];
280
+ result[3] = values[1];
281
+ result[4] = values[4];
282
+ result[5] = values[7];
283
+ result[6] = values[2];
284
+ result[7] = values[5];
285
+ result[8] = values[8];
286
+ return result;
386
287
  }
387
- result[0] = m00;
388
- result[1] = m10;
389
- result[2] = m20;
390
- result[3] = m01;
391
- result[4] = m11;
392
- result[5] = m21;
393
- result[6] = m02;
394
- result[7] = m12;
395
- result[8] = m22;
396
- return result;
397
- };
398
288
 
399
- /**
400
- * Computes a Matrix3 instance representing a non-uniform scale.
401
- *
402
- * @param {Cartesian3} scale The x, y, and z scale factors.
403
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
404
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
405
- *
406
- * @example
407
- * // Creates
408
- * // [7.0, 0.0, 0.0]
409
- * // [0.0, 8.0, 0.0]
410
- * // [0.0, 0.0, 9.0]
411
- * const m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
412
- */
413
- Matrix3.fromScale = function (scale, result) {
414
- //>>includeStart('debug', pragmas.debug);
415
- Check.typeOf.object("scale", scale);
416
- //>>includeEnd('debug');
289
+ /**
290
+ * Computes a 3x3 rotation matrix from the provided quaternion.
291
+ *
292
+ * @param {Quaternion} quaternion the quaternion to use.
293
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
294
+ * @returns {Matrix3} The 3x3 rotation matrix from this quaternion.
295
+ */
296
+ static fromQuaternion(quaternion, result) {
297
+ //>>includeStart('debug', pragmas.debug);
298
+ Check.typeOf.object("quaternion", quaternion);
299
+ //>>includeEnd('debug');
417
300
 
418
- if (!defined(result)) {
419
- return new Matrix3(scale.x, 0.0, 0.0, 0.0, scale.y, 0.0, 0.0, 0.0, scale.z);
301
+ const x2 = quaternion.x * quaternion.x;
302
+ const xy = quaternion.x * quaternion.y;
303
+ const xz = quaternion.x * quaternion.z;
304
+ const xw = quaternion.x * quaternion.w;
305
+ const y2 = quaternion.y * quaternion.y;
306
+ const yz = quaternion.y * quaternion.z;
307
+ const yw = quaternion.y * quaternion.w;
308
+ const z2 = quaternion.z * quaternion.z;
309
+ const zw = quaternion.z * quaternion.w;
310
+ const w2 = quaternion.w * quaternion.w;
311
+
312
+ const m00 = x2 - y2 - z2 + w2;
313
+ const m01 = 2.0 * (xy - zw);
314
+ const m02 = 2.0 * (xz + yw);
315
+
316
+ const m10 = 2.0 * (xy + zw);
317
+ const m11 = -x2 + y2 - z2 + w2;
318
+ const m12 = 2.0 * (yz - xw);
319
+
320
+ const m20 = 2.0 * (xz - yw);
321
+ const m21 = 2.0 * (yz + xw);
322
+ const m22 = -x2 - y2 + z2 + w2;
323
+
324
+ if (!defined(result)) {
325
+ return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
326
+ }
327
+ result[0] = m00;
328
+ result[1] = m10;
329
+ result[2] = m20;
330
+ result[3] = m01;
331
+ result[4] = m11;
332
+ result[5] = m21;
333
+ result[6] = m02;
334
+ result[7] = m12;
335
+ result[8] = m22;
336
+ return result;
420
337
  }
421
338
 
422
- result[0] = scale.x;
423
- result[1] = 0.0;
424
- result[2] = 0.0;
425
- result[3] = 0.0;
426
- result[4] = scale.y;
427
- result[5] = 0.0;
428
- result[6] = 0.0;
429
- result[7] = 0.0;
430
- result[8] = scale.z;
431
- return result;
432
- };
339
+ /**
340
+ * Computes a 3x3 rotation matrix from the provided headingPitchRoll. (see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles )
341
+ *
342
+ * @param {HeadingPitchRoll} headingPitchRoll the headingPitchRoll to use.
343
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
344
+ * @returns {Matrix3} The 3x3 rotation matrix from this headingPitchRoll.
345
+ */
346
+ static fromHeadingPitchRoll(headingPitchRoll, result) {
347
+ //>>includeStart('debug', pragmas.debug);
348
+ Check.typeOf.object("headingPitchRoll", headingPitchRoll);
349
+ //>>includeEnd('debug');
433
350
 
434
- /**
435
- * Computes a Matrix3 instance representing a uniform scale.
436
- *
437
- * @param {number} scale The uniform scale factor.
438
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
439
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
440
- *
441
- * @example
442
- * // Creates
443
- * // [2.0, 0.0, 0.0]
444
- * // [0.0, 2.0, 0.0]
445
- * // [0.0, 0.0, 2.0]
446
- * const m = Cesium.Matrix3.fromUniformScale(2.0);
447
- */
448
- Matrix3.fromUniformScale = function (scale, result) {
449
- //>>includeStart('debug', pragmas.debug);
450
- Check.typeOf.number("scale", scale);
451
- //>>includeEnd('debug');
351
+ const cosTheta = Math.cos(-headingPitchRoll.pitch);
352
+ const cosPsi = Math.cos(-headingPitchRoll.heading);
353
+ const cosPhi = Math.cos(headingPitchRoll.roll);
354
+ const sinTheta = Math.sin(-headingPitchRoll.pitch);
355
+ const sinPsi = Math.sin(-headingPitchRoll.heading);
356
+ const sinPhi = Math.sin(headingPitchRoll.roll);
452
357
 
453
- if (!defined(result)) {
454
- return new Matrix3(scale, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, scale);
455
- }
358
+ const m00 = cosTheta * cosPsi;
359
+ const m01 = -cosPhi * sinPsi + sinPhi * sinTheta * cosPsi;
360
+ const m02 = sinPhi * sinPsi + cosPhi * sinTheta * cosPsi;
456
361
 
457
- result[0] = scale;
458
- result[1] = 0.0;
459
- result[2] = 0.0;
460
- result[3] = 0.0;
461
- result[4] = scale;
462
- result[5] = 0.0;
463
- result[6] = 0.0;
464
- result[7] = 0.0;
465
- result[8] = scale;
466
- return result;
467
- };
362
+ const m10 = cosTheta * sinPsi;
363
+ const m11 = cosPhi * cosPsi + sinPhi * sinTheta * sinPsi;
364
+ const m12 = -sinPhi * cosPsi + cosPhi * sinTheta * sinPsi;
468
365
 
469
- /**
470
- * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.
471
- *
472
- * @param {Cartesian3} vector the vector on the left hand side of the cross product operation.
473
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
474
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
475
- *
476
- * @example
477
- * // Creates
478
- * // [0.0, -9.0, 8.0]
479
- * // [9.0, 0.0, -7.0]
480
- * // [-8.0, 7.0, 0.0]
481
- * const m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));
482
- */
483
- Matrix3.fromCrossProduct = function (vector, result) {
484
- //>>includeStart('debug', pragmas.debug);
485
- Check.typeOf.object("vector", vector);
486
- //>>includeEnd('debug');
487
-
488
- if (!defined(result)) {
489
- return new Matrix3(
490
- 0.0,
491
- -vector.z,
492
- vector.y,
493
- vector.z,
494
- 0.0,
495
- -vector.x,
496
- -vector.y,
497
- vector.x,
498
- 0.0,
499
- );
366
+ const m20 = -sinTheta;
367
+ const m21 = sinPhi * cosTheta;
368
+ const m22 = cosPhi * cosTheta;
369
+
370
+ if (!defined(result)) {
371
+ return new Matrix3(m00, m01, m02, m10, m11, m12, m20, m21, m22);
372
+ }
373
+ result[0] = m00;
374
+ result[1] = m10;
375
+ result[2] = m20;
376
+ result[3] = m01;
377
+ result[4] = m11;
378
+ result[5] = m21;
379
+ result[6] = m02;
380
+ result[7] = m12;
381
+ result[8] = m22;
382
+ return result;
500
383
  }
501
384
 
502
- result[0] = 0.0;
503
- result[1] = vector.z;
504
- result[2] = -vector.y;
505
- result[3] = -vector.z;
506
- result[4] = 0.0;
507
- result[5] = vector.x;
508
- result[6] = vector.y;
509
- result[7] = -vector.x;
510
- result[8] = 0.0;
511
- return result;
512
- };
385
+ /**
386
+ * Computes a Matrix3 instance representing a non-uniform scale.
387
+ *
388
+ * @param {Cartesian3} scale The x, y, and z scale factors.
389
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
390
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
391
+ *
392
+ * @example
393
+ * // Creates
394
+ * // [7.0, 0.0, 0.0]
395
+ * // [0.0, 8.0, 0.0]
396
+ * // [0.0, 0.0, 9.0]
397
+ * const m = Cesium.Matrix3.fromScale(new Cesium.Cartesian3(7.0, 8.0, 9.0));
398
+ */
399
+ static fromScale(scale, result) {
400
+ //>>includeStart('debug', pragmas.debug);
401
+ Check.typeOf.object("scale", scale);
402
+ //>>includeEnd('debug');
513
403
 
514
- /**
515
- * Creates a rotation matrix around the x-axis.
516
- *
517
- * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
518
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
519
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
520
- *
521
- * @example
522
- * // Rotate a point 45 degrees counterclockwise around the x-axis.
523
- * const p = new Cesium.Cartesian3(5, 6, 7);
524
- * const m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));
525
- * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
526
- */
527
- Matrix3.fromRotationX = function (angle, result) {
528
- //>>includeStart('debug', pragmas.debug);
529
- Check.typeOf.number("angle", angle);
530
- //>>includeEnd('debug');
531
-
532
- const cosAngle = Math.cos(angle);
533
- const sinAngle = Math.sin(angle);
534
-
535
- if (!defined(result)) {
536
- return new Matrix3(
537
- 1.0,
538
- 0.0,
539
- 0.0,
540
- 0.0,
541
- cosAngle,
542
- -sinAngle,
543
- 0.0,
544
- sinAngle,
545
- cosAngle,
546
- );
404
+ if (!defined(result)) {
405
+ return new Matrix3(
406
+ scale.x,
407
+ 0.0,
408
+ 0.0,
409
+ 0.0,
410
+ scale.y,
411
+ 0.0,
412
+ 0.0,
413
+ 0.0,
414
+ scale.z,
415
+ );
416
+ }
417
+
418
+ result[0] = scale.x;
419
+ result[1] = 0.0;
420
+ result[2] = 0.0;
421
+ result[3] = 0.0;
422
+ result[4] = scale.y;
423
+ result[5] = 0.0;
424
+ result[6] = 0.0;
425
+ result[7] = 0.0;
426
+ result[8] = scale.z;
427
+ return result;
547
428
  }
548
429
 
549
- result[0] = 1.0;
550
- result[1] = 0.0;
551
- result[2] = 0.0;
552
- result[3] = 0.0;
553
- result[4] = cosAngle;
554
- result[5] = sinAngle;
555
- result[6] = 0.0;
556
- result[7] = -sinAngle;
557
- result[8] = cosAngle;
430
+ /**
431
+ * Computes a Matrix3 instance representing a uniform scale.
432
+ *
433
+ * @param {number} scale The uniform scale factor.
434
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
435
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
436
+ *
437
+ * @example
438
+ * // Creates
439
+ * // [2.0, 0.0, 0.0]
440
+ * // [0.0, 2.0, 0.0]
441
+ * // [0.0, 0.0, 2.0]
442
+ * const m = Cesium.Matrix3.fromUniformScale(2.0);
443
+ */
444
+ static fromUniformScale(scale, result) {
445
+ //>>includeStart('debug', pragmas.debug);
446
+ Check.typeOf.number("scale", scale);
447
+ //>>includeEnd('debug');
558
448
 
559
- return result;
560
- };
449
+ if (!defined(result)) {
450
+ return new Matrix3(scale, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, scale);
451
+ }
561
452
 
562
- /**
563
- * Creates a rotation matrix around the y-axis.
564
- *
565
- * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
566
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
567
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
568
- *
569
- * @example
570
- * // Rotate a point 45 degrees counterclockwise around the y-axis.
571
- * const p = new Cesium.Cartesian3(5, 6, 7);
572
- * const m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));
573
- * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
574
- */
575
- Matrix3.fromRotationY = function (angle, result) {
576
- //>>includeStart('debug', pragmas.debug);
577
- Check.typeOf.number("angle", angle);
578
- //>>includeEnd('debug');
579
-
580
- const cosAngle = Math.cos(angle);
581
- const sinAngle = Math.sin(angle);
582
-
583
- if (!defined(result)) {
584
- return new Matrix3(
585
- cosAngle,
586
- 0.0,
587
- sinAngle,
588
- 0.0,
589
- 1.0,
590
- 0.0,
591
- -sinAngle,
592
- 0.0,
593
- cosAngle,
594
- );
453
+ result[0] = scale;
454
+ result[1] = 0.0;
455
+ result[2] = 0.0;
456
+ result[3] = 0.0;
457
+ result[4] = scale;
458
+ result[5] = 0.0;
459
+ result[6] = 0.0;
460
+ result[7] = 0.0;
461
+ result[8] = scale;
462
+ return result;
595
463
  }
596
464
 
597
- result[0] = cosAngle;
598
- result[1] = 0.0;
599
- result[2] = -sinAngle;
600
- result[3] = 0.0;
601
- result[4] = 1.0;
602
- result[5] = 0.0;
603
- result[6] = sinAngle;
604
- result[7] = 0.0;
605
- result[8] = cosAngle;
465
+ /**
466
+ * Computes a Matrix3 instance representing the cross product equivalent matrix of a Cartesian3 vector.
467
+ *
468
+ * @param {Cartesian3} vector the vector on the left hand side of the cross product operation.
469
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
470
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
471
+ *
472
+ * @example
473
+ * // Creates
474
+ * // [0.0, -9.0, 8.0]
475
+ * // [9.0, 0.0, -7.0]
476
+ * // [-8.0, 7.0, 0.0]
477
+ * const m = Cesium.Matrix3.fromCrossProduct(new Cesium.Cartesian3(7.0, 8.0, 9.0));
478
+ */
479
+ static fromCrossProduct(vector, result) {
480
+ //>>includeStart('debug', pragmas.debug);
481
+ Check.typeOf.object("vector", vector);
482
+ //>>includeEnd('debug');
606
483
 
607
- return result;
608
- };
484
+ if (!defined(result)) {
485
+ return new Matrix3(
486
+ 0.0,
487
+ -vector.z,
488
+ vector.y,
489
+ vector.z,
490
+ 0.0,
491
+ -vector.x,
492
+ -vector.y,
493
+ vector.x,
494
+ 0.0,
495
+ );
496
+ }
609
497
 
610
- /**
611
- * Creates a rotation matrix around the z-axis.
612
- *
613
- * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
614
- * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
615
- * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
616
- *
617
- * @example
618
- * // Rotate a point 45 degrees counterclockwise around the z-axis.
619
- * const p = new Cesium.Cartesian3(5, 6, 7);
620
- * const m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));
621
- * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
622
- */
623
- Matrix3.fromRotationZ = function (angle, result) {
624
- //>>includeStart('debug', pragmas.debug);
625
- Check.typeOf.number("angle", angle);
626
- //>>includeEnd('debug');
627
-
628
- const cosAngle = Math.cos(angle);
629
- const sinAngle = Math.sin(angle);
630
-
631
- if (!defined(result)) {
632
- return new Matrix3(
633
- cosAngle,
634
- -sinAngle,
635
- 0.0,
636
- sinAngle,
637
- cosAngle,
638
- 0.0,
639
- 0.0,
640
- 0.0,
641
- 1.0,
642
- );
498
+ result[0] = 0.0;
499
+ result[1] = vector.z;
500
+ result[2] = -vector.y;
501
+ result[3] = -vector.z;
502
+ result[4] = 0.0;
503
+ result[5] = vector.x;
504
+ result[6] = vector.y;
505
+ result[7] = -vector.x;
506
+ result[8] = 0.0;
507
+ return result;
643
508
  }
644
509
 
645
- result[0] = cosAngle;
646
- result[1] = sinAngle;
647
- result[2] = 0.0;
648
- result[3] = -sinAngle;
649
- result[4] = cosAngle;
650
- result[5] = 0.0;
651
- result[6] = 0.0;
652
- result[7] = 0.0;
653
- result[8] = 1.0;
510
+ /**
511
+ * Creates a rotation matrix around the x-axis.
512
+ *
513
+ * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
514
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
515
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
516
+ *
517
+ * @example
518
+ * // Rotate a point 45 degrees counterclockwise around the x-axis.
519
+ * const p = new Cesium.Cartesian3(5, 6, 7);
520
+ * const m = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(45.0));
521
+ * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
522
+ */
523
+ static fromRotationX(angle, result) {
524
+ //>>includeStart('debug', pragmas.debug);
525
+ Check.typeOf.number("angle", angle);
526
+ //>>includeEnd('debug');
654
527
 
655
- return result;
656
- };
528
+ const cosAngle = Math.cos(angle);
529
+ const sinAngle = Math.sin(angle);
530
+
531
+ if (!defined(result)) {
532
+ return new Matrix3(
533
+ 1.0,
534
+ 0.0,
535
+ 0.0,
536
+ 0.0,
537
+ cosAngle,
538
+ -sinAngle,
539
+ 0.0,
540
+ sinAngle,
541
+ cosAngle,
542
+ );
543
+ }
657
544
 
658
- /**
659
- * Creates an Array from the provided Matrix3 instance.
660
- * The array will be in column-major order.
661
- *
662
- * @param {Matrix3} matrix The matrix to use..
663
- * @param {number[]} [result] The Array onto which to store the result.
664
- * @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.
665
- */
666
- Matrix3.toArray = function (matrix, result) {
667
- //>>includeStart('debug', pragmas.debug);
668
- Check.typeOf.object("matrix", matrix);
669
- //>>includeEnd('debug');
670
-
671
- if (!defined(result)) {
672
- return [
673
- matrix[0],
674
- matrix[1],
675
- matrix[2],
676
- matrix[3],
677
- matrix[4],
678
- matrix[5],
679
- matrix[6],
680
- matrix[7],
681
- matrix[8],
682
- ];
545
+ result[0] = 1.0;
546
+ result[1] = 0.0;
547
+ result[2] = 0.0;
548
+ result[3] = 0.0;
549
+ result[4] = cosAngle;
550
+ result[5] = sinAngle;
551
+ result[6] = 0.0;
552
+ result[7] = -sinAngle;
553
+ result[8] = cosAngle;
554
+
555
+ return result;
683
556
  }
684
- result[0] = matrix[0];
685
- result[1] = matrix[1];
686
- result[2] = matrix[2];
687
- result[3] = matrix[3];
688
- result[4] = matrix[4];
689
- result[5] = matrix[5];
690
- result[6] = matrix[6];
691
- result[7] = matrix[7];
692
- result[8] = matrix[8];
693
- return result;
694
- };
695
557
 
696
- /**
697
- * Computes the array index of the element at the provided row and column.
698
- *
699
- * @param {number} column The zero-based index of the column.
700
- * @param {number} row The zero-based index of the row.
701
- * @returns {number} The index of the element at the provided row and column.
702
- *
703
- * @exception {DeveloperError} row must be 0, 1, or 2.
704
- * @exception {DeveloperError} column must be 0, 1, or 2.
705
- *
706
- * @example
707
- * const myMatrix = new Cesium.Matrix3();
708
- * const column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);
709
- * const column1Row0 = myMatrix[column1Row0Index]
710
- * myMatrix[column1Row0Index] = 10.0;
711
- */
712
- Matrix3.getElementIndex = function (column, row) {
713
- //>>includeStart('debug', pragmas.debug);
714
- Check.typeOf.number.greaterThanOrEquals("row", row, 0);
715
- Check.typeOf.number.lessThanOrEquals("row", row, 2);
716
- Check.typeOf.number.greaterThanOrEquals("column", column, 0);
717
- Check.typeOf.number.lessThanOrEquals("column", column, 2);
718
- //>>includeEnd('debug');
558
+ /**
559
+ * Creates a rotation matrix around the y-axis.
560
+ *
561
+ * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
562
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
563
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
564
+ *
565
+ * @example
566
+ * // Rotate a point 45 degrees counterclockwise around the y-axis.
567
+ * const p = new Cesium.Cartesian3(5, 6, 7);
568
+ * const m = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(45.0));
569
+ * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
570
+ */
571
+ static fromRotationY(angle, result) {
572
+ //>>includeStart('debug', pragmas.debug);
573
+ Check.typeOf.number("angle", angle);
574
+ //>>includeEnd('debug');
719
575
 
720
- return column * 3 + row;
721
- };
576
+ const cosAngle = Math.cos(angle);
577
+ const sinAngle = Math.sin(angle);
578
+
579
+ if (!defined(result)) {
580
+ return new Matrix3(
581
+ cosAngle,
582
+ 0.0,
583
+ sinAngle,
584
+ 0.0,
585
+ 1.0,
586
+ 0.0,
587
+ -sinAngle,
588
+ 0.0,
589
+ cosAngle,
590
+ );
591
+ }
722
592
 
723
- /**
724
- * Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.
725
- *
726
- * @param {Matrix3} matrix The matrix to use.
727
- * @param {number} index The zero-based index of the column to retrieve.
728
- * @param {Cartesian3} result The object onto which to store the result.
729
- * @returns {Cartesian3} The modified result parameter.
730
- *
731
- * @exception {DeveloperError} index must be 0, 1, or 2.
732
- */
733
- Matrix3.getColumn = function (matrix, index, result) {
734
- //>>includeStart('debug', pragmas.debug);
735
- Check.typeOf.object("matrix", matrix);
736
- Check.typeOf.number.greaterThanOrEquals("index", index, 0);
737
- Check.typeOf.number.lessThanOrEquals("index", index, 2);
738
- Check.typeOf.object("result", result);
739
- //>>includeEnd('debug');
740
-
741
- const startIndex = index * 3;
742
- const x = matrix[startIndex];
743
- const y = matrix[startIndex + 1];
744
- const z = matrix[startIndex + 2];
745
-
746
- result.x = x;
747
- result.y = y;
748
- result.z = z;
749
- return result;
750
- };
593
+ result[0] = cosAngle;
594
+ result[1] = 0.0;
595
+ result[2] = -sinAngle;
596
+ result[3] = 0.0;
597
+ result[4] = 1.0;
598
+ result[5] = 0.0;
599
+ result[6] = sinAngle;
600
+ result[7] = 0.0;
601
+ result[8] = cosAngle;
602
+
603
+ return result;
604
+ }
751
605
 
752
- /**
753
- * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.
754
- *
755
- * @param {Matrix3} matrix The matrix to use.
756
- * @param {number} index The zero-based index of the column to set.
757
- * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.
758
- * @param {Matrix3} result The object onto which to store the result.
759
- * @returns {Matrix3} The modified result parameter.
760
- *
761
- * @exception {DeveloperError} index must be 0, 1, or 2.
762
- */
763
- Matrix3.setColumn = function (matrix, index, cartesian, result) {
764
- //>>includeStart('debug', pragmas.debug);
765
- Check.typeOf.object("matrix", matrix);
766
- Check.typeOf.number.greaterThanOrEquals("index", index, 0);
767
- Check.typeOf.number.lessThanOrEquals("index", index, 2);
768
- Check.typeOf.object("cartesian", cartesian);
769
- Check.typeOf.object("result", result);
770
- //>>includeEnd('debug');
771
-
772
- result = Matrix3.clone(matrix, result);
773
- const startIndex = index * 3;
774
- result[startIndex] = cartesian.x;
775
- result[startIndex + 1] = cartesian.y;
776
- result[startIndex + 2] = cartesian.z;
777
- return result;
778
- };
606
+ /**
607
+ * Creates a rotation matrix around the z-axis.
608
+ *
609
+ * @param {number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
610
+ * @param {Matrix3} [result] The object in which the result will be stored, if undefined a new instance will be created.
611
+ * @returns {Matrix3} The modified result parameter, or a new Matrix3 instance if one was not provided.
612
+ *
613
+ * @example
614
+ * // Rotate a point 45 degrees counterclockwise around the z-axis.
615
+ * const p = new Cesium.Cartesian3(5, 6, 7);
616
+ * const m = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(45.0));
617
+ * const rotated = Cesium.Matrix3.multiplyByVector(m, p, new Cesium.Cartesian3());
618
+ */
619
+ static fromRotationZ(angle, result) {
620
+ //>>includeStart('debug', pragmas.debug);
621
+ Check.typeOf.number("angle", angle);
622
+ //>>includeEnd('debug');
779
623
 
780
- /**
781
- * Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.
782
- *
783
- * @param {Matrix3} matrix The matrix to use.
784
- * @param {number} index The zero-based index of the row to retrieve.
785
- * @param {Cartesian3} result The object onto which to store the result.
786
- * @returns {Cartesian3} The modified result parameter.
787
- *
788
- * @exception {DeveloperError} index must be 0, 1, or 2.
789
- */
790
- Matrix3.getRow = function (matrix, index, result) {
791
- //>>includeStart('debug', pragmas.debug);
792
- Check.typeOf.object("matrix", matrix);
793
- Check.typeOf.number.greaterThanOrEquals("index", index, 0);
794
- Check.typeOf.number.lessThanOrEquals("index", index, 2);
795
- Check.typeOf.object("result", result);
796
- //>>includeEnd('debug');
797
-
798
- const x = matrix[index];
799
- const y = matrix[index + 3];
800
- const z = matrix[index + 6];
801
-
802
- result.x = x;
803
- result.y = y;
804
- result.z = z;
805
- return result;
806
- };
624
+ const cosAngle = Math.cos(angle);
625
+ const sinAngle = Math.sin(angle);
626
+
627
+ if (!defined(result)) {
628
+ return new Matrix3(
629
+ cosAngle,
630
+ -sinAngle,
631
+ 0.0,
632
+ sinAngle,
633
+ cosAngle,
634
+ 0.0,
635
+ 0.0,
636
+ 0.0,
637
+ 1.0,
638
+ );
639
+ }
807
640
 
808
- /**
809
- * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.
810
- *
811
- * @param {Matrix3} matrix The matrix to use.
812
- * @param {number} index The zero-based index of the row to set.
813
- * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.
814
- * @param {Matrix3} result The object onto which to store the result.
815
- * @returns {Matrix3} The modified result parameter.
816
- *
817
- * @exception {DeveloperError} index must be 0, 1, or 2.
818
- */
819
- Matrix3.setRow = function (matrix, index, cartesian, result) {
820
- //>>includeStart('debug', pragmas.debug);
821
- Check.typeOf.object("matrix", matrix);
822
- Check.typeOf.number.greaterThanOrEquals("index", index, 0);
823
- Check.typeOf.number.lessThanOrEquals("index", index, 2);
824
- Check.typeOf.object("cartesian", cartesian);
825
- Check.typeOf.object("result", result);
826
- //>>includeEnd('debug');
827
-
828
- result = Matrix3.clone(matrix, result);
829
- result[index] = cartesian.x;
830
- result[index + 3] = cartesian.y;
831
- result[index + 6] = cartesian.z;
832
- return result;
833
- };
641
+ result[0] = cosAngle;
642
+ result[1] = sinAngle;
643
+ result[2] = 0.0;
644
+ result[3] = -sinAngle;
645
+ result[4] = cosAngle;
646
+ result[5] = 0.0;
647
+ result[6] = 0.0;
648
+ result[7] = 0.0;
649
+ result[8] = 1.0;
650
+
651
+ return result;
652
+ }
834
653
 
835
- const scaleScratch1 = new Cartesian3();
654
+ /**
655
+ * Creates an Array from the provided Matrix3 instance.
656
+ * The array will be in column-major order.
657
+ *
658
+ * @param {Matrix3} matrix The matrix to use..
659
+ * @param {number[]} [result] The Array onto which to store the result.
660
+ * @returns {number[]} The modified Array parameter or a new Array instance if one was not provided.
661
+ */
662
+ static toArray(matrix, result) {
663
+ //>>includeStart('debug', pragmas.debug);
664
+ Check.typeOf.object("matrix", matrix);
665
+ //>>includeEnd('debug');
836
666
 
837
- /**
838
- * Computes a new matrix that replaces the scale with the provided scale.
839
- * This assumes the matrix is an affine transformation.
840
- *
841
- * @param {Matrix3} matrix The matrix to use.
842
- * @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.
843
- * @param {Matrix3} result The object onto which to store the result.
844
- * @returns {Matrix3} The modified result parameter.
845
- *
846
- * @see Matrix3.setUniformScale
847
- * @see Matrix3.fromScale
848
- * @see Matrix3.fromUniformScale
849
- * @see Matrix3.multiplyByScale
850
- * @see Matrix3.multiplyByUniformScale
851
- * @see Matrix3.getScale
852
- */
853
- Matrix3.setScale = function (matrix, scale, result) {
854
- //>>includeStart('debug', pragmas.debug);
855
- Check.typeOf.object("matrix", matrix);
856
- Check.typeOf.object("scale", scale);
857
- Check.typeOf.object("result", result);
858
- //>>includeEnd('debug');
859
-
860
- const existingScale = Matrix3.getScale(matrix, scaleScratch1);
861
- const scaleRatioX = scale.x / existingScale.x;
862
- const scaleRatioY = scale.y / existingScale.y;
863
- const scaleRatioZ = scale.z / existingScale.z;
864
-
865
- result[0] = matrix[0] * scaleRatioX;
866
- result[1] = matrix[1] * scaleRatioX;
867
- result[2] = matrix[2] * scaleRatioX;
868
- result[3] = matrix[3] * scaleRatioY;
869
- result[4] = matrix[4] * scaleRatioY;
870
- result[5] = matrix[5] * scaleRatioY;
871
- result[6] = matrix[6] * scaleRatioZ;
872
- result[7] = matrix[7] * scaleRatioZ;
873
- result[8] = matrix[8] * scaleRatioZ;
667
+ if (!defined(result)) {
668
+ return [
669
+ matrix[0],
670
+ matrix[1],
671
+ matrix[2],
672
+ matrix[3],
673
+ matrix[4],
674
+ matrix[5],
675
+ matrix[6],
676
+ matrix[7],
677
+ matrix[8],
678
+ ];
679
+ }
680
+ result[0] = matrix[0];
681
+ result[1] = matrix[1];
682
+ result[2] = matrix[2];
683
+ result[3] = matrix[3];
684
+ result[4] = matrix[4];
685
+ result[5] = matrix[5];
686
+ result[6] = matrix[6];
687
+ result[7] = matrix[7];
688
+ result[8] = matrix[8];
689
+ return result;
690
+ }
874
691
 
875
- return result;
876
- };
692
+ /**
693
+ * Computes the array index of the element at the provided row and column.
694
+ *
695
+ * @param {number} column The zero-based index of the column.
696
+ * @param {number} row The zero-based index of the row.
697
+ * @returns {number} The index of the element at the provided row and column.
698
+ *
699
+ * @exception {DeveloperError} row must be 0, 1, or 2.
700
+ * @exception {DeveloperError} column must be 0, 1, or 2.
701
+ *
702
+ * @example
703
+ * const myMatrix = new Cesium.Matrix3();
704
+ * const column1Row0Index = Cesium.Matrix3.getElementIndex(1, 0);
705
+ * const column1Row0 = myMatrix[column1Row0Index]
706
+ * myMatrix[column1Row0Index] = 10.0;
707
+ */
708
+ static getElementIndex(column, row) {
709
+ //>>includeStart('debug', pragmas.debug);
710
+ Check.typeOf.number.greaterThanOrEquals("row", row, 0);
711
+ Check.typeOf.number.lessThanOrEquals("row", row, 2);
712
+ Check.typeOf.number.greaterThanOrEquals("column", column, 0);
713
+ Check.typeOf.number.lessThanOrEquals("column", column, 2);
714
+ //>>includeEnd('debug');
877
715
 
878
- const scaleScratch2 = new Cartesian3();
716
+ return column * 3 + row;
717
+ }
879
718
 
880
- /**
881
- * Computes a new matrix that replaces the scale with the provided uniform scale.
882
- * This assumes the matrix is an affine transformation.
883
- *
884
- * @param {Matrix3} matrix The matrix to use.
885
- * @param {number} scale The uniform scale that replaces the scale of the provided matrix.
886
- * @param {Matrix3} result The object onto which to store the result.
887
- * @returns {Matrix3} The modified result parameter.
888
- *
889
- * @see Matrix3.setScale
890
- * @see Matrix3.fromScale
891
- * @see Matrix3.fromUniformScale
892
- * @see Matrix3.multiplyByScale
893
- * @see Matrix3.multiplyByUniformScale
894
- * @see Matrix3.getScale
895
- */
896
- Matrix3.setUniformScale = function (matrix, scale, result) {
897
- //>>includeStart('debug', pragmas.debug);
898
- Check.typeOf.object("matrix", matrix);
899
- Check.typeOf.number("scale", scale);
900
- Check.typeOf.object("result", result);
901
- //>>includeEnd('debug');
902
-
903
- const existingScale = Matrix3.getScale(matrix, scaleScratch2);
904
- const scaleRatioX = scale / existingScale.x;
905
- const scaleRatioY = scale / existingScale.y;
906
- const scaleRatioZ = scale / existingScale.z;
907
-
908
- result[0] = matrix[0] * scaleRatioX;
909
- result[1] = matrix[1] * scaleRatioX;
910
- result[2] = matrix[2] * scaleRatioX;
911
- result[3] = matrix[3] * scaleRatioY;
912
- result[4] = matrix[4] * scaleRatioY;
913
- result[5] = matrix[5] * scaleRatioY;
914
- result[6] = matrix[6] * scaleRatioZ;
915
- result[7] = matrix[7] * scaleRatioZ;
916
- result[8] = matrix[8] * scaleRatioZ;
719
+ /**
720
+ * Retrieves a copy of the matrix column at the provided index as a Cartesian3 instance.
721
+ *
722
+ * @param {Matrix3} matrix The matrix to use.
723
+ * @param {number} index The zero-based index of the column to retrieve.
724
+ * @param {Cartesian3} result The object onto which to store the result.
725
+ * @returns {Cartesian3} The modified result parameter.
726
+ *
727
+ * @exception {DeveloperError} index must be 0, 1, or 2.
728
+ */
729
+ static getColumn(matrix, index, result) {
730
+ //>>includeStart('debug', pragmas.debug);
731
+ Check.typeOf.object("matrix", matrix);
732
+ Check.typeOf.number.greaterThanOrEquals("index", index, 0);
733
+ Check.typeOf.number.lessThanOrEquals("index", index, 2);
734
+ Check.typeOf.object("result", result);
735
+ //>>includeEnd('debug');
917
736
 
918
- return result;
919
- };
737
+ const startIndex = index * 3;
920
738
 
921
- const scratchColumn = new Cartesian3();
739
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
740
+ const x = matrix[startIndex];
741
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
742
+ const y = matrix[startIndex + 1];
743
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
744
+ const z = matrix[startIndex + 2];
922
745
 
923
- /**
924
- * Extracts the non-uniform scale assuming the matrix is an affine transformation.
925
- *
926
- * @param {Matrix3} matrix The matrix.
927
- * @param {Cartesian3} result The object onto which to store the result.
928
- * @returns {Cartesian3} The modified result parameter.
929
- *
930
- * @see Matrix3.multiplyByScale
931
- * @see Matrix3.multiplyByUniformScale
932
- * @see Matrix3.fromScale
933
- * @see Matrix3.fromUniformScale
934
- * @see Matrix3.setScale
935
- * @see Matrix3.setUniformScale
936
- */
937
- Matrix3.getScale = function (matrix, result) {
938
- //>>includeStart('debug', pragmas.debug);
939
- Check.typeOf.object("matrix", matrix);
940
- Check.typeOf.object("result", result);
941
- //>>includeEnd('debug');
942
-
943
- result.x = Cartesian3.magnitude(
944
- Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn),
945
- );
946
- result.y = Cartesian3.magnitude(
947
- Cartesian3.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn),
948
- );
949
- result.z = Cartesian3.magnitude(
950
- Cartesian3.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn),
951
- );
952
- return result;
953
- };
746
+ result.x = x;
747
+ result.y = y;
748
+ result.z = z;
749
+ return result;
750
+ }
954
751
 
955
- const scaleScratch3 = new Cartesian3();
752
+ /**
753
+ * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian3 instance.
754
+ *
755
+ * @param {Matrix3} matrix The matrix to use.
756
+ * @param {number} index The zero-based index of the column to set.
757
+ * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified column.
758
+ * @param {Matrix3} result The object onto which to store the result.
759
+ * @returns {Matrix3} The modified result parameter.
760
+ *
761
+ * @exception {DeveloperError} index must be 0, 1, or 2.
762
+ */
763
+ static setColumn(matrix, index, cartesian, result) {
764
+ //>>includeStart('debug', pragmas.debug);
765
+ Check.typeOf.object("matrix", matrix);
766
+ Check.typeOf.number.greaterThanOrEquals("index", index, 0);
767
+ Check.typeOf.number.lessThanOrEquals("index", index, 2);
768
+ Check.typeOf.object("cartesian", cartesian);
769
+ Check.typeOf.object("result", result);
770
+ //>>includeEnd('debug');
956
771
 
957
- /**
958
- * Computes the maximum scale assuming the matrix is an affine transformation.
959
- * The maximum scale is the maximum length of the column vectors.
960
- *
961
- * @param {Matrix3} matrix The matrix.
962
- * @returns {number} The maximum scale.
963
- */
964
- Matrix3.getMaximumScale = function (matrix) {
965
- Matrix3.getScale(matrix, scaleScratch3);
966
- return Cartesian3.maximumComponent(scaleScratch3);
967
- };
772
+ result = Matrix3.clone(matrix, result);
773
+ const startIndex = index * 3;
968
774
 
969
- const scaleScratch4 = new Cartesian3();
775
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
776
+ result[startIndex] = cartesian.x;
777
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
778
+ result[startIndex + 1] = cartesian.y;
779
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
780
+ result[startIndex + 2] = cartesian.z;
970
781
 
971
- /**
972
- * Sets the rotation assuming the matrix is an affine transformation.
973
- *
974
- * @param {Matrix3} matrix The matrix.
975
- * @param {Matrix3} rotation The rotation matrix.
976
- * @param {Matrix3} result The object onto which to store the result.
977
- * @returns {Matrix3} The modified result parameter.
978
- *
979
- * @see Matrix3.getRotation
980
- */
981
- Matrix3.setRotation = function (matrix, rotation, result) {
982
- //>>includeStart('debug', pragmas.debug);
983
- Check.typeOf.object("matrix", matrix);
984
- Check.typeOf.object("result", result);
985
- //>>includeEnd('debug');
986
-
987
- const scale = Matrix3.getScale(matrix, scaleScratch4);
988
-
989
- result[0] = rotation[0] * scale.x;
990
- result[1] = rotation[1] * scale.x;
991
- result[2] = rotation[2] * scale.x;
992
- result[3] = rotation[3] * scale.y;
993
- result[4] = rotation[4] * scale.y;
994
- result[5] = rotation[5] * scale.y;
995
- result[6] = rotation[6] * scale.z;
996
- result[7] = rotation[7] * scale.z;
997
- result[8] = rotation[8] * scale.z;
782
+ return result;
783
+ }
998
784
 
999
- return result;
1000
- };
785
+ /**
786
+ * Retrieves a copy of the matrix row at the provided index as a Cartesian3 instance.
787
+ *
788
+ * @param {Matrix3} matrix The matrix to use.
789
+ * @param {number} index The zero-based index of the row to retrieve.
790
+ * @param {Cartesian3} result The object onto which to store the result.
791
+ * @returns {Cartesian3} The modified result parameter.
792
+ *
793
+ * @exception {DeveloperError} index must be 0, 1, or 2.
794
+ */
795
+ static getRow(matrix, index, result) {
796
+ //>>includeStart('debug', pragmas.debug);
797
+ Check.typeOf.object("matrix", matrix);
798
+ Check.typeOf.number.greaterThanOrEquals("index", index, 0);
799
+ Check.typeOf.number.lessThanOrEquals("index", index, 2);
800
+ Check.typeOf.object("result", result);
801
+ //>>includeEnd('debug');
1001
802
 
1002
- const scaleScratch5 = new Cartesian3();
803
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
804
+ const x = matrix[index];
805
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
806
+ const y = matrix[index + 3];
807
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
808
+ const z = matrix[index + 6];
809
+
810
+ result.x = x;
811
+ result.y = y;
812
+ result.z = z;
813
+ return result;
814
+ }
1003
815
 
1004
- /**
1005
- * Extracts the rotation matrix assuming the matrix is an affine transformation.
1006
- *
1007
- * @param {Matrix3} matrix The matrix.
1008
- * @param {Matrix3} result The object onto which to store the result.
1009
- * @returns {Matrix3} The modified result parameter.
1010
- *
1011
- * @see Matrix3.setRotation
1012
- */
1013
- Matrix3.getRotation = function (matrix, result) {
1014
- //>>includeStart('debug', pragmas.debug);
1015
- Check.typeOf.object("matrix", matrix);
1016
- Check.typeOf.object("result", result);
1017
- //>>includeEnd('debug');
1018
-
1019
- const scale = Matrix3.getScale(matrix, scaleScratch5);
1020
-
1021
- result[0] = matrix[0] / scale.x;
1022
- result[1] = matrix[1] / scale.x;
1023
- result[2] = matrix[2] / scale.x;
1024
- result[3] = matrix[3] / scale.y;
1025
- result[4] = matrix[4] / scale.y;
1026
- result[5] = matrix[5] / scale.y;
1027
- result[6] = matrix[6] / scale.z;
1028
- result[7] = matrix[7] / scale.z;
1029
- result[8] = matrix[8] / scale.z;
816
+ /**
817
+ * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian3 instance.
818
+ *
819
+ * @param {Matrix3} matrix The matrix to use.
820
+ * @param {number} index The zero-based index of the row to set.
821
+ * @param {Cartesian3} cartesian The Cartesian whose values will be assigned to the specified row.
822
+ * @param {Matrix3} result The object onto which to store the result.
823
+ * @returns {Matrix3} The modified result parameter.
824
+ *
825
+ * @exception {DeveloperError} index must be 0, 1, or 2.
826
+ */
827
+ static setRow(matrix, index, cartesian, result) {
828
+ //>>includeStart('debug', pragmas.debug);
829
+ Check.typeOf.object("matrix", matrix);
830
+ Check.typeOf.number.greaterThanOrEquals("index", index, 0);
831
+ Check.typeOf.number.lessThanOrEquals("index", index, 2);
832
+ Check.typeOf.object("cartesian", cartesian);
833
+ Check.typeOf.object("result", result);
834
+ //>>includeEnd('debug');
1030
835
 
1031
- return result;
1032
- };
836
+ result = Matrix3.clone(matrix, result);
1033
837
 
1034
- /**
1035
- * Computes the product of two matrices.
1036
- *
1037
- * @param {Matrix3} left The first matrix.
1038
- * @param {Matrix3} right The second matrix.
1039
- * @param {Matrix3} result The object onto which to store the result.
1040
- * @returns {Matrix3} The modified result parameter.
1041
- */
1042
- Matrix3.multiply = function (left, right, result) {
1043
- //>>includeStart('debug', pragmas.debug);
1044
- Check.typeOf.object("left", left);
1045
- Check.typeOf.object("right", right);
1046
- Check.typeOf.object("result", result);
1047
- //>>includeEnd('debug');
1048
-
1049
- const column0Row0 =
1050
- left[0] * right[0] + left[3] * right[1] + left[6] * right[2];
1051
- const column0Row1 =
1052
- left[1] * right[0] + left[4] * right[1] + left[7] * right[2];
1053
- const column0Row2 =
1054
- left[2] * right[0] + left[5] * right[1] + left[8] * right[2];
1055
-
1056
- const column1Row0 =
1057
- left[0] * right[3] + left[3] * right[4] + left[6] * right[5];
1058
- const column1Row1 =
1059
- left[1] * right[3] + left[4] * right[4] + left[7] * right[5];
1060
- const column1Row2 =
1061
- left[2] * right[3] + left[5] * right[4] + left[8] * right[5];
1062
-
1063
- const column2Row0 =
1064
- left[0] * right[6] + left[3] * right[7] + left[6] * right[8];
1065
- const column2Row1 =
1066
- left[1] * right[6] + left[4] * right[7] + left[7] * right[8];
1067
- const column2Row2 =
1068
- left[2] * right[6] + left[5] * right[7] + left[8] * right[8];
1069
-
1070
- result[0] = column0Row0;
1071
- result[1] = column0Row1;
1072
- result[2] = column0Row2;
1073
- result[3] = column1Row0;
1074
- result[4] = column1Row1;
1075
- result[5] = column1Row2;
1076
- result[6] = column2Row0;
1077
- result[7] = column2Row1;
1078
- result[8] = column2Row2;
1079
- return result;
1080
- };
838
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
839
+ result[index] = cartesian.x;
840
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
841
+ result[index + 3] = cartesian.y;
842
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
843
+ result[index + 6] = cartesian.z;
1081
844
 
1082
- /**
1083
- * Computes the sum of two matrices.
1084
- *
1085
- * @param {Matrix3} left The first matrix.
1086
- * @param {Matrix3} right The second matrix.
1087
- * @param {Matrix3} result The object onto which to store the result.
1088
- * @returns {Matrix3} The modified result parameter.
1089
- */
1090
- Matrix3.add = function (left, right, result) {
1091
- //>>includeStart('debug', pragmas.debug);
1092
- Check.typeOf.object("left", left);
1093
- Check.typeOf.object("right", right);
1094
- Check.typeOf.object("result", result);
1095
- //>>includeEnd('debug');
1096
-
1097
- result[0] = left[0] + right[0];
1098
- result[1] = left[1] + right[1];
1099
- result[2] = left[2] + right[2];
1100
- result[3] = left[3] + right[3];
1101
- result[4] = left[4] + right[4];
1102
- result[5] = left[5] + right[5];
1103
- result[6] = left[6] + right[6];
1104
- result[7] = left[7] + right[7];
1105
- result[8] = left[8] + right[8];
1106
- return result;
1107
- };
845
+ return result;
846
+ }
1108
847
 
1109
- /**
1110
- * Computes the difference of two matrices.
1111
- *
1112
- * @param {Matrix3} left The first matrix.
1113
- * @param {Matrix3} right The second matrix.
1114
- * @param {Matrix3} result The object onto which to store the result.
1115
- * @returns {Matrix3} The modified result parameter.
1116
- */
1117
- Matrix3.subtract = function (left, right, result) {
1118
- //>>includeStart('debug', pragmas.debug);
1119
- Check.typeOf.object("left", left);
1120
- Check.typeOf.object("right", right);
1121
- Check.typeOf.object("result", result);
1122
- //>>includeEnd('debug');
1123
-
1124
- result[0] = left[0] - right[0];
1125
- result[1] = left[1] - right[1];
1126
- result[2] = left[2] - right[2];
1127
- result[3] = left[3] - right[3];
1128
- result[4] = left[4] - right[4];
1129
- result[5] = left[5] - right[5];
1130
- result[6] = left[6] - right[6];
1131
- result[7] = left[7] - right[7];
1132
- result[8] = left[8] - right[8];
1133
- return result;
1134
- };
848
+ /**
849
+ * Computes a new matrix that replaces the scale with the provided scale.
850
+ * This assumes the matrix is an affine transformation.
851
+ *
852
+ * @param {Matrix3} matrix The matrix to use.
853
+ * @param {Cartesian3} scale The scale that replaces the scale of the provided matrix.
854
+ * @param {Matrix3} result The object onto which to store the result.
855
+ * @returns {Matrix3} The modified result parameter.
856
+ *
857
+ * @see Matrix3.setUniformScale
858
+ * @see Matrix3.fromScale
859
+ * @see Matrix3.fromUniformScale
860
+ * @see Matrix3.multiplyByScale
861
+ * @see Matrix3.multiplyByUniformScale
862
+ * @see Matrix3.getScale
863
+ */
864
+ static setScale(matrix, scale, result) {
865
+ //>>includeStart('debug', pragmas.debug);
866
+ Check.typeOf.object("matrix", matrix);
867
+ Check.typeOf.object("scale", scale);
868
+ Check.typeOf.object("result", result);
869
+ //>>includeEnd('debug');
1135
870
 
1136
- /**
1137
- * Computes the product of a matrix and a column vector.
1138
- *
1139
- * @param {Matrix3} matrix The matrix.
1140
- * @param {Cartesian3} cartesian The column.
1141
- * @param {Cartesian3} result The object onto which to store the result.
1142
- * @returns {Cartesian3} The modified result parameter.
1143
- */
1144
- Matrix3.multiplyByVector = function (matrix, cartesian, result) {
1145
- //>>includeStart('debug', pragmas.debug);
1146
- Check.typeOf.object("matrix", matrix);
1147
- Check.typeOf.object("cartesian", cartesian);
1148
- Check.typeOf.object("result", result);
1149
- //>>includeEnd('debug');
1150
-
1151
- const vX = cartesian.x;
1152
- const vY = cartesian.y;
1153
- const vZ = cartesian.z;
1154
-
1155
- const x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;
1156
- const y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;
1157
- const z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;
1158
-
1159
- result.x = x;
1160
- result.y = y;
1161
- result.z = z;
1162
- return result;
1163
- };
871
+ const existingScale = Matrix3.getScale(matrix, scaleScratch1);
872
+ const scaleRatioX = scale.x / existingScale.x;
873
+ const scaleRatioY = scale.y / existingScale.y;
874
+ const scaleRatioZ = scale.z / existingScale.z;
875
+
876
+ result[0] = matrix[0] * scaleRatioX;
877
+ result[1] = matrix[1] * scaleRatioX;
878
+ result[2] = matrix[2] * scaleRatioX;
879
+ result[3] = matrix[3] * scaleRatioY;
880
+ result[4] = matrix[4] * scaleRatioY;
881
+ result[5] = matrix[5] * scaleRatioY;
882
+ result[6] = matrix[6] * scaleRatioZ;
883
+ result[7] = matrix[7] * scaleRatioZ;
884
+ result[8] = matrix[8] * scaleRatioZ;
885
+
886
+ return result;
887
+ }
1164
888
 
1165
- /**
1166
- * Computes the product of a matrix and a scalar.
1167
- *
1168
- * @param {Matrix3} matrix The matrix.
1169
- * @param {number} scalar The number to multiply by.
1170
- * @param {Matrix3} result The object onto which to store the result.
1171
- * @returns {Matrix3} The modified result parameter.
1172
- */
1173
- Matrix3.multiplyByScalar = function (matrix, scalar, result) {
1174
- //>>includeStart('debug', pragmas.debug);
1175
- Check.typeOf.object("matrix", matrix);
1176
- Check.typeOf.number("scalar", scalar);
1177
- Check.typeOf.object("result", result);
1178
- //>>includeEnd('debug');
1179
-
1180
- result[0] = matrix[0] * scalar;
1181
- result[1] = matrix[1] * scalar;
1182
- result[2] = matrix[2] * scalar;
1183
- result[3] = matrix[3] * scalar;
1184
- result[4] = matrix[4] * scalar;
1185
- result[5] = matrix[5] * scalar;
1186
- result[6] = matrix[6] * scalar;
1187
- result[7] = matrix[7] * scalar;
1188
- result[8] = matrix[8] * scalar;
1189
- return result;
1190
- };
889
+ /**
890
+ * Computes a new matrix that replaces the scale with the provided uniform scale.
891
+ * This assumes the matrix is an affine transformation.
892
+ *
893
+ * @param {Matrix3} matrix The matrix to use.
894
+ * @param {number} scale The uniform scale that replaces the scale of the provided matrix.
895
+ * @param {Matrix3} result The object onto which to store the result.
896
+ * @returns {Matrix3} The modified result parameter.
897
+ *
898
+ * @see Matrix3.setScale
899
+ * @see Matrix3.fromScale
900
+ * @see Matrix3.fromUniformScale
901
+ * @see Matrix3.multiplyByScale
902
+ * @see Matrix3.multiplyByUniformScale
903
+ * @see Matrix3.getScale
904
+ */
905
+ static setUniformScale(matrix, scale, result) {
906
+ //>>includeStart('debug', pragmas.debug);
907
+ Check.typeOf.object("matrix", matrix);
908
+ Check.typeOf.number("scale", scale);
909
+ Check.typeOf.object("result", result);
910
+ //>>includeEnd('debug');
1191
911
 
1192
- /**
1193
- * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.
1194
- *
1195
- * @param {Matrix3} matrix The matrix on the left-hand side.
1196
- * @param {Cartesian3} scale The non-uniform scale on the right-hand side.
1197
- * @param {Matrix3} result The object onto which to store the result.
1198
- * @returns {Matrix3} The modified result parameter.
1199
- *
1200
- *
1201
- * @example
1202
- * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);
1203
- * Cesium.Matrix3.multiplyByScale(m, scale, m);
1204
- *
1205
- * @see Matrix3.multiplyByUniformScale
1206
- * @see Matrix3.fromScale
1207
- * @see Matrix3.fromUniformScale
1208
- * @see Matrix3.setScale
1209
- * @see Matrix3.setUniformScale
1210
- * @see Matrix3.getScale
1211
- */
1212
- Matrix3.multiplyByScale = function (matrix, scale, result) {
1213
- //>>includeStart('debug', pragmas.debug);
1214
- Check.typeOf.object("matrix", matrix);
1215
- Check.typeOf.object("scale", scale);
1216
- Check.typeOf.object("result", result);
1217
- //>>includeEnd('debug');
1218
-
1219
- result[0] = matrix[0] * scale.x;
1220
- result[1] = matrix[1] * scale.x;
1221
- result[2] = matrix[2] * scale.x;
1222
- result[3] = matrix[3] * scale.y;
1223
- result[4] = matrix[4] * scale.y;
1224
- result[5] = matrix[5] * scale.y;
1225
- result[6] = matrix[6] * scale.z;
1226
- result[7] = matrix[7] * scale.z;
1227
- result[8] = matrix[8] * scale.z;
912
+ const existingScale = Matrix3.getScale(matrix, scaleScratch2);
913
+ const scaleRatioX = scale / existingScale.x;
914
+ const scaleRatioY = scale / existingScale.y;
915
+ const scaleRatioZ = scale / existingScale.z;
916
+
917
+ result[0] = matrix[0] * scaleRatioX;
918
+ result[1] = matrix[1] * scaleRatioX;
919
+ result[2] = matrix[2] * scaleRatioX;
920
+ result[3] = matrix[3] * scaleRatioY;
921
+ result[4] = matrix[4] * scaleRatioY;
922
+ result[5] = matrix[5] * scaleRatioY;
923
+ result[6] = matrix[6] * scaleRatioZ;
924
+ result[7] = matrix[7] * scaleRatioZ;
925
+ result[8] = matrix[8] * scaleRatioZ;
926
+
927
+ return result;
928
+ }
1228
929
 
1229
- return result;
1230
- };
930
+ /**
931
+ * Extracts the non-uniform scale assuming the matrix is an affine transformation.
932
+ *
933
+ * @param {Matrix3} matrix The matrix.
934
+ * @param {Cartesian3} result The object onto which to store the result.
935
+ * @returns {Cartesian3} The modified result parameter.
936
+ *
937
+ * @see Matrix3.multiplyByScale
938
+ * @see Matrix3.multiplyByUniformScale
939
+ * @see Matrix3.fromScale
940
+ * @see Matrix3.fromUniformScale
941
+ * @see Matrix3.setScale
942
+ * @see Matrix3.setUniformScale
943
+ */
944
+ static getScale(matrix, result) {
945
+ //>>includeStart('debug', pragmas.debug);
946
+ Check.typeOf.object("matrix", matrix);
947
+ Check.typeOf.object("result", result);
948
+ //>>includeEnd('debug');
1231
949
 
1232
- /**
1233
- * Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.
1234
- *
1235
- * @param {Matrix3} matrix The matrix on the left-hand side.
1236
- * @param {number} scale The uniform scale on the right-hand side.
1237
- * @param {Matrix3} result The object onto which to store the result.
1238
- * @returns {Matrix3} The modified result parameter.
1239
- *
1240
- * @example
1241
- * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromUniformScale(scale), m);
1242
- * Cesium.Matrix3.multiplyByUniformScale(m, scale, m);
1243
- *
1244
- * @see Matrix3.multiplyByScale
1245
- * @see Matrix3.fromScale
1246
- * @see Matrix3.fromUniformScale
1247
- * @see Matrix3.setScale
1248
- * @see Matrix3.setUniformScale
1249
- * @see Matrix3.getScale
1250
- */
1251
- Matrix3.multiplyByUniformScale = function (matrix, scale, result) {
1252
- //>>includeStart('debug', pragmas.debug);
1253
- Check.typeOf.object("matrix", matrix);
1254
- Check.typeOf.number("scale", scale);
1255
- Check.typeOf.object("result", result);
1256
- //>>includeEnd('debug');
1257
-
1258
- result[0] = matrix[0] * scale;
1259
- result[1] = matrix[1] * scale;
1260
- result[2] = matrix[2] * scale;
1261
- result[3] = matrix[3] * scale;
1262
- result[4] = matrix[4] * scale;
1263
- result[5] = matrix[5] * scale;
1264
- result[6] = matrix[6] * scale;
1265
- result[7] = matrix[7] * scale;
1266
- result[8] = matrix[8] * scale;
950
+ result.x = Cartesian3.magnitude(
951
+ Cartesian3.fromElements(matrix[0], matrix[1], matrix[2], scratchColumn),
952
+ );
953
+ result.y = Cartesian3.magnitude(
954
+ Cartesian3.fromElements(matrix[3], matrix[4], matrix[5], scratchColumn),
955
+ );
956
+ result.z = Cartesian3.magnitude(
957
+ Cartesian3.fromElements(matrix[6], matrix[7], matrix[8], scratchColumn),
958
+ );
959
+ return result;
960
+ }
1267
961
 
1268
- return result;
1269
- };
962
+ /**
963
+ * Computes the maximum scale assuming the matrix is an affine transformation.
964
+ * The maximum scale is the maximum length of the column vectors.
965
+ *
966
+ * @param {Matrix3} matrix The matrix.
967
+ * @returns {number} The maximum scale.
968
+ */
969
+ static getMaximumScale(matrix) {
970
+ Matrix3.getScale(matrix, scaleScratch3);
971
+ return Cartesian3.maximumComponent(scaleScratch3);
972
+ }
1270
973
 
1271
- /**
1272
- * Creates a negated copy of the provided matrix.
1273
- *
1274
- * @param {Matrix3} matrix The matrix to negate.
1275
- * @param {Matrix3} result The object onto which to store the result.
1276
- * @returns {Matrix3} The modified result parameter.
1277
- */
1278
- Matrix3.negate = function (matrix, result) {
1279
- //>>includeStart('debug', pragmas.debug);
1280
- Check.typeOf.object("matrix", matrix);
1281
- Check.typeOf.object("result", result);
1282
- //>>includeEnd('debug');
1283
-
1284
- result[0] = -matrix[0];
1285
- result[1] = -matrix[1];
1286
- result[2] = -matrix[2];
1287
- result[3] = -matrix[3];
1288
- result[4] = -matrix[4];
1289
- result[5] = -matrix[5];
1290
- result[6] = -matrix[6];
1291
- result[7] = -matrix[7];
1292
- result[8] = -matrix[8];
1293
- return result;
1294
- };
974
+ /**
975
+ * Sets the rotation assuming the matrix is an affine transformation.
976
+ *
977
+ * @param {Matrix3} matrix The matrix.
978
+ * @param {Matrix3} rotation The rotation matrix.
979
+ * @param {Matrix3} result The object onto which to store the result.
980
+ * @returns {Matrix3} The modified result parameter.
981
+ *
982
+ * @see Matrix3.getRotation
983
+ */
984
+ static setRotation(matrix, rotation, result) {
985
+ //>>includeStart('debug', pragmas.debug);
986
+ Check.typeOf.object("matrix", matrix);
987
+ Check.typeOf.object("result", result);
988
+ //>>includeEnd('debug');
1295
989
 
1296
- /**
1297
- * Computes the transpose of the provided matrix.
1298
- *
1299
- * @param {Matrix3} matrix The matrix to transpose.
1300
- * @param {Matrix3} result The object onto which to store the result.
1301
- * @returns {Matrix3} The modified result parameter.
1302
- */
1303
- Matrix3.transpose = function (matrix, result) {
1304
- //>>includeStart('debug', pragmas.debug);
1305
- Check.typeOf.object("matrix", matrix);
1306
- Check.typeOf.object("result", result);
1307
- //>>includeEnd('debug');
1308
-
1309
- const column0Row0 = matrix[0];
1310
- const column0Row1 = matrix[3];
1311
- const column0Row2 = matrix[6];
1312
- const column1Row0 = matrix[1];
1313
- const column1Row1 = matrix[4];
1314
- const column1Row2 = matrix[7];
1315
- const column2Row0 = matrix[2];
1316
- const column2Row1 = matrix[5];
1317
- const column2Row2 = matrix[8];
1318
-
1319
- result[0] = column0Row0;
1320
- result[1] = column0Row1;
1321
- result[2] = column0Row2;
1322
- result[3] = column1Row0;
1323
- result[4] = column1Row1;
1324
- result[5] = column1Row2;
1325
- result[6] = column2Row0;
1326
- result[7] = column2Row1;
1327
- result[8] = column2Row2;
1328
- return result;
1329
- };
990
+ const scale = Matrix3.getScale(matrix, scaleScratch4);
1330
991
 
1331
- function computeFrobeniusNorm(matrix) {
1332
- let norm = 0.0;
1333
- for (let i = 0; i < 9; ++i) {
1334
- const temp = matrix[i];
1335
- norm += temp * temp;
992
+ result[0] = rotation[0] * scale.x;
993
+ result[1] = rotation[1] * scale.x;
994
+ result[2] = rotation[2] * scale.x;
995
+ result[3] = rotation[3] * scale.y;
996
+ result[4] = rotation[4] * scale.y;
997
+ result[5] = rotation[5] * scale.y;
998
+ result[6] = rotation[6] * scale.z;
999
+ result[7] = rotation[7] * scale.z;
1000
+ result[8] = rotation[8] * scale.z;
1001
+
1002
+ return result;
1336
1003
  }
1337
1004
 
1338
- return Math.sqrt(norm);
1339
- }
1005
+ /**
1006
+ * Extracts the rotation matrix assuming the matrix is an affine transformation.
1007
+ *
1008
+ * @param {Matrix3} matrix The matrix.
1009
+ * @param {Matrix3} result The object onto which to store the result.
1010
+ * @returns {Matrix3} The modified result parameter.
1011
+ *
1012
+ * @see Matrix3.setRotation
1013
+ */
1014
+ static getRotation(matrix, result) {
1015
+ //>>includeStart('debug', pragmas.debug);
1016
+ Check.typeOf.object("matrix", matrix);
1017
+ Check.typeOf.object("result", result);
1018
+ //>>includeEnd('debug');
1340
1019
 
1341
- const rowVal = [1, 0, 0];
1342
- const colVal = [2, 2, 1];
1020
+ const scale = Matrix3.getScale(matrix, scaleScratch5);
1343
1021
 
1344
- function offDiagonalFrobeniusNorm(matrix) {
1345
- // Computes the "off-diagonal" Frobenius norm.
1346
- // Assumes matrix is symmetric.
1022
+ result[0] = matrix[0] / scale.x;
1023
+ result[1] = matrix[1] / scale.x;
1024
+ result[2] = matrix[2] / scale.x;
1025
+ result[3] = matrix[3] / scale.y;
1026
+ result[4] = matrix[4] / scale.y;
1027
+ result[5] = matrix[5] / scale.y;
1028
+ result[6] = matrix[6] / scale.z;
1029
+ result[7] = matrix[7] / scale.z;
1030
+ result[8] = matrix[8] / scale.z;
1347
1031
 
1348
- let norm = 0.0;
1349
- for (let i = 0; i < 3; ++i) {
1350
- const temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];
1351
- norm += 2.0 * temp * temp;
1032
+ return result;
1352
1033
  }
1353
1034
 
1354
- return Math.sqrt(norm);
1355
- }
1035
+ /**
1036
+ * Computes the product of two matrices.
1037
+ *
1038
+ * @param {Matrix3} left The first matrix.
1039
+ * @param {Matrix3} right The second matrix.
1040
+ * @param {Matrix3} result The object onto which to store the result.
1041
+ * @returns {Matrix3} The modified result parameter.
1042
+ */
1043
+ static multiply(left, right, result) {
1044
+ //>>includeStart('debug', pragmas.debug);
1045
+ Check.typeOf.object("left", left);
1046
+ Check.typeOf.object("right", right);
1047
+ Check.typeOf.object("result", result);
1048
+ //>>includeEnd('debug');
1356
1049
 
1357
- function shurDecomposition(matrix, result) {
1358
- // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
1359
- // section 8.4.2 The 2by2 Symmetric Schur Decomposition.
1360
- //
1361
- // The routine takes a matrix, which is assumed to be symmetric, and
1362
- // finds the largest off-diagonal term, and then creates
1363
- // a matrix (result) which can be used to help reduce it
1050
+ const column0Row0 =
1051
+ left[0] * right[0] + left[3] * right[1] + left[6] * right[2];
1052
+ const column0Row1 =
1053
+ left[1] * right[0] + left[4] * right[1] + left[7] * right[2];
1054
+ const column0Row2 =
1055
+ left[2] * right[0] + left[5] * right[1] + left[8] * right[2];
1056
+
1057
+ const column1Row0 =
1058
+ left[0] * right[3] + left[3] * right[4] + left[6] * right[5];
1059
+ const column1Row1 =
1060
+ left[1] * right[3] + left[4] * right[4] + left[7] * right[5];
1061
+ const column1Row2 =
1062
+ left[2] * right[3] + left[5] * right[4] + left[8] * right[5];
1063
+
1064
+ const column2Row0 =
1065
+ left[0] * right[6] + left[3] * right[7] + left[6] * right[8];
1066
+ const column2Row1 =
1067
+ left[1] * right[6] + left[4] * right[7] + left[7] * right[8];
1068
+ const column2Row2 =
1069
+ left[2] * right[6] + left[5] * right[7] + left[8] * right[8];
1070
+
1071
+ result[0] = column0Row0;
1072
+ result[1] = column0Row1;
1073
+ result[2] = column0Row2;
1074
+ result[3] = column1Row0;
1075
+ result[4] = column1Row1;
1076
+ result[5] = column1Row2;
1077
+ result[6] = column2Row0;
1078
+ result[7] = column2Row1;
1079
+ result[8] = column2Row2;
1080
+ return result;
1081
+ }
1364
1082
 
1365
- const tolerance = CesiumMath.EPSILON15;
1083
+ /**
1084
+ * Computes the sum of two matrices.
1085
+ *
1086
+ * @param {Matrix3} left The first matrix.
1087
+ * @param {Matrix3} right The second matrix.
1088
+ * @param {Matrix3} result The object onto which to store the result.
1089
+ * @returns {Matrix3} The modified result parameter.
1090
+ */
1091
+ static add(left, right, result) {
1092
+ //>>includeStart('debug', pragmas.debug);
1093
+ Check.typeOf.object("left", left);
1094
+ Check.typeOf.object("right", right);
1095
+ Check.typeOf.object("result", result);
1096
+ //>>includeEnd('debug');
1366
1097
 
1367
- let maxDiagonal = 0.0;
1368
- let rotAxis = 1;
1098
+ result[0] = left[0] + right[0];
1099
+ result[1] = left[1] + right[1];
1100
+ result[2] = left[2] + right[2];
1101
+ result[3] = left[3] + right[3];
1102
+ result[4] = left[4] + right[4];
1103
+ result[5] = left[5] + right[5];
1104
+ result[6] = left[6] + right[6];
1105
+ result[7] = left[7] + right[7];
1106
+ result[8] = left[8] + right[8];
1107
+ return result;
1108
+ }
1369
1109
 
1370
- // find pivot (rotAxis) based on max diagonal of matrix
1371
- for (let i = 0; i < 3; ++i) {
1372
- const temp = Math.abs(
1373
- matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])],
1374
- );
1375
- if (temp > maxDiagonal) {
1376
- rotAxis = i;
1377
- maxDiagonal = temp;
1378
- }
1110
+ /**
1111
+ * Computes the difference of two matrices.
1112
+ *
1113
+ * @param {Matrix3} left The first matrix.
1114
+ * @param {Matrix3} right The second matrix.
1115
+ * @param {Matrix3} result The object onto which to store the result.
1116
+ * @returns {Matrix3} The modified result parameter.
1117
+ */
1118
+ static subtract(left, right, result) {
1119
+ //>>includeStart('debug', pragmas.debug);
1120
+ Check.typeOf.object("left", left);
1121
+ Check.typeOf.object("right", right);
1122
+ Check.typeOf.object("result", result);
1123
+ //>>includeEnd('debug');
1124
+
1125
+ result[0] = left[0] - right[0];
1126
+ result[1] = left[1] - right[1];
1127
+ result[2] = left[2] - right[2];
1128
+ result[3] = left[3] - right[3];
1129
+ result[4] = left[4] - right[4];
1130
+ result[5] = left[5] - right[5];
1131
+ result[6] = left[6] - right[6];
1132
+ result[7] = left[7] - right[7];
1133
+ result[8] = left[8] - right[8];
1134
+ return result;
1135
+ }
1136
+
1137
+ /**
1138
+ * Computes the product of a matrix and a column vector.
1139
+ *
1140
+ * @param {Matrix3} matrix The matrix.
1141
+ * @param {Cartesian3} cartesian The column.
1142
+ * @param {Cartesian3} result The object onto which to store the result.
1143
+ * @returns {Cartesian3} The modified result parameter.
1144
+ */
1145
+ static multiplyByVector(matrix, cartesian, result) {
1146
+ //>>includeStart('debug', pragmas.debug);
1147
+ Check.typeOf.object("matrix", matrix);
1148
+ Check.typeOf.object("cartesian", cartesian);
1149
+ Check.typeOf.object("result", result);
1150
+ //>>includeEnd('debug');
1151
+
1152
+ const vX = cartesian.x;
1153
+ const vY = cartesian.y;
1154
+ const vZ = cartesian.z;
1155
+
1156
+ const x = matrix[0] * vX + matrix[3] * vY + matrix[6] * vZ;
1157
+ const y = matrix[1] * vX + matrix[4] * vY + matrix[7] * vZ;
1158
+ const z = matrix[2] * vX + matrix[5] * vY + matrix[8] * vZ;
1159
+
1160
+ result.x = x;
1161
+ result.y = y;
1162
+ result.z = z;
1163
+ return result;
1164
+ }
1165
+
1166
+ /**
1167
+ * Computes the product of a matrix and a scalar.
1168
+ *
1169
+ * @param {Matrix3} matrix The matrix.
1170
+ * @param {number} scalar The number to multiply by.
1171
+ * @param {Matrix3} result The object onto which to store the result.
1172
+ * @returns {Matrix3} The modified result parameter.
1173
+ */
1174
+ static multiplyByScalar(matrix, scalar, result) {
1175
+ //>>includeStart('debug', pragmas.debug);
1176
+ Check.typeOf.object("matrix", matrix);
1177
+ Check.typeOf.number("scalar", scalar);
1178
+ Check.typeOf.object("result", result);
1179
+ //>>includeEnd('debug');
1180
+
1181
+ result[0] = matrix[0] * scalar;
1182
+ result[1] = matrix[1] * scalar;
1183
+ result[2] = matrix[2] * scalar;
1184
+ result[3] = matrix[3] * scalar;
1185
+ result[4] = matrix[4] * scalar;
1186
+ result[5] = matrix[5] * scalar;
1187
+ result[6] = matrix[6] * scalar;
1188
+ result[7] = matrix[7] * scalar;
1189
+ result[8] = matrix[8] * scalar;
1190
+ return result;
1191
+ }
1192
+
1193
+ /**
1194
+ * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.
1195
+ *
1196
+ * @param {Matrix3} matrix The matrix on the left-hand side.
1197
+ * @param {Cartesian3} scale The non-uniform scale on the right-hand side.
1198
+ * @param {Matrix3} result The object onto which to store the result.
1199
+ * @returns {Matrix3} The modified result parameter.
1200
+ *
1201
+ *
1202
+ * @example
1203
+ * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromScale(scale), m);
1204
+ * Cesium.Matrix3.multiplyByScale(m, scale, m);
1205
+ *
1206
+ * @see Matrix3.multiplyByUniformScale
1207
+ * @see Matrix3.fromScale
1208
+ * @see Matrix3.fromUniformScale
1209
+ * @see Matrix3.setScale
1210
+ * @see Matrix3.setUniformScale
1211
+ * @see Matrix3.getScale
1212
+ */
1213
+ static multiplyByScale(matrix, scale, result) {
1214
+ //>>includeStart('debug', pragmas.debug);
1215
+ Check.typeOf.object("matrix", matrix);
1216
+ Check.typeOf.object("scale", scale);
1217
+ Check.typeOf.object("result", result);
1218
+ //>>includeEnd('debug');
1219
+
1220
+ result[0] = matrix[0] * scale.x;
1221
+ result[1] = matrix[1] * scale.x;
1222
+ result[2] = matrix[2] * scale.x;
1223
+ result[3] = matrix[3] * scale.y;
1224
+ result[4] = matrix[4] * scale.y;
1225
+ result[5] = matrix[5] * scale.y;
1226
+ result[6] = matrix[6] * scale.z;
1227
+ result[7] = matrix[7] * scale.z;
1228
+ result[8] = matrix[8] * scale.z;
1229
+
1230
+ return result;
1231
+ }
1232
+
1233
+ /**
1234
+ * Computes the product of a matrix times a uniform scale, as if the scale were a scale matrix.
1235
+ *
1236
+ * @param {Matrix3} matrix The matrix on the left-hand side.
1237
+ * @param {number} scale The uniform scale on the right-hand side.
1238
+ * @param {Matrix3} result The object onto which to store the result.
1239
+ * @returns {Matrix3} The modified result parameter.
1240
+ *
1241
+ * @example
1242
+ * // Instead of Cesium.Matrix3.multiply(m, Cesium.Matrix3.fromUniformScale(scale), m);
1243
+ * Cesium.Matrix3.multiplyByUniformScale(m, scale, m);
1244
+ *
1245
+ * @see Matrix3.multiplyByScale
1246
+ * @see Matrix3.fromScale
1247
+ * @see Matrix3.fromUniformScale
1248
+ * @see Matrix3.setScale
1249
+ * @see Matrix3.setUniformScale
1250
+ * @see Matrix3.getScale
1251
+ */
1252
+ static multiplyByUniformScale(matrix, scale, result) {
1253
+ //>>includeStart('debug', pragmas.debug);
1254
+ Check.typeOf.object("matrix", matrix);
1255
+ Check.typeOf.number("scale", scale);
1256
+ Check.typeOf.object("result", result);
1257
+ //>>includeEnd('debug');
1258
+
1259
+ result[0] = matrix[0] * scale;
1260
+ result[1] = matrix[1] * scale;
1261
+ result[2] = matrix[2] * scale;
1262
+ result[3] = matrix[3] * scale;
1263
+ result[4] = matrix[4] * scale;
1264
+ result[5] = matrix[5] * scale;
1265
+ result[6] = matrix[6] * scale;
1266
+ result[7] = matrix[7] * scale;
1267
+ result[8] = matrix[8] * scale;
1268
+
1269
+ return result;
1270
+ }
1271
+
1272
+ /**
1273
+ * Creates a negated copy of the provided matrix.
1274
+ *
1275
+ * @param {Matrix3} matrix The matrix to negate.
1276
+ * @param {Matrix3} result The object onto which to store the result.
1277
+ * @returns {Matrix3} The modified result parameter.
1278
+ */
1279
+ static negate(matrix, result) {
1280
+ //>>includeStart('debug', pragmas.debug);
1281
+ Check.typeOf.object("matrix", matrix);
1282
+ Check.typeOf.object("result", result);
1283
+ //>>includeEnd('debug');
1284
+
1285
+ result[0] = -matrix[0];
1286
+ result[1] = -matrix[1];
1287
+ result[2] = -matrix[2];
1288
+ result[3] = -matrix[3];
1289
+ result[4] = -matrix[4];
1290
+ result[5] = -matrix[5];
1291
+ result[6] = -matrix[6];
1292
+ result[7] = -matrix[7];
1293
+ result[8] = -matrix[8];
1294
+ return result;
1379
1295
  }
1380
1296
 
1381
- let c = 1.0;
1382
- let s = 0.0;
1297
+ /**
1298
+ * Computes the transpose of the provided matrix.
1299
+ *
1300
+ * @param {Matrix3} matrix The matrix to transpose.
1301
+ * @param {Matrix3} result The object onto which to store the result.
1302
+ * @returns {Matrix3} The modified result parameter.
1303
+ */
1304
+ static transpose(matrix, result) {
1305
+ //>>includeStart('debug', pragmas.debug);
1306
+ Check.typeOf.object("matrix", matrix);
1307
+ Check.typeOf.object("result", result);
1308
+ //>>includeEnd('debug');
1383
1309
 
1384
- const p = rowVal[rotAxis];
1385
- const q = colVal[rotAxis];
1310
+ const column0Row0 = matrix[0];
1311
+ const column0Row1 = matrix[3];
1312
+ const column0Row2 = matrix[6];
1313
+ const column1Row0 = matrix[1];
1314
+ const column1Row1 = matrix[4];
1315
+ const column1Row2 = matrix[7];
1316
+ const column2Row0 = matrix[2];
1317
+ const column2Row1 = matrix[5];
1318
+ const column2Row2 = matrix[8];
1319
+
1320
+ result[0] = column0Row0;
1321
+ result[1] = column0Row1;
1322
+ result[2] = column0Row2;
1323
+ result[3] = column1Row0;
1324
+ result[4] = column1Row1;
1325
+ result[5] = column1Row2;
1326
+ result[6] = column2Row0;
1327
+ result[7] = column2Row1;
1328
+ result[8] = column2Row2;
1329
+ return result;
1330
+ }
1386
1331
 
1387
- if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {
1388
- const qq = matrix[Matrix3.getElementIndex(q, q)];
1389
- const pp = matrix[Matrix3.getElementIndex(p, p)];
1390
- const qp = matrix[Matrix3.getElementIndex(q, p)];
1332
+ /**
1333
+ * Computes the eigenvectors and eigenvalues of a symmetric matrix.
1334
+ * <p>
1335
+ * Returns a diagonal matrix and unitary matrix such that:
1336
+ * <code>matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)</code>
1337
+ * </p>
1338
+ * <p>
1339
+ * The values along the diagonal of the diagonal matrix are the eigenvalues. The columns
1340
+ * of the unitary matrix are the corresponding eigenvectors.
1341
+ * </p>
1342
+ *
1343
+ * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.
1344
+ * @param {EigenDecompositionResult} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.
1345
+ * @returns {EigenDecompositionResult} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.
1346
+ *
1347
+ * @example
1348
+ * const a = //... symetric matrix
1349
+ * const result = {
1350
+ * unitary : new Cesium.Matrix3(),
1351
+ * diagonal : new Cesium.Matrix3()
1352
+ * };
1353
+ * Cesium.Matrix3.computeEigenDecomposition(a, result);
1354
+ *
1355
+ * const unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());
1356
+ * const b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());
1357
+ * Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a
1358
+ *
1359
+ * const lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue
1360
+ * const v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector
1361
+ * const c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)
1362
+ */
1363
+ static computeEigenDecomposition(matrix, result) {
1364
+ //>>includeStart('debug', pragmas.debug);
1365
+ Check.typeOf.object("matrix", matrix);
1366
+ //>>includeEnd('debug');
1391
1367
 
1392
- const tau = (qq - pp) / 2.0 / qp;
1393
- let t;
1368
+ // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
1369
+ // section 8.4.3 The Classical Jacobi Algorithm
1394
1370
 
1395
- if (tau < 0.0) {
1396
- t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
1397
- } else {
1398
- t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));
1371
+ const tolerance = CesiumMath.EPSILON20;
1372
+ const maxSweeps = 10;
1373
+
1374
+ let count = 0;
1375
+ let sweep = 0;
1376
+
1377
+ if (!defined(result)) {
1378
+ result = {};
1399
1379
  }
1400
1380
 
1401
- c = 1.0 / Math.sqrt(1.0 + t * t);
1402
- s = t * c;
1381
+ const unitaryMatrix = (result.unitary = Matrix3.clone(
1382
+ Matrix3.IDENTITY,
1383
+ result.unitary,
1384
+ ));
1385
+ const diagMatrix = (result.diagonal = Matrix3.clone(
1386
+ matrix,
1387
+ result.diagonal,
1388
+ ));
1389
+
1390
+ const epsilon = tolerance * computeFrobeniusNorm(diagMatrix);
1391
+
1392
+ while (
1393
+ sweep < maxSweeps &&
1394
+ offDiagonalFrobeniusNorm(diagMatrix) > epsilon
1395
+ ) {
1396
+ shurDecomposition(diagMatrix, jMatrix);
1397
+ Matrix3.transpose(jMatrix, jMatrixTranspose);
1398
+ Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);
1399
+ Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);
1400
+ Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);
1401
+
1402
+ if (++count > 2) {
1403
+ ++sweep;
1404
+ count = 0;
1405
+ }
1406
+ }
1407
+
1408
+ return result;
1403
1409
  }
1404
1410
 
1405
- result = Matrix3.clone(Matrix3.IDENTITY, result);
1411
+ /**
1412
+ * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
1413
+ *
1414
+ * @param {Matrix3} matrix The matrix with signed elements.
1415
+ * @param {Matrix3} result The object onto which to store the result.
1416
+ * @returns {Matrix3} The modified result parameter.
1417
+ */
1418
+ static abs(matrix, result) {
1419
+ //>>includeStart('debug', pragmas.debug);
1420
+ Check.typeOf.object("matrix", matrix);
1421
+ Check.typeOf.object("result", result);
1422
+ //>>includeEnd('debug');
1406
1423
 
1407
- result[Matrix3.getElementIndex(p, p)] = result[
1408
- Matrix3.getElementIndex(q, q)
1409
- ] = c;
1410
- result[Matrix3.getElementIndex(q, p)] = s;
1411
- result[Matrix3.getElementIndex(p, q)] = -s;
1424
+ result[0] = Math.abs(matrix[0]);
1425
+ result[1] = Math.abs(matrix[1]);
1426
+ result[2] = Math.abs(matrix[2]);
1427
+ result[3] = Math.abs(matrix[3]);
1428
+ result[4] = Math.abs(matrix[4]);
1429
+ result[5] = Math.abs(matrix[5]);
1430
+ result[6] = Math.abs(matrix[6]);
1431
+ result[7] = Math.abs(matrix[7]);
1432
+ result[8] = Math.abs(matrix[8]);
1433
+
1434
+ return result;
1435
+ }
1412
1436
 
1413
- return result;
1414
- }
1437
+ /**
1438
+ * Computes the determinant of the provided matrix.
1439
+ *
1440
+ * @param {Matrix3} matrix The matrix to use.
1441
+ * @returns {number} The value of the determinant of the matrix.
1442
+ */
1443
+ static determinant(matrix) {
1444
+ //>>includeStart('debug', pragmas.debug);
1445
+ Check.typeOf.object("matrix", matrix);
1446
+ //>>includeEnd('debug');
1415
1447
 
1416
- const jMatrix = new Matrix3();
1417
- const jMatrixTranspose = new Matrix3();
1448
+ const m11 = matrix[0];
1449
+ const m21 = matrix[3];
1450
+ const m31 = matrix[6];
1451
+ const m12 = matrix[1];
1452
+ const m22 = matrix[4];
1453
+ const m32 = matrix[7];
1454
+ const m13 = matrix[2];
1455
+ const m23 = matrix[5];
1456
+ const m33 = matrix[8];
1457
+
1458
+ return (
1459
+ m11 * (m22 * m33 - m23 * m32) +
1460
+ m12 * (m23 * m31 - m21 * m33) +
1461
+ m13 * (m21 * m32 - m22 * m31)
1462
+ );
1463
+ }
1418
1464
 
1419
- /**
1420
- * Computes the eigenvectors and eigenvalues of a symmetric matrix.
1421
- * <p>
1422
- * Returns a diagonal matrix and unitary matrix such that:
1423
- * <code>matrix = unitary matrix * diagonal matrix * transpose(unitary matrix)</code>
1424
- * </p>
1425
- * <p>
1426
- * The values along the diagonal of the diagonal matrix are the eigenvalues. The columns
1427
- * of the unitary matrix are the corresponding eigenvectors.
1428
- * </p>
1429
- *
1430
- * @param {Matrix3} matrix The matrix to decompose into diagonal and unitary matrix. Expected to be symmetric.
1431
- * @param {object} [result] An object with unitary and diagonal properties which are matrices onto which to store the result.
1432
- * @returns {object} An object with unitary and diagonal properties which are the unitary and diagonal matrices, respectively.
1433
- *
1434
- * @example
1435
- * const a = //... symetric matrix
1436
- * const result = {
1437
- * unitary : new Cesium.Matrix3(),
1438
- * diagonal : new Cesium.Matrix3()
1439
- * };
1440
- * Cesium.Matrix3.computeEigenDecomposition(a, result);
1441
- *
1442
- * const unitaryTranspose = Cesium.Matrix3.transpose(result.unitary, new Cesium.Matrix3());
1443
- * const b = Cesium.Matrix3.multiply(result.unitary, result.diagonal, new Cesium.Matrix3());
1444
- * Cesium.Matrix3.multiply(b, unitaryTranspose, b); // b is now equal to a
1445
- *
1446
- * const lambda = Cesium.Matrix3.getColumn(result.diagonal, 0, new Cesium.Cartesian3()).x; // first eigenvalue
1447
- * const v = Cesium.Matrix3.getColumn(result.unitary, 0, new Cesium.Cartesian3()); // first eigenvector
1448
- * const c = Cesium.Cartesian3.multiplyByScalar(v, lambda, new Cesium.Cartesian3()); // equal to Cesium.Matrix3.multiplyByVector(a, v)
1449
- */
1450
- Matrix3.computeEigenDecomposition = function (matrix, result) {
1451
- //>>includeStart('debug', pragmas.debug);
1452
- Check.typeOf.object("matrix", matrix);
1453
- //>>includeEnd('debug');
1465
+ /**
1466
+ * Computes the inverse of the provided matrix.
1467
+ *
1468
+ * @param {Matrix3} matrix The matrix to invert.
1469
+ * @param {Matrix3} result The object onto which to store the result.
1470
+ * @returns {Matrix3} The modified result parameter.
1471
+ *
1472
+ * @exception {DeveloperError} matrix is not invertible.
1473
+ */
1474
+ static inverse(matrix, result) {
1475
+ //>>includeStart('debug', pragmas.debug);
1476
+ Check.typeOf.object("matrix", matrix);
1477
+ Check.typeOf.object("result", result);
1478
+ //>>includeEnd('debug');
1454
1479
 
1455
- // This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
1456
- // section 8.4.3 The Classical Jacobi Algorithm
1480
+ const m11 = matrix[0];
1481
+ const m21 = matrix[1];
1482
+ const m31 = matrix[2];
1483
+ const m12 = matrix[3];
1484
+ const m22 = matrix[4];
1485
+ const m32 = matrix[5];
1486
+ const m13 = matrix[6];
1487
+ const m23 = matrix[7];
1488
+ const m33 = matrix[8];
1457
1489
 
1458
- const tolerance = CesiumMath.EPSILON20;
1459
- const maxSweeps = 10;
1490
+ const determinant = Matrix3.determinant(matrix);
1460
1491
 
1461
- let count = 0;
1462
- let sweep = 0;
1492
+ //>>includeStart('debug', pragmas.debug);
1493
+ if (Math.abs(determinant) <= CesiumMath.EPSILON15) {
1494
+ throw new DeveloperError("matrix is not invertible");
1495
+ }
1496
+ //>>includeEnd('debug');
1463
1497
 
1464
- if (!defined(result)) {
1465
- result = {};
1498
+ result[0] = m22 * m33 - m23 * m32;
1499
+ result[1] = m23 * m31 - m21 * m33;
1500
+ result[2] = m21 * m32 - m22 * m31;
1501
+ result[3] = m13 * m32 - m12 * m33;
1502
+ result[4] = m11 * m33 - m13 * m31;
1503
+ result[5] = m12 * m31 - m11 * m32;
1504
+ result[6] = m12 * m23 - m13 * m22;
1505
+ result[7] = m13 * m21 - m11 * m23;
1506
+ result[8] = m11 * m22 - m12 * m21;
1507
+
1508
+ const scale = 1.0 / determinant;
1509
+ return Matrix3.multiplyByScalar(result, scale, result);
1466
1510
  }
1467
1511
 
1468
- const unitaryMatrix = (result.unitary = Matrix3.clone(
1469
- Matrix3.IDENTITY,
1470
- result.unitary,
1471
- ));
1472
- const diagMatrix = (result.diagonal = Matrix3.clone(matrix, result.diagonal));
1512
+ /**
1513
+ * Computes the inverse transpose of a matrix.
1514
+ *
1515
+ * @param {Matrix3} matrix The matrix to transpose and invert.
1516
+ * @param {Matrix3} result The object onto which to store the result.
1517
+ * @returns {Matrix3} The modified result parameter.
1518
+ */
1519
+ static inverseTranspose(matrix, result) {
1520
+ //>>includeStart('debug', pragmas.debug);
1521
+ Check.typeOf.object("matrix", matrix);
1522
+ Check.typeOf.object("result", result);
1523
+ //>>includeEnd('debug');
1473
1524
 
1474
- const epsilon = tolerance * computeFrobeniusNorm(diagMatrix);
1525
+ return Matrix3.inverse(
1526
+ Matrix3.transpose(matrix, scratchTransposeMatrix),
1527
+ result,
1528
+ );
1529
+ }
1475
1530
 
1476
- while (sweep < maxSweeps && offDiagonalFrobeniusNorm(diagMatrix) > epsilon) {
1477
- shurDecomposition(diagMatrix, jMatrix);
1478
- Matrix3.transpose(jMatrix, jMatrixTranspose);
1479
- Matrix3.multiply(diagMatrix, jMatrix, diagMatrix);
1480
- Matrix3.multiply(jMatrixTranspose, diagMatrix, diagMatrix);
1481
- Matrix3.multiply(unitaryMatrix, jMatrix, unitaryMatrix);
1531
+ /**
1532
+ * Compares the provided matrices componentwise and returns
1533
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
1534
+ *
1535
+ * @param {Matrix3} [left] The first matrix.
1536
+ * @param {Matrix3} [right] The second matrix.
1537
+ * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
1538
+ */
1539
+ static equals(left, right) {
1540
+ return (
1541
+ left === right ||
1542
+ (defined(left) &&
1543
+ defined(right) &&
1544
+ left[0] === right[0] &&
1545
+ left[1] === right[1] &&
1546
+ left[2] === right[2] &&
1547
+ left[3] === right[3] &&
1548
+ left[4] === right[4] &&
1549
+ left[5] === right[5] &&
1550
+ left[6] === right[6] &&
1551
+ left[7] === right[7] &&
1552
+ left[8] === right[8])
1553
+ );
1554
+ }
1482
1555
 
1483
- if (++count > 2) {
1484
- ++sweep;
1485
- count = 0;
1486
- }
1556
+ /**
1557
+ * Compares the provided matrices componentwise and returns
1558
+ * <code>true</code> if they are within the provided epsilon,
1559
+ * <code>false</code> otherwise.
1560
+ *
1561
+ * @param {Matrix3} [left] The first matrix.
1562
+ * @param {Matrix3} [right] The second matrix.
1563
+ * @param {number} [epsilon=0] The epsilon to use for equality testing.
1564
+ * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
1565
+ */
1566
+ static equalsEpsilon(left, right, epsilon) {
1567
+ epsilon = epsilon ?? 0;
1568
+
1569
+ return (
1570
+ left === right ||
1571
+ (defined(left) &&
1572
+ defined(right) &&
1573
+ Math.abs(left[0] - right[0]) <= epsilon &&
1574
+ Math.abs(left[1] - right[1]) <= epsilon &&
1575
+ Math.abs(left[2] - right[2]) <= epsilon &&
1576
+ Math.abs(left[3] - right[3]) <= epsilon &&
1577
+ Math.abs(left[4] - right[4]) <= epsilon &&
1578
+ Math.abs(left[5] - right[5]) <= epsilon &&
1579
+ Math.abs(left[6] - right[6]) <= epsilon &&
1580
+ Math.abs(left[7] - right[7]) <= epsilon &&
1581
+ Math.abs(left[8] - right[8]) <= epsilon)
1582
+ );
1487
1583
  }
1488
1584
 
1489
- return result;
1490
- };
1585
+ /**
1586
+ * Gets the number of items in the collection.
1587
+ *
1588
+ * @type {number}
1589
+ */
1590
+ get length() {
1591
+ return Matrix3.packedLength;
1592
+ }
1491
1593
 
1492
- /**
1493
- * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
1494
- *
1495
- * @param {Matrix3} matrix The matrix with signed elements.
1496
- * @param {Matrix3} result The object onto which to store the result.
1497
- * @returns {Matrix3} The modified result parameter.
1498
- */
1499
- Matrix3.abs = function (matrix, result) {
1500
- //>>includeStart('debug', pragmas.debug);
1501
- Check.typeOf.object("matrix", matrix);
1502
- Check.typeOf.object("result", result);
1503
- //>>includeEnd('debug');
1504
-
1505
- result[0] = Math.abs(matrix[0]);
1506
- result[1] = Math.abs(matrix[1]);
1507
- result[2] = Math.abs(matrix[2]);
1508
- result[3] = Math.abs(matrix[3]);
1509
- result[4] = Math.abs(matrix[4]);
1510
- result[5] = Math.abs(matrix[5]);
1511
- result[6] = Math.abs(matrix[6]);
1512
- result[7] = Math.abs(matrix[7]);
1513
- result[8] = Math.abs(matrix[8]);
1594
+ /**
1595
+ * Duplicates the provided Matrix3 instance.
1596
+ *
1597
+ * @param {Matrix3} [result] The object onto which to store the result.
1598
+ * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
1599
+ */
1600
+ clone(result) {
1601
+ return Matrix3.clone(this, result);
1602
+ }
1514
1603
 
1515
- return result;
1516
- };
1604
+ /**
1605
+ * Compares this matrix to the provided matrix componentwise and returns
1606
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
1607
+ *
1608
+ * @param {Matrix3} [right] The right hand side matrix.
1609
+ * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
1610
+ */
1611
+ equals(right) {
1612
+ return Matrix3.equals(this, right);
1613
+ }
1517
1614
 
1518
- /**
1519
- * Computes the determinant of the provided matrix.
1520
- *
1521
- * @param {Matrix3} matrix The matrix to use.
1522
- * @returns {number} The value of the determinant of the matrix.
1523
- */
1524
- Matrix3.determinant = function (matrix) {
1525
- //>>includeStart('debug', pragmas.debug);
1526
- Check.typeOf.object("matrix", matrix);
1527
- //>>includeEnd('debug');
1528
-
1529
- const m11 = matrix[0];
1530
- const m21 = matrix[3];
1531
- const m31 = matrix[6];
1532
- const m12 = matrix[1];
1533
- const m22 = matrix[4];
1534
- const m32 = matrix[7];
1535
- const m13 = matrix[2];
1536
- const m23 = matrix[5];
1537
- const m33 = matrix[8];
1538
-
1539
- return (
1540
- m11 * (m22 * m33 - m23 * m32) +
1541
- m12 * (m23 * m31 - m21 * m33) +
1542
- m13 * (m21 * m32 - m22 * m31)
1543
- );
1544
- };
1615
+ /**
1616
+ * Compares provided matrix and array, starting from a given array offset.
1617
+ *
1618
+ * @param {Matrix3} matrix
1619
+ * @param {number[]} array
1620
+ * @param {number} offset
1621
+ * @ignore
1622
+ */
1623
+ static equalsArray(matrix, array, offset) {
1624
+ return (
1625
+ matrix[0] === array[offset] &&
1626
+ matrix[1] === array[offset + 1] &&
1627
+ matrix[2] === array[offset + 2] &&
1628
+ matrix[3] === array[offset + 3] &&
1629
+ matrix[4] === array[offset + 4] &&
1630
+ matrix[5] === array[offset + 5] &&
1631
+ matrix[6] === array[offset + 6] &&
1632
+ matrix[7] === array[offset + 7] &&
1633
+ matrix[8] === array[offset + 8]
1634
+ );
1635
+ }
1545
1636
 
1546
- /**
1547
- * Computes the inverse of the provided matrix.
1548
- *
1549
- * @param {Matrix3} matrix The matrix to invert.
1550
- * @param {Matrix3} result The object onto which to store the result.
1551
- * @returns {Matrix3} The modified result parameter.
1552
- *
1553
- * @exception {DeveloperError} matrix is not invertible.
1554
- */
1555
- Matrix3.inverse = function (matrix, result) {
1556
- //>>includeStart('debug', pragmas.debug);
1557
- Check.typeOf.object("matrix", matrix);
1558
- Check.typeOf.object("result", result);
1559
- //>>includeEnd('debug');
1560
-
1561
- const m11 = matrix[0];
1562
- const m21 = matrix[1];
1563
- const m31 = matrix[2];
1564
- const m12 = matrix[3];
1565
- const m22 = matrix[4];
1566
- const m32 = matrix[5];
1567
- const m13 = matrix[6];
1568
- const m23 = matrix[7];
1569
- const m33 = matrix[8];
1570
-
1571
- const determinant = Matrix3.determinant(matrix);
1572
-
1573
- //>>includeStart('debug', pragmas.debug);
1574
- if (Math.abs(determinant) <= CesiumMath.EPSILON15) {
1575
- throw new DeveloperError("matrix is not invertible");
1637
+ /**
1638
+ * Compares this matrix to the provided matrix componentwise and returns
1639
+ * <code>true</code> if they are within the provided epsilon,
1640
+ * <code>false</code> otherwise.
1641
+ *
1642
+ * @param {Matrix3} [right] The right hand side matrix.
1643
+ * @param {number} [epsilon=0] The epsilon to use for equality testing.
1644
+ * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
1645
+ */
1646
+ equalsEpsilon(right, epsilon) {
1647
+ return Matrix3.equalsEpsilon(this, right, epsilon);
1576
1648
  }
1577
- //>>includeEnd('debug');
1578
-
1579
- result[0] = m22 * m33 - m23 * m32;
1580
- result[1] = m23 * m31 - m21 * m33;
1581
- result[2] = m21 * m32 - m22 * m31;
1582
- result[3] = m13 * m32 - m12 * m33;
1583
- result[4] = m11 * m33 - m13 * m31;
1584
- result[5] = m12 * m31 - m11 * m32;
1585
- result[6] = m12 * m23 - m13 * m22;
1586
- result[7] = m13 * m21 - m11 * m23;
1587
- result[8] = m11 * m22 - m12 * m21;
1588
-
1589
- const scale = 1.0 / determinant;
1590
- return Matrix3.multiplyByScalar(result, scale, result);
1591
- };
1592
1649
 
1593
- const scratchTransposeMatrix = new Matrix3();
1650
+ /**
1651
+ * Creates a string representing this Matrix with each row being
1652
+ * on a separate line and in the format '(column0, column1, column2)'.
1653
+ *
1654
+ * @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.
1655
+ */
1656
+ toString() {
1657
+ return (
1658
+ `(${this[0]}, ${this[3]}, ${this[6]})\n` +
1659
+ `(${this[1]}, ${this[4]}, ${this[7]})\n` +
1660
+ `(${this[2]}, ${this[5]}, ${this[8]})`
1661
+ );
1662
+ }
1663
+ }
1594
1664
 
1595
1665
  /**
1596
- * Computes the inverse transpose of a matrix.
1597
- *
1598
- * @param {Matrix3} matrix The matrix to transpose and invert.
1599
- * @param {Matrix3} result The object onto which to store the result.
1600
- * @returns {Matrix3} The modified result parameter.
1666
+ * The number of elements used to pack the object into an array.
1667
+ * @type {number}
1601
1668
  */
1602
- Matrix3.inverseTranspose = function (matrix, result) {
1603
- //>>includeStart('debug', pragmas.debug);
1604
- Check.typeOf.object("matrix", matrix);
1605
- Check.typeOf.object("result", result);
1606
- //>>includeEnd('debug');
1607
-
1608
- return Matrix3.inverse(
1609
- Matrix3.transpose(matrix, scratchTransposeMatrix),
1610
- result,
1611
- );
1612
- };
1669
+ Matrix3.packedLength = 9;
1613
1670
 
1614
1671
  /**
1615
- * Compares the provided matrices componentwise and returns
1616
- * <code>true</code> if they are equal, <code>false</code> otherwise.
1672
+ * Creates a Matrix3 from 9 consecutive elements in an array.
1617
1673
  *
1618
- * @param {Matrix3} [left] The first matrix.
1619
- * @param {Matrix3} [right] The second matrix.
1620
- * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
1621
- */
1622
- Matrix3.equals = function (left, right) {
1623
- return (
1624
- left === right ||
1625
- (defined(left) &&
1626
- defined(right) &&
1627
- left[0] === right[0] &&
1628
- left[1] === right[1] &&
1629
- left[2] === right[2] &&
1630
- left[3] === right[3] &&
1631
- left[4] === right[4] &&
1632
- left[5] === right[5] &&
1633
- left[6] === right[6] &&
1634
- left[7] === right[7] &&
1635
- left[8] === right[8])
1636
- );
1637
- };
1638
-
1639
- /**
1640
- * Compares the provided matrices componentwise and returns
1641
- * <code>true</code> if they are within the provided epsilon,
1642
- * <code>false</code> otherwise.
1674
+ * @function
1675
+ * @param {number[]} array The array whose 9 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
1676
+ * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
1677
+ * @param {Matrix3} [result] The object onto which to store the result.
1678
+ * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
1643
1679
  *
1644
- * @param {Matrix3} [left] The first matrix.
1645
- * @param {Matrix3} [right] The second matrix.
1646
- * @param {number} [epsilon=0] The epsilon to use for equality testing.
1647
- * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
1680
+ * @example
1681
+ * // Create the Matrix3:
1682
+ * // [1.0, 2.0, 3.0]
1683
+ * // [1.0, 2.0, 3.0]
1684
+ * // [1.0, 2.0, 3.0]
1685
+ *
1686
+ * const v = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
1687
+ * const m = Cesium.Matrix3.fromArray(v);
1688
+ *
1689
+ * // Create same Matrix3 with using an offset into an array
1690
+ * const v2 = [0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0];
1691
+ * const m2 = Cesium.Matrix3.fromArray(v2, 2);
1648
1692
  */
1649
- Matrix3.equalsEpsilon = function (left, right, epsilon) {
1650
- epsilon = epsilon ?? 0;
1651
-
1652
- return (
1653
- left === right ||
1654
- (defined(left) &&
1655
- defined(right) &&
1656
- Math.abs(left[0] - right[0]) <= epsilon &&
1657
- Math.abs(left[1] - right[1]) <= epsilon &&
1658
- Math.abs(left[2] - right[2]) <= epsilon &&
1659
- Math.abs(left[3] - right[3]) <= epsilon &&
1660
- Math.abs(left[4] - right[4]) <= epsilon &&
1661
- Math.abs(left[5] - right[5]) <= epsilon &&
1662
- Math.abs(left[6] - right[6]) <= epsilon &&
1663
- Math.abs(left[7] - right[7]) <= epsilon &&
1664
- Math.abs(left[8] - right[8]) <= epsilon)
1665
- );
1666
- };
1693
+ Matrix3.fromArray = Matrix3.unpack;
1667
1694
 
1668
1695
  /**
1669
1696
  * An immutable Matrix3 instance initialized to the identity matrix.
@@ -1757,82 +1784,123 @@ Matrix3.COLUMN2ROW1 = 7;
1757
1784
  */
1758
1785
  Matrix3.COLUMN2ROW2 = 8;
1759
1786
 
1760
- Object.defineProperties(Matrix3.prototype, {
1761
- /**
1762
- * Gets the number of items in the collection.
1763
- * @memberof Matrix3.prototype
1764
- *
1765
- * @type {number}
1766
- */
1767
- length: {
1768
- get: function () {
1769
- return Matrix3.packedLength;
1770
- },
1771
- },
1772
- });
1787
+ const scaleScratch1 = new Cartesian3();
1788
+ const scaleScratch2 = new Cartesian3();
1789
+ const scratchColumn = new Cartesian3();
1790
+ const scaleScratch3 = new Cartesian3();
1791
+ const scaleScratch4 = new Cartesian3();
1792
+ const scaleScratch5 = new Cartesian3();
1773
1793
 
1774
- /**
1775
- * Duplicates the provided Matrix3 instance.
1776
- *
1777
- * @param {Matrix3} [result] The object onto which to store the result.
1778
- * @returns {Matrix3} The modified result parameter or a new Matrix3 instance if one was not provided.
1779
- */
1780
- Matrix3.prototype.clone = function (result) {
1781
- return Matrix3.clone(this, result);
1782
- };
1794
+ const jMatrix = new Matrix3();
1795
+ const jMatrixTranspose = new Matrix3();
1796
+ const scratchTransposeMatrix = new Matrix3();
1783
1797
 
1784
1798
  /**
1785
- * Compares this matrix to the provided matrix componentwise and returns
1786
- * <code>true</code> if they are equal, <code>false</code> otherwise.
1787
- *
1788
- * @param {Matrix3} [right] The right hand side matrix.
1789
- * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
1799
+ * @param {Matrix3} matrix
1800
+ * @ignore
1790
1801
  */
1791
- Matrix3.prototype.equals = function (right) {
1792
- return Matrix3.equals(this, right);
1793
- };
1802
+ function computeFrobeniusNorm(matrix) {
1803
+ let norm = 0.0;
1804
+ for (let i = 0; i < 9; ++i) {
1805
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1806
+ const temp = matrix[i];
1807
+ norm += temp * temp;
1808
+ }
1794
1809
 
1795
- /**
1796
- * @private
1797
- */
1798
- Matrix3.equalsArray = function (matrix, array, offset) {
1799
- return (
1800
- matrix[0] === array[offset] &&
1801
- matrix[1] === array[offset + 1] &&
1802
- matrix[2] === array[offset + 2] &&
1803
- matrix[3] === array[offset + 3] &&
1804
- matrix[4] === array[offset + 4] &&
1805
- matrix[5] === array[offset + 5] &&
1806
- matrix[6] === array[offset + 6] &&
1807
- matrix[7] === array[offset + 7] &&
1808
- matrix[8] === array[offset + 8]
1809
- );
1810
- };
1810
+ return Math.sqrt(norm);
1811
+ }
1812
+
1813
+ const rowVal = [1, 0, 0];
1814
+ const colVal = [2, 2, 1];
1811
1815
 
1812
1816
  /**
1813
- * Compares this matrix to the provided matrix componentwise and returns
1814
- * <code>true</code> if they are within the provided epsilon,
1815
- * <code>false</code> otherwise.
1816
- *
1817
- * @param {Matrix3} [right] The right hand side matrix.
1818
- * @param {number} [epsilon=0] The epsilon to use for equality testing.
1819
- * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
1817
+ * @param {Matrix3} matrix
1818
+ * @ignore
1820
1819
  */
1821
- Matrix3.prototype.equalsEpsilon = function (right, epsilon) {
1822
- return Matrix3.equalsEpsilon(this, right, epsilon);
1823
- };
1820
+ function offDiagonalFrobeniusNorm(matrix) {
1821
+ // Computes the "off-diagonal" Frobenius norm.
1822
+ // Assumes matrix is symmetric.
1823
+
1824
+ let norm = 0.0;
1825
+ for (let i = 0; i < 3; ++i) {
1826
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1827
+ const temp = matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])];
1828
+ norm += 2.0 * temp * temp;
1829
+ }
1830
+
1831
+ return Math.sqrt(norm);
1832
+ }
1824
1833
 
1825
1834
  /**
1826
- * Creates a string representing this Matrix with each row being
1827
- * on a separate line and in the format '(column0, column1, column2)'.
1835
+ * This routine was created based upon Matrix Computations, 3rd ed., by Golub and Van Loan,
1836
+ * section 8.4.2 The 2by2 Symmetric Schur Decomposition.
1837
+ *
1838
+ * The routine takes a matrix, which is assumed to be symmetric, and
1839
+ * finds the largest off-diagonal term, and then creates
1840
+ * a matrix (result) which can be used to help reduce it
1828
1841
  *
1829
- * @returns {string} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1, column2)'.
1842
+ * @param {Matrix3} matrix
1843
+ * @param {Matrix3} result
1844
+ * @ignore
1830
1845
  */
1831
- Matrix3.prototype.toString = function () {
1832
- return (
1833
- `(${this[0]}, ${this[3]}, ${this[6]})\n` +
1834
- `(${this[1]}, ${this[4]}, ${this[7]})\n` +
1835
- `(${this[2]}, ${this[5]}, ${this[8]})`
1836
- );
1837
- };
1846
+ function shurDecomposition(matrix, result) {
1847
+ const tolerance = CesiumMath.EPSILON15;
1848
+
1849
+ let maxDiagonal = 0.0;
1850
+ let rotAxis = 1;
1851
+
1852
+ // find pivot (rotAxis) based on max diagonal of matrix
1853
+ for (let i = 0; i < 3; ++i) {
1854
+ const temp = Math.abs(
1855
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1856
+ matrix[Matrix3.getElementIndex(colVal[i], rowVal[i])],
1857
+ );
1858
+ if (temp > maxDiagonal) {
1859
+ rotAxis = i;
1860
+ maxDiagonal = temp;
1861
+ }
1862
+ }
1863
+
1864
+ let c = 1.0;
1865
+ let s = 0.0;
1866
+
1867
+ const p = rowVal[rotAxis];
1868
+ const q = colVal[rotAxis];
1869
+
1870
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1871
+ if (Math.abs(matrix[Matrix3.getElementIndex(q, p)]) > tolerance) {
1872
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1873
+ const qq = matrix[Matrix3.getElementIndex(q, q)];
1874
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1875
+ const pp = matrix[Matrix3.getElementIndex(p, p)];
1876
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1877
+ const qp = matrix[Matrix3.getElementIndex(q, p)];
1878
+
1879
+ const tau = (qq - pp) / 2.0 / qp;
1880
+ let t;
1881
+
1882
+ if (tau < 0.0) {
1883
+ t = -1.0 / (-tau + Math.sqrt(1.0 + tau * tau));
1884
+ } else {
1885
+ t = 1.0 / (tau + Math.sqrt(1.0 + tau * tau));
1886
+ }
1887
+
1888
+ c = 1.0 / Math.sqrt(1.0 + t * t);
1889
+ s = t * c;
1890
+ }
1891
+
1892
+ result = Matrix3.clone(Matrix3.IDENTITY, result);
1893
+
1894
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1895
+ result[Matrix3.getElementIndex(p, p)] = result[
1896
+ Matrix3.getElementIndex(q, q)
1897
+ ] = c;
1898
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1899
+ result[Matrix3.getElementIndex(q, p)] = s;
1900
+ // @ts-expect-error TODO(tsd-jsdoc): Requires index signature support.
1901
+ result[Matrix3.getElementIndex(p, q)] = -s;
1902
+
1903
+ return result;
1904
+ }
1905
+
1838
1906
  export default Matrix3;