@cesium/engine 22.2.0 → 23.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 (282) hide show
  1. package/Build/Workers/{chunk-YFEZPDAY.js → chunk-2GL2EUEE.js} +11 -11
  2. package/Build/Workers/{chunk-A3NUMZBG.js → chunk-2WI4HGJU.js} +6 -6
  3. package/Build/Workers/{chunk-3JB2X2PR.js → chunk-36LBFITA.js} +665 -366
  4. package/Build/Workers/{chunk-VSZ5DB2W.js → chunk-3B65YFXC.js} +1 -1
  5. package/Build/Workers/{chunk-PSHZAHFE.js → chunk-4LGFX2P5.js} +11 -11
  6. package/Build/Workers/{chunk-AMWXJ5A7.js → chunk-4UNQX2MP.js} +2 -2
  7. package/Build/Workers/{chunk-LDSQMLRC.js → chunk-52K3GJKG.js} +3 -3
  8. package/Build/Workers/{chunk-MSTAVM2N.js → chunk-56OHFSLH.js} +10 -10
  9. package/Build/Workers/{chunk-IWOSJVFQ.js → chunk-5A7YSAXT.js} +14 -14
  10. package/Build/Workers/{chunk-PMDPP22G.js → chunk-5JP5FG7U.js} +7 -7
  11. package/Build/Workers/{chunk-DIJ7IG5D.js → chunk-5R7SBUTW.js} +10 -10
  12. package/Build/Workers/chunk-5VKZVPO5.js +1829 -0
  13. package/Build/Workers/{chunk-L2FSBEW2.js → chunk-6FVFM2KB.js} +5 -5
  14. package/Build/Workers/{chunk-G6WQA27G.js → chunk-6SLGTBB2.js} +5 -5
  15. package/Build/Workers/{chunk-3HUEBDFC.js → chunk-7KRN6JPQ.js} +14 -14
  16. package/Build/Workers/{chunk-GMHDOQPH.js → chunk-AA33B6PU.js} +4 -4
  17. package/Build/Workers/{chunk-7CDQUIP5.js → chunk-AP6XWET5.js} +8 -8
  18. package/Build/Workers/{chunk-IVN5HSOI.js → chunk-APDKMX7W.js} +6 -6
  19. package/Build/Workers/{chunk-72LZ3FN6.js → chunk-ARCFIOKA.js} +12 -12
  20. package/Build/Workers/{chunk-UBJYWGMV.js → chunk-BNBD2YZK.js} +16 -16
  21. package/Build/Workers/{chunk-VGH2CSC7.js → chunk-DT5SJBKA.js} +29 -15
  22. package/Build/Workers/{chunk-ED4UXMYY.js → chunk-ESD4IEOU.js} +5 -5
  23. package/Build/Workers/{chunk-JFN2DQHY.js → chunk-FSDVXW7M.js} +5 -5
  24. package/Build/Workers/{chunk-JERDRSEI.js → chunk-G3YT7M7A.js} +1 -1
  25. package/Build/Workers/{chunk-NY3CWLIZ.js → chunk-GN5NEUDT.js} +8 -8
  26. package/Build/Workers/{chunk-O3GWUTWM.js → chunk-HYLEKKO5.js} +1 -1
  27. package/Build/Workers/{chunk-64PJ4MTB.js → chunk-HYTFXWMY.js} +7 -7
  28. package/Build/Workers/{chunk-FPRM6PCE.js → chunk-IFA7VHHP.js} +560 -306
  29. package/Build/Workers/{chunk-FM5XPC2E.js → chunk-IYVDOB5V.js} +4 -4
  30. package/Build/Workers/{chunk-P7ISUYLW.js → chunk-JUGY5AZN.js} +4 -4
  31. package/Build/Workers/{chunk-JONWM4IO.js → chunk-KPYU6YZG.js} +1 -1
  32. package/Build/Workers/{chunk-JUOSYFXT.js → chunk-L7RDJ4V7.js} +1 -1
  33. package/Build/Workers/{chunk-MWGB6DLR.js → chunk-LDQWNMEC.js} +1 -1
  34. package/Build/Workers/{chunk-C6FTHSJA.js → chunk-MQJG522T.js} +6 -6
  35. package/Build/Workers/{chunk-WH4HDRGN.js → chunk-MT5M7RLZ.js} +2 -2
  36. package/Build/Workers/{chunk-4ZQN7M7E.js → chunk-N4AWE7TZ.js} +10 -10
  37. package/Build/Workers/{chunk-SDUH3N6G.js → chunk-NAYRNPEP.js} +4 -4
  38. package/Build/Workers/{chunk-7OPRTZBT.js → chunk-NNHU33JK.js} +7 -7
  39. package/Build/Workers/{chunk-CQCEPC6N.js → chunk-NQCAZU7S.js} +13 -13
  40. package/Build/Workers/{chunk-35J4D6PX.js → chunk-NUYLNQKV.js} +2 -2
  41. package/Build/Workers/{chunk-I45CATZK.js → chunk-OC6X22PG.js} +9 -9
  42. package/Build/Workers/{chunk-7MGTX4WP.js → chunk-OHBM4YG4.js} +12 -12
  43. package/Build/Workers/{chunk-DCR62BCO.js → chunk-OMXN7YF4.js} +12 -12
  44. package/Build/Workers/{chunk-XPNY2VY3.js → chunk-OQ3EAJNW.js} +2 -2
  45. package/Build/Workers/{chunk-4I7BCCNU.js → chunk-OQBPOKPZ.js} +6 -6
  46. package/Build/Workers/{chunk-2JNPWPLE.js → chunk-PQVNT5CJ.js} +6 -6
  47. package/Build/Workers/{chunk-K64RQCRK.js → chunk-QA24Q62E.js} +17 -17
  48. package/Build/Workers/{chunk-K6BXEBAF.js → chunk-QQX7S5QT.js} +17 -17
  49. package/Build/Workers/{chunk-2YVTOY5Z.js → chunk-QTOHIXGF.js} +10 -10
  50. package/Build/Workers/{chunk-4MCPC4TE.js → chunk-R7M4XNPP.js} +8 -8
  51. package/Build/Workers/{chunk-C35SJ4QP.js → chunk-SGKTBHFQ.js} +13 -13
  52. package/Build/Workers/{chunk-BKYJBTHW.js → chunk-SQTRWKO2.js} +5 -5
  53. package/Build/Workers/{chunk-I4D5IP46.js → chunk-T43FXHNC.js} +7 -7
  54. package/Build/Workers/{chunk-QO6Z5UJE.js → chunk-UEEGWJJP.js} +2 -2
  55. package/Build/Workers/{chunk-ZUWF63QU.js → chunk-WKXDCVBO.js} +4 -4
  56. package/Build/Workers/{chunk-N5MNKWED.js → chunk-Y5AJSEEN.js} +2 -2
  57. package/Build/Workers/{chunk-V26Y7ZQL.js → chunk-ZIW5FCIW.js} +37 -27
  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 +22 -22
  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 +22 -22
  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 +20 -12
  107. package/Build/Workers/transcodeKTX2.js +6 -6
  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/AttributeCompression.js +53 -6
  112. package/Source/Core/BoxGeometry.js +1 -1
  113. package/Source/Core/Cartesian2.js +689 -684
  114. package/Source/Core/Cartesian3.js +1044 -1043
  115. package/Source/Core/Cartesian4.js +816 -813
  116. package/Source/Core/CornerType.js +1 -1
  117. package/Source/Core/CorridorGeometry.js +1 -1
  118. package/Source/Core/FeatureDetection.js +1 -32
  119. package/Source/Core/Geometry.js +1 -1
  120. package/Source/Core/GoogleMaps.js +23 -2
  121. package/Source/Core/IntersectionTests.js +2 -2
  122. package/Source/Core/Ion.js +1 -1
  123. package/Source/Core/OpenCageGeocoderService.js +2 -3
  124. package/Source/Core/PinBuilder.js +1 -1
  125. package/Source/Core/PolygonGeometry.js +1 -1
  126. package/Source/Core/PolylineGeometry.js +1 -1
  127. package/Source/Core/PolylineVolumeGeometry.js +1 -1
  128. package/Source/Core/RectangleGeometry.js +1 -1
  129. package/Source/Core/ScreenSpaceEventHandler.js +4 -8
  130. package/Source/Core/TerrainMesh.js +11 -8
  131. package/Source/Core/TerrainPicker.js +24 -7
  132. package/Source/Core/VideoSynchronizer.js +1 -1
  133. package/Source/Core/WallGeometry.js +1 -1
  134. package/Source/Core/globalTypes.js +16 -0
  135. package/Source/Core/writeTextToCanvas.js +40 -86
  136. package/Source/DataSources/BillboardGraphics.js +1 -1
  137. package/Source/DataSources/BoxGraphics.js +1 -1
  138. package/Source/DataSources/CallbackPositionProperty.js +1 -1
  139. package/Source/DataSources/CorridorGraphics.js +1 -1
  140. package/Source/DataSources/CzmlDataSource.js +1 -1
  141. package/Source/DataSources/EllipseGraphics.js +1 -1
  142. package/Source/DataSources/EllipsoidGraphics.js +1 -1
  143. package/Source/DataSources/Entity.js +1 -1
  144. package/Source/DataSources/EntityCluster.js +2 -2
  145. package/Source/DataSources/GeoJsonDataSource.js +2 -2
  146. package/Source/DataSources/GpxDataSource.js +1 -1
  147. package/Source/DataSources/KmlDataSource.js +1 -1
  148. package/Source/DataSources/KmlTour.js +1 -1
  149. package/Source/DataSources/LabelGraphics.js +1 -1
  150. package/Source/DataSources/ModelGraphics.js +1 -1
  151. package/Source/DataSources/PlaneGraphics.js +1 -1
  152. package/Source/DataSources/PolygonGraphics.js +1 -1
  153. package/Source/DataSources/PolylineGraphics.js +1 -1
  154. package/Source/DataSources/PolylineVolumeGraphics.js +1 -1
  155. package/Source/DataSources/RectangleGraphics.js +1 -1
  156. package/Source/DataSources/WallGraphics.js +1 -1
  157. package/Source/DataSources/exportKml.js +1 -1
  158. package/Source/Renderer/Context.js +11 -10
  159. package/Source/Renderer/ContextLimits.js +66 -33
  160. package/Source/Renderer/ShaderDestination.js +54 -13
  161. package/Source/Renderer/ShaderSource.js +19 -18
  162. package/Source/Renderer/Texture.js +1 -1
  163. package/Source/Renderer/Texture3D.js +166 -7
  164. package/Source/Renderer/TextureAtlas.js +2 -2
  165. package/Source/Scene/Appearance.js +1 -1
  166. package/Source/Scene/ArcGisMapService.js +1 -1
  167. package/Source/Scene/Billboard.js +8 -5
  168. package/Source/Scene/BillboardCollection.js +65 -26
  169. package/Source/Scene/BillboardTexture.js +4 -1
  170. package/Source/Scene/BufferLoader.js +65 -74
  171. package/Source/Scene/Camera.js +13 -2
  172. package/Source/Scene/ClippingPlaneCollection.js +2 -2
  173. package/Source/Scene/CloudCollection.js +2 -2
  174. package/Source/Scene/CubeMapPanorama.js +351 -0
  175. package/Source/Scene/CumulusCloud.js +1 -1
  176. package/Source/Scene/DerivedCommand.js +8 -31
  177. package/Source/Scene/DracoLoader.js +79 -78
  178. package/Source/Scene/DynamicEnvironmentMapManager.js +41 -26
  179. package/Source/Scene/EquirectangularPanorama.js +264 -0
  180. package/Source/Scene/Fog.js +1 -1
  181. package/Source/Scene/FrameState.js +7 -0
  182. package/Source/Scene/GaussianSplatPrimitive.js +907 -168
  183. package/Source/Scene/Globe.js +3 -10
  184. package/Source/Scene/GlobeSurfaceShaderSet.js +36 -32
  185. package/Source/Scene/GltfBufferViewLoader.js +109 -118
  186. package/Source/Scene/GltfDracoLoader.js +167 -176
  187. package/Source/Scene/GltfImageLoader.js +91 -101
  188. package/Source/Scene/GltfIndexBufferLoader.js +228 -241
  189. package/Source/Scene/GltfJsonLoader.js +90 -99
  190. package/Source/Scene/GltfLoader.js +323 -324
  191. package/Source/Scene/GltfSpzLoader.js +127 -134
  192. package/Source/Scene/GltfStructuralMetadataLoader.js +181 -186
  193. package/Source/Scene/GltfTextureLoader.js +217 -231
  194. package/Source/Scene/GltfVertexBufferLoader.js +267 -276
  195. package/Source/Scene/GoogleStreetViewCubeMapPanoramaProvider.js +341 -0
  196. package/Source/Scene/ImageBasedLighting.js +2 -2
  197. package/Source/Scene/ImageryLayerCollection.js +2 -2
  198. package/Source/Scene/ImageryProvider.js +2 -2
  199. package/Source/Scene/Label.js +7 -5
  200. package/Source/Scene/LabelCollection.js +60 -2
  201. package/Source/Scene/Material.js +1 -1
  202. package/Source/Scene/MaterialAppearance.js +1 -1
  203. package/Source/Scene/Megatexture.js +174 -242
  204. package/Source/Scene/MetadataClassProperty.js +212 -7
  205. package/Source/Scene/MetadataComponentType.js +162 -127
  206. package/Source/Scene/MetadataSchemaLoader.js +60 -67
  207. package/Source/Scene/MetadataTable.js +14 -0
  208. package/Source/Scene/MetadataTableProperty.js +14 -0
  209. package/Source/Scene/Model/B3dmLoader.js +216 -224
  210. package/Source/Scene/Model/CustomShader.js +6 -1
  211. package/Source/Scene/Model/CustomShaderPipelineStage.js +122 -7
  212. package/Source/Scene/Model/GeoJsonLoader.js +53 -61
  213. package/Source/Scene/Model/GeometryPipelineStage.js +17 -3
  214. package/Source/Scene/Model/I3dmLoader.js +232 -240
  215. package/Source/Scene/Model/MaterialPipelineStage.js +17 -0
  216. package/Source/Scene/Model/MetadataPipelineStage.js +438 -22
  217. package/Source/Scene/Model/Model.js +1 -1
  218. package/Source/Scene/Model/PntsLoader.js +78 -89
  219. package/Source/Scene/ModelComponents.js +10 -0
  220. package/Source/Scene/Panorama.js +53 -0
  221. package/Source/Scene/PanoramaProvider.js +43 -0
  222. package/Source/Scene/ParticleSystem.js +2 -2
  223. package/Source/Scene/PointPrimitive.js +1 -1
  224. package/Source/Scene/PointPrimitiveCollection.js +14 -22
  225. package/Source/Scene/Polyline.js +0 -1
  226. package/Source/Scene/PolylineCollection.js +1 -4
  227. package/Source/Scene/PolylineColorAppearance.js +1 -6
  228. package/Source/Scene/PolylineMaterialAppearance.js +1 -6
  229. package/Source/Scene/PostProcessStageCollection.js +1 -1
  230. package/Source/Scene/PropertyTable.js +43 -0
  231. package/Source/Scene/PropertyTexture.js +1 -1
  232. package/Source/Scene/PropertyTextureProperty.js +0 -97
  233. package/Source/Scene/QuadtreePrimitive.js +6 -3
  234. package/Source/Scene/ResourceLoader.js +84 -92
  235. package/Source/Scene/Scene.js +12 -0
  236. package/Source/Scene/ShadowMap.js +1 -2
  237. package/Source/Scene/SkyBox.js +29 -164
  238. package/Source/Scene/StructuralMetadata.js +18 -3
  239. package/Source/Scene/Vector3DTileClampedPolylines.js +1 -5
  240. package/Source/Scene/Vector3DTilePolylines.js +1 -5
  241. package/Source/Scene/VoxelPrimitive.js +16 -33
  242. package/Source/Scene/VoxelRenderResources.js +1 -8
  243. package/Source/Scene/VoxelTraversal.js +16 -61
  244. package/Source/Scene/WebMapTileServiceImageryProvider.js +1 -1
  245. package/Source/Scene/createElevationBandMaterial.js +1 -1
  246. package/Source/Scene/parseStructuralMetadata.js +244 -0
  247. package/Source/Scene/processVoxelProperties.js +1 -1
  248. package/Source/Shaders/BillboardCollectionFS.glsl +66 -40
  249. package/Source/Shaders/BillboardCollectionFS.js +67 -40
  250. package/Source/Shaders/BillboardCollectionVS.glsl +22 -31
  251. package/Source/Shaders/BillboardCollectionVS.js +22 -31
  252. package/Source/Shaders/Builtin/CzmBuiltins.js +4 -0
  253. package/Source/Shaders/Builtin/Functions/columbusViewMorph.glsl +8 -1
  254. package/Source/Shaders/Builtin/Functions/columbusViewMorph.js +8 -1
  255. package/Source/Shaders/Builtin/Functions/decodeRGB8.glsl +22 -0
  256. package/Source/Shaders/Builtin/Functions/decodeRGB8.js +24 -0
  257. package/Source/Shaders/Builtin/Functions/unpackTexture.glsl +35 -0
  258. package/Source/Shaders/Builtin/Functions/unpackTexture.js +37 -0
  259. package/Source/Shaders/CubeMapPanoramaVS.glsl +11 -0
  260. package/Source/Shaders/CubeMapPanoramaVS.js +13 -0
  261. package/Source/Shaders/Model/MetadataStageFS.glsl +2 -1
  262. package/Source/Shaders/Model/MetadataStageFS.js +2 -1
  263. package/Source/Shaders/Model/MetadataStageVS.glsl +2 -1
  264. package/Source/Shaders/Model/MetadataStageVS.js +2 -1
  265. package/Source/Shaders/Model/ModelFS.glsl +9 -1
  266. package/Source/Shaders/Model/ModelFS.js +9 -1
  267. package/Source/Shaders/Model/ModelVS.glsl +4 -2
  268. package/Source/Shaders/Model/ModelVS.js +4 -2
  269. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +8 -39
  270. package/Source/Shaders/PointPrimitiveCollectionVS.js +8 -39
  271. package/Source/Shaders/Voxels/IntersectionUtils.glsl +1 -1
  272. package/Source/Shaders/Voxels/IntersectionUtils.js +1 -1
  273. package/Source/Shaders/Voxels/Megatexture.glsl +15 -83
  274. package/Source/Shaders/Voxels/Megatexture.js +15 -83
  275. package/Source/Shaders/Voxels/Octree.glsl +6 -9
  276. package/Source/Shaders/Voxels/Octree.js +6 -9
  277. package/Source/Widget/CesiumWidget.js +1 -1
  278. package/Source/Workers/incrementallyBuildTerrainPicker.js +16 -2
  279. package/index.d.ts +582 -193
  280. package/index.js +91 -83
  281. package/package.json +2 -1
  282. package/Build/Workers/chunk-ZGWX2R5I.js +0 -1443
@@ -1,1129 +1,1182 @@
1
+ // @ts-check
2
+
1
3
  import Check from "./Check.js";
2
4
  import defined from "./defined.js";
3
5
  import DeveloperError from "./DeveloperError.js";
4
6
  import CesiumMath from "./Math.js";
5
7
 
8
+ /** @import {TypedArray} from "./globalTypes.js"; */
9
+ /** @import Cartesian4 from "./Cartesian4.js"; */
10
+ /** @import Ellipsoid from "./Ellipsoid.js"; */
11
+ /** @import Spherical from "./Spherical.js"; */
12
+
6
13
  /**
7
14
  * A 3D Cartesian point.
8
- * @alias Cartesian3
9
- * @constructor
10
- *
11
- * @param {number} [x=0.0] The X component.
12
- * @param {number} [y=0.0] The Y component.
13
- * @param {number} [z=0.0] The Z component.
14
15
  *
15
16
  * @see Cartesian2
16
17
  * @see Cartesian4
17
18
  * @see Packable
18
19
  */
19
- function Cartesian3(x, y, z) {
20
+ class Cartesian3 {
20
21
  /**
21
- * The X component.
22
- * @type {number}
23
- * @default 0.0
22
+ * @param {number} [x=0.0] The X component.
23
+ * @param {number} [y=0.0] The Y component.
24
+ * @param {number} [z=0.0] The Z component.
24
25
  */
25
- this.x = x ?? 0.0;
26
+ constructor(x, y, z) {
27
+ /**
28
+ * The X component.
29
+ * @type {number}
30
+ * @default 0.0
31
+ */
32
+ this.x = x ?? 0.0;
33
+
34
+ /**
35
+ * The Y component.
36
+ * @type {number}
37
+ * @default 0.0
38
+ */
39
+ this.y = y ?? 0.0;
40
+
41
+ /**
42
+ * The Z component.
43
+ * @type {number}
44
+ * @default 0.0
45
+ */
46
+ this.z = z ?? 0.0;
47
+ }
26
48
 
27
49
  /**
28
- * The Y component.
29
- * @type {number}
30
- * @default 0.0
50
+ * Converts the provided Spherical into Cartesian3 coordinates.
51
+ *
52
+ * @param {Spherical} spherical The Spherical to be converted to Cartesian3.
53
+ * @param {Cartesian3} [result] The object onto which to store the result.
54
+ * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
31
55
  */
32
- this.y = y ?? 0.0;
56
+ static fromSpherical(spherical, result) {
57
+ //>>includeStart('debug', pragmas.debug);
58
+ Check.typeOf.object("spherical", spherical);
59
+ //>>includeEnd('debug');
60
+
61
+ if (!defined(result)) {
62
+ result = new Cartesian3();
63
+ }
64
+
65
+ const clock = spherical.clock;
66
+ const cone = spherical.cone;
67
+ const magnitude = spherical.magnitude ?? 1.0;
68
+ const radial = magnitude * Math.sin(cone);
69
+ result.x = radial * Math.cos(clock);
70
+ result.y = radial * Math.sin(clock);
71
+ result.z = magnitude * Math.cos(cone);
72
+ return result;
73
+ }
33
74
 
34
75
  /**
35
- * The Z component.
36
- * @type {number}
37
- * @default 0.0
76
+ * Creates a Cartesian3 instance from x, y and z coordinates.
77
+ *
78
+ * @param {number} x The x coordinate.
79
+ * @param {number} y The y coordinate.
80
+ * @param {number} z The z coordinate.
81
+ * @param {Cartesian3} [result] The object onto which to store the result.
82
+ * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
38
83
  */
39
- this.z = z ?? 0.0;
40
- }
84
+ static fromElements(x, y, z, result) {
85
+ if (!defined(result)) {
86
+ return new Cartesian3(x, y, z);
87
+ }
41
88
 
42
- /**
43
- * Converts the provided Spherical into Cartesian3 coordinates.
44
- *
45
- * @param {Spherical} spherical The Spherical to be converted to Cartesian3.
46
- * @param {Cartesian3} [result] The object onto which to store the result.
47
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
48
- */
49
- Cartesian3.fromSpherical = function (spherical, result) {
50
- //>>includeStart('debug', pragmas.debug);
51
- Check.typeOf.object("spherical", spherical);
52
- //>>includeEnd('debug');
89
+ result.x = x;
90
+ result.y = y;
91
+ result.z = z;
92
+ return result;
93
+ }
53
94
 
54
- if (!defined(result)) {
55
- result = new Cartesian3();
95
+ /**
96
+ * Duplicates a Cartesian3 instance.
97
+ *
98
+ * @param {Cartesian3} cartesian The Cartesian to duplicate.
99
+ * @param {Cartesian3} [result] The object onto which to store the result.
100
+ * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)
101
+ */
102
+ static clone(cartesian, result) {
103
+ if (!defined(cartesian)) {
104
+ return undefined;
105
+ }
106
+ if (!defined(result)) {
107
+ return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);
108
+ }
109
+
110
+ result.x = cartesian.x;
111
+ result.y = cartesian.y;
112
+ result.z = cartesian.z;
113
+ return result;
56
114
  }
57
115
 
58
- const clock = spherical.clock;
59
- const cone = spherical.cone;
60
- const magnitude = spherical.magnitude ?? 1.0;
61
- const radial = magnitude * Math.sin(cone);
62
- result.x = radial * Math.cos(clock);
63
- result.y = radial * Math.sin(clock);
64
- result.z = magnitude * Math.cos(cone);
65
- return result;
66
- };
116
+ /**
117
+ * Stores the provided instance into the provided array.
118
+ *
119
+ * @param {Cartesian3} value The value to pack.
120
+ * @param {number[]|TypedArray} array The array to pack into.
121
+ * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
122
+ *
123
+ * @returns {number[]|TypedArray} The array that was packed into
124
+ */
125
+ static pack(value, array, startingIndex) {
126
+ //>>includeStart('debug', pragmas.debug);
127
+ Check.typeOf.object("value", value);
128
+ Check.defined("array", array);
129
+ //>>includeEnd('debug');
67
130
 
68
- /**
69
- * Creates a Cartesian3 instance from x, y and z coordinates.
70
- *
71
- * @param {number} x The x coordinate.
72
- * @param {number} y The y coordinate.
73
- * @param {number} z The z coordinate.
74
- * @param {Cartesian3} [result] The object onto which to store the result.
75
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
76
- */
77
- Cartesian3.fromElements = function (x, y, z, result) {
78
- if (!defined(result)) {
79
- return new Cartesian3(x, y, z);
131
+ startingIndex = startingIndex ?? 0;
132
+
133
+ array[startingIndex++] = value.x;
134
+ array[startingIndex++] = value.y;
135
+ array[startingIndex] = value.z;
136
+
137
+ return array;
80
138
  }
81
139
 
82
- result.x = x;
83
- result.y = y;
84
- result.z = z;
85
- return result;
86
- };
140
+ /**
141
+ * Retrieves an instance from a packed array.
142
+ *
143
+ * @param {number[]|TypedArray} array The packed array.
144
+ * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
145
+ * @param {Cartesian3} [result] The object into which to store the result.
146
+ * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
147
+ */
148
+ static unpack(array, startingIndex, result) {
149
+ //>>includeStart('debug', pragmas.debug);
150
+ Check.defined("array", array);
151
+ //>>includeEnd('debug');
152
+
153
+ startingIndex = startingIndex ?? 0;
87
154
 
88
- /**
89
- * Duplicates a Cartesian3 instance.
90
- *
91
- * @param {Cartesian3} cartesian The Cartesian to duplicate.
92
- * @param {Cartesian3} [result] The object onto which to store the result.
93
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided. (Returns undefined if cartesian is undefined)
94
- */
95
- Cartesian3.clone = function (cartesian, result) {
96
- if (!defined(cartesian)) {
97
- return undefined;
155
+ if (!defined(result)) {
156
+ result = new Cartesian3();
157
+ }
158
+ result.x = array[startingIndex++];
159
+ result.y = array[startingIndex++];
160
+ result.z = array[startingIndex];
161
+ return result;
98
162
  }
99
- if (!defined(result)) {
100
- return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);
163
+
164
+ /**
165
+ * Flattens an array of Cartesian3s into an array of components.
166
+ *
167
+ * @param {Cartesian3[]} array The array of cartesians to pack.
168
+ * @param {number[]|TypedArray} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 3 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 3) elements.
169
+ * @returns {number[]|TypedArray} The packed array.
170
+ */
171
+ static packArray(array, result) {
172
+ //>>includeStart('debug', pragmas.debug);
173
+ Check.defined("array", array);
174
+ //>>includeEnd('debug');
175
+
176
+ const length = array.length;
177
+ const resultLength = length * 3;
178
+ if (!defined(result)) {
179
+ result = new Array(resultLength);
180
+ } else if (!Array.isArray(result) && result.length !== resultLength) {
181
+ //>>includeStart('debug', pragmas.debug);
182
+ throw new DeveloperError(
183
+ "If result is a typed array, it must have exactly array.length * 3 elements",
184
+ );
185
+ //>>includeEnd('debug');
186
+ } else if (result.length !== resultLength) {
187
+ /** @type {number[]} */ (result).length = resultLength;
188
+ }
189
+
190
+ for (let i = 0; i < length; ++i) {
191
+ Cartesian3.pack(array[i], result, i * 3);
192
+ }
193
+ return result;
101
194
  }
102
195
 
103
- result.x = cartesian.x;
104
- result.y = cartesian.y;
105
- result.z = cartesian.z;
106
- return result;
107
- };
196
+ /**
197
+ * Unpacks an array of cartesian components into an array of Cartesian3s.
198
+ *
199
+ * @param {number[]|TypedArray} array The array of components to unpack.
200
+ * @param {Cartesian3[]} [result] The array onto which to store the result.
201
+ * @returns {Cartesian3[]} The unpacked array.
202
+ */
203
+ static unpackArray(array, result) {
204
+ //>>includeStart('debug', pragmas.debug);
205
+ Check.defined("array", array);
206
+ Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 3);
207
+ if (array.length % 3 !== 0) {
208
+ throw new DeveloperError("array length must be a multiple of 3.");
209
+ }
210
+ //>>includeEnd('debug');
108
211
 
109
- /**
110
- * Creates a Cartesian3 instance from an existing Cartesian4. This simply takes the
111
- * x, y, and z properties of the Cartesian4 and drops w.
112
- * @function
113
- *
114
- * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian3 instance from.
115
- * @param {Cartesian3} [result] The object onto which to store the result.
116
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
117
- */
118
- Cartesian3.fromCartesian4 = Cartesian3.clone;
212
+ const length = array.length;
213
+ if (!defined(result)) {
214
+ result = new Array(length / 3);
215
+ } else {
216
+ result.length = length / 3;
217
+ }
119
218
 
120
- /**
121
- * The number of elements used to pack the object into an array.
122
- * @type {number}
123
- */
124
- Cartesian3.packedLength = 3;
219
+ for (let i = 0; i < length; i += 3) {
220
+ const index = i / 3;
221
+ result[index] = Cartesian3.unpack(array, i, result[index]);
222
+ }
223
+ return result;
224
+ }
125
225
 
126
- /**
127
- * Stores the provided instance into the provided array.
128
- *
129
- * @param {Cartesian3} value The value to pack.
130
- * @param {number[]} array The array to pack into.
131
- * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
132
- *
133
- * @returns {number[]} The array that was packed into
134
- */
135
- Cartesian3.pack = function (value, array, startingIndex) {
136
- //>>includeStart('debug', pragmas.debug);
137
- Check.typeOf.object("value", value);
138
- Check.defined("array", array);
139
- //>>includeEnd('debug');
226
+ /**
227
+ * Computes the value of the maximum component for the supplied Cartesian.
228
+ *
229
+ * @param {Cartesian3} cartesian The cartesian to use.
230
+ * @returns {number} The value of the maximum component.
231
+ */
232
+ static maximumComponent(cartesian) {
233
+ //>>includeStart('debug', pragmas.debug);
234
+ Check.typeOf.object("cartesian", cartesian);
235
+ //>>includeEnd('debug');
140
236
 
141
- startingIndex = startingIndex ?? 0;
237
+ return Math.max(cartesian.x, cartesian.y, cartesian.z);
238
+ }
142
239
 
143
- array[startingIndex++] = value.x;
144
- array[startingIndex++] = value.y;
145
- array[startingIndex] = value.z;
240
+ /**
241
+ * Computes the value of the minimum component for the supplied Cartesian.
242
+ *
243
+ * @param {Cartesian3} cartesian The cartesian to use.
244
+ * @returns {number} The value of the minimum component.
245
+ */
246
+ static minimumComponent(cartesian) {
247
+ //>>includeStart('debug', pragmas.debug);
248
+ Check.typeOf.object("cartesian", cartesian);
249
+ //>>includeEnd('debug');
146
250
 
147
- return array;
148
- };
251
+ return Math.min(cartesian.x, cartesian.y, cartesian.z);
252
+ }
149
253
 
150
- /**
151
- * Retrieves an instance from a packed array.
152
- *
153
- * @param {number[]} array The packed array.
154
- * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
155
- * @param {Cartesian3} [result] The object into which to store the result.
156
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
157
- */
158
- Cartesian3.unpack = function (array, startingIndex, result) {
159
- //>>includeStart('debug', pragmas.debug);
160
- Check.defined("array", array);
161
- //>>includeEnd('debug');
254
+ /**
255
+ * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
256
+ *
257
+ * @param {Cartesian3} first A cartesian to compare.
258
+ * @param {Cartesian3} second A cartesian to compare.
259
+ * @param {Cartesian3} result The object into which to store the result.
260
+ * @returns {Cartesian3} A cartesian with the minimum components.
261
+ */
262
+ static minimumByComponent(first, second, result) {
263
+ //>>includeStart('debug', pragmas.debug);
264
+ Check.typeOf.object("first", first);
265
+ Check.typeOf.object("second", second);
266
+ Check.typeOf.object("result", result);
267
+ //>>includeEnd('debug');
162
268
 
163
- startingIndex = startingIndex ?? 0;
269
+ result.x = Math.min(first.x, second.x);
270
+ result.y = Math.min(first.y, second.y);
271
+ result.z = Math.min(first.z, second.z);
164
272
 
165
- if (!defined(result)) {
166
- result = new Cartesian3();
273
+ return result;
167
274
  }
168
- result.x = array[startingIndex++];
169
- result.y = array[startingIndex++];
170
- result.z = array[startingIndex];
171
- return result;
172
- };
173
275
 
174
- /**
175
- * Flattens an array of Cartesian3s into an array of components.
176
- *
177
- * @param {Cartesian3[]} array The array of cartesians to pack.
178
- * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 3 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 3) elements.
179
- * @returns {number[]} The packed array.
180
- */
181
- Cartesian3.packArray = function (array, result) {
182
- //>>includeStart('debug', pragmas.debug);
183
- Check.defined("array", array);
184
- //>>includeEnd('debug');
185
-
186
- const length = array.length;
187
- const resultLength = length * 3;
188
- if (!defined(result)) {
189
- result = new Array(resultLength);
190
- } else if (!Array.isArray(result) && result.length !== resultLength) {
276
+ /**
277
+ * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
278
+ *
279
+ * @param {Cartesian3} first A cartesian to compare.
280
+ * @param {Cartesian3} second A cartesian to compare.
281
+ * @param {Cartesian3} result The object into which to store the result.
282
+ * @returns {Cartesian3} A cartesian with the maximum components.
283
+ */
284
+ static maximumByComponent(first, second, result) {
285
+ //>>includeStart('debug', pragmas.debug);
286
+ Check.typeOf.object("first", first);
287
+ Check.typeOf.object("second", second);
288
+ Check.typeOf.object("result", result);
289
+ //>>includeEnd('debug');
290
+
291
+ result.x = Math.max(first.x, second.x);
292
+ result.y = Math.max(first.y, second.y);
293
+ result.z = Math.max(first.z, second.z);
294
+ return result;
295
+ }
296
+
297
+ /**
298
+ * Constrain a value to lie between two values.
299
+ *
300
+ * @param {Cartesian3} value The value to clamp.
301
+ * @param {Cartesian3} min The minimum bound.
302
+ * @param {Cartesian3} max The maximum bound.
303
+ * @param {Cartesian3} result The object into which to store the result.
304
+ * @returns {Cartesian3} The clamped value such that min <= value <= max.
305
+ */
306
+ static clamp(value, min, max, result) {
307
+ //>>includeStart('debug', pragmas.debug);
308
+ Check.typeOf.object("value", value);
309
+ Check.typeOf.object("min", min);
310
+ Check.typeOf.object("max", max);
311
+ Check.typeOf.object("result", result);
312
+ //>>includeEnd('debug');
313
+
314
+ const x = CesiumMath.clamp(value.x, min.x, max.x);
315
+ const y = CesiumMath.clamp(value.y, min.y, max.y);
316
+ const z = CesiumMath.clamp(value.z, min.z, max.z);
317
+
318
+ result.x = x;
319
+ result.y = y;
320
+ result.z = z;
321
+
322
+ return result;
323
+ }
324
+
325
+ /**
326
+ * Computes the provided Cartesian's squared magnitude.
327
+ *
328
+ * @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.
329
+ * @returns {number} The squared magnitude.
330
+ */
331
+ static magnitudeSquared(cartesian) {
191
332
  //>>includeStart('debug', pragmas.debug);
192
- throw new DeveloperError(
193
- "If result is a typed array, it must have exactly array.length * 3 elements",
333
+ Check.typeOf.object("cartesian", cartesian);
334
+ //>>includeEnd('debug');
335
+
336
+ return (
337
+ cartesian.x * cartesian.x +
338
+ cartesian.y * cartesian.y +
339
+ cartesian.z * cartesian.z
194
340
  );
341
+ }
342
+
343
+ /**
344
+ * Computes the Cartesian's magnitude (length).
345
+ *
346
+ * @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.
347
+ * @returns {number} The magnitude.
348
+ */
349
+ static magnitude(cartesian) {
350
+ return Math.sqrt(Cartesian3.magnitudeSquared(cartesian));
351
+ }
352
+
353
+ /**
354
+ * Computes the distance between two points.
355
+ *
356
+ * @param {Cartesian3} left The first point to compute the distance from.
357
+ * @param {Cartesian3} right The second point to compute the distance to.
358
+ * @returns {number} The distance between two points.
359
+ *
360
+ * @example
361
+ * // Returns 1.0
362
+ * const d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));
363
+ */
364
+ static distance(left, right) {
365
+ //>>includeStart('debug', pragmas.debug);
366
+ Check.typeOf.object("left", left);
367
+ Check.typeOf.object("right", right);
195
368
  //>>includeEnd('debug');
196
- } else if (result.length !== resultLength) {
197
- result.length = resultLength;
369
+
370
+ Cartesian3.subtract(left, right, distanceScratch);
371
+ return Cartesian3.magnitude(distanceScratch);
198
372
  }
199
373
 
200
- for (let i = 0; i < length; ++i) {
201
- Cartesian3.pack(array[i], result, i * 3);
374
+ /**
375
+ * Computes the squared distance between two points. Comparing squared distances
376
+ * using this function is more efficient than comparing distances using {@link Cartesian3#distance}.
377
+ *
378
+ * @param {Cartesian3} left The first point to compute the distance from.
379
+ * @param {Cartesian3} right The second point to compute the distance to.
380
+ * @returns {number} The distance between two points.
381
+ *
382
+ * @example
383
+ * // Returns 4.0, not 2.0
384
+ * const d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));
385
+ */
386
+ static distanceSquared(left, right) {
387
+ //>>includeStart('debug', pragmas.debug);
388
+ Check.typeOf.object("left", left);
389
+ Check.typeOf.object("right", right);
390
+ //>>includeEnd('debug');
391
+
392
+ Cartesian3.subtract(left, right, distanceScratch);
393
+ return Cartesian3.magnitudeSquared(distanceScratch);
202
394
  }
203
- return result;
204
- };
205
395
 
206
- /**
207
- * Unpacks an array of cartesian components into an array of Cartesian3s.
208
- *
209
- * @param {number[]} array The array of components to unpack.
210
- * @param {Cartesian3[]} [result] The array onto which to store the result.
211
- * @returns {Cartesian3[]} The unpacked array.
212
- */
213
- Cartesian3.unpackArray = function (array, result) {
214
- //>>includeStart('debug', pragmas.debug);
215
- Check.defined("array", array);
216
- Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 3);
217
- if (array.length % 3 !== 0) {
218
- throw new DeveloperError("array length must be a multiple of 3.");
396
+ /**
397
+ * Computes the normalized form of the supplied Cartesian.
398
+ *
399
+ * @param {Cartesian3} cartesian The Cartesian to be normalized.
400
+ * @param {Cartesian3} result The object onto which to store the result.
401
+ * @returns {Cartesian3} The modified result parameter.
402
+ */
403
+ static normalize(cartesian, result) {
404
+ //>>includeStart('debug', pragmas.debug);
405
+ Check.typeOf.object("cartesian", cartesian);
406
+ Check.typeOf.object("result", result);
407
+ //>>includeEnd('debug');
408
+
409
+ const magnitude = Cartesian3.magnitude(cartesian);
410
+
411
+ result.x = cartesian.x / magnitude;
412
+ result.y = cartesian.y / magnitude;
413
+ result.z = cartesian.z / magnitude;
414
+
415
+ //>>includeStart('debug', pragmas.debug);
416
+ if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
417
+ throw new DeveloperError("normalized result is not a number");
418
+ }
419
+ //>>includeEnd('debug');
420
+
421
+ return result;
219
422
  }
220
- //>>includeEnd('debug');
221
423
 
222
- const length = array.length;
223
- if (!defined(result)) {
224
- result = new Array(length / 3);
225
- } else {
226
- result.length = length / 3;
424
+ /**
425
+ * Computes the dot (scalar) product of two Cartesians.
426
+ *
427
+ * @param {Cartesian3} left The first Cartesian.
428
+ * @param {Cartesian3} right The second Cartesian.
429
+ * @returns {number} The dot product.
430
+ */
431
+ static dot(left, right) {
432
+ //>>includeStart('debug', pragmas.debug);
433
+ Check.typeOf.object("left", left);
434
+ Check.typeOf.object("right", right);
435
+ //>>includeEnd('debug');
436
+
437
+ return left.x * right.x + left.y * right.y + left.z * right.z;
227
438
  }
228
439
 
229
- for (let i = 0; i < length; i += 3) {
230
- const index = i / 3;
231
- result[index] = Cartesian3.unpack(array, i, result[index]);
440
+ /**
441
+ * Computes the componentwise product of two Cartesians.
442
+ *
443
+ * @param {Cartesian3} left The first Cartesian.
444
+ * @param {Cartesian3} right The second Cartesian.
445
+ * @param {Cartesian3} result The object onto which to store the result.
446
+ * @returns {Cartesian3} The modified result parameter.
447
+ */
448
+ static multiplyComponents(left, right, result) {
449
+ //>>includeStart('debug', pragmas.debug);
450
+ Check.typeOf.object("left", left);
451
+ Check.typeOf.object("right", right);
452
+ Check.typeOf.object("result", result);
453
+ //>>includeEnd('debug');
454
+
455
+ result.x = left.x * right.x;
456
+ result.y = left.y * right.y;
457
+ result.z = left.z * right.z;
458
+ return result;
232
459
  }
233
- return result;
234
- };
235
460
 
236
- /**
237
- * Creates a Cartesian3 from three consecutive elements in an array.
238
- * @function
239
- *
240
- * @param {number[]} array The array whose three consecutive elements correspond to the x, y, and z components, respectively.
241
- * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
242
- * @param {Cartesian3} [result] The object onto which to store the result.
243
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
244
- *
245
- * @example
246
- * // Create a Cartesian3 with (1.0, 2.0, 3.0)
247
- * const v = [1.0, 2.0, 3.0];
248
- * const p = Cesium.Cartesian3.fromArray(v);
249
- *
250
- * // Create a Cartesian3 with (1.0, 2.0, 3.0) using an offset into an array
251
- * const v2 = [0.0, 0.0, 1.0, 2.0, 3.0];
252
- * const p2 = Cesium.Cartesian3.fromArray(v2, 2);
253
- */
254
- Cartesian3.fromArray = Cartesian3.unpack;
461
+ /**
462
+ * Computes the componentwise quotient of two Cartesians.
463
+ *
464
+ * @param {Cartesian3} left The first Cartesian.
465
+ * @param {Cartesian3} right The second Cartesian.
466
+ * @param {Cartesian3} result The object onto which to store the result.
467
+ * @returns {Cartesian3} The modified result parameter.
468
+ */
469
+ static divideComponents(left, right, result) {
470
+ //>>includeStart('debug', pragmas.debug);
471
+ Check.typeOf.object("left", left);
472
+ Check.typeOf.object("right", right);
473
+ Check.typeOf.object("result", result);
474
+ //>>includeEnd('debug');
255
475
 
256
- /**
257
- * Computes the value of the maximum component for the supplied Cartesian.
258
- *
259
- * @param {Cartesian3} cartesian The cartesian to use.
260
- * @returns {number} The value of the maximum component.
261
- */
262
- Cartesian3.maximumComponent = function (cartesian) {
263
- //>>includeStart('debug', pragmas.debug);
264
- Check.typeOf.object("cartesian", cartesian);
265
- //>>includeEnd('debug');
476
+ result.x = left.x / right.x;
477
+ result.y = left.y / right.y;
478
+ result.z = left.z / right.z;
479
+ return result;
480
+ }
266
481
 
267
- return Math.max(cartesian.x, cartesian.y, cartesian.z);
268
- };
482
+ /**
483
+ * Computes the componentwise sum of two Cartesians.
484
+ *
485
+ * @param {Cartesian3} left The first Cartesian.
486
+ * @param {Cartesian3} right The second Cartesian.
487
+ * @param {Cartesian3} result The object onto which to store the result.
488
+ * @returns {Cartesian3} The modified result parameter.
489
+ */
490
+ static add(left, right, result) {
491
+ //>>includeStart('debug', pragmas.debug);
492
+ Check.typeOf.object("left", left);
493
+ Check.typeOf.object("right", right);
494
+ Check.typeOf.object("result", result);
495
+ //>>includeEnd('debug');
269
496
 
270
- /**
271
- * Computes the value of the minimum component for the supplied Cartesian.
272
- *
273
- * @param {Cartesian3} cartesian The cartesian to use.
274
- * @returns {number} The value of the minimum component.
275
- */
276
- Cartesian3.minimumComponent = function (cartesian) {
277
- //>>includeStart('debug', pragmas.debug);
278
- Check.typeOf.object("cartesian", cartesian);
279
- //>>includeEnd('debug');
497
+ result.x = left.x + right.x;
498
+ result.y = left.y + right.y;
499
+ result.z = left.z + right.z;
500
+ return result;
501
+ }
280
502
 
281
- return Math.min(cartesian.x, cartesian.y, cartesian.z);
282
- };
503
+ /**
504
+ * Computes the componentwise difference of two Cartesians.
505
+ *
506
+ * @param {Cartesian3} left The first Cartesian.
507
+ * @param {Cartesian3} right The second Cartesian.
508
+ * @param {Cartesian3} result The object onto which to store the result.
509
+ * @returns {Cartesian3} The modified result parameter.
510
+ */
511
+ static subtract(left, right, result) {
512
+ //>>includeStart('debug', pragmas.debug);
513
+ Check.typeOf.object("left", left);
514
+ Check.typeOf.object("right", right);
515
+ Check.typeOf.object("result", result);
516
+ //>>includeEnd('debug');
283
517
 
284
- /**
285
- * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
286
- *
287
- * @param {Cartesian3} first A cartesian to compare.
288
- * @param {Cartesian3} second A cartesian to compare.
289
- * @param {Cartesian3} result The object into which to store the result.
290
- * @returns {Cartesian3} A cartesian with the minimum components.
291
- */
292
- Cartesian3.minimumByComponent = function (first, second, result) {
293
- //>>includeStart('debug', pragmas.debug);
294
- Check.typeOf.object("first", first);
295
- Check.typeOf.object("second", second);
296
- Check.typeOf.object("result", result);
297
- //>>includeEnd('debug');
518
+ result.x = left.x - right.x;
519
+ result.y = left.y - right.y;
520
+ result.z = left.z - right.z;
521
+ return result;
522
+ }
298
523
 
299
- result.x = Math.min(first.x, second.x);
300
- result.y = Math.min(first.y, second.y);
301
- result.z = Math.min(first.z, second.z);
524
+ /**
525
+ * Multiplies the provided Cartesian componentwise by the provided scalar.
526
+ *
527
+ * @param {Cartesian3} cartesian The Cartesian to be scaled.
528
+ * @param {number} scalar The scalar to multiply with.
529
+ * @param {Cartesian3} result The object onto which to store the result.
530
+ * @returns {Cartesian3} The modified result parameter.
531
+ */
532
+ static multiplyByScalar(cartesian, scalar, result) {
533
+ //>>includeStart('debug', pragmas.debug);
534
+ Check.typeOf.object("cartesian", cartesian);
535
+ Check.typeOf.number("scalar", scalar);
536
+ Check.typeOf.object("result", result);
537
+ //>>includeEnd('debug');
302
538
 
303
- return result;
304
- };
539
+ result.x = cartesian.x * scalar;
540
+ result.y = cartesian.y * scalar;
541
+ result.z = cartesian.z * scalar;
542
+ return result;
543
+ }
305
544
 
306
- /**
307
- * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
308
- *
309
- * @param {Cartesian3} first A cartesian to compare.
310
- * @param {Cartesian3} second A cartesian to compare.
311
- * @param {Cartesian3} result The object into which to store the result.
312
- * @returns {Cartesian3} A cartesian with the maximum components.
313
- */
314
- Cartesian3.maximumByComponent = function (first, second, result) {
315
- //>>includeStart('debug', pragmas.debug);
316
- Check.typeOf.object("first", first);
317
- Check.typeOf.object("second", second);
318
- Check.typeOf.object("result", result);
319
- //>>includeEnd('debug');
320
-
321
- result.x = Math.max(first.x, second.x);
322
- result.y = Math.max(first.y, second.y);
323
- result.z = Math.max(first.z, second.z);
324
- return result;
325
- };
545
+ /**
546
+ * Divides the provided Cartesian componentwise by the provided scalar.
547
+ *
548
+ * @param {Cartesian3} cartesian The Cartesian to be divided.
549
+ * @param {number} scalar The scalar to divide by.
550
+ * @param {Cartesian3} result The object onto which to store the result.
551
+ * @returns {Cartesian3} The modified result parameter.
552
+ */
553
+ static divideByScalar(cartesian, scalar, result) {
554
+ //>>includeStart('debug', pragmas.debug);
555
+ Check.typeOf.object("cartesian", cartesian);
556
+ Check.typeOf.number("scalar", scalar);
557
+ Check.typeOf.object("result", result);
558
+ //>>includeEnd('debug');
326
559
 
327
- /**
328
- * Constrain a value to lie between two values.
329
- *
330
- * @param {Cartesian3} cartesian The value to clamp.
331
- * @param {Cartesian3} min The minimum bound.
332
- * @param {Cartesian3} max The maximum bound.
333
- * @param {Cartesian3} result The object into which to store the result.
334
- * @returns {Cartesian3} The clamped value such that min <= value <= max.
335
- */
336
- Cartesian3.clamp = function (value, min, max, result) {
337
- //>>includeStart('debug', pragmas.debug);
338
- Check.typeOf.object("value", value);
339
- Check.typeOf.object("min", min);
340
- Check.typeOf.object("max", max);
341
- Check.typeOf.object("result", result);
342
- //>>includeEnd('debug');
560
+ result.x = cartesian.x / scalar;
561
+ result.y = cartesian.y / scalar;
562
+ result.z = cartesian.z / scalar;
563
+ return result;
564
+ }
343
565
 
344
- const x = CesiumMath.clamp(value.x, min.x, max.x);
345
- const y = CesiumMath.clamp(value.y, min.y, max.y);
346
- const z = CesiumMath.clamp(value.z, min.z, max.z);
566
+ /**
567
+ * Negates the provided Cartesian.
568
+ *
569
+ * @param {Cartesian3} cartesian The Cartesian to be negated.
570
+ * @param {Cartesian3} result The object onto which to store the result.
571
+ * @returns {Cartesian3} The modified result parameter.
572
+ */
573
+ static negate(cartesian, result) {
574
+ //>>includeStart('debug', pragmas.debug);
575
+ Check.typeOf.object("cartesian", cartesian);
576
+ Check.typeOf.object("result", result);
577
+ //>>includeEnd('debug');
347
578
 
348
- result.x = x;
349
- result.y = y;
350
- result.z = z;
579
+ result.x = -cartesian.x;
580
+ result.y = -cartesian.y;
581
+ result.z = -cartesian.z;
582
+ return result;
583
+ }
351
584
 
352
- return result;
353
- };
585
+ /**
586
+ * Computes the absolute value of the provided Cartesian.
587
+ *
588
+ * @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.
589
+ * @param {Cartesian3} result The object onto which to store the result.
590
+ * @returns {Cartesian3} The modified result parameter.
591
+ */
592
+ static abs(cartesian, result) {
593
+ //>>includeStart('debug', pragmas.debug);
594
+ Check.typeOf.object("cartesian", cartesian);
595
+ Check.typeOf.object("result", result);
596
+ //>>includeEnd('debug');
354
597
 
355
- /**
356
- * Computes the provided Cartesian's squared magnitude.
357
- *
358
- * @param {Cartesian3} cartesian The Cartesian instance whose squared magnitude is to be computed.
359
- * @returns {number} The squared magnitude.
360
- */
361
- Cartesian3.magnitudeSquared = function (cartesian) {
362
- //>>includeStart('debug', pragmas.debug);
363
- Check.typeOf.object("cartesian", cartesian);
364
- //>>includeEnd('debug');
365
-
366
- return (
367
- cartesian.x * cartesian.x +
368
- cartesian.y * cartesian.y +
369
- cartesian.z * cartesian.z
370
- );
371
- };
598
+ result.x = Math.abs(cartesian.x);
599
+ result.y = Math.abs(cartesian.y);
600
+ result.z = Math.abs(cartesian.z);
601
+ return result;
602
+ }
372
603
 
373
- /**
374
- * Computes the Cartesian's magnitude (length).
375
- *
376
- * @param {Cartesian3} cartesian The Cartesian instance whose magnitude is to be computed.
377
- * @returns {number} The magnitude.
378
- */
379
- Cartesian3.magnitude = function (cartesian) {
380
- return Math.sqrt(Cartesian3.magnitudeSquared(cartesian));
381
- };
604
+ /**
605
+ * Computes the linear interpolation or extrapolation at t using the provided cartesians.
606
+ *
607
+ * @param {Cartesian3} start The value corresponding to t at 0.0.
608
+ * @param {Cartesian3} end The value corresponding to t at 1.0.
609
+ * @param {number} t The point along t at which to interpolate.
610
+ * @param {Cartesian3} result The object onto which to store the result.
611
+ * @returns {Cartesian3} The modified result parameter.
612
+ */
613
+ static lerp(start, end, t, result) {
614
+ //>>includeStart('debug', pragmas.debug);
615
+ Check.typeOf.object("start", start);
616
+ Check.typeOf.object("end", end);
617
+ Check.typeOf.number("t", t);
618
+ Check.typeOf.object("result", result);
619
+ //>>includeEnd('debug');
382
620
 
383
- const distanceScratch = new Cartesian3();
621
+ Cartesian3.multiplyByScalar(end, t, lerpScratch);
622
+ result = Cartesian3.multiplyByScalar(start, 1.0 - t, result);
623
+ return Cartesian3.add(lerpScratch, result, result);
624
+ }
384
625
 
385
- /**
386
- * Computes the distance between two points.
387
- *
388
- * @param {Cartesian3} left The first point to compute the distance from.
389
- * @param {Cartesian3} right The second point to compute the distance to.
390
- * @returns {number} The distance between two points.
391
- *
392
- * @example
393
- * // Returns 1.0
394
- * const d = Cesium.Cartesian3.distance(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(2.0, 0.0, 0.0));
395
- */
396
- Cartesian3.distance = function (left, right) {
397
- //>>includeStart('debug', pragmas.debug);
398
- Check.typeOf.object("left", left);
399
- Check.typeOf.object("right", right);
400
- //>>includeEnd('debug');
626
+ /**
627
+ * Returns the angle, in radians, between the provided Cartesians.
628
+ *
629
+ * @param {Cartesian3} left The first Cartesian.
630
+ * @param {Cartesian3} right The second Cartesian.
631
+ * @returns {number} The angle between the Cartesians.
632
+ */
633
+ static angleBetween(left, right) {
634
+ //>>includeStart('debug', pragmas.debug);
635
+ Check.typeOf.object("left", left);
636
+ Check.typeOf.object("right", right);
637
+ //>>includeEnd('debug');
401
638
 
402
- Cartesian3.subtract(left, right, distanceScratch);
403
- return Cartesian3.magnitude(distanceScratch);
404
- };
639
+ Cartesian3.normalize(left, angleBetweenScratch);
640
+ Cartesian3.normalize(right, angleBetweenScratch2);
641
+ const cosine = Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);
642
+ const sine = Cartesian3.magnitude(
643
+ Cartesian3.cross(
644
+ angleBetweenScratch,
645
+ angleBetweenScratch2,
646
+ angleBetweenScratch,
647
+ ),
648
+ );
649
+ return Math.atan2(sine, cosine);
650
+ }
405
651
 
406
- /**
407
- * Computes the squared distance between two points. Comparing squared distances
408
- * using this function is more efficient than comparing distances using {@link Cartesian3#distance}.
409
- *
410
- * @param {Cartesian3} left The first point to compute the distance from.
411
- * @param {Cartesian3} right The second point to compute the distance to.
412
- * @returns {number} The distance between two points.
413
- *
414
- * @example
415
- * // Returns 4.0, not 2.0
416
- * const d = Cesium.Cartesian3.distanceSquared(new Cesium.Cartesian3(1.0, 0.0, 0.0), new Cesium.Cartesian3(3.0, 0.0, 0.0));
417
- */
418
- Cartesian3.distanceSquared = function (left, right) {
419
- //>>includeStart('debug', pragmas.debug);
420
- Check.typeOf.object("left", left);
421
- Check.typeOf.object("right", right);
422
- //>>includeEnd('debug');
652
+ /**
653
+ * Returns the axis that is most orthogonal to the provided Cartesian.
654
+ *
655
+ * @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.
656
+ * @param {Cartesian3} result The object onto which to store the result.
657
+ * @returns {Cartesian3} The most orthogonal axis.
658
+ */
659
+ static mostOrthogonalAxis(cartesian, result) {
660
+ //>>includeStart('debug', pragmas.debug);
661
+ Check.typeOf.object("cartesian", cartesian);
662
+ Check.typeOf.object("result", result);
663
+ //>>includeEnd('debug');
423
664
 
424
- Cartesian3.subtract(left, right, distanceScratch);
425
- return Cartesian3.magnitudeSquared(distanceScratch);
426
- };
665
+ const f = Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);
666
+ Cartesian3.abs(f, f);
667
+
668
+ if (f.x <= f.y) {
669
+ if (f.x <= f.z) {
670
+ result = Cartesian3.clone(Cartesian3.UNIT_X, result);
671
+ } else {
672
+ result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
673
+ }
674
+ } else if (f.y <= f.z) {
675
+ result = Cartesian3.clone(Cartesian3.UNIT_Y, result);
676
+ } else {
677
+ result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
678
+ }
427
679
 
428
- /**
429
- * Computes the normalized form of the supplied Cartesian.
430
- *
431
- * @param {Cartesian3} cartesian The Cartesian to be normalized.
432
- * @param {Cartesian3} result The object onto which to store the result.
433
- * @returns {Cartesian3} The modified result parameter.
434
- */
435
- Cartesian3.normalize = function (cartesian, result) {
436
- //>>includeStart('debug', pragmas.debug);
437
- Check.typeOf.object("cartesian", cartesian);
438
- Check.typeOf.object("result", result);
439
- //>>includeEnd('debug');
680
+ return result;
681
+ }
440
682
 
441
- const magnitude = Cartesian3.magnitude(cartesian);
683
+ /**
684
+ * Projects vector a onto vector b
685
+ * @param {Cartesian3} a The vector that needs projecting
686
+ * @param {Cartesian3} b The vector to project onto
687
+ * @param {Cartesian3} result The result cartesian
688
+ * @returns {Cartesian3} The modified result parameter
689
+ */
690
+ static projectVector(a, b, result) {
691
+ //>>includeStart('debug', pragmas.debug);
692
+ Check.defined("a", a);
693
+ Check.defined("b", b);
694
+ Check.defined("result", result);
695
+ //>>includeEnd('debug');
696
+
697
+ const scalar = Cartesian3.dot(a, b) / Cartesian3.dot(b, b);
698
+ return Cartesian3.multiplyByScalar(b, scalar, result);
699
+ }
700
+
701
+ /**
702
+ * Compares the provided Cartesians componentwise and returns
703
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
704
+ *
705
+ * @param {Cartesian3} [left] The first Cartesian.
706
+ * @param {Cartesian3} [right] The second Cartesian.
707
+ * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
708
+ */
709
+ static equals(left, right) {
710
+ return (
711
+ left === right ||
712
+ (defined(left) &&
713
+ defined(right) &&
714
+ left.x === right.x &&
715
+ left.y === right.y &&
716
+ left.z === right.z)
717
+ );
718
+ }
442
719
 
443
- result.x = cartesian.x / magnitude;
444
- result.y = cartesian.y / magnitude;
445
- result.z = cartesian.z / magnitude;
720
+ /**
721
+ * @param {Cartesian3} cartesian
722
+ * @param {number[]} array
723
+ * @param {number} offset
724
+ * @private
725
+ */
726
+ static equalsArray(cartesian, array, offset) {
727
+ return (
728
+ cartesian.x === array[offset] &&
729
+ cartesian.y === array[offset + 1] &&
730
+ cartesian.z === array[offset + 2]
731
+ );
732
+ }
446
733
 
447
- //>>includeStart('debug', pragmas.debug);
448
- if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
449
- throw new DeveloperError("normalized result is not a number");
734
+ /**
735
+ * Compares the provided Cartesians componentwise and returns
736
+ * <code>true</code> if they pass an absolute or relative tolerance test,
737
+ * <code>false</code> otherwise.
738
+ *
739
+ * @param {Cartesian3} [left] The first Cartesian.
740
+ * @param {Cartesian3} [right] The second Cartesian.
741
+ * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
742
+ * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
743
+ * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
744
+ */
745
+ static equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon) {
746
+ return (
747
+ left === right ||
748
+ (defined(left) &&
749
+ defined(right) &&
750
+ CesiumMath.equalsEpsilon(
751
+ left.x,
752
+ right.x,
753
+ relativeEpsilon,
754
+ absoluteEpsilon,
755
+ ) &&
756
+ CesiumMath.equalsEpsilon(
757
+ left.y,
758
+ right.y,
759
+ relativeEpsilon,
760
+ absoluteEpsilon,
761
+ ) &&
762
+ CesiumMath.equalsEpsilon(
763
+ left.z,
764
+ right.z,
765
+ relativeEpsilon,
766
+ absoluteEpsilon,
767
+ ))
768
+ );
450
769
  }
451
- //>>includeEnd('debug');
452
770
 
453
- return result;
454
- };
771
+ /**
772
+ * Computes the cross (outer) product of two Cartesians.
773
+ *
774
+ * @param {Cartesian3} left The first Cartesian.
775
+ * @param {Cartesian3} right The second Cartesian.
776
+ * @param {Cartesian3} result The object onto which to store the result.
777
+ * @returns {Cartesian3} The cross product.
778
+ */
779
+ static cross(left, right, result) {
780
+ //>>includeStart('debug', pragmas.debug);
781
+ Check.typeOf.object("left", left);
782
+ Check.typeOf.object("right", right);
783
+ Check.typeOf.object("result", result);
784
+ //>>includeEnd('debug');
455
785
 
456
- /**
457
- * Computes the dot (scalar) product of two Cartesians.
458
- *
459
- * @param {Cartesian3} left The first Cartesian.
460
- * @param {Cartesian3} right The second Cartesian.
461
- * @returns {number} The dot product.
462
- */
463
- Cartesian3.dot = function (left, right) {
464
- //>>includeStart('debug', pragmas.debug);
465
- Check.typeOf.object("left", left);
466
- Check.typeOf.object("right", right);
467
- //>>includeEnd('debug');
786
+ const leftX = left.x;
787
+ const leftY = left.y;
788
+ const leftZ = left.z;
789
+ const rightX = right.x;
790
+ const rightY = right.y;
791
+ const rightZ = right.z;
792
+
793
+ const x = leftY * rightZ - leftZ * rightY;
794
+ const y = leftZ * rightX - leftX * rightZ;
795
+ const z = leftX * rightY - leftY * rightX;
796
+
797
+ result.x = x;
798
+ result.y = y;
799
+ result.z = z;
800
+ return result;
801
+ }
468
802
 
469
- return left.x * right.x + left.y * right.y + left.z * right.z;
470
- };
803
+ /**
804
+ * Computes the midpoint between the right and left Cartesian.
805
+ * @param {Cartesian3} left The first Cartesian.
806
+ * @param {Cartesian3} right The second Cartesian.
807
+ * @param {Cartesian3} result The object onto which to store the result.
808
+ * @returns {Cartesian3} The midpoint.
809
+ */
810
+ static midpoint(left, right, result) {
811
+ //>>includeStart('debug', pragmas.debug);
812
+ Check.typeOf.object("left", left);
813
+ Check.typeOf.object("right", right);
814
+ Check.typeOf.object("result", result);
815
+ //>>includeEnd('debug');
471
816
 
472
- /**
473
- * Computes the componentwise product of two Cartesians.
474
- *
475
- * @param {Cartesian3} left The first Cartesian.
476
- * @param {Cartesian3} right The second Cartesian.
477
- * @param {Cartesian3} result The object onto which to store the result.
478
- * @returns {Cartesian3} The modified result parameter.
479
- */
480
- Cartesian3.multiplyComponents = function (left, right, result) {
481
- //>>includeStart('debug', pragmas.debug);
482
- Check.typeOf.object("left", left);
483
- Check.typeOf.object("right", right);
484
- Check.typeOf.object("result", result);
485
- //>>includeEnd('debug');
486
-
487
- result.x = left.x * right.x;
488
- result.y = left.y * right.y;
489
- result.z = left.z * right.z;
490
- return result;
491
- };
817
+ result.x = (left.x + right.x) * 0.5;
818
+ result.y = (left.y + right.y) * 0.5;
819
+ result.z = (left.z + right.z) * 0.5;
492
820
 
493
- /**
494
- * Computes the componentwise quotient of two Cartesians.
495
- *
496
- * @param {Cartesian3} left The first Cartesian.
497
- * @param {Cartesian3} right The second Cartesian.
498
- * @param {Cartesian3} result The object onto which to store the result.
499
- * @returns {Cartesian3} The modified result parameter.
500
- */
501
- Cartesian3.divideComponents = function (left, right, result) {
502
- //>>includeStart('debug', pragmas.debug);
503
- Check.typeOf.object("left", left);
504
- Check.typeOf.object("right", right);
505
- Check.typeOf.object("result", result);
506
- //>>includeEnd('debug');
507
-
508
- result.x = left.x / right.x;
509
- result.y = left.y / right.y;
510
- result.z = left.z / right.z;
511
- return result;
512
- };
821
+ return result;
822
+ }
513
823
 
514
- /**
515
- * Computes the componentwise sum of two Cartesians.
516
- *
517
- * @param {Cartesian3} left The first Cartesian.
518
- * @param {Cartesian3} right The second Cartesian.
519
- * @param {Cartesian3} result The object onto which to store the result.
520
- * @returns {Cartesian3} The modified result parameter.
521
- */
522
- Cartesian3.add = function (left, right, result) {
523
- //>>includeStart('debug', pragmas.debug);
524
- Check.typeOf.object("left", left);
525
- Check.typeOf.object("right", right);
526
- Check.typeOf.object("result", result);
527
- //>>includeEnd('debug');
528
-
529
- result.x = left.x + right.x;
530
- result.y = left.y + right.y;
531
- result.z = left.z + right.z;
532
- return result;
533
- };
824
+ /**
825
+ * Returns a Cartesian3 position from longitude and latitude values given in degrees.
826
+ *
827
+ * @param {number} longitude The longitude, in degrees
828
+ * @param {number} latitude The latitude, in degrees
829
+ * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
830
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
831
+ * @param {Cartesian3} [result] The object onto which to store the result.
832
+ * @returns {Cartesian3} The position
833
+ *
834
+ * @example
835
+ * const position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);
836
+ */
837
+ static fromDegrees(longitude, latitude, height, ellipsoid, result) {
838
+ //>>includeStart('debug', pragmas.debug);
839
+ Check.typeOf.number("longitude", longitude);
840
+ Check.typeOf.number("latitude", latitude);
841
+ //>>includeEnd('debug');
534
842
 
535
- /**
536
- * Computes the componentwise difference of two Cartesians.
537
- *
538
- * @param {Cartesian3} left The first Cartesian.
539
- * @param {Cartesian3} right The second Cartesian.
540
- * @param {Cartesian3} result The object onto which to store the result.
541
- * @returns {Cartesian3} The modified result parameter.
542
- */
543
- Cartesian3.subtract = function (left, right, result) {
544
- //>>includeStart('debug', pragmas.debug);
545
- Check.typeOf.object("left", left);
546
- Check.typeOf.object("right", right);
547
- Check.typeOf.object("result", result);
548
- //>>includeEnd('debug');
549
-
550
- result.x = left.x - right.x;
551
- result.y = left.y - right.y;
552
- result.z = left.z - right.z;
553
- return result;
554
- };
843
+ longitude = CesiumMath.toRadians(longitude);
844
+ latitude = CesiumMath.toRadians(latitude);
845
+ return Cartesian3.fromRadians(
846
+ longitude,
847
+ latitude,
848
+ height,
849
+ ellipsoid,
850
+ result,
851
+ );
852
+ }
555
853
 
556
- /**
557
- * Multiplies the provided Cartesian componentwise by the provided scalar.
558
- *
559
- * @param {Cartesian3} cartesian The Cartesian to be scaled.
560
- * @param {number} scalar The scalar to multiply with.
561
- * @param {Cartesian3} result The object onto which to store the result.
562
- * @returns {Cartesian3} The modified result parameter.
563
- */
564
- Cartesian3.multiplyByScalar = function (cartesian, scalar, result) {
565
- //>>includeStart('debug', pragmas.debug);
566
- Check.typeOf.object("cartesian", cartesian);
567
- Check.typeOf.number("scalar", scalar);
568
- Check.typeOf.object("result", result);
569
- //>>includeEnd('debug');
570
-
571
- result.x = cartesian.x * scalar;
572
- result.y = cartesian.y * scalar;
573
- result.z = cartesian.z * scalar;
574
- return result;
575
- };
854
+ /**
855
+ * Returns a Cartesian3 position from longitude and latitude values given in radians.
856
+ *
857
+ * @param {number} longitude The longitude, in radians
858
+ * @param {number} latitude The latitude, in radians
859
+ * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
860
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
861
+ * @param {Cartesian3} [result] The object onto which to store the result.
862
+ * @returns {Cartesian3} The position
863
+ *
864
+ * @example
865
+ * const position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);
866
+ */
867
+ static fromRadians(longitude, latitude, height, ellipsoid, result) {
868
+ //>>includeStart('debug', pragmas.debug);
869
+ Check.typeOf.number("longitude", longitude);
870
+ Check.typeOf.number("latitude", latitude);
871
+ //>>includeEnd('debug');
576
872
 
577
- /**
578
- * Divides the provided Cartesian componentwise by the provided scalar.
579
- *
580
- * @param {Cartesian3} cartesian The Cartesian to be divided.
581
- * @param {number} scalar The scalar to divide by.
582
- * @param {Cartesian3} result The object onto which to store the result.
583
- * @returns {Cartesian3} The modified result parameter.
584
- */
585
- Cartesian3.divideByScalar = function (cartesian, scalar, result) {
586
- //>>includeStart('debug', pragmas.debug);
587
- Check.typeOf.object("cartesian", cartesian);
588
- Check.typeOf.number("scalar", scalar);
589
- Check.typeOf.object("result", result);
590
- //>>includeEnd('debug');
591
-
592
- result.x = cartesian.x / scalar;
593
- result.y = cartesian.y / scalar;
594
- result.z = cartesian.z / scalar;
595
- return result;
596
- };
873
+ height = height ?? 0.0;
597
874
 
598
- /**
599
- * Negates the provided Cartesian.
600
- *
601
- * @param {Cartesian3} cartesian The Cartesian to be negated.
602
- * @param {Cartesian3} result The object onto which to store the result.
603
- * @returns {Cartesian3} The modified result parameter.
604
- */
605
- Cartesian3.negate = function (cartesian, result) {
606
- //>>includeStart('debug', pragmas.debug);
607
- Check.typeOf.object("cartesian", cartesian);
608
- Check.typeOf.object("result", result);
609
- //>>includeEnd('debug');
610
-
611
- result.x = -cartesian.x;
612
- result.y = -cartesian.y;
613
- result.z = -cartesian.z;
614
- return result;
615
- };
875
+ const radiiSquared = !defined(ellipsoid)
876
+ ? Cartesian3._ellipsoidRadiiSquared
877
+ : // @ts-expect-error Requires type-checking on Ellipsoid.js.
878
+ ellipsoid.radiiSquared;
616
879
 
617
- /**
618
- * Computes the absolute value of the provided Cartesian.
619
- *
620
- * @param {Cartesian3} cartesian The Cartesian whose absolute value is to be computed.
621
- * @param {Cartesian3} result The object onto which to store the result.
622
- * @returns {Cartesian3} The modified result parameter.
623
- */
624
- Cartesian3.abs = function (cartesian, result) {
625
- //>>includeStart('debug', pragmas.debug);
626
- Check.typeOf.object("cartesian", cartesian);
627
- Check.typeOf.object("result", result);
628
- //>>includeEnd('debug');
629
-
630
- result.x = Math.abs(cartesian.x);
631
- result.y = Math.abs(cartesian.y);
632
- result.z = Math.abs(cartesian.z);
633
- return result;
634
- };
880
+ const cosLatitude = Math.cos(latitude);
881
+ scratchN.x = cosLatitude * Math.cos(longitude);
882
+ scratchN.y = cosLatitude * Math.sin(longitude);
883
+ scratchN.z = Math.sin(latitude);
884
+ scratchN = Cartesian3.normalize(scratchN, scratchN);
635
885
 
636
- const lerpScratch = new Cartesian3();
637
- /**
638
- * Computes the linear interpolation or extrapolation at t using the provided cartesians.
639
- *
640
- * @param {Cartesian3} start The value corresponding to t at 0.0.
641
- * @param {Cartesian3} end The value corresponding to t at 1.0.
642
- * @param {number} t The point along t at which to interpolate.
643
- * @param {Cartesian3} result The object onto which to store the result.
644
- * @returns {Cartesian3} The modified result parameter.
645
- */
646
- Cartesian3.lerp = function (start, end, t, result) {
647
- //>>includeStart('debug', pragmas.debug);
648
- Check.typeOf.object("start", start);
649
- Check.typeOf.object("end", end);
650
- Check.typeOf.number("t", t);
651
- Check.typeOf.object("result", result);
652
- //>>includeEnd('debug');
653
-
654
- Cartesian3.multiplyByScalar(end, t, lerpScratch);
655
- result = Cartesian3.multiplyByScalar(start, 1.0 - t, result);
656
- return Cartesian3.add(lerpScratch, result, result);
657
- };
886
+ Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);
887
+ const gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK));
888
+ scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK);
889
+ scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN);
658
890
 
659
- const angleBetweenScratch = new Cartesian3();
660
- const angleBetweenScratch2 = new Cartesian3();
661
- /**
662
- * Returns the angle, in radians, between the provided Cartesians.
663
- *
664
- * @param {Cartesian3} left The first Cartesian.
665
- * @param {Cartesian3} right The second Cartesian.
666
- * @returns {number} The angle between the Cartesians.
667
- */
668
- Cartesian3.angleBetween = function (left, right) {
669
- //>>includeStart('debug', pragmas.debug);
670
- Check.typeOf.object("left", left);
671
- Check.typeOf.object("right", right);
672
- //>>includeEnd('debug');
673
-
674
- Cartesian3.normalize(left, angleBetweenScratch);
675
- Cartesian3.normalize(right, angleBetweenScratch2);
676
- const cosine = Cartesian3.dot(angleBetweenScratch, angleBetweenScratch2);
677
- const sine = Cartesian3.magnitude(
678
- Cartesian3.cross(
679
- angleBetweenScratch,
680
- angleBetweenScratch2,
681
- angleBetweenScratch,
682
- ),
683
- );
684
- return Math.atan2(sine, cosine);
685
- };
891
+ if (!defined(result)) {
892
+ result = new Cartesian3();
893
+ }
894
+ return Cartesian3.add(scratchK, scratchN, result);
895
+ }
686
896
 
687
- const mostOrthogonalAxisScratch = new Cartesian3();
688
- /**
689
- * Returns the axis that is most orthogonal to the provided Cartesian.
690
- *
691
- * @param {Cartesian3} cartesian The Cartesian on which to find the most orthogonal axis.
692
- * @param {Cartesian3} result The object onto which to store the result.
693
- * @returns {Cartesian3} The most orthogonal axis.
694
- */
695
- Cartesian3.mostOrthogonalAxis = function (cartesian, result) {
696
- //>>includeStart('debug', pragmas.debug);
697
- Check.typeOf.object("cartesian", cartesian);
698
- Check.typeOf.object("result", result);
699
- //>>includeEnd('debug');
700
-
701
- const f = Cartesian3.normalize(cartesian, mostOrthogonalAxisScratch);
702
- Cartesian3.abs(f, f);
703
-
704
- if (f.x <= f.y) {
705
- if (f.x <= f.z) {
706
- result = Cartesian3.clone(Cartesian3.UNIT_X, result);
897
+ /**
898
+ * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.
899
+ *
900
+ * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
901
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the coordinates lie.
902
+ * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
903
+ * @returns {Cartesian3[]} The array of positions.
904
+ *
905
+ * @example
906
+ * const positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);
907
+ */
908
+ static fromDegreesArray(coordinates, ellipsoid, result) {
909
+ //>>includeStart('debug', pragmas.debug);
910
+ Check.defined("coordinates", coordinates);
911
+ if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
912
+ throw new DeveloperError(
913
+ "the number of coordinates must be a multiple of 2 and at least 2",
914
+ );
915
+ }
916
+ //>>includeEnd('debug');
917
+
918
+ const length = coordinates.length;
919
+ if (!defined(result)) {
920
+ result = new Array(length / 2);
707
921
  } else {
708
- result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
922
+ result.length = length / 2;
709
923
  }
710
- } else if (f.y <= f.z) {
711
- result = Cartesian3.clone(Cartesian3.UNIT_Y, result);
712
- } else {
713
- result = Cartesian3.clone(Cartesian3.UNIT_Z, result);
714
- }
715
924
 
716
- return result;
717
- };
925
+ for (let i = 0; i < length; i += 2) {
926
+ const longitude = coordinates[i];
927
+ const latitude = coordinates[i + 1];
928
+ const index = i / 2;
929
+ result[index] = Cartesian3.fromDegrees(
930
+ longitude,
931
+ latitude,
932
+ 0,
933
+ ellipsoid,
934
+ result[index],
935
+ );
936
+ }
718
937
 
719
- /**
720
- * Projects vector a onto vector b
721
- * @param {Cartesian3} a The vector that needs projecting
722
- * @param {Cartesian3} b The vector to project onto
723
- * @param {Cartesian3} result The result cartesian
724
- * @returns {Cartesian3} The modified result parameter
725
- */
726
- Cartesian3.projectVector = function (a, b, result) {
727
- //>>includeStart('debug', pragmas.debug);
728
- Check.defined("a", a);
729
- Check.defined("b", b);
730
- Check.defined("result", result);
731
- //>>includeEnd('debug');
938
+ return result;
939
+ }
732
940
 
733
- const scalar = Cartesian3.dot(a, b) / Cartesian3.dot(b, b);
734
- return Cartesian3.multiplyByScalar(b, scalar, result);
735
- };
941
+ /**
942
+ * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.
943
+ *
944
+ * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
945
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the coordinates lie.
946
+ * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
947
+ * @returns {Cartesian3[]} The array of positions.
948
+ *
949
+ * @example
950
+ * const positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);
951
+ */
952
+ static fromRadiansArray(coordinates, ellipsoid, result) {
953
+ //>>includeStart('debug', pragmas.debug);
954
+ Check.defined("coordinates", coordinates);
955
+ if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
956
+ throw new DeveloperError(
957
+ "the number of coordinates must be a multiple of 2 and at least 2",
958
+ );
959
+ }
960
+ //>>includeEnd('debug');
736
961
 
737
- /**
738
- * Compares the provided Cartesians componentwise and returns
739
- * <code>true</code> if they are equal, <code>false</code> otherwise.
740
- *
741
- * @param {Cartesian3} [left] The first Cartesian.
742
- * @param {Cartesian3} [right] The second Cartesian.
743
- * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
744
- */
745
- Cartesian3.equals = function (left, right) {
746
- return (
747
- left === right ||
748
- (defined(left) &&
749
- defined(right) &&
750
- left.x === right.x &&
751
- left.y === right.y &&
752
- left.z === right.z)
753
- );
754
- };
962
+ const length = coordinates.length;
963
+ if (!defined(result)) {
964
+ result = new Array(length / 2);
965
+ } else {
966
+ result.length = length / 2;
967
+ }
755
968
 
756
- /**
757
- * @private
758
- */
759
- Cartesian3.equalsArray = function (cartesian, array, offset) {
760
- return (
761
- cartesian.x === array[offset] &&
762
- cartesian.y === array[offset + 1] &&
763
- cartesian.z === array[offset + 2]
764
- );
765
- };
969
+ for (let i = 0; i < length; i += 2) {
970
+ const longitude = coordinates[i];
971
+ const latitude = coordinates[i + 1];
972
+ const index = i / 2;
973
+ result[index] = Cartesian3.fromRadians(
974
+ longitude,
975
+ latitude,
976
+ 0,
977
+ ellipsoid,
978
+ result[index],
979
+ );
980
+ }
766
981
 
767
- /**
768
- * Compares the provided Cartesians componentwise and returns
769
- * <code>true</code> if they pass an absolute or relative tolerance test,
770
- * <code>false</code> otherwise.
771
- *
772
- * @param {Cartesian3} [left] The first Cartesian.
773
- * @param {Cartesian3} [right] The second Cartesian.
774
- * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
775
- * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
776
- * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
777
- */
778
- Cartesian3.equalsEpsilon = function (
779
- left,
780
- right,
781
- relativeEpsilon,
782
- absoluteEpsilon,
783
- ) {
784
- return (
785
- left === right ||
786
- (defined(left) &&
787
- defined(right) &&
788
- CesiumMath.equalsEpsilon(
789
- left.x,
790
- right.x,
791
- relativeEpsilon,
792
- absoluteEpsilon,
793
- ) &&
794
- CesiumMath.equalsEpsilon(
795
- left.y,
796
- right.y,
797
- relativeEpsilon,
798
- absoluteEpsilon,
799
- ) &&
800
- CesiumMath.equalsEpsilon(
801
- left.z,
802
- right.z,
803
- relativeEpsilon,
804
- absoluteEpsilon,
805
- ))
806
- );
807
- };
982
+ return result;
983
+ }
808
984
 
809
- /**
810
- * Computes the cross (outer) product of two Cartesians.
811
- *
812
- * @param {Cartesian3} left The first Cartesian.
813
- * @param {Cartesian3} right The second Cartesian.
814
- * @param {Cartesian3} result The object onto which to store the result.
815
- * @returns {Cartesian3} The cross product.
816
- */
817
- Cartesian3.cross = function (left, right, result) {
818
- //>>includeStart('debug', pragmas.debug);
819
- Check.typeOf.object("left", left);
820
- Check.typeOf.object("right", right);
821
- Check.typeOf.object("result", result);
822
- //>>includeEnd('debug');
823
-
824
- const leftX = left.x;
825
- const leftY = left.y;
826
- const leftZ = left.z;
827
- const rightX = right.x;
828
- const rightY = right.y;
829
- const rightZ = right.z;
830
-
831
- const x = leftY * rightZ - leftZ * rightY;
832
- const y = leftZ * rightX - leftX * rightZ;
833
- const z = leftX * rightY - leftY * rightX;
834
-
835
- result.x = x;
836
- result.y = y;
837
- result.z = z;
838
- return result;
839
- };
985
+ /**
986
+ * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.
987
+ *
988
+ * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
989
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
990
+ * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
991
+ * @returns {Cartesian3[]} The array of positions.
992
+ *
993
+ * @example
994
+ * const positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);
995
+ */
996
+ static fromDegreesArrayHeights(coordinates, ellipsoid, result) {
997
+ //>>includeStart('debug', pragmas.debug);
998
+ Check.defined("coordinates", coordinates);
999
+ if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
1000
+ throw new DeveloperError(
1001
+ "the number of coordinates must be a multiple of 3 and at least 3",
1002
+ );
1003
+ }
1004
+ //>>includeEnd('debug');
840
1005
 
841
- /**
842
- * Computes the midpoint between the right and left Cartesian.
843
- * @param {Cartesian3} left The first Cartesian.
844
- * @param {Cartesian3} right The second Cartesian.
845
- * @param {Cartesian3} result The object onto which to store the result.
846
- * @returns {Cartesian3} The midpoint.
847
- */
848
- Cartesian3.midpoint = function (left, right, result) {
849
- //>>includeStart('debug', pragmas.debug);
850
- Check.typeOf.object("left", left);
851
- Check.typeOf.object("right", right);
852
- Check.typeOf.object("result", result);
853
- //>>includeEnd('debug');
1006
+ const length = coordinates.length;
1007
+ if (!defined(result)) {
1008
+ result = new Array(length / 3);
1009
+ } else {
1010
+ result.length = length / 3;
1011
+ }
854
1012
 
855
- result.x = (left.x + right.x) * 0.5;
856
- result.y = (left.y + right.y) * 0.5;
857
- result.z = (left.z + right.z) * 0.5;
1013
+ for (let i = 0; i < length; i += 3) {
1014
+ const longitude = coordinates[i];
1015
+ const latitude = coordinates[i + 1];
1016
+ const height = coordinates[i + 2];
1017
+ const index = i / 3;
1018
+ result[index] = Cartesian3.fromDegrees(
1019
+ longitude,
1020
+ latitude,
1021
+ height,
1022
+ ellipsoid,
1023
+ result[index],
1024
+ );
1025
+ }
858
1026
 
859
- return result;
860
- };
1027
+ return result;
1028
+ }
861
1029
 
862
- /**
863
- * Returns a Cartesian3 position from longitude and latitude values given in degrees.
864
- *
865
- * @param {number} longitude The longitude, in degrees
866
- * @param {number} latitude The latitude, in degrees
867
- * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
868
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
869
- * @param {Cartesian3} [result] The object onto which to store the result.
870
- * @returns {Cartesian3} The position
871
- *
872
- * @example
873
- * const position = Cesium.Cartesian3.fromDegrees(-115.0, 37.0);
874
- */
875
- Cartesian3.fromDegrees = function (
876
- longitude,
877
- latitude,
878
- height,
879
- ellipsoid,
880
- result,
881
- ) {
882
- //>>includeStart('debug', pragmas.debug);
883
- Check.typeOf.number("longitude", longitude);
884
- Check.typeOf.number("latitude", latitude);
885
- //>>includeEnd('debug');
886
-
887
- longitude = CesiumMath.toRadians(longitude);
888
- latitude = CesiumMath.toRadians(latitude);
889
- return Cartesian3.fromRadians(longitude, latitude, height, ellipsoid, result);
890
- };
1030
+ /**
1031
+ * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.
1032
+ *
1033
+ * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
1034
+ * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
1035
+ * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
1036
+ * @returns {Cartesian3[]} The array of positions.
1037
+ *
1038
+ * @example
1039
+ * const positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);
1040
+ */
1041
+ static fromRadiansArrayHeights(coordinates, ellipsoid, result) {
1042
+ //>>includeStart('debug', pragmas.debug);
1043
+ Check.defined("coordinates", coordinates);
1044
+ if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
1045
+ throw new DeveloperError(
1046
+ "the number of coordinates must be a multiple of 3 and at least 3",
1047
+ );
1048
+ }
1049
+ //>>includeEnd('debug');
891
1050
 
892
- let scratchN = new Cartesian3();
893
- let scratchK = new Cartesian3();
1051
+ const length = coordinates.length;
1052
+ if (!defined(result)) {
1053
+ result = new Array(length / 3);
1054
+ } else {
1055
+ result.length = length / 3;
1056
+ }
894
1057
 
895
- // To prevent a circular dependency, this value is overridden by Ellipsoid when Ellipsoid.default is set
896
- Cartesian3._ellipsoidRadiiSquared = new Cartesian3(
897
- 6378137.0 * 6378137.0,
898
- 6378137.0 * 6378137.0,
899
- 6356752.3142451793 * 6356752.3142451793,
900
- );
1058
+ for (let i = 0; i < length; i += 3) {
1059
+ const longitude = coordinates[i];
1060
+ const latitude = coordinates[i + 1];
1061
+ const height = coordinates[i + 2];
1062
+ const index = i / 3;
1063
+ result[index] = Cartesian3.fromRadians(
1064
+ longitude,
1065
+ latitude,
1066
+ height,
1067
+ ellipsoid,
1068
+ result[index],
1069
+ );
1070
+ }
901
1071
 
902
- /**
903
- * Returns a Cartesian3 position from longitude and latitude values given in radians.
904
- *
905
- * @param {number} longitude The longitude, in radians
906
- * @param {number} latitude The latitude, in radians
907
- * @param {number} [height=0.0] The height, in meters, above the ellipsoid.
908
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
909
- * @param {Cartesian3} [result] The object onto which to store the result.
910
- * @returns {Cartesian3} The position
911
- *
912
- * @example
913
- * const position = Cesium.Cartesian3.fromRadians(-2.007, 0.645);
914
- */
915
- Cartesian3.fromRadians = function (
916
- longitude,
917
- latitude,
918
- height,
919
- ellipsoid,
920
- result,
921
- ) {
922
- //>>includeStart('debug', pragmas.debug);
923
- Check.typeOf.number("longitude", longitude);
924
- Check.typeOf.number("latitude", latitude);
925
- //>>includeEnd('debug');
926
-
927
- height = height ?? 0.0;
928
-
929
- const radiiSquared = !defined(ellipsoid)
930
- ? Cartesian3._ellipsoidRadiiSquared
931
- : ellipsoid.radiiSquared;
932
-
933
- const cosLatitude = Math.cos(latitude);
934
- scratchN.x = cosLatitude * Math.cos(longitude);
935
- scratchN.y = cosLatitude * Math.sin(longitude);
936
- scratchN.z = Math.sin(latitude);
937
- scratchN = Cartesian3.normalize(scratchN, scratchN);
938
-
939
- Cartesian3.multiplyComponents(radiiSquared, scratchN, scratchK);
940
- const gamma = Math.sqrt(Cartesian3.dot(scratchN, scratchK));
941
- scratchK = Cartesian3.divideByScalar(scratchK, gamma, scratchK);
942
- scratchN = Cartesian3.multiplyByScalar(scratchN, height, scratchN);
943
-
944
- if (!defined(result)) {
945
- result = new Cartesian3();
1072
+ return result;
946
1073
  }
947
- return Cartesian3.add(scratchK, scratchN, result);
948
- };
949
1074
 
950
- /**
951
- * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in degrees.
952
- *
953
- * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
954
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the coordinates lie.
955
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
956
- * @returns {Cartesian3[]} The array of positions.
957
- *
958
- * @example
959
- * const positions = Cesium.Cartesian3.fromDegreesArray([-115.0, 37.0, -107.0, 33.0]);
960
- */
961
- Cartesian3.fromDegreesArray = function (coordinates, ellipsoid, result) {
962
- //>>includeStart('debug', pragmas.debug);
963
- Check.defined("coordinates", coordinates);
964
- if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
965
- throw new DeveloperError(
966
- "the number of coordinates must be a multiple of 2 and at least 2",
967
- );
1075
+ /**
1076
+ * Duplicates this Cartesian3 instance.
1077
+ *
1078
+ * @param {Cartesian3} [result] The object onto which to store the result.
1079
+ * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
1080
+ */
1081
+ clone(result) {
1082
+ return Cartesian3.clone(this, result);
968
1083
  }
969
- //>>includeEnd('debug');
970
1084
 
971
- const length = coordinates.length;
972
- if (!defined(result)) {
973
- result = new Array(length / 2);
974
- } else {
975
- result.length = length / 2;
1085
+ /**
1086
+ * Compares this Cartesian against the provided Cartesian componentwise and returns
1087
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
1088
+ *
1089
+ * @param {Cartesian3} [right] The right hand side Cartesian.
1090
+ * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
1091
+ */
1092
+ equals(right) {
1093
+ return Cartesian3.equals(this, right);
976
1094
  }
977
1095
 
978
- for (let i = 0; i < length; i += 2) {
979
- const longitude = coordinates[i];
980
- const latitude = coordinates[i + 1];
981
- const index = i / 2;
982
- result[index] = Cartesian3.fromDegrees(
983
- longitude,
984
- latitude,
985
- 0,
986
- ellipsoid,
987
- result[index],
1096
+ /**
1097
+ * Compares this Cartesian against the provided Cartesian componentwise and returns
1098
+ * <code>true</code> if they pass an absolute or relative tolerance test,
1099
+ * <code>false</code> otherwise.
1100
+ *
1101
+ * @param {Cartesian3} [right] The right hand side Cartesian.
1102
+ * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
1103
+ * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
1104
+ * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
1105
+ */
1106
+ equalsEpsilon(right, relativeEpsilon, absoluteEpsilon) {
1107
+ return Cartesian3.equalsEpsilon(
1108
+ this,
1109
+ right,
1110
+ relativeEpsilon,
1111
+ absoluteEpsilon,
988
1112
  );
989
1113
  }
990
1114
 
991
- return result;
992
- };
1115
+ /**
1116
+ * Creates a string representing this Cartesian in the format '(x, y, z)'.
1117
+ *
1118
+ * @returns {string} A string representing this Cartesian in the format '(x, y, z)'.
1119
+ */
1120
+ toString() {
1121
+ return `(${this.x}, ${this.y}, ${this.z})`;
1122
+ }
1123
+ }
993
1124
 
994
1125
  /**
995
- * Returns an array of Cartesian3 positions given an array of longitude and latitude values given in radians.
996
- *
997
- * @param {number[]} coordinates A list of longitude and latitude values. Values alternate [longitude, latitude, longitude, latitude...].
998
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the coordinates lie.
999
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
1000
- * @returns {Cartesian3[]} The array of positions.
1126
+ * Creates a Cartesian3 instance from an existing Cartesian4. This simply takes the
1127
+ * x, y, and z properties of the Cartesian4 and drops w.
1128
+ * @function
1001
1129
  *
1002
- * @example
1003
- * const positions = Cesium.Cartesian3.fromRadiansArray([-2.007, 0.645, -1.867, .575]);
1130
+ * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian3 instance from.
1131
+ * @param {Cartesian3} [result] The object onto which to store the result.
1132
+ * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
1004
1133
  */
1005
- Cartesian3.fromRadiansArray = function (coordinates, ellipsoid, result) {
1006
- //>>includeStart('debug', pragmas.debug);
1007
- Check.defined("coordinates", coordinates);
1008
- if (coordinates.length < 2 || coordinates.length % 2 !== 0) {
1009
- throw new DeveloperError(
1010
- "the number of coordinates must be a multiple of 2 and at least 2",
1011
- );
1012
- }
1013
- //>>includeEnd('debug');
1014
-
1015
- const length = coordinates.length;
1016
- if (!defined(result)) {
1017
- result = new Array(length / 2);
1018
- } else {
1019
- result.length = length / 2;
1020
- }
1021
-
1022
- for (let i = 0; i < length; i += 2) {
1023
- const longitude = coordinates[i];
1024
- const latitude = coordinates[i + 1];
1025
- const index = i / 2;
1026
- result[index] = Cartesian3.fromRadians(
1027
- longitude,
1028
- latitude,
1029
- 0,
1030
- ellipsoid,
1031
- result[index],
1032
- );
1033
- }
1134
+ Cartesian3.fromCartesian4 = Cartesian3.clone;
1034
1135
 
1035
- return result;
1036
- };
1136
+ /**
1137
+ * The number of elements used to pack the object into an array.
1138
+ * @type {number}
1139
+ */
1140
+ Cartesian3.packedLength = 3;
1037
1141
 
1038
1142
  /**
1039
- * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in degrees.
1143
+ * Creates a Cartesian3 from three consecutive elements in an array.
1144
+ * @function
1040
1145
  *
1041
- * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
1042
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
1043
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
1044
- * @returns {Cartesian3[]} The array of positions.
1146
+ * @param {number[]} array The array whose three consecutive elements correspond to the x, y, and z components, respectively.
1147
+ * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
1148
+ * @param {Cartesian3} [result] The object onto which to store the result.
1149
+ * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
1045
1150
  *
1046
1151
  * @example
1047
- * const positions = Cesium.Cartesian3.fromDegreesArrayHeights([-115.0, 37.0, 100000.0, -107.0, 33.0, 150000.0]);
1152
+ * // Create a Cartesian3 with (1.0, 2.0, 3.0)
1153
+ * const v = [1.0, 2.0, 3.0];
1154
+ * const p = Cesium.Cartesian3.fromArray(v);
1155
+ *
1156
+ * // Create a Cartesian3 with (1.0, 2.0, 3.0) using an offset into an array
1157
+ * const v2 = [0.0, 0.0, 1.0, 2.0, 3.0];
1158
+ * const p2 = Cesium.Cartesian3.fromArray(v2, 2);
1048
1159
  */
1049
- Cartesian3.fromDegreesArrayHeights = function (coordinates, ellipsoid, result) {
1050
- //>>includeStart('debug', pragmas.debug);
1051
- Check.defined("coordinates", coordinates);
1052
- if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
1053
- throw new DeveloperError(
1054
- "the number of coordinates must be a multiple of 3 and at least 3",
1055
- );
1056
- }
1057
- //>>includeEnd('debug');
1058
-
1059
- const length = coordinates.length;
1060
- if (!defined(result)) {
1061
- result = new Array(length / 3);
1062
- } else {
1063
- result.length = length / 3;
1064
- }
1160
+ Cartesian3.fromArray = Cartesian3.unpack;
1065
1161
 
1066
- for (let i = 0; i < length; i += 3) {
1067
- const longitude = coordinates[i];
1068
- const latitude = coordinates[i + 1];
1069
- const height = coordinates[i + 2];
1070
- const index = i / 3;
1071
- result[index] = Cartesian3.fromDegrees(
1072
- longitude,
1073
- latitude,
1074
- height,
1075
- ellipsoid,
1076
- result[index],
1077
- );
1078
- }
1162
+ const distanceScratch = new Cartesian3();
1079
1163
 
1080
- return result;
1081
- };
1164
+ const lerpScratch = new Cartesian3();
1082
1165
 
1083
- /**
1084
- * Returns an array of Cartesian3 positions given an array of longitude, latitude and height values where longitude and latitude are given in radians.
1085
- *
1086
- * @param {number[]} coordinates A list of longitude, latitude and height values. Values alternate [longitude, latitude, height, longitude, latitude, height...].
1087
- * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the position lies.
1088
- * @param {Cartesian3[]} [result] An array of Cartesian3 objects to store the result.
1089
- * @returns {Cartesian3[]} The array of positions.
1090
- *
1091
- * @example
1092
- * const positions = Cesium.Cartesian3.fromRadiansArrayHeights([-2.007, 0.645, 100000.0, -1.867, .575, 150000.0]);
1093
- */
1094
- Cartesian3.fromRadiansArrayHeights = function (coordinates, ellipsoid, result) {
1095
- //>>includeStart('debug', pragmas.debug);
1096
- Check.defined("coordinates", coordinates);
1097
- if (coordinates.length < 3 || coordinates.length % 3 !== 0) {
1098
- throw new DeveloperError(
1099
- "the number of coordinates must be a multiple of 3 and at least 3",
1100
- );
1101
- }
1102
- //>>includeEnd('debug');
1166
+ const angleBetweenScratch = new Cartesian3();
1167
+ const angleBetweenScratch2 = new Cartesian3();
1103
1168
 
1104
- const length = coordinates.length;
1105
- if (!defined(result)) {
1106
- result = new Array(length / 3);
1107
- } else {
1108
- result.length = length / 3;
1109
- }
1169
+ const mostOrthogonalAxisScratch = new Cartesian3();
1110
1170
 
1111
- for (let i = 0; i < length; i += 3) {
1112
- const longitude = coordinates[i];
1113
- const latitude = coordinates[i + 1];
1114
- const height = coordinates[i + 2];
1115
- const index = i / 3;
1116
- result[index] = Cartesian3.fromRadians(
1117
- longitude,
1118
- latitude,
1119
- height,
1120
- ellipsoid,
1121
- result[index],
1122
- );
1123
- }
1171
+ let scratchN = new Cartesian3();
1172
+ let scratchK = new Cartesian3();
1124
1173
 
1125
- return result;
1126
- };
1174
+ // To prevent a circular dependency, this value is overridden by Ellipsoid when Ellipsoid.default is set
1175
+ Cartesian3._ellipsoidRadiiSquared = new Cartesian3(
1176
+ 6378137.0 * 6378137.0,
1177
+ 6378137.0 * 6378137.0,
1178
+ 6356752.3142451793 * 6356752.3142451793,
1179
+ );
1127
1180
 
1128
1181
  /**
1129
1182
  * An immutable Cartesian3 instance initialized to (0.0, 0.0, 0.0).
@@ -1165,56 +1218,4 @@ Cartesian3.UNIT_Y = Object.freeze(new Cartesian3(0.0, 1.0, 0.0));
1165
1218
  */
1166
1219
  Cartesian3.UNIT_Z = Object.freeze(new Cartesian3(0.0, 0.0, 1.0));
1167
1220
 
1168
- /**
1169
- * Duplicates this Cartesian3 instance.
1170
- *
1171
- * @param {Cartesian3} [result] The object onto which to store the result.
1172
- * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if one was not provided.
1173
- */
1174
- Cartesian3.prototype.clone = function (result) {
1175
- return Cartesian3.clone(this, result);
1176
- };
1177
-
1178
- /**
1179
- * Compares this Cartesian against the provided Cartesian componentwise and returns
1180
- * <code>true</code> if they are equal, <code>false</code> otherwise.
1181
- *
1182
- * @param {Cartesian3} [right] The right hand side Cartesian.
1183
- * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
1184
- */
1185
- Cartesian3.prototype.equals = function (right) {
1186
- return Cartesian3.equals(this, right);
1187
- };
1188
-
1189
- /**
1190
- * Compares this Cartesian against the provided Cartesian componentwise and returns
1191
- * <code>true</code> if they pass an absolute or relative tolerance test,
1192
- * <code>false</code> otherwise.
1193
- *
1194
- * @param {Cartesian3} [right] The right hand side Cartesian.
1195
- * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
1196
- * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
1197
- * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
1198
- */
1199
- Cartesian3.prototype.equalsEpsilon = function (
1200
- right,
1201
- relativeEpsilon,
1202
- absoluteEpsilon,
1203
- ) {
1204
- return Cartesian3.equalsEpsilon(
1205
- this,
1206
- right,
1207
- relativeEpsilon,
1208
- absoluteEpsilon,
1209
- );
1210
- };
1211
-
1212
- /**
1213
- * Creates a string representing this Cartesian in the format '(x, y, z)'.
1214
- *
1215
- * @returns {string} A string representing this Cartesian in the format '(x, y, z)'.
1216
- */
1217
- Cartesian3.prototype.toString = function () {
1218
- return `(${this.x}, ${this.y}, ${this.z})`;
1219
- };
1220
1221
  export default Cartesian3;