@cesium/engine 22.3.0 → 23.0.1

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 (193) hide show
  1. package/Build/Workers/{chunk-XLIJV3YZ.js → chunk-2M7DKGLW.js} +10 -10
  2. package/Build/Workers/{chunk-AFGP5BXS.js → chunk-2OBWHTIC.js} +7 -7
  3. package/Build/Workers/{chunk-K4PGSAR5.js → chunk-3UQ2YMPP.js} +8 -8
  4. package/Build/Workers/{chunk-W5NV72VR.js → chunk-4JJQRZYL.js} +17 -17
  5. package/Build/Workers/{chunk-EUDHHS7K.js → chunk-54O3AGOA.js} +6 -6
  6. package/Build/Workers/{chunk-MASEF4OV.js → chunk-66OWUDO7.js} +8 -8
  7. package/Build/Workers/{chunk-E4YDCSQK.js → chunk-6U5QMZU3.js} +9 -9
  8. package/Build/Workers/{chunk-FDOLXORR.js → chunk-77DJBHMI.js} +7 -7
  9. package/Build/Workers/{chunk-PJLRXIMS.js → chunk-ALTCIHRH.js} +17 -17
  10. package/Build/Workers/{chunk-FUDC3KOT.js → chunk-B2VA6IEL.js} +5 -5
  11. package/Build/Workers/{chunk-7U5YNLF3.js → chunk-BTP3634E.js} +1 -1
  12. package/Build/Workers/{chunk-EY5HOJFQ.js → chunk-C6HHBKT5.js} +5 -5
  13. package/Build/Workers/{chunk-K2PLKJJG.js → chunk-CID5SY7L.js} +5 -5
  14. package/Build/Workers/{chunk-YHPBT4I5.js → chunk-CJ7ZDY77.js} +5 -5
  15. package/Build/Workers/{chunk-NVL7JXAQ.js → chunk-CNLXMOPM.js} +10 -10
  16. package/Build/Workers/{chunk-IHFAFGR2.js → chunk-CVAAIRNP.js} +2 -2
  17. package/Build/Workers/{chunk-IXL46IYV.js → chunk-CYOPNGPX.js} +12 -12
  18. package/Build/Workers/{chunk-6GBGEUWR.js → chunk-DNMASBMH.js} +2 -2
  19. package/Build/Workers/{chunk-NO3LMU7T.js → chunk-EIC3VAOZ.js} +7 -7
  20. package/Build/Workers/{chunk-S2KVL7OJ.js → chunk-FCJQO4NC.js} +8 -8
  21. package/Build/Workers/{chunk-TMGLPEZW.js → chunk-FKU77FNM.js} +4 -4
  22. package/Build/Workers/{chunk-EOSX23OS.js → chunk-FXSRA5UG.js} +4 -4
  23. package/Build/Workers/{chunk-D2PEV362.js → chunk-G6MJ3ZW3.js} +10 -10
  24. package/Build/Workers/{chunk-2MLJ46ZZ.js → chunk-GLCPE2BJ.js} +13 -13
  25. package/Build/Workers/{chunk-N66PIK46.js → chunk-H3TVRJLY.js} +4 -4
  26. package/Build/Workers/chunk-HNDE73JK.js +1829 -0
  27. package/Build/Workers/{chunk-4R6FGUFP.js → chunk-HXEPZWJN.js} +29 -15
  28. package/Build/Workers/{chunk-4BBANFU6.js → chunk-IJ3SUMK3.js} +1 -1
  29. package/Build/Workers/{chunk-4O2ARYS7.js → chunk-JUKGMJX7.js} +1 -1
  30. package/Build/Workers/{chunk-OOYICVOK.js → chunk-K7UTK4OM.js} +1 -1
  31. package/Build/Workers/{chunk-WUWPKBOZ.js → chunk-LHFC4R7Z.js} +6 -6
  32. package/Build/Workers/{chunk-T5MJDW43.js → chunk-MNSNOONX.js} +7 -7
  33. package/Build/Workers/{chunk-FS42VX2H.js → chunk-N6HRZLS6.js} +2 -2
  34. package/Build/Workers/{chunk-HWGP4GVC.js → chunk-O67UP5YO.js} +13 -13
  35. package/Build/Workers/{chunk-EAAH543Q.js → chunk-OZYB3AOR.js} +11 -11
  36. package/Build/Workers/{chunk-LWZHJWYK.js → chunk-PAFMAR7A.js} +665 -366
  37. package/Build/Workers/{chunk-VRAAQ3FS.js → chunk-PBECJOWF.js} +2 -2
  38. package/Build/Workers/{chunk-VIQIKMTZ.js → chunk-PGZ3B6CB.js} +14 -14
  39. package/Build/Workers/{chunk-KIJR26N3.js → chunk-PQTSXJBJ.js} +16 -16
  40. package/Build/Workers/{chunk-TY5JXMVO.js → chunk-PUO7BYDY.js} +1 -1
  41. package/Build/Workers/{chunk-6WDMPXQ7.js → chunk-QNABVTTP.js} +12 -12
  42. package/Build/Workers/{chunk-7ATKQRBM.js → chunk-QPXGGVHC.js} +10 -10
  43. package/Build/Workers/{chunk-5PJB7ASO.js → chunk-RZX6LOG6.js} +6 -6
  44. package/Build/Workers/{chunk-N6XBJBI7.js → chunk-S53HSRT6.js} +6 -6
  45. package/Build/Workers/{chunk-Y5MRBKQN.js → chunk-TFPG3ZKW.js} +18 -18
  46. package/Build/Workers/{chunk-AWELU5C6.js → chunk-TMCTZ5E3.js} +14 -14
  47. package/Build/Workers/{chunk-ZGGVEGTA.js → chunk-TNXOPEIG.js} +12 -12
  48. package/Build/Workers/{chunk-BO22JHBX.js → chunk-TXYQNXNW.js} +3 -3
  49. package/Build/Workers/{chunk-TCOUGKXF.js → chunk-U4SWB6TI.js} +4 -4
  50. package/Build/Workers/{chunk-D6OKR3BQ.js → chunk-UEWYSOFD.js} +2 -2
  51. package/Build/Workers/{chunk-7SLNBIZS.js → chunk-UOQB7XQI.js} +560 -277
  52. package/Build/Workers/{chunk-ZWWN2CQH.js → chunk-VPWYHFQA.js} +4 -4
  53. package/Build/Workers/{chunk-M5DVYXJJ.js → chunk-VX774SWE.js} +6 -6
  54. package/Build/Workers/{chunk-WHLGBMBC.js → chunk-XPMXRJDD.js} +5 -5
  55. package/Build/Workers/{chunk-L4OFWHNI.js → chunk-YDR5LX5Z.js} +1 -1
  56. package/Build/Workers/{chunk-LK7GEFGB.js → chunk-YSJRB2UZ.js} +2 -2
  57. package/Build/Workers/{chunk-D63Z7KKL.js → chunk-ZEMJQKHD.js} +11 -11
  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 +10 -10
  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/Cartesian2.js +689 -684
  113. package/Source/Core/Cartesian3.js +1044 -1043
  114. package/Source/Core/Cartesian4.js +816 -813
  115. package/Source/Core/GoogleMaps.js +23 -2
  116. package/Source/Core/Ion.js +1 -1
  117. package/Source/Core/OpenCageGeocoderService.js +2 -3
  118. package/Source/Core/globalTypes.js +16 -0
  119. package/Source/Renderer/ShaderDestination.js +54 -13
  120. package/Source/Scene/ArcGisMapService.js +1 -1
  121. package/Source/Scene/Billboard.js +7 -4
  122. package/Source/Scene/BillboardCollection.js +64 -25
  123. package/Source/Scene/BufferLoader.js +65 -74
  124. package/Source/Scene/CubeMapPanorama.js +351 -0
  125. package/Source/Scene/DerivedCommand.js +8 -31
  126. package/Source/Scene/DracoLoader.js +79 -78
  127. package/Source/Scene/EquirectangularPanorama.js +264 -0
  128. package/Source/Scene/FrameState.js +7 -0
  129. package/Source/Scene/GaussianSplatPrimitive.js +906 -167
  130. package/Source/Scene/GlobeSurfaceShaderSet.js +36 -32
  131. package/Source/Scene/GltfBufferViewLoader.js +109 -118
  132. package/Source/Scene/GltfDracoLoader.js +167 -176
  133. package/Source/Scene/GltfImageLoader.js +91 -101
  134. package/Source/Scene/GltfIndexBufferLoader.js +228 -241
  135. package/Source/Scene/GltfJsonLoader.js +90 -99
  136. package/Source/Scene/GltfLoader.js +325 -324
  137. package/Source/Scene/GltfSpzLoader.js +127 -134
  138. package/Source/Scene/GltfStructuralMetadataLoader.js +181 -186
  139. package/Source/Scene/GltfTextureLoader.js +217 -231
  140. package/Source/Scene/GltfVertexBufferLoader.js +267 -276
  141. package/Source/Scene/GoogleStreetViewCubeMapPanoramaProvider.js +341 -0
  142. package/Source/Scene/Label.js +6 -4
  143. package/Source/Scene/LabelCollection.js +59 -1
  144. package/Source/Scene/MetadataClassProperty.js +212 -7
  145. package/Source/Scene/MetadataComponentType.js +162 -127
  146. package/Source/Scene/MetadataSchemaLoader.js +60 -67
  147. package/Source/Scene/MetadataTable.js +14 -0
  148. package/Source/Scene/MetadataTableProperty.js +14 -0
  149. package/Source/Scene/Model/B3dmLoader.js +216 -224
  150. package/Source/Scene/Model/CustomShader.js +6 -1
  151. package/Source/Scene/Model/CustomShaderPipelineStage.js +122 -7
  152. package/Source/Scene/Model/GeoJsonLoader.js +53 -61
  153. package/Source/Scene/Model/GeometryPipelineStage.js +17 -3
  154. package/Source/Scene/Model/I3dmLoader.js +232 -240
  155. package/Source/Scene/Model/MaterialPipelineStage.js +1 -1
  156. package/Source/Scene/Model/MetadataPipelineStage.js +438 -22
  157. package/Source/Scene/Model/PntsLoader.js +78 -89
  158. package/Source/Scene/Panorama.js +53 -0
  159. package/Source/Scene/PanoramaProvider.js +43 -0
  160. package/Source/Scene/PointPrimitiveCollection.js +14 -22
  161. package/Source/Scene/PropertyTable.js +43 -0
  162. package/Source/Scene/PropertyTexture.js +1 -1
  163. package/Source/Scene/PropertyTextureProperty.js +0 -97
  164. package/Source/Scene/ResourceLoader.js +84 -92
  165. package/Source/Scene/Scene.js +12 -0
  166. package/Source/Scene/SkyBox.js +29 -164
  167. package/Source/Scene/StructuralMetadata.js +18 -3
  168. package/Source/Scene/parseStructuralMetadata.js +244 -0
  169. package/Source/Shaders/BillboardCollectionFS.glsl +66 -40
  170. package/Source/Shaders/BillboardCollectionFS.js +67 -40
  171. package/Source/Shaders/BillboardCollectionVS.glsl +22 -31
  172. package/Source/Shaders/BillboardCollectionVS.js +22 -31
  173. package/Source/Shaders/Builtin/CzmBuiltins.js +4 -0
  174. package/Source/Shaders/Builtin/Functions/decodeRGB8.glsl +22 -0
  175. package/Source/Shaders/Builtin/Functions/decodeRGB8.js +24 -0
  176. package/Source/Shaders/Builtin/Functions/unpackTexture.glsl +35 -0
  177. package/Source/Shaders/Builtin/Functions/unpackTexture.js +37 -0
  178. package/Source/Shaders/CubeMapPanoramaVS.glsl +11 -0
  179. package/Source/Shaders/CubeMapPanoramaVS.js +13 -0
  180. package/Source/Shaders/Model/MetadataStageFS.glsl +2 -1
  181. package/Source/Shaders/Model/MetadataStageFS.js +2 -1
  182. package/Source/Shaders/Model/MetadataStageVS.glsl +2 -1
  183. package/Source/Shaders/Model/MetadataStageVS.js +2 -1
  184. package/Source/Shaders/Model/ModelFS.glsl +2 -2
  185. package/Source/Shaders/Model/ModelFS.js +2 -2
  186. package/Source/Shaders/Model/ModelVS.glsl +2 -2
  187. package/Source/Shaders/Model/ModelVS.js +2 -2
  188. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +8 -39
  189. package/Source/Shaders/PointPrimitiveCollectionVS.js +8 -39
  190. package/index.d.ts +564 -189
  191. package/index.js +83 -75
  192. package/package.json +1 -1
  193. package/Build/Workers/chunk-LYBNPUEI.js +0 -1443
@@ -1,740 +1,797 @@
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 Cartesian3 from "./Cartesian3.js"; */
10
+ /** @import Cartesian4 from "./Cartesian4.js"; */
11
+
6
12
  /**
7
13
  * A 2D Cartesian point.
8
- * @alias Cartesian2
9
- * @constructor
10
- *
11
- * @param {number} [x=0.0] The X component.
12
- * @param {number} [y=0.0] The Y component.
13
14
  *
14
15
  * @see Cartesian3
15
16
  * @see Cartesian4
16
17
  * @see Packable
17
18
  */
18
- function Cartesian2(x, y) {
19
+ class Cartesian2 {
19
20
  /**
20
- * The X component.
21
- * @type {number}
22
- * @default 0.0
21
+ * @param {number} [x=0.0] The X component.
22
+ * @param {number} [y=0.0] The Y component.
23
23
  */
24
- this.x = x ?? 0.0;
24
+ constructor(x, y) {
25
+ /**
26
+ * The X component.
27
+ * @type {number}
28
+ * @default 0.0
29
+ */
30
+ this.x = x ?? 0.0;
31
+
32
+ /**
33
+ * The Y component.
34
+ * @type {number}
35
+ * @default 0.0
36
+ */
37
+ this.y = y ?? 0.0;
38
+ }
25
39
 
26
40
  /**
27
- * The Y component.
28
- * @type {number}
29
- * @default 0.0
41
+ * Creates a Cartesian2 instance from x and y coordinates.
42
+ *
43
+ * @param {number} x The x coordinate.
44
+ * @param {number} y The y coordinate.
45
+ * @param {Cartesian2} [result] The object onto which to store the result.
46
+ * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
30
47
  */
31
- this.y = y ?? 0.0;
32
- }
48
+ static fromElements(x, y, result) {
49
+ if (!defined(result)) {
50
+ return new Cartesian2(x, y);
51
+ }
52
+
53
+ result.x = x;
54
+ result.y = y;
55
+ return result;
56
+ }
33
57
 
34
- /**
35
- * Creates a Cartesian2 instance from x and y coordinates.
36
- *
37
- * @param {number} x The x coordinate.
38
- * @param {number} y The y coordinate.
39
- * @param {Cartesian2} [result] The object onto which to store the result.
40
- * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
41
- */
42
- Cartesian2.fromElements = function (x, y, result) {
43
- if (!defined(result)) {
44
- return new Cartesian2(x, y);
58
+ /**
59
+ * Duplicates a Cartesian2 instance.
60
+ *
61
+ * @param {Cartesian2} cartesian The Cartesian to duplicate.
62
+ * @param {Cartesian2} [result] The object onto which to store the result.
63
+ * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. (Returns undefined if cartesian is undefined)
64
+ */
65
+ static clone(cartesian, result) {
66
+ if (!defined(cartesian)) {
67
+ return undefined;
68
+ }
69
+ if (!defined(result)) {
70
+ return new Cartesian2(cartesian.x, cartesian.y);
71
+ }
72
+
73
+ result.x = cartesian.x;
74
+ result.y = cartesian.y;
75
+ return result;
45
76
  }
46
77
 
47
- result.x = x;
48
- result.y = y;
49
- return result;
50
- };
78
+ /**
79
+ * Stores the provided instance into the provided array.
80
+ *
81
+ * @param {Cartesian2} value The value to pack.
82
+ * @param {number[]|TypedArray} array The array to pack into.
83
+ * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
84
+ *
85
+ * @returns {number[]|TypedArray} The array that was packed into
86
+ */
87
+ static pack(value, array, startingIndex) {
88
+ //>>includeStart('debug', pragmas.debug);
89
+ Check.typeOf.object("value", value);
90
+ Check.defined("array", array);
91
+ //>>includeEnd('debug');
51
92
 
52
- /**
53
- * Duplicates a Cartesian2 instance.
54
- *
55
- * @param {Cartesian2} cartesian The Cartesian to duplicate.
56
- * @param {Cartesian2} [result] The object onto which to store the result.
57
- * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. (Returns undefined if cartesian is undefined)
58
- */
59
- Cartesian2.clone = function (cartesian, result) {
60
- if (!defined(cartesian)) {
61
- return undefined;
93
+ startingIndex = startingIndex ?? 0;
94
+
95
+ array[startingIndex++] = value.x;
96
+ array[startingIndex] = value.y;
97
+
98
+ return array;
62
99
  }
63
- if (!defined(result)) {
64
- return new Cartesian2(cartesian.x, cartesian.y);
100
+
101
+ /**
102
+ * Retrieves an instance from a packed array.
103
+ *
104
+ * @param {number[]|TypedArray} array The packed array.
105
+ * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
106
+ * @param {Cartesian2} [result] The object into which to store the result.
107
+ * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
108
+ */
109
+ static unpack(array, startingIndex, result) {
110
+ //>>includeStart('debug', pragmas.debug);
111
+ Check.defined("array", array);
112
+ //>>includeEnd('debug');
113
+
114
+ startingIndex = startingIndex ?? 0;
115
+
116
+ if (!defined(result)) {
117
+ result = new Cartesian2();
118
+ }
119
+ result.x = array[startingIndex++];
120
+ result.y = array[startingIndex];
121
+ return result;
65
122
  }
66
123
 
67
- result.x = cartesian.x;
68
- result.y = cartesian.y;
69
- return result;
70
- };
124
+ /**
125
+ * Flattens an array of Cartesian2s into an array of components.
126
+ *
127
+ * @param {Cartesian2[]} array The array of cartesians to pack.
128
+ * @param {number[]|TypedArray} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 2 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 2) elements.
129
+ * @returns {number[]|TypedArray} The packed array.
130
+ */
131
+ static packArray(array, result) {
132
+ //>>includeStart('debug', pragmas.debug);
133
+ Check.defined("array", array);
134
+ //>>includeEnd('debug');
71
135
 
72
- /**
73
- * Creates a Cartesian2 instance from an existing Cartesian3. This simply takes the
74
- * x and y properties of the Cartesian3 and drops z.
75
- * @function
76
- *
77
- * @param {Cartesian3} cartesian The Cartesian3 instance to create a Cartesian2 instance from.
78
- * @param {Cartesian2} [result] The object onto which to store the result.
79
- * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
80
- */
81
- Cartesian2.fromCartesian3 = Cartesian2.clone;
136
+ const length = array.length;
137
+ const resultLength = length * 2;
138
+ if (!defined(result)) {
139
+ result = new Array(resultLength);
140
+ } else if (!Array.isArray(result) && result.length !== resultLength) {
141
+ //>>includeStart('debug', pragmas.debug);
142
+ throw new DeveloperError(
143
+ "If result is a typed array, it must have exactly array.length * 2 elements",
144
+ );
145
+ //>>includeEnd('debug');
146
+ } else if (result.length !== resultLength) {
147
+ /** @type {number[]} */ (result).length = resultLength;
148
+ }
149
+
150
+ for (let i = 0; i < length; ++i) {
151
+ Cartesian2.pack(array[i], result, i * 2);
152
+ }
153
+ return result;
154
+ }
82
155
 
83
- /**
84
- * Creates a Cartesian2 instance from an existing Cartesian4. This simply takes the
85
- * x and y properties of the Cartesian4 and drops z and w.
86
- * @function
87
- *
88
- * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian2 instance from.
89
- * @param {Cartesian2} [result] The object onto which to store the result.
90
- * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
91
- */
92
- Cartesian2.fromCartesian4 = Cartesian2.clone;
156
+ /**
157
+ * Unpacks an array of cartesian components into an array of Cartesian2s.
158
+ *
159
+ * @param {number[]} array The array of components to unpack.
160
+ * @param {Cartesian2[]} [result] The array onto which to store the result.
161
+ * @returns {Cartesian2[]} The unpacked array.
162
+ */
163
+ static unpackArray(array, result) {
164
+ //>>includeStart('debug', pragmas.debug);
165
+ Check.defined("array", array);
166
+ Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 2);
167
+ if (array.length % 2 !== 0) {
168
+ throw new DeveloperError("array length must be a multiple of 2.");
169
+ }
170
+ //>>includeEnd('debug');
93
171
 
94
- /**
95
- * The number of elements used to pack the object into an array.
96
- * @type {number}
97
- */
98
- Cartesian2.packedLength = 2;
172
+ const length = array.length;
173
+ if (!defined(result)) {
174
+ result = new Array(length / 2);
175
+ } else {
176
+ result.length = length / 2;
177
+ }
178
+
179
+ for (let i = 0; i < length; i += 2) {
180
+ const index = i / 2;
181
+ result[index] = Cartesian2.unpack(array, i, result[index]);
182
+ }
183
+ return result;
184
+ }
99
185
 
100
- /**
101
- * Stores the provided instance into the provided array.
102
- *
103
- * @param {Cartesian2} value The value to pack.
104
- * @param {number[]} array The array to pack into.
105
- * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
106
- *
107
- * @returns {number[]} The array that was packed into
108
- */
109
- Cartesian2.pack = function (value, array, startingIndex) {
110
- //>>includeStart('debug', pragmas.debug);
111
- Check.typeOf.object("value", value);
112
- Check.defined("array", array);
113
- //>>includeEnd('debug');
186
+ /**
187
+ * Computes the value of the maximum component for the supplied Cartesian.
188
+ *
189
+ * @param {Cartesian2} cartesian The cartesian to use.
190
+ * @returns {number} The value of the maximum component.
191
+ */
192
+ static maximumComponent(cartesian) {
193
+ //>>includeStart('debug', pragmas.debug);
194
+ Check.typeOf.object("cartesian", cartesian);
195
+ //>>includeEnd('debug');
114
196
 
115
- startingIndex = startingIndex ?? 0;
197
+ return Math.max(cartesian.x, cartesian.y);
198
+ }
116
199
 
117
- array[startingIndex++] = value.x;
118
- array[startingIndex] = value.y;
200
+ /**
201
+ * Computes the value of the minimum component for the supplied Cartesian.
202
+ *
203
+ * @param {Cartesian2} cartesian The cartesian to use.
204
+ * @returns {number} The value of the minimum component.
205
+ */
206
+ static minimumComponent(cartesian) {
207
+ //>>includeStart('debug', pragmas.debug);
208
+ Check.typeOf.object("cartesian", cartesian);
209
+ //>>includeEnd('debug');
119
210
 
120
- return array;
121
- };
211
+ return Math.min(cartesian.x, cartesian.y);
212
+ }
122
213
 
123
- /**
124
- * Retrieves an instance from a packed array.
125
- *
126
- * @param {number[]} array The packed array.
127
- * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
128
- * @param {Cartesian2} [result] The object into which to store the result.
129
- * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
130
- */
131
- Cartesian2.unpack = function (array, startingIndex, result) {
132
- //>>includeStart('debug', pragmas.debug);
133
- Check.defined("array", array);
134
- //>>includeEnd('debug');
214
+ /**
215
+ * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
216
+ *
217
+ * @param {Cartesian2} first A cartesian to compare.
218
+ * @param {Cartesian2} second A cartesian to compare.
219
+ * @param {Cartesian2} result The object into which to store the result.
220
+ * @returns {Cartesian2} A cartesian with the minimum components.
221
+ */
222
+ static minimumByComponent(first, second, result) {
223
+ //>>includeStart('debug', pragmas.debug);
224
+ Check.typeOf.object("first", first);
225
+ Check.typeOf.object("second", second);
226
+ Check.typeOf.object("result", result);
227
+ //>>includeEnd('debug');
135
228
 
136
- startingIndex = startingIndex ?? 0;
229
+ result.x = Math.min(first.x, second.x);
230
+ result.y = Math.min(first.y, second.y);
137
231
 
138
- if (!defined(result)) {
139
- result = new Cartesian2();
232
+ return result;
140
233
  }
141
- result.x = array[startingIndex++];
142
- result.y = array[startingIndex];
143
- return result;
144
- };
145
234
 
146
- /**
147
- * Flattens an array of Cartesian2s into an array of components.
148
- *
149
- * @param {Cartesian2[]} array The array of cartesians to pack.
150
- * @param {number[]} [result] The array onto which to store the result. If this is a typed array, it must have array.length * 2 components, else a {@link DeveloperError} will be thrown. If it is a regular array, it will be resized to have (array.length * 2) elements.
151
- * @returns {number[]} The packed array.
152
- */
153
- Cartesian2.packArray = function (array, result) {
154
- //>>includeStart('debug', pragmas.debug);
155
- Check.defined("array", array);
156
- //>>includeEnd('debug');
157
-
158
- const length = array.length;
159
- const resultLength = length * 2;
160
- if (!defined(result)) {
161
- result = new Array(resultLength);
162
- } else if (!Array.isArray(result) && result.length !== resultLength) {
235
+ /**
236
+ * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
237
+ *
238
+ * @param {Cartesian2} first A cartesian to compare.
239
+ * @param {Cartesian2} second A cartesian to compare.
240
+ * @param {Cartesian2} result The object into which to store the result.
241
+ * @returns {Cartesian2} A cartesian with the maximum components.
242
+ */
243
+ static maximumByComponent(first, second, result) {
163
244
  //>>includeStart('debug', pragmas.debug);
164
- throw new DeveloperError(
165
- "If result is a typed array, it must have exactly array.length * 2 elements",
166
- );
245
+ Check.typeOf.object("first", first);
246
+ Check.typeOf.object("second", second);
247
+ Check.typeOf.object("result", result);
167
248
  //>>includeEnd('debug');
168
- } else if (result.length !== resultLength) {
169
- result.length = resultLength;
249
+
250
+ result.x = Math.max(first.x, second.x);
251
+ result.y = Math.max(first.y, second.y);
252
+ return result;
170
253
  }
171
254
 
172
- for (let i = 0; i < length; ++i) {
173
- Cartesian2.pack(array[i], result, i * 2);
255
+ /**
256
+ * Constrain a value to lie between two values.
257
+ *
258
+ * @param {Cartesian2} value The value to clamp.
259
+ * @param {Cartesian2} min The minimum bound.
260
+ * @param {Cartesian2} max The maximum bound.
261
+ * @param {Cartesian2} result The object into which to store the result.
262
+ * @returns {Cartesian2} The clamped value such that min <= result <= max.
263
+ */
264
+ static clamp(value, min, max, result) {
265
+ //>>includeStart('debug', pragmas.debug);
266
+ Check.typeOf.object("value", value);
267
+ Check.typeOf.object("min", min);
268
+ Check.typeOf.object("max", max);
269
+ Check.typeOf.object("result", result);
270
+ //>>includeEnd('debug');
271
+
272
+ const x = CesiumMath.clamp(value.x, min.x, max.x);
273
+ const y = CesiumMath.clamp(value.y, min.y, max.y);
274
+
275
+ result.x = x;
276
+ result.y = y;
277
+
278
+ return result;
174
279
  }
175
- return result;
176
- };
177
280
 
178
- /**
179
- * Unpacks an array of cartesian components into an array of Cartesian2s.
180
- *
181
- * @param {number[]} array The array of components to unpack.
182
- * @param {Cartesian2[]} [result] The array onto which to store the result.
183
- * @returns {Cartesian2[]} The unpacked array.
184
- */
185
- Cartesian2.unpackArray = function (array, result) {
186
- //>>includeStart('debug', pragmas.debug);
187
- Check.defined("array", array);
188
- Check.typeOf.number.greaterThanOrEquals("array.length", array.length, 2);
189
- if (array.length % 2 !== 0) {
190
- throw new DeveloperError("array length must be a multiple of 2.");
281
+ /**
282
+ * Computes the provided Cartesian's squared magnitude.
283
+ *
284
+ * @param {Cartesian2} cartesian The Cartesian instance whose squared magnitude is to be computed.
285
+ * @returns {number} The squared magnitude.
286
+ */
287
+ static magnitudeSquared(cartesian) {
288
+ //>>includeStart('debug', pragmas.debug);
289
+ Check.typeOf.object("cartesian", cartesian);
290
+ //>>includeEnd('debug');
291
+
292
+ return cartesian.x * cartesian.x + cartesian.y * cartesian.y;
191
293
  }
192
- //>>includeEnd('debug');
193
294
 
194
- const length = array.length;
195
- if (!defined(result)) {
196
- result = new Array(length / 2);
197
- } else {
198
- result.length = length / 2;
295
+ /**
296
+ * Computes the Cartesian's magnitude (length).
297
+ *
298
+ * @param {Cartesian2} cartesian The Cartesian instance whose magnitude is to be computed.
299
+ * @returns {number} The magnitude.
300
+ */
301
+ static magnitude(cartesian) {
302
+ return Math.sqrt(Cartesian2.magnitudeSquared(cartesian));
199
303
  }
200
304
 
201
- for (let i = 0; i < length; i += 2) {
202
- const index = i / 2;
203
- result[index] = Cartesian2.unpack(array, i, result[index]);
305
+ /**
306
+ * Computes the distance between two points.
307
+ *
308
+ * @param {Cartesian2} left The first point to compute the distance from.
309
+ * @param {Cartesian2} right The second point to compute the distance to.
310
+ * @returns {number} The distance between two points.
311
+ *
312
+ * @example
313
+ * // Returns 1.0
314
+ * const d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(2.0, 0.0));
315
+ */
316
+ static distance(left, right) {
317
+ //>>includeStart('debug', pragmas.debug);
318
+ Check.typeOf.object("left", left);
319
+ Check.typeOf.object("right", right);
320
+ //>>includeEnd('debug');
321
+
322
+ Cartesian2.subtract(left, right, distanceScratch);
323
+ return Cartesian2.magnitude(distanceScratch);
204
324
  }
205
- return result;
206
- };
207
325
 
208
- /**
209
- * Creates a Cartesian2 from two consecutive elements in an array.
210
- * @function
211
- *
212
- * @param {number[]} array The array whose two consecutive elements correspond to the x and y components, respectively.
213
- * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
214
- * @param {Cartesian2} [result] The object onto which to store the result.
215
- * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
216
- *
217
- * @example
218
- * // Create a Cartesian2 with (1.0, 2.0)
219
- * const v = [1.0, 2.0];
220
- * const p = Cesium.Cartesian2.fromArray(v);
221
- *
222
- * // Create a Cartesian2 with (1.0, 2.0) using an offset into an array
223
- * const v2 = [0.0, 0.0, 1.0, 2.0];
224
- * const p2 = Cesium.Cartesian2.fromArray(v2, 2);
225
- */
226
- Cartesian2.fromArray = Cartesian2.unpack;
326
+ /**
327
+ * Computes the squared distance between two points. Comparing squared distances
328
+ * using this function is more efficient than comparing distances using {@link Cartesian2#distance}.
329
+ *
330
+ * @param {Cartesian2} left The first point to compute the distance from.
331
+ * @param {Cartesian2} right The second point to compute the distance to.
332
+ * @returns {number} The distance between two points.
333
+ *
334
+ * @example
335
+ * // Returns 4.0, not 2.0
336
+ * const d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(3.0, 0.0));
337
+ */
338
+ static distanceSquared(left, right) {
339
+ //>>includeStart('debug', pragmas.debug);
340
+ Check.typeOf.object("left", left);
341
+ Check.typeOf.object("right", right);
342
+ //>>includeEnd('debug');
227
343
 
228
- /**
229
- * Computes the value of the maximum component for the supplied Cartesian.
230
- *
231
- * @param {Cartesian2} cartesian The cartesian to use.
232
- * @returns {number} The value of the maximum component.
233
- */
234
- Cartesian2.maximumComponent = function (cartesian) {
235
- //>>includeStart('debug', pragmas.debug);
236
- Check.typeOf.object("cartesian", cartesian);
237
- //>>includeEnd('debug');
344
+ Cartesian2.subtract(left, right, distanceScratch);
345
+ return Cartesian2.magnitudeSquared(distanceScratch);
346
+ }
238
347
 
239
- return Math.max(cartesian.x, cartesian.y);
240
- };
348
+ /**
349
+ * Computes the normalized form of the supplied Cartesian.
350
+ *
351
+ * @param {Cartesian2} cartesian The Cartesian to be normalized.
352
+ * @param {Cartesian2} result The object onto which to store the result.
353
+ * @returns {Cartesian2} The modified result parameter.
354
+ */
355
+ static normalize(cartesian, result) {
356
+ //>>includeStart('debug', pragmas.debug);
357
+ Check.typeOf.object("cartesian", cartesian);
358
+ Check.typeOf.object("result", result);
359
+ //>>includeEnd('debug');
241
360
 
242
- /**
243
- * Computes the value of the minimum component for the supplied Cartesian.
244
- *
245
- * @param {Cartesian2} cartesian The cartesian to use.
246
- * @returns {number} The value of the minimum component.
247
- */
248
- Cartesian2.minimumComponent = function (cartesian) {
249
- //>>includeStart('debug', pragmas.debug);
250
- Check.typeOf.object("cartesian", cartesian);
251
- //>>includeEnd('debug');
361
+ const magnitude = Cartesian2.magnitude(cartesian);
252
362
 
253
- return Math.min(cartesian.x, cartesian.y);
254
- };
363
+ result.x = cartesian.x / magnitude;
364
+ result.y = cartesian.y / magnitude;
255
365
 
256
- /**
257
- * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
258
- *
259
- * @param {Cartesian2} first A cartesian to compare.
260
- * @param {Cartesian2} second A cartesian to compare.
261
- * @param {Cartesian2} result The object into which to store the result.
262
- * @returns {Cartesian2} A cartesian with the minimum components.
263
- */
264
- Cartesian2.minimumByComponent = function (first, second, result) {
265
- //>>includeStart('debug', pragmas.debug);
266
- Check.typeOf.object("first", first);
267
- Check.typeOf.object("second", second);
268
- Check.typeOf.object("result", result);
269
- //>>includeEnd('debug');
366
+ //>>includeStart('debug', pragmas.debug);
367
+ if (isNaN(result.x) || isNaN(result.y)) {
368
+ throw new DeveloperError("normalized result is not a number");
369
+ }
370
+ //>>includeEnd('debug');
270
371
 
271
- result.x = Math.min(first.x, second.x);
272
- result.y = Math.min(first.y, second.y);
372
+ return result;
373
+ }
273
374
 
274
- return result;
275
- };
375
+ /**
376
+ * Computes the dot (scalar) product of two Cartesians.
377
+ *
378
+ * @param {Cartesian2} left The first Cartesian.
379
+ * @param {Cartesian2} right The second Cartesian.
380
+ * @returns {number} The dot product.
381
+ */
382
+ static dot(left, right) {
383
+ //>>includeStart('debug', pragmas.debug);
384
+ Check.typeOf.object("left", left);
385
+ Check.typeOf.object("right", right);
386
+ //>>includeEnd('debug');
276
387
 
277
- /**
278
- * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
279
- *
280
- * @param {Cartesian2} first A cartesian to compare.
281
- * @param {Cartesian2} second A cartesian to compare.
282
- * @param {Cartesian2} result The object into which to store the result.
283
- * @returns {Cartesian2} A cartesian with the maximum components.
284
- */
285
- Cartesian2.maximumByComponent = function (first, second, result) {
286
- //>>includeStart('debug', pragmas.debug);
287
- Check.typeOf.object("first", first);
288
- Check.typeOf.object("second", second);
289
- Check.typeOf.object("result", result);
290
- //>>includeEnd('debug');
291
-
292
- result.x = Math.max(first.x, second.x);
293
- result.y = Math.max(first.y, second.y);
294
- return result;
295
- };
388
+ return left.x * right.x + left.y * right.y;
389
+ }
296
390
 
297
- /**
298
- * Constrain a value to lie between two values.
299
- *
300
- * @param {Cartesian2} value The value to clamp.
301
- * @param {Cartesian2} min The minimum bound.
302
- * @param {Cartesian2} max The maximum bound.
303
- * @param {Cartesian2} result The object into which to store the result.
304
- * @returns {Cartesian2} The clamped value such that min <= result <= max.
305
- */
306
- Cartesian2.clamp = function (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');
391
+ /**
392
+ * Computes the magnitude of the cross product that would result from implicitly setting the Z coordinate of the input vectors to 0
393
+ *
394
+ * @param {Cartesian2} left The first Cartesian.
395
+ * @param {Cartesian2} right The second Cartesian.
396
+ * @returns {number} The cross product.
397
+ */
398
+ static cross(left, right) {
399
+ //>>includeStart('debug', pragmas.debug);
400
+ Check.typeOf.object("left", left);
401
+ Check.typeOf.object("right", right);
402
+ //>>includeEnd('debug');
313
403
 
314
- const x = CesiumMath.clamp(value.x, min.x, max.x);
315
- const y = CesiumMath.clamp(value.y, min.y, max.y);
404
+ return left.x * right.y - left.y * right.x;
405
+ }
316
406
 
317
- result.x = x;
318
- result.y = y;
407
+ /**
408
+ * Computes the componentwise product of two Cartesians.
409
+ *
410
+ * @param {Cartesian2} left The first Cartesian.
411
+ * @param {Cartesian2} right The second Cartesian.
412
+ * @param {Cartesian2} result The object onto which to store the result.
413
+ * @returns {Cartesian2} The modified result parameter.
414
+ */
415
+ static multiplyComponents(left, right, result) {
416
+ //>>includeStart('debug', pragmas.debug);
417
+ Check.typeOf.object("left", left);
418
+ Check.typeOf.object("right", right);
419
+ Check.typeOf.object("result", result);
420
+ //>>includeEnd('debug');
319
421
 
320
- return result;
321
- };
422
+ result.x = left.x * right.x;
423
+ result.y = left.y * right.y;
424
+ return result;
425
+ }
322
426
 
323
- /**
324
- * Computes the provided Cartesian's squared magnitude.
325
- *
326
- * @param {Cartesian2} cartesian The Cartesian instance whose squared magnitude is to be computed.
327
- * @returns {number} The squared magnitude.
328
- */
329
- Cartesian2.magnitudeSquared = function (cartesian) {
330
- //>>includeStart('debug', pragmas.debug);
331
- Check.typeOf.object("cartesian", cartesian);
332
- //>>includeEnd('debug');
427
+ /**
428
+ * Computes the componentwise quotient of two Cartesians.
429
+ *
430
+ * @param {Cartesian2} left The first Cartesian.
431
+ * @param {Cartesian2} right The second Cartesian.
432
+ * @param {Cartesian2} result The object onto which to store the result.
433
+ * @returns {Cartesian2} The modified result parameter.
434
+ */
435
+ static divideComponents(left, right, result) {
436
+ //>>includeStart('debug', pragmas.debug);
437
+ Check.typeOf.object("left", left);
438
+ Check.typeOf.object("right", right);
439
+ Check.typeOf.object("result", result);
440
+ //>>includeEnd('debug');
333
441
 
334
- return cartesian.x * cartesian.x + cartesian.y * cartesian.y;
335
- };
442
+ result.x = left.x / right.x;
443
+ result.y = left.y / right.y;
444
+ return result;
445
+ }
336
446
 
337
- /**
338
- * Computes the Cartesian's magnitude (length).
339
- *
340
- * @param {Cartesian2} cartesian The Cartesian instance whose magnitude is to be computed.
341
- * @returns {number} The magnitude.
342
- */
343
- Cartesian2.magnitude = function (cartesian) {
344
- return Math.sqrt(Cartesian2.magnitudeSquared(cartesian));
345
- };
447
+ /**
448
+ * Computes the componentwise sum of two Cartesians.
449
+ *
450
+ * @param {Cartesian2} left The first Cartesian.
451
+ * @param {Cartesian2} right The second Cartesian.
452
+ * @param {Cartesian2} result The object onto which to store the result.
453
+ * @returns {Cartesian2} The modified result parameter.
454
+ */
455
+ static add(left, right, result) {
456
+ //>>includeStart('debug', pragmas.debug);
457
+ Check.typeOf.object("left", left);
458
+ Check.typeOf.object("right", right);
459
+ Check.typeOf.object("result", result);
460
+ //>>includeEnd('debug');
346
461
 
347
- const distanceScratch = new Cartesian2();
462
+ result.x = left.x + right.x;
463
+ result.y = left.y + right.y;
464
+ return result;
465
+ }
348
466
 
349
- /**
350
- * Computes the distance between two points.
351
- *
352
- * @param {Cartesian2} left The first point to compute the distance from.
353
- * @param {Cartesian2} right The second point to compute the distance to.
354
- * @returns {number} The distance between two points.
355
- *
356
- * @example
357
- * // Returns 1.0
358
- * const d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(2.0, 0.0));
359
- */
360
- Cartesian2.distance = function (left, right) {
361
- //>>includeStart('debug', pragmas.debug);
362
- Check.typeOf.object("left", left);
363
- Check.typeOf.object("right", right);
364
- //>>includeEnd('debug');
467
+ /**
468
+ * Computes the componentwise difference of two Cartesians.
469
+ *
470
+ * @param {Cartesian2} left The first Cartesian.
471
+ * @param {Cartesian2} right The second Cartesian.
472
+ * @param {Cartesian2} result The object onto which to store the result.
473
+ * @returns {Cartesian2} The modified result parameter.
474
+ */
475
+ static subtract(left, right, result) {
476
+ //>>includeStart('debug', pragmas.debug);
477
+ Check.typeOf.object("left", left);
478
+ Check.typeOf.object("right", right);
479
+ Check.typeOf.object("result", result);
480
+ //>>includeEnd('debug');
365
481
 
366
- Cartesian2.subtract(left, right, distanceScratch);
367
- return Cartesian2.magnitude(distanceScratch);
368
- };
482
+ result.x = left.x - right.x;
483
+ result.y = left.y - right.y;
484
+ return result;
485
+ }
369
486
 
370
- /**
371
- * Computes the squared distance between two points. Comparing squared distances
372
- * using this function is more efficient than comparing distances using {@link Cartesian2#distance}.
373
- *
374
- * @param {Cartesian2} left The first point to compute the distance from.
375
- * @param {Cartesian2} right The second point to compute the distance to.
376
- * @returns {number} The distance between two points.
377
- *
378
- * @example
379
- * // Returns 4.0, not 2.0
380
- * const d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(3.0, 0.0));
381
- */
382
- Cartesian2.distanceSquared = function (left, right) {
383
- //>>includeStart('debug', pragmas.debug);
384
- Check.typeOf.object("left", left);
385
- Check.typeOf.object("right", right);
386
- //>>includeEnd('debug');
487
+ /**
488
+ * Multiplies the provided Cartesian componentwise by the provided scalar.
489
+ *
490
+ * @param {Cartesian2} cartesian The Cartesian to be scaled.
491
+ * @param {number} scalar The scalar to multiply with.
492
+ * @param {Cartesian2} result The object onto which to store the result.
493
+ * @returns {Cartesian2} The modified result parameter.
494
+ */
495
+ static multiplyByScalar(cartesian, scalar, result) {
496
+ //>>includeStart('debug', pragmas.debug);
497
+ Check.typeOf.object("cartesian", cartesian);
498
+ Check.typeOf.number("scalar", scalar);
499
+ Check.typeOf.object("result", result);
500
+ //>>includeEnd('debug');
387
501
 
388
- Cartesian2.subtract(left, right, distanceScratch);
389
- return Cartesian2.magnitudeSquared(distanceScratch);
390
- };
502
+ result.x = cartesian.x * scalar;
503
+ result.y = cartesian.y * scalar;
504
+ return result;
505
+ }
391
506
 
392
- /**
393
- * Computes the normalized form of the supplied Cartesian.
394
- *
395
- * @param {Cartesian2} cartesian The Cartesian to be normalized.
396
- * @param {Cartesian2} result The object onto which to store the result.
397
- * @returns {Cartesian2} The modified result parameter.
398
- */
399
- Cartesian2.normalize = function (cartesian, result) {
400
- //>>includeStart('debug', pragmas.debug);
401
- Check.typeOf.object("cartesian", cartesian);
402
- Check.typeOf.object("result", result);
403
- //>>includeEnd('debug');
507
+ /**
508
+ * Divides the provided Cartesian componentwise by the provided scalar.
509
+ *
510
+ * @param {Cartesian2} cartesian The Cartesian to be divided.
511
+ * @param {number} scalar The scalar to divide by.
512
+ * @param {Cartesian2} result The object onto which to store the result.
513
+ * @returns {Cartesian2} The modified result parameter.
514
+ */
515
+ static divideByScalar(cartesian, scalar, result) {
516
+ //>>includeStart('debug', pragmas.debug);
517
+ Check.typeOf.object("cartesian", cartesian);
518
+ Check.typeOf.number("scalar", scalar);
519
+ Check.typeOf.object("result", result);
520
+ //>>includeEnd('debug');
404
521
 
405
- const magnitude = Cartesian2.magnitude(cartesian);
522
+ result.x = cartesian.x / scalar;
523
+ result.y = cartesian.y / scalar;
524
+ return result;
525
+ }
406
526
 
407
- result.x = cartesian.x / magnitude;
408
- result.y = cartesian.y / magnitude;
527
+ /**
528
+ * Negates the provided Cartesian.
529
+ *
530
+ * @param {Cartesian2} cartesian The Cartesian to be negated.
531
+ * @param {Cartesian2} result The object onto which to store the result.
532
+ * @returns {Cartesian2} The modified result parameter.
533
+ */
534
+ static negate(cartesian, result) {
535
+ //>>includeStart('debug', pragmas.debug);
536
+ Check.typeOf.object("cartesian", cartesian);
537
+ Check.typeOf.object("result", result);
538
+ //>>includeEnd('debug');
409
539
 
410
- //>>includeStart('debug', pragmas.debug);
411
- if (isNaN(result.x) || isNaN(result.y)) {
412
- throw new DeveloperError("normalized result is not a number");
540
+ result.x = -cartesian.x;
541
+ result.y = -cartesian.y;
542
+ return result;
413
543
  }
414
- //>>includeEnd('debug');
415
544
 
416
- return result;
417
- };
545
+ /**
546
+ * Computes the absolute value of the provided Cartesian.
547
+ *
548
+ * @param {Cartesian2} cartesian The Cartesian whose absolute value is to be computed.
549
+ * @param {Cartesian2} result The object onto which to store the result.
550
+ * @returns {Cartesian2} The modified result parameter.
551
+ */
552
+ static abs(cartesian, result) {
553
+ //>>includeStart('debug', pragmas.debug);
554
+ Check.typeOf.object("cartesian", cartesian);
555
+ Check.typeOf.object("result", result);
556
+ //>>includeEnd('debug');
418
557
 
419
- /**
420
- * Computes the dot (scalar) product of two Cartesians.
421
- *
422
- * @param {Cartesian2} left The first Cartesian.
423
- * @param {Cartesian2} right The second Cartesian.
424
- * @returns {number} The dot product.
425
- */
426
- Cartesian2.dot = function (left, right) {
427
- //>>includeStart('debug', pragmas.debug);
428
- Check.typeOf.object("left", left);
429
- Check.typeOf.object("right", right);
430
- //>>includeEnd('debug');
558
+ result.x = Math.abs(cartesian.x);
559
+ result.y = Math.abs(cartesian.y);
560
+ return result;
561
+ }
431
562
 
432
- return left.x * right.x + left.y * right.y;
433
- };
563
+ /**
564
+ * Computes the linear interpolation or extrapolation at t using the provided cartesians.
565
+ *
566
+ * @param {Cartesian2} start The value corresponding to t at 0.0.
567
+ * @param {Cartesian2} end The value corresponding to t at 1.0.
568
+ * @param {number} t The point along t at which to interpolate.
569
+ * @param {Cartesian2} result The object onto which to store the result.
570
+ * @returns {Cartesian2} The modified result parameter.
571
+ */
572
+ static lerp(start, end, t, result) {
573
+ //>>includeStart('debug', pragmas.debug);
574
+ Check.typeOf.object("start", start);
575
+ Check.typeOf.object("end", end);
576
+ Check.typeOf.number("t", t);
577
+ Check.typeOf.object("result", result);
578
+ //>>includeEnd('debug');
434
579
 
435
- /**
436
- * Computes the magnitude of the cross product that would result from implicitly setting the Z coordinate of the input vectors to 0
437
- *
438
- * @param {Cartesian2} left The first Cartesian.
439
- * @param {Cartesian2} right The second Cartesian.
440
- * @returns {number} The cross product.
441
- */
442
- Cartesian2.cross = function (left, right) {
443
- //>>includeStart('debug', pragmas.debug);
444
- Check.typeOf.object("left", left);
445
- Check.typeOf.object("right", right);
446
- //>>includeEnd('debug');
580
+ Cartesian2.multiplyByScalar(end, t, lerpScratch);
581
+ result = Cartesian2.multiplyByScalar(start, 1.0 - t, result);
582
+ return Cartesian2.add(lerpScratch, result, result);
583
+ }
447
584
 
448
- return left.x * right.y - left.y * right.x;
449
- };
585
+ /**
586
+ * Returns the angle, in radians, between the provided Cartesians.
587
+ *
588
+ * @param {Cartesian2} left The first Cartesian.
589
+ * @param {Cartesian2} right The second Cartesian.
590
+ * @returns {number} The angle between the Cartesians.
591
+ */
592
+ static angleBetween(left, right) {
593
+ //>>includeStart('debug', pragmas.debug);
594
+ Check.typeOf.object("left", left);
595
+ Check.typeOf.object("right", right);
596
+ //>>includeEnd('debug');
450
597
 
451
- /**
452
- * Computes the componentwise product of two Cartesians.
453
- *
454
- * @param {Cartesian2} left The first Cartesian.
455
- * @param {Cartesian2} right The second Cartesian.
456
- * @param {Cartesian2} result The object onto which to store the result.
457
- * @returns {Cartesian2} The modified result parameter.
458
- */
459
- Cartesian2.multiplyComponents = function (left, right, result) {
460
- //>>includeStart('debug', pragmas.debug);
461
- Check.typeOf.object("left", left);
462
- Check.typeOf.object("right", right);
463
- Check.typeOf.object("result", result);
464
- //>>includeEnd('debug');
465
-
466
- result.x = left.x * right.x;
467
- result.y = left.y * right.y;
468
- return result;
469
- };
598
+ Cartesian2.normalize(left, angleBetweenScratch);
599
+ Cartesian2.normalize(right, angleBetweenScratch2);
600
+ return CesiumMath.acosClamped(
601
+ Cartesian2.dot(angleBetweenScratch, angleBetweenScratch2),
602
+ );
603
+ }
470
604
 
471
- /**
472
- * Computes the componentwise quotient of two Cartesians.
473
- *
474
- * @param {Cartesian2} left The first Cartesian.
475
- * @param {Cartesian2} right The second Cartesian.
476
- * @param {Cartesian2} result The object onto which to store the result.
477
- * @returns {Cartesian2} The modified result parameter.
478
- */
479
- Cartesian2.divideComponents = function (left, right, result) {
480
- //>>includeStart('debug', pragmas.debug);
481
- Check.typeOf.object("left", left);
482
- Check.typeOf.object("right", right);
483
- Check.typeOf.object("result", result);
484
- //>>includeEnd('debug');
485
-
486
- result.x = left.x / right.x;
487
- result.y = left.y / right.y;
488
- return result;
489
- };
605
+ /**
606
+ * Returns the axis that is most orthogonal to the provided Cartesian.
607
+ *
608
+ * @param {Cartesian2} cartesian The Cartesian on which to find the most orthogonal axis.
609
+ * @param {Cartesian2} result The object onto which to store the result.
610
+ * @returns {Cartesian2} The most orthogonal axis.
611
+ */
612
+ static mostOrthogonalAxis(cartesian, result) {
613
+ //>>includeStart('debug', pragmas.debug);
614
+ Check.typeOf.object("cartesian", cartesian);
615
+ Check.typeOf.object("result", result);
616
+ //>>includeEnd('debug');
490
617
 
491
- /**
492
- * Computes the componentwise sum of two Cartesians.
493
- *
494
- * @param {Cartesian2} left The first Cartesian.
495
- * @param {Cartesian2} right The second Cartesian.
496
- * @param {Cartesian2} result The object onto which to store the result.
497
- * @returns {Cartesian2} The modified result parameter.
498
- */
499
- Cartesian2.add = function (left, right, result) {
500
- //>>includeStart('debug', pragmas.debug);
501
- Check.typeOf.object("left", left);
502
- Check.typeOf.object("right", right);
503
- Check.typeOf.object("result", result);
504
- //>>includeEnd('debug');
505
-
506
- result.x = left.x + right.x;
507
- result.y = left.y + right.y;
508
- return result;
509
- };
618
+ const f = Cartesian2.normalize(cartesian, mostOrthogonalAxisScratch);
619
+ Cartesian2.abs(f, f);
510
620
 
511
- /**
512
- * Computes the componentwise difference of two Cartesians.
513
- *
514
- * @param {Cartesian2} left The first Cartesian.
515
- * @param {Cartesian2} right The second Cartesian.
516
- * @param {Cartesian2} result The object onto which to store the result.
517
- * @returns {Cartesian2} The modified result parameter.
518
- */
519
- Cartesian2.subtract = function (left, right, result) {
520
- //>>includeStart('debug', pragmas.debug);
521
- Check.typeOf.object("left", left);
522
- Check.typeOf.object("right", right);
523
- Check.typeOf.object("result", result);
524
- //>>includeEnd('debug');
525
-
526
- result.x = left.x - right.x;
527
- result.y = left.y - right.y;
528
- return result;
529
- };
621
+ if (f.x <= f.y) {
622
+ result = Cartesian2.clone(Cartesian2.UNIT_X, result);
623
+ } else {
624
+ result = Cartesian2.clone(Cartesian2.UNIT_Y, result);
625
+ }
530
626
 
531
- /**
532
- * Multiplies the provided Cartesian componentwise by the provided scalar.
533
- *
534
- * @param {Cartesian2} cartesian The Cartesian to be scaled.
535
- * @param {number} scalar The scalar to multiply with.
536
- * @param {Cartesian2} result The object onto which to store the result.
537
- * @returns {Cartesian2} The modified result parameter.
538
- */
539
- Cartesian2.multiplyByScalar = function (cartesian, scalar, result) {
540
- //>>includeStart('debug', pragmas.debug);
541
- Check.typeOf.object("cartesian", cartesian);
542
- Check.typeOf.number("scalar", scalar);
543
- Check.typeOf.object("result", result);
544
- //>>includeEnd('debug');
545
-
546
- result.x = cartesian.x * scalar;
547
- result.y = cartesian.y * scalar;
548
- return result;
549
- };
627
+ return result;
628
+ }
550
629
 
551
- /**
552
- * Divides the provided Cartesian componentwise by the provided scalar.
553
- *
554
- * @param {Cartesian2} cartesian The Cartesian to be divided.
555
- * @param {number} scalar The scalar to divide by.
556
- * @param {Cartesian2} result The object onto which to store the result.
557
- * @returns {Cartesian2} The modified result parameter.
558
- */
559
- Cartesian2.divideByScalar = function (cartesian, scalar, result) {
560
- //>>includeStart('debug', pragmas.debug);
561
- Check.typeOf.object("cartesian", cartesian);
562
- Check.typeOf.number("scalar", scalar);
563
- Check.typeOf.object("result", result);
564
- //>>includeEnd('debug');
565
-
566
- result.x = cartesian.x / scalar;
567
- result.y = cartesian.y / scalar;
568
- return result;
569
- };
630
+ /**
631
+ * Compares the provided Cartesians componentwise and returns
632
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
633
+ *
634
+ * @param {Cartesian2} [left] The first Cartesian.
635
+ * @param {Cartesian2} [right] The second Cartesian.
636
+ * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
637
+ */
638
+ static equals(left, right) {
639
+ return (
640
+ left === right ||
641
+ (defined(left) &&
642
+ defined(right) &&
643
+ left.x === right.x &&
644
+ left.y === right.y)
645
+ );
646
+ }
570
647
 
571
- /**
572
- * Negates the provided Cartesian.
573
- *
574
- * @param {Cartesian2} cartesian The Cartesian to be negated.
575
- * @param {Cartesian2} result The object onto which to store the result.
576
- * @returns {Cartesian2} The modified result parameter.
577
- */
578
- Cartesian2.negate = function (cartesian, result) {
579
- //>>includeStart('debug', pragmas.debug);
580
- Check.typeOf.object("cartesian", cartesian);
581
- Check.typeOf.object("result", result);
582
- //>>includeEnd('debug');
648
+ /**
649
+ * @param {Cartesian2} cartesian
650
+ * @param {number[]} array
651
+ * @param {number} offset
652
+ * @private
653
+ */
654
+ static equalsArray(cartesian, array, offset) {
655
+ return cartesian.x === array[offset] && cartesian.y === array[offset + 1];
656
+ }
583
657
 
584
- result.x = -cartesian.x;
585
- result.y = -cartesian.y;
586
- return result;
587
- };
658
+ /**
659
+ * Compares the provided Cartesians componentwise and returns
660
+ * <code>true</code> if they pass an absolute or relative tolerance test,
661
+ * <code>false</code> otherwise.
662
+ *
663
+ * @param {Cartesian2} [left] The first Cartesian.
664
+ * @param {Cartesian2} [right] The second Cartesian.
665
+ * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
666
+ * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
667
+ * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
668
+ */
669
+ static equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon) {
670
+ return (
671
+ left === right ||
672
+ (defined(left) &&
673
+ defined(right) &&
674
+ CesiumMath.equalsEpsilon(
675
+ left.x,
676
+ right.x,
677
+ relativeEpsilon,
678
+ absoluteEpsilon,
679
+ ) &&
680
+ CesiumMath.equalsEpsilon(
681
+ left.y,
682
+ right.y,
683
+ relativeEpsilon,
684
+ absoluteEpsilon,
685
+ ))
686
+ );
687
+ }
588
688
 
589
- /**
590
- * Computes the absolute value of the provided Cartesian.
591
- *
592
- * @param {Cartesian2} cartesian The Cartesian whose absolute value is to be computed.
593
- * @param {Cartesian2} result The object onto which to store the result.
594
- * @returns {Cartesian2} The modified result parameter.
595
- */
596
- Cartesian2.abs = function (cartesian, result) {
597
- //>>includeStart('debug', pragmas.debug);
598
- Check.typeOf.object("cartesian", cartesian);
599
- Check.typeOf.object("result", result);
600
- //>>includeEnd('debug');
689
+ /**
690
+ * Duplicates this Cartesian2 instance.
691
+ *
692
+ * @param {Cartesian2} [result] The object onto which to store the result.
693
+ * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
694
+ */
695
+ clone(result) {
696
+ return Cartesian2.clone(this, result);
697
+ }
601
698
 
602
- result.x = Math.abs(cartesian.x);
603
- result.y = Math.abs(cartesian.y);
604
- return result;
605
- };
699
+ /**
700
+ * Compares this Cartesian against the provided Cartesian componentwise and returns
701
+ * <code>true</code> if they are equal, <code>false</code> otherwise.
702
+ *
703
+ * @param {Cartesian2} [right] The right hand side Cartesian.
704
+ * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
705
+ */
706
+ equals(right) {
707
+ return Cartesian2.equals(this, right);
708
+ }
606
709
 
607
- const lerpScratch = new Cartesian2();
608
- /**
609
- * Computes the linear interpolation or extrapolation at t using the provided cartesians.
610
- *
611
- * @param {Cartesian2} start The value corresponding to t at 0.0.
612
- * @param {Cartesian2} end The value corresponding to t at 1.0.
613
- * @param {number} t The point along t at which to interpolate.
614
- * @param {Cartesian2} result The object onto which to store the result.
615
- * @returns {Cartesian2} The modified result parameter.
616
- */
617
- Cartesian2.lerp = function (start, end, t, result) {
618
- //>>includeStart('debug', pragmas.debug);
619
- Check.typeOf.object("start", start);
620
- Check.typeOf.object("end", end);
621
- Check.typeOf.number("t", t);
622
- Check.typeOf.object("result", result);
623
- //>>includeEnd('debug');
624
-
625
- Cartesian2.multiplyByScalar(end, t, lerpScratch);
626
- result = Cartesian2.multiplyByScalar(start, 1.0 - t, result);
627
- return Cartesian2.add(lerpScratch, result, result);
628
- };
710
+ /**
711
+ * Compares this Cartesian against the provided Cartesian componentwise and returns
712
+ * <code>true</code> if they pass an absolute or relative tolerance test,
713
+ * <code>false</code> otherwise.
714
+ *
715
+ * @param {Cartesian2} [right] The right hand side Cartesian.
716
+ * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
717
+ * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
718
+ * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
719
+ */
720
+ equalsEpsilon(right, relativeEpsilon, absoluteEpsilon) {
721
+ return Cartesian2.equalsEpsilon(
722
+ this,
723
+ right,
724
+ relativeEpsilon,
725
+ absoluteEpsilon,
726
+ );
727
+ }
629
728
 
630
- const angleBetweenScratch = new Cartesian2();
631
- const angleBetweenScratch2 = new Cartesian2();
632
- /**
633
- * Returns the angle, in radians, between the provided Cartesians.
634
- *
635
- * @param {Cartesian2} left The first Cartesian.
636
- * @param {Cartesian2} right The second Cartesian.
637
- * @returns {number} The angle between the Cartesians.
638
- */
639
- Cartesian2.angleBetween = function (left, right) {
640
- //>>includeStart('debug', pragmas.debug);
641
- Check.typeOf.object("left", left);
642
- Check.typeOf.object("right", right);
643
- //>>includeEnd('debug');
644
-
645
- Cartesian2.normalize(left, angleBetweenScratch);
646
- Cartesian2.normalize(right, angleBetweenScratch2);
647
- return CesiumMath.acosClamped(
648
- Cartesian2.dot(angleBetweenScratch, angleBetweenScratch2),
649
- );
650
- };
729
+ /**
730
+ * Creates a string representing this Cartesian in the format '(x, y)'.
731
+ *
732
+ * @returns {string} A string representing the provided Cartesian in the format '(x, y)'.
733
+ */
734
+ toString() {
735
+ return `(${this.x}, ${this.y})`;
736
+ }
737
+ }
651
738
 
652
- const mostOrthogonalAxisScratch = new Cartesian2();
653
739
  /**
654
- * Returns the axis that is most orthogonal to the provided Cartesian.
740
+ * Creates a Cartesian2 instance from an existing Cartesian3. This simply takes the
741
+ * x and y properties of the Cartesian3 and drops z.
742
+ * @function
655
743
  *
656
- * @param {Cartesian2} cartesian The Cartesian on which to find the most orthogonal axis.
657
- * @param {Cartesian2} result The object onto which to store the result.
658
- * @returns {Cartesian2} The most orthogonal axis.
744
+ * @param {Cartesian3} cartesian The Cartesian3 instance to create a Cartesian2 instance from.
745
+ * @param {Cartesian2} [result] The object onto which to store the result.
746
+ * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
659
747
  */
660
- Cartesian2.mostOrthogonalAxis = function (cartesian, result) {
661
- //>>includeStart('debug', pragmas.debug);
662
- Check.typeOf.object("cartesian", cartesian);
663
- Check.typeOf.object("result", result);
664
- //>>includeEnd('debug');
665
-
666
- const f = Cartesian2.normalize(cartesian, mostOrthogonalAxisScratch);
667
- Cartesian2.abs(f, f);
668
-
669
- if (f.x <= f.y) {
670
- result = Cartesian2.clone(Cartesian2.UNIT_X, result);
671
- } else {
672
- result = Cartesian2.clone(Cartesian2.UNIT_Y, result);
673
- }
674
-
675
- return result;
676
- };
748
+ Cartesian2.fromCartesian3 = Cartesian2.clone;
677
749
 
678
750
  /**
679
- * Compares the provided Cartesians componentwise and returns
680
- * <code>true</code> if they are equal, <code>false</code> otherwise.
751
+ * Creates a Cartesian2 instance from an existing Cartesian4. This simply takes the
752
+ * x and y properties of the Cartesian4 and drops z and w.
753
+ * @function
681
754
  *
682
- * @param {Cartesian2} [left] The first Cartesian.
683
- * @param {Cartesian2} [right] The second Cartesian.
684
- * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
755
+ * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian2 instance from.
756
+ * @param {Cartesian2} [result] The object onto which to store the result.
757
+ * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
685
758
  */
686
- Cartesian2.equals = function (left, right) {
687
- return (
688
- left === right ||
689
- (defined(left) &&
690
- defined(right) &&
691
- left.x === right.x &&
692
- left.y === right.y)
693
- );
694
- };
759
+ Cartesian2.fromCartesian4 = Cartesian2.clone;
695
760
 
696
761
  /**
697
- * @private
762
+ * The number of elements used to pack the object into an array.
763
+ * @type {number}
698
764
  */
699
- Cartesian2.equalsArray = function (cartesian, array, offset) {
700
- return cartesian.x === array[offset] && cartesian.y === array[offset + 1];
701
- };
765
+ Cartesian2.packedLength = 2;
702
766
 
703
767
  /**
704
- * Compares the provided Cartesians componentwise and returns
705
- * <code>true</code> if they pass an absolute or relative tolerance test,
706
- * <code>false</code> otherwise.
768
+ * Creates a Cartesian2 from two consecutive elements in an array.
769
+ * @function
707
770
  *
708
- * @param {Cartesian2} [left] The first Cartesian.
709
- * @param {Cartesian2} [right] The second Cartesian.
710
- * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
711
- * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
712
- * @returns {boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
771
+ * @param {number[]} array The array whose two consecutive elements correspond to the x and y components, respectively.
772
+ * @param {number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
773
+ * @param {Cartesian2} [result] The object onto which to store the result.
774
+ * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
775
+ *
776
+ * @example
777
+ * // Create a Cartesian2 with (1.0, 2.0)
778
+ * const v = [1.0, 2.0];
779
+ * const p = Cesium.Cartesian2.fromArray(v);
780
+ *
781
+ * // Create a Cartesian2 with (1.0, 2.0) using an offset into an array
782
+ * const v2 = [0.0, 0.0, 1.0, 2.0];
783
+ * const p2 = Cesium.Cartesian2.fromArray(v2, 2);
713
784
  */
714
- Cartesian2.equalsEpsilon = function (
715
- left,
716
- right,
717
- relativeEpsilon,
718
- absoluteEpsilon,
719
- ) {
720
- return (
721
- left === right ||
722
- (defined(left) &&
723
- defined(right) &&
724
- CesiumMath.equalsEpsilon(
725
- left.x,
726
- right.x,
727
- relativeEpsilon,
728
- absoluteEpsilon,
729
- ) &&
730
- CesiumMath.equalsEpsilon(
731
- left.y,
732
- right.y,
733
- relativeEpsilon,
734
- absoluteEpsilon,
735
- ))
736
- );
737
- };
785
+ Cartesian2.fromArray = Cartesian2.unpack;
786
+
787
+ const distanceScratch = new Cartesian2();
788
+
789
+ const lerpScratch = new Cartesian2();
790
+
791
+ const angleBetweenScratch = new Cartesian2();
792
+ const angleBetweenScratch2 = new Cartesian2();
793
+
794
+ const mostOrthogonalAxisScratch = new Cartesian2();
738
795
 
739
796
  /**
740
797
  * An immutable Cartesian2 instance initialized to (0.0, 0.0).
@@ -768,56 +825,4 @@ Cartesian2.UNIT_X = Object.freeze(new Cartesian2(1.0, 0.0));
768
825
  */
769
826
  Cartesian2.UNIT_Y = Object.freeze(new Cartesian2(0.0, 1.0));
770
827
 
771
- /**
772
- * Duplicates this Cartesian2 instance.
773
- *
774
- * @param {Cartesian2} [result] The object onto which to store the result.
775
- * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
776
- */
777
- Cartesian2.prototype.clone = function (result) {
778
- return Cartesian2.clone(this, result);
779
- };
780
-
781
- /**
782
- * Compares this Cartesian against the provided Cartesian componentwise and returns
783
- * <code>true</code> if they are equal, <code>false</code> otherwise.
784
- *
785
- * @param {Cartesian2} [right] The right hand side Cartesian.
786
- * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
787
- */
788
- Cartesian2.prototype.equals = function (right) {
789
- return Cartesian2.equals(this, right);
790
- };
791
-
792
- /**
793
- * Compares this Cartesian against the provided Cartesian componentwise and returns
794
- * <code>true</code> if they pass an absolute or relative tolerance test,
795
- * <code>false</code> otherwise.
796
- *
797
- * @param {Cartesian2} [right] The right hand side Cartesian.
798
- * @param {number} [relativeEpsilon=0] The relative epsilon tolerance to use for equality testing.
799
- * @param {number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
800
- * @returns {boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
801
- */
802
- Cartesian2.prototype.equalsEpsilon = function (
803
- right,
804
- relativeEpsilon,
805
- absoluteEpsilon,
806
- ) {
807
- return Cartesian2.equalsEpsilon(
808
- this,
809
- right,
810
- relativeEpsilon,
811
- absoluteEpsilon,
812
- );
813
- };
814
-
815
- /**
816
- * Creates a string representing this Cartesian in the format '(x, y)'.
817
- *
818
- * @returns {string} A string representing the provided Cartesian in the format '(x, y)'.
819
- */
820
- Cartesian2.prototype.toString = function () {
821
- return `(${this.x}, ${this.y})`;
822
- };
823
828
  export default Cartesian2;