Newer
Older
XinYang_SanWei+RongYun / public / static / Cesium / Workers / Cartesian2-16a61632.js
@raoxianxuan raoxianxuan on 21 Dec 2021 93 KB gis
  1. /**
  2. * Cesium - https://github.com/CesiumGS/cesium
  3. *
  4. * Copyright 2011-2020 Cesium Contributors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Columbus View (Pat. Pend.)
  19. *
  20. * Portions licensed separately.
  21. * See https://github.com/CesiumGS/cesium/blob/master/LICENSE.md for full licensing details.
  22. */
  23. define(['exports', './when-8d13db60', './Check-70bec281', './Math-61ede240', './Cartographic-f2a06374'], function (exports, when, Check, _Math, Cartographic) { 'use strict';
  24.  
  25. function initialize(ellipsoid, x, y, z) {
  26. x = when.defaultValue(x, 0.0);
  27. y = when.defaultValue(y, 0.0);
  28. z = when.defaultValue(z, 0.0);
  29.  
  30. //>>includeStart('debug', pragmas.debug);
  31. Check.Check.typeOf.number.greaterThanOrEquals('x', x, 0.0);
  32. Check.Check.typeOf.number.greaterThanOrEquals('y', y, 0.0);
  33. Check.Check.typeOf.number.greaterThanOrEquals('z', z, 0.0);
  34. //>>includeEnd('debug');
  35.  
  36. if(_Math.CesiumMath.equalsEpsilon(z, 6356752.3142451793, _Math.CesiumMath.EPSILON10)){
  37. _Math.CesiumMath.Radius = z;
  38. }
  39.  
  40. ellipsoid._radii = new Cartographic.Cartesian3(x, y, z);
  41.  
  42. ellipsoid._radiiSquared = new Cartographic.Cartesian3(x * x,
  43. y * y,
  44. z * z);
  45.  
  46. ellipsoid._radiiToTheFourth = new Cartographic.Cartesian3(x * x * x * x,
  47. y * y * y * y,
  48. z * z * z * z);
  49.  
  50. ellipsoid._oneOverRadii = new Cartographic.Cartesian3(x === 0.0 ? 0.0 : 1.0 / x,
  51. y === 0.0 ? 0.0 : 1.0 / y,
  52. z === 0.0 ? 0.0 : 1.0 / z);
  53.  
  54. ellipsoid._oneOverRadiiSquared = new Cartographic.Cartesian3(x === 0.0 ? 0.0 : 1.0 / (x * x),
  55. y === 0.0 ? 0.0 : 1.0 / (y * y),
  56. z === 0.0 ? 0.0 : 1.0 / (z * z));
  57.  
  58. ellipsoid._minimumRadius = Math.min(x, y, z);
  59.  
  60. ellipsoid._maximumRadius = Math.max(x, y, z);
  61.  
  62. ellipsoid._centerToleranceSquared = _Math.CesiumMath.EPSILON1;
  63.  
  64. if (ellipsoid._radiiSquared.z !== 0) {
  65. ellipsoid._squaredXOverSquaredZ = ellipsoid._radiiSquared.x / ellipsoid._radiiSquared.z;
  66. }
  67. }
  68.  
  69. /**
  70. * A quadratic surface defined in Cartesian coordinates by the equation
  71. * <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used
  72. * by Cesium to represent the shape of planetary bodies.
  73. *
  74. * Rather than constructing this object directly, one of the provided
  75. * constants is normally used.
  76. * @alias Ellipsoid
  77. * @constructor
  78. *
  79. * @param {Number} [x=0] The radius in the x direction.
  80. * @param {Number} [y=0] The radius in the y direction.
  81. * @param {Number} [z=0] The radius in the z direction.
  82. *
  83. * @exception {DeveloperError} All radii components must be greater than or equal to zero.
  84. *
  85. * @see Ellipsoid.fromCartesian3
  86. * @see Ellipsoid.WGS84
  87. * @see Ellipsoid.UNIT_SPHERE
  88. */
  89. function Ellipsoid(x, y, z) {
  90. this._radii = undefined;
  91. this._radiiSquared = undefined;
  92. this._radiiToTheFourth = undefined;
  93. this._oneOverRadii = undefined;
  94. this._oneOverRadiiSquared = undefined;
  95. this._minimumRadius = undefined;
  96. this._maximumRadius = undefined;
  97. this._centerToleranceSquared = undefined;
  98. this._squaredXOverSquaredZ = undefined;
  99.  
  100. initialize(this, x, y, z);
  101. }
  102.  
  103. Object.defineProperties(Ellipsoid.prototype, {
  104. /**
  105. * Gets the radii of the ellipsoid.
  106. * @memberof Ellipsoid.prototype
  107. * @type {Cartesian3}
  108. * @readonly
  109. */
  110. radii : {
  111. get: function() {
  112. return this._radii;
  113. }
  114. },
  115. /**
  116. * Gets the squared radii of the ellipsoid.
  117. * @memberof Ellipsoid.prototype
  118. * @type {Cartesian3}
  119. * @readonly
  120. */
  121. radiiSquared : {
  122. get : function() {
  123. return this._radiiSquared;
  124. }
  125. },
  126. /**
  127. * Gets the radii of the ellipsoid raise to the fourth power.
  128. * @memberof Ellipsoid.prototype
  129. * @type {Cartesian3}
  130. * @readonly
  131. */
  132. radiiToTheFourth : {
  133. get : function() {
  134. return this._radiiToTheFourth;
  135. }
  136. },
  137. /**
  138. * Gets one over the radii of the ellipsoid.
  139. * @memberof Ellipsoid.prototype
  140. * @type {Cartesian3}
  141. * @readonly
  142. */
  143. oneOverRadii : {
  144. get : function() {
  145. return this._oneOverRadii;
  146. }
  147. },
  148. /**
  149. * Gets one over the squared radii of the ellipsoid.
  150. * @memberof Ellipsoid.prototype
  151. * @type {Cartesian3}
  152. * @readonly
  153. */
  154. oneOverRadiiSquared : {
  155. get : function() {
  156. return this._oneOverRadiiSquared;
  157. }
  158. },
  159. /**
  160. * Gets the minimum radius of the ellipsoid.
  161. * @memberof Ellipsoid.prototype
  162. * @type {Number}
  163. * @readonly
  164. */
  165. minimumRadius : {
  166. get : function() {
  167. return this._minimumRadius;
  168. }
  169. },
  170. /**
  171. * Gets the maximum radius of the ellipsoid.
  172. * @memberof Ellipsoid.prototype
  173. * @type {Number}
  174. * @readonly
  175. */
  176. maximumRadius : {
  177. get : function() {
  178. return this._maximumRadius;
  179. }
  180. }
  181. });
  182.  
  183. /**
  184. * Duplicates an Ellipsoid instance.
  185. *
  186. * @param {Ellipsoid} ellipsoid The ellipsoid to duplicate.
  187. * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
  188. * instance should be created.
  189. * @returns {Ellipsoid} The cloned Ellipsoid. (Returns undefined if ellipsoid is undefined)
  190. */
  191. Ellipsoid.clone = function(ellipsoid, result) {
  192. if (!when.defined(ellipsoid)) {
  193. return undefined;
  194. }
  195. var radii = ellipsoid._radii;
  196.  
  197. if (!when.defined(result)) {
  198. return new Ellipsoid(radii.x, radii.y, radii.z);
  199. }
  200.  
  201. Cartographic.Cartesian3.clone(radii, result._radii);
  202. Cartographic.Cartesian3.clone(ellipsoid._radiiSquared, result._radiiSquared);
  203. Cartographic.Cartesian3.clone(ellipsoid._radiiToTheFourth, result._radiiToTheFourth);
  204. Cartographic.Cartesian3.clone(ellipsoid._oneOverRadii, result._oneOverRadii);
  205. Cartographic.Cartesian3.clone(ellipsoid._oneOverRadiiSquared, result._oneOverRadiiSquared);
  206. result._minimumRadius = ellipsoid._minimumRadius;
  207. result._maximumRadius = ellipsoid._maximumRadius;
  208. result._centerToleranceSquared = ellipsoid._centerToleranceSquared;
  209.  
  210. return result;
  211. };
  212.  
  213. /**
  214. * Computes an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.
  215. *
  216. * @param {Cartesian3} [cartesian=Cartesian3.ZERO] The ellipsoid's radius in the x, y, and z directions.
  217. * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
  218. * instance should be created.
  219. * @returns {Ellipsoid} A new Ellipsoid instance.
  220. *
  221. * @exception {DeveloperError} All radii components must be greater than or equal to zero.
  222. *
  223. * @see Ellipsoid.WGS84
  224. * @see Ellipsoid.UNIT_SPHERE
  225. */
  226. Ellipsoid.fromCartesian3 = function(cartesian, result) {
  227. if (!when.defined(result)) {
  228. result = new Ellipsoid();
  229. }
  230.  
  231. if (!when.defined(cartesian)) {
  232. return result;
  233. }
  234.  
  235. initialize(result, cartesian.x, cartesian.y, cartesian.z);
  236. return result;
  237. };
  238.  
  239. /**
  240. * An Ellipsoid instance initialized to the WGS84 standard.
  241. *
  242. * @type {Ellipsoid}
  243. * @constant
  244. */
  245. Ellipsoid.WGS84 = Object.freeze(new Ellipsoid(6378137.0, 6378137.0, _Math.CesiumMath.Radius));
  246.  
  247. Ellipsoid.XIAN80 = Object.freeze(new Ellipsoid(6378140.0, 6378140.0, 6356755.29));
  248.  
  249. Ellipsoid.CGCS2000 = Object.freeze(new Ellipsoid(6378137.0, 6378137.0, 6356752.31));
  250.  
  251. /**
  252. * An Ellipsoid instance initialized to radii of (1.0, 1.0, 1.0).
  253. *
  254. * @type {Ellipsoid}
  255. * @constant
  256. */
  257. Ellipsoid.UNIT_SPHERE = Object.freeze(new Ellipsoid(1.0, 1.0, 1.0));
  258.  
  259. /**
  260. * An Ellipsoid instance initialized to a sphere with the lunar radius.
  261. *
  262. * @type {Ellipsoid}
  263. * @constant
  264. */
  265. Ellipsoid.MOON = Object.freeze(new Ellipsoid(_Math.CesiumMath.LUNAR_RADIUS, _Math.CesiumMath.LUNAR_RADIUS, _Math.CesiumMath.LUNAR_RADIUS));
  266.  
  267. /**
  268. * Duplicates an Ellipsoid instance.
  269. *
  270. * @param {Ellipsoid} [result] The object onto which to store the result, or undefined if a new
  271. * instance should be created.
  272. * @returns {Ellipsoid} The cloned Ellipsoid.
  273. */
  274. Ellipsoid.prototype.clone = function(result) {
  275. return Ellipsoid.clone(this, result);
  276. };
  277.  
  278. /**
  279. * The number of elements used to pack the object into an array.
  280. * @type {Number}
  281. */
  282. Ellipsoid.packedLength = Cartographic.Cartesian3.packedLength;
  283.  
  284. /**
  285. * Stores the provided instance into the provided array.
  286. *
  287. * @param {Ellipsoid} value The value to pack.
  288. * @param {Number[]} array The array to pack into.
  289. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  290. *
  291. * @returns {Number[]} The array that was packed into
  292. */
  293. Ellipsoid.pack = function(value, array, startingIndex) {
  294. //>>includeStart('debug', pragmas.debug);
  295. Check.Check.typeOf.object('value', value);
  296. Check.Check.defined('array', array);
  297. //>>includeEnd('debug');
  298.  
  299. startingIndex = when.defaultValue(startingIndex, 0);
  300.  
  301. Cartographic.Cartesian3.pack(value._radii, array, startingIndex);
  302.  
  303. return array;
  304. };
  305.  
  306. /**
  307. * Retrieves an instance from a packed array.
  308. *
  309. * @param {Number[]} array The packed array.
  310. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  311. * @param {Ellipsoid} [result] The object into which to store the result.
  312. * @returns {Ellipsoid} The modified result parameter or a new Ellipsoid instance if one was not provided.
  313. */
  314. Ellipsoid.unpack = function(array, startingIndex, result) {
  315. //>>includeStart('debug', pragmas.debug);
  316. Check.Check.defined('array', array);
  317. //>>includeEnd('debug');
  318.  
  319. startingIndex = when.defaultValue(startingIndex, 0);
  320.  
  321. var radii = Cartographic.Cartesian3.unpack(array, startingIndex);
  322. return Ellipsoid.fromCartesian3(radii, result);
  323. };
  324.  
  325. /**
  326. * Computes the unit vector directed from the center of this ellipsoid toward the provided Cartesian position.
  327. * @function
  328. *
  329. * @param {Cartesian3} cartesian The Cartesian for which to to determine the geocentric normal.
  330. * @param {Cartesian3} [result] The object onto which to store the result.
  331. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  332. */
  333. Ellipsoid.prototype.geocentricSurfaceNormal = Cartographic.Cartesian3.normalize;
  334.  
  335. /**
  336. * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
  337. *
  338. * @param {Cartographic} cartographic The cartographic position for which to to determine the geodetic normal.
  339. * @param {Cartesian3} [result] The object onto which to store the result.
  340. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  341. */
  342. Ellipsoid.prototype.geodeticSurfaceNormalCartographic = function(cartographic, result) {
  343. //>>includeStart('debug', pragmas.debug);
  344. Check.Check.typeOf.object('cartographic', cartographic);
  345. //>>includeEnd('debug');
  346.  
  347. var longitude = cartographic.longitude;
  348. var latitude = cartographic.latitude;
  349. var cosLatitude = Math.cos(latitude);
  350.  
  351. var x = cosLatitude * Math.cos(longitude);
  352. var y = cosLatitude * Math.sin(longitude);
  353. var z = Math.sin(latitude);
  354.  
  355. if (!when.defined(result)) {
  356. result = new Cartographic.Cartesian3();
  357. }
  358. result.x = x;
  359. result.y = y;
  360. result.z = z;
  361. return Cartographic.Cartesian3.normalize(result, result);
  362. };
  363.  
  364. /**
  365. * Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.
  366. *
  367. * @param {Cartesian3} cartesian The Cartesian position for which to to determine the surface normal.
  368. * @param {Cartesian3} [result] The object onto which to store the result.
  369. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  370. */
  371. Ellipsoid.prototype.geodeticSurfaceNormal = function(cartesian, result) {
  372. if (!when.defined(result)) {
  373. result = new Cartographic.Cartesian3();
  374. }
  375. result = Cartographic.Cartesian3.multiplyComponents(cartesian, this._oneOverRadiiSquared, result);
  376. return Cartographic.Cartesian3.normalize(result, result);
  377. };
  378.  
  379. var cartographicToCartesianNormal = new Cartographic.Cartesian3();
  380. var cartographicToCartesianK = new Cartographic.Cartesian3();
  381.  
  382. /**
  383. * Converts the provided cartographic to Cartesian representation.
  384. *
  385. * @param {Cartographic} cartographic The cartographic position.
  386. * @param {Cartesian3} [result] The object onto which to store the result.
  387. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  388. *
  389. * @example
  390. * //Create a Cartographic and determine it's Cartesian representation on a WGS84 ellipsoid.
  391. * var position = new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 5000);
  392. * var cartesianPosition = Cesium.Ellipsoid.WGS84.cartographicToCartesian(position);
  393. */
  394. Ellipsoid.prototype.cartographicToCartesian = function(cartographic, result) {
  395. //`cartographic is required` is thrown from geodeticSurfaceNormalCartographic.
  396. var n = cartographicToCartesianNormal;
  397. var k = cartographicToCartesianK;
  398. this.geodeticSurfaceNormalCartographic(cartographic, n);
  399. Cartographic.Cartesian3.multiplyComponents(this._radiiSquared, n, k);
  400. var gamma = Math.sqrt(Cartographic.Cartesian3.dot(n, k));
  401. Cartographic.Cartesian3.divideByScalar(k, gamma, k);
  402. Cartographic.Cartesian3.multiplyByScalar(n, cartographic.height, n);
  403.  
  404. if (!when.defined(result)) {
  405. result = new Cartographic.Cartesian3();
  406. }
  407. return Cartographic.Cartesian3.add(k, n, result);
  408. };
  409.  
  410. /**
  411. * Converts the provided array of cartographics to an array of Cartesians.
  412. *
  413. * @param {Cartographic[]} cartographics An array of cartographic positions.
  414. * @param {Cartesian3[]} [result] The object onto which to store the result.
  415. * @returns {Cartesian3[]} The modified result parameter or a new Array instance if none was provided.
  416. *
  417. * @example
  418. * //Convert an array of Cartographics and determine their Cartesian representation on a WGS84 ellipsoid.
  419. * var positions = [new Cesium.Cartographic(Cesium.Math.toRadians(21), Cesium.Math.toRadians(78), 0),
  420. * new Cesium.Cartographic(Cesium.Math.toRadians(21.321), Cesium.Math.toRadians(78.123), 100),
  421. * new Cesium.Cartographic(Cesium.Math.toRadians(21.645), Cesium.Math.toRadians(78.456), 250)];
  422. * var cartesianPositions = Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray(positions);
  423. */
  424. Ellipsoid.prototype.cartographicArrayToCartesianArray = function(cartographics, result) {
  425. //>>includeStart('debug', pragmas.debug);
  426. Check.Check.defined('cartographics', cartographics);
  427. //>>includeEnd('debug')
  428.  
  429. var length = cartographics.length;
  430. if (!when.defined(result)) {
  431. result = new Array(length);
  432. } else {
  433. result.length = length;
  434. }
  435. for ( var i = 0; i < length; i++) {
  436. result[i] = this.cartographicToCartesian(cartographics[i], result[i]);
  437. }
  438. return result;
  439. };
  440.  
  441. var cartesianToCartographicN = new Cartographic.Cartesian3();
  442. var cartesianToCartographicP = new Cartographic.Cartesian3();
  443. var cartesianToCartographicH = new Cartographic.Cartesian3();
  444.  
  445. /**
  446. * Converts the provided cartesian to cartographic representation.
  447. * The cartesian is undefined at the center of the ellipsoid.
  448. *
  449. * @param {Cartesian3} cartesian The Cartesian position to convert to cartographic representation.
  450. * @param {Cartographic} [result] The object onto which to store the result.
  451. * @returns {Cartographic} The modified result parameter, new Cartographic instance if none was provided, or undefined if the cartesian is at the center of the ellipsoid.
  452. *
  453. * @example
  454. * //Create a Cartesian and determine it's Cartographic representation on a WGS84 ellipsoid.
  455. * var position = new Cesium.Cartesian3(17832.12, 83234.52, 952313.73);
  456. * var cartographicPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
  457. */
  458. Ellipsoid.prototype.cartesianToCartographic = function(cartesian, result) {
  459. //`cartesian is required.` is thrown from scaleToGeodeticSurface
  460. var p = this.scaleToGeodeticSurface(cartesian, cartesianToCartographicP);
  461.  
  462. if (!when.defined(p)) {
  463. return undefined;
  464. }
  465.  
  466. var n = this.geodeticSurfaceNormal(p, cartesianToCartographicN);
  467. var h = Cartographic.Cartesian3.subtract(cartesian, p, cartesianToCartographicH);
  468.  
  469. var longitude = Math.atan2(n.y, n.x);
  470. var latitude = Math.asin(n.z);
  471. var height = _Math.CesiumMath.sign(Cartographic.Cartesian3.dot(h, cartesian)) * Cartographic.Cartesian3.magnitude(h);
  472.  
  473. if (!when.defined(result)) {
  474. return new Cartographic.Cartographic(longitude, latitude, height);
  475. }
  476. result.longitude = longitude;
  477. result.latitude = latitude;
  478. result.height = height;
  479. return result;
  480. };
  481.  
  482. /**
  483. * Converts the provided array of cartesians to an array of cartographics.
  484. *
  485. * @param {Cartesian3[]} cartesians An array of Cartesian positions.
  486. * @param {Cartographic[]} [result] The object onto which to store the result.
  487. * @returns {Cartographic[]} The modified result parameter or a new Array instance if none was provided.
  488. *
  489. * @example
  490. * //Create an array of Cartesians and determine their Cartographic representation on a WGS84 ellipsoid.
  491. * var positions = [new Cesium.Cartesian3(17832.12, 83234.52, 952313.73),
  492. * new Cesium.Cartesian3(17832.13, 83234.53, 952313.73),
  493. * new Cesium.Cartesian3(17832.14, 83234.54, 952313.73)]
  494. * var cartographicPositions = Cesium.Ellipsoid.WGS84.cartesianArrayToCartographicArray(positions);
  495. */
  496. Ellipsoid.prototype.cartesianArrayToCartographicArray = function(cartesians, result) {
  497. //>>includeStart('debug', pragmas.debug);
  498. Check.Check.defined('cartesians', cartesians);
  499. //>>includeEnd('debug');
  500.  
  501. var length = cartesians.length;
  502. if (!when.defined(result)) {
  503. result = new Array(length);
  504. } else {
  505. result.length = length;
  506. }
  507. for ( var i = 0; i < length; ++i) {
  508. result[i] = this.cartesianToCartographic(cartesians[i], result[i]);
  509. }
  510. return result;
  511. };
  512.  
  513. /**
  514. * Scales the provided Cartesian position along the geodetic surface normal
  515. * so that it is on the surface of this ellipsoid. If the position is
  516. * at the center of the ellipsoid, this function returns undefined.
  517. *
  518. * @param {Cartesian3} cartesian The Cartesian position to scale.
  519. * @param {Cartesian3} [result] The object onto which to store the result.
  520. * @returns {Cartesian3} The modified result parameter, a new Cartesian3 instance if none was provided, or undefined if the position is at the center.
  521. */
  522. Ellipsoid.prototype.scaleToGeodeticSurface = function(cartesian, result) {
  523. return Cartographic.scaleToGeodeticSurface(cartesian, this._oneOverRadii, this._oneOverRadiiSquared, this._centerToleranceSquared, result);
  524. };
  525.  
  526. /**
  527. * Scales the provided Cartesian position along the geocentric surface normal
  528. * so that it is on the surface of this ellipsoid.
  529. *
  530. * @param {Cartesian3} cartesian The Cartesian position to scale.
  531. * @param {Cartesian3} [result] The object onto which to store the result.
  532. * @returns {Cartesian3} The modified result parameter or a new Cartesian3 instance if none was provided.
  533. */
  534. Ellipsoid.prototype.scaleToGeocentricSurface = function(cartesian, result) {
  535. //>>includeStart('debug', pragmas.debug);
  536. Check.Check.typeOf.object('cartesian', cartesian);
  537. //>>includeEnd('debug');
  538.  
  539. if (!when.defined(result)) {
  540. result = new Cartographic.Cartesian3();
  541. }
  542.  
  543. var positionX = cartesian.x;
  544. var positionY = cartesian.y;
  545. var positionZ = cartesian.z;
  546. var oneOverRadiiSquared = this._oneOverRadiiSquared;
  547.  
  548. var beta = 1.0 / Math.sqrt((positionX * positionX) * oneOverRadiiSquared.x +
  549. (positionY * positionY) * oneOverRadiiSquared.y +
  550. (positionZ * positionZ) * oneOverRadiiSquared.z);
  551.  
  552. return Cartographic.Cartesian3.multiplyByScalar(cartesian, beta, result);
  553. };
  554.  
  555. /**
  556. * Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
  557. * its components by the result of {@link Ellipsoid#oneOverRadii}.
  558. *
  559. * @param {Cartesian3} position The position to transform.
  560. * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
  561. * return a new instance.
  562. * @returns {Cartesian3} The position expressed in the scaled space. The returned instance is the
  563. * one passed as the result parameter if it is not undefined, or a new instance of it is.
  564. */
  565. Ellipsoid.prototype.transformPositionToScaledSpace = function(position, result) {
  566. if (!when.defined(result)) {
  567. result = new Cartographic.Cartesian3();
  568. }
  569.  
  570. return Cartographic.Cartesian3.multiplyComponents(position, this._oneOverRadii, result);
  571. };
  572.  
  573. /**
  574. * Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
  575. * its components by the result of {@link Ellipsoid#radii}.
  576. *
  577. * @param {Cartesian3} position The position to transform.
  578. * @param {Cartesian3} [result] The position to which to copy the result, or undefined to create and
  579. * return a new instance.
  580. * @returns {Cartesian3} The position expressed in the unscaled space. The returned instance is the
  581. * one passed as the result parameter if it is not undefined, or a new instance of it is.
  582. */
  583. Ellipsoid.prototype.transformPositionFromScaledSpace = function(position, result) {
  584. if (!when.defined(result)) {
  585. result = new Cartographic.Cartesian3();
  586. }
  587.  
  588. return Cartographic.Cartesian3.multiplyComponents(position, this._radii, result);
  589. };
  590.  
  591. /**
  592. * Compares this Ellipsoid against the provided Ellipsoid componentwise and returns
  593. * <code>true</code> if they are equal, <code>false</code> otherwise.
  594. *
  595. * @param {Ellipsoid} [right] The other Ellipsoid.
  596. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  597. */
  598. Ellipsoid.prototype.equals = function(right) {
  599. return (this === right) ||
  600. (when.defined(right) &&
  601. Cartographic.Cartesian3.equals(this._radii, right._radii));
  602. };
  603.  
  604. /**
  605. * Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.
  606. *
  607. * @returns {String} A string representing this ellipsoid in the format '(radii.x, radii.y, radii.z)'.
  608. */
  609. Ellipsoid.prototype.toString = function() {
  610. return this._radii.toString();
  611. };
  612.  
  613. /**
  614. * Computes a point which is the intersection of the surface normal with the z-axis.
  615. *
  616. * @param {Cartesian3} position the position. must be on the surface of the ellipsoid.
  617. * @param {Number} [buffer = 0.0] A buffer to subtract from the ellipsoid size when checking if the point is inside the ellipsoid.
  618. * In earth case, with common earth datums, there is no need for this buffer since the intersection point is always (relatively) very close to the center.
  619. * In WGS84 datum, intersection point is at max z = +-42841.31151331382 (0.673% of z-axis).
  620. * Intersection point could be outside the ellipsoid if the ratio of MajorAxis / AxisOfRotation is bigger than the square root of 2
  621. * @param {Cartesian3} [result] The cartesian to which to copy the result, or undefined to create and
  622. * return a new instance.
  623. * @returns {Cartesian3 | undefined} the intersection point if it's inside the ellipsoid, undefined otherwise
  624. *
  625. * @exception {DeveloperError} position is required.
  626. * @exception {DeveloperError} Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y).
  627. * @exception {DeveloperError} Ellipsoid.radii.z must be greater than 0.
  628. */
  629. Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function(position, buffer, result) {
  630. //>>includeStart('debug', pragmas.debug);
  631. Check.Check.typeOf.object('position', position);
  632.  
  633. if (!_Math.CesiumMath.equalsEpsilon(this._radii.x, this._radii.y, _Math.CesiumMath.EPSILON15)) {
  634. throw new Check.DeveloperError('Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)');
  635. }
  636.  
  637. Check.Check.typeOf.number.greaterThan('Ellipsoid.radii.z', this._radii.z, 0);
  638. //>>includeEnd('debug');
  639.  
  640. buffer = when.defaultValue(buffer, 0.0);
  641.  
  642. var squaredXOverSquaredZ = this._squaredXOverSquaredZ;
  643.  
  644. if (!when.defined(result)) {
  645. result = new Cartographic.Cartesian3();
  646. }
  647.  
  648. result.x = 0.0;
  649. result.y = 0.0;
  650. result.z = position.z * (1 - squaredXOverSquaredZ);
  651.  
  652. if (Math.abs(result.z) >= this._radii.z - buffer) {
  653. return undefined;
  654. }
  655.  
  656. return result;
  657. };
  658.  
  659. /**
  660. * A two dimensional region specified as longitude and latitude coordinates.
  661. *
  662. * @alias Rectangle
  663. * @constructor
  664. *
  665. * @param {Number} [west=0.0] The westernmost longitude, in radians, in the range [-Pi, Pi].
  666. * @param {Number} [south=0.0] The southernmost latitude, in radians, in the range [-Pi/2, Pi/2].
  667. * @param {Number} [east=0.0] The easternmost longitude, in radians, in the range [-Pi, Pi].
  668. * @param {Number} [north=0.0] The northernmost latitude, in radians, in the range [-Pi/2, Pi/2].
  669. *
  670. * @see Packable
  671. */
  672. function Rectangle(west, south, east, north) {
  673. /**
  674. * The westernmost longitude in radians in the range [-Pi, Pi].
  675. *
  676. * @type {Number}
  677. * @default 0.0
  678. */
  679. this.west = when.defaultValue(west, 0.0);
  680.  
  681. /**
  682. * The southernmost latitude in radians in the range [-Pi/2, Pi/2].
  683. *
  684. * @type {Number}
  685. * @default 0.0
  686. */
  687. this.south = when.defaultValue(south, 0.0);
  688.  
  689. /**
  690. * The easternmost longitude in radians in the range [-Pi, Pi].
  691. *
  692. * @type {Number}
  693. * @default 0.0
  694. */
  695. this.east = when.defaultValue(east, 0.0);
  696.  
  697. /**
  698. * The northernmost latitude in radians in the range [-Pi/2, Pi/2].
  699. *
  700. * @type {Number}
  701. * @default 0.0
  702. */
  703. this.north = when.defaultValue(north, 0.0);
  704. }
  705.  
  706. Object.defineProperties(Rectangle.prototype, {
  707. /**
  708. * Gets the width of the rectangle in radians.
  709. * @memberof Rectangle.prototype
  710. * @type {Number}
  711. */
  712. width : {
  713. get : function() {
  714. return Rectangle.computeWidth(this);
  715. }
  716. },
  717.  
  718. /**
  719. * Gets the height of the rectangle in radians.
  720. * @memberof Rectangle.prototype
  721. * @type {Number}
  722. */
  723. height : {
  724. get : function() {
  725. return Rectangle.computeHeight(this);
  726. }
  727. }
  728. });
  729.  
  730. /**
  731. * The number of elements used to pack the object into an array.
  732. * @type {Number}
  733. */
  734. Rectangle.packedLength = 4;
  735.  
  736. /**
  737. * Stores the provided instance into the provided array.
  738. *
  739. * @param {Rectangle} value The value to pack.
  740. * @param {Number[]} array The array to pack into.
  741. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  742. *
  743. * @returns {Number[]} The array that was packed into
  744. */
  745. Rectangle.pack = function(value, array, startingIndex) {
  746. //>>includeStart('debug', pragmas.debug);
  747. Check.Check.typeOf.object('value', value);
  748. Check.Check.defined('array', array);
  749. //>>includeEnd('debug');
  750.  
  751. startingIndex = when.defaultValue(startingIndex, 0);
  752.  
  753. array[startingIndex++] = value.west;
  754. array[startingIndex++] = value.south;
  755. array[startingIndex++] = value.east;
  756. array[startingIndex] = value.north;
  757.  
  758. return array;
  759. };
  760.  
  761. /**
  762. * Retrieves an instance from a packed array.
  763. *
  764. * @param {Number[]} array The packed array.
  765. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  766. * @param {Rectangle} [result] The object into which to store the result.
  767. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.
  768. */
  769. Rectangle.unpack = function(array, startingIndex, result) {
  770. //>>includeStart('debug', pragmas.debug);
  771. Check.Check.defined('array', array);
  772. //>>includeEnd('debug');
  773.  
  774. startingIndex = when.defaultValue(startingIndex, 0);
  775.  
  776. if (!when.defined(result)) {
  777. result = new Rectangle();
  778. }
  779.  
  780. result.west = array[startingIndex++];
  781. result.south = array[startingIndex++];
  782. result.east = array[startingIndex++];
  783. result.north = array[startingIndex];
  784. return result;
  785. };
  786.  
  787. /**
  788. * Computes the width of a rectangle in radians.
  789. * @param {Rectangle} rectangle The rectangle to compute the width of.
  790. * @returns {Number} The width.
  791. */
  792. Rectangle.computeWidth = function(rectangle) {
  793. //>>includeStart('debug', pragmas.debug);
  794. Check.Check.typeOf.object('rectangle', rectangle);
  795. //>>includeEnd('debug');
  796. var east = rectangle.east;
  797. var west = rectangle.west;
  798. if (east < west) {
  799. east += _Math.CesiumMath.TWO_PI;
  800. }
  801. return east - west;
  802. };
  803.  
  804. /**
  805. * Computes the height of a rectangle in radians.
  806. * @param {Rectangle} rectangle The rectangle to compute the height of.
  807. * @returns {Number} The height.
  808. */
  809. Rectangle.computeHeight = function(rectangle) {
  810. //>>includeStart('debug', pragmas.debug);
  811. Check.Check.typeOf.object('rectangle', rectangle);
  812. //>>includeEnd('debug');
  813. return rectangle.north - rectangle.south;
  814. };
  815.  
  816. /**
  817. * Creates a rectangle given the boundary longitude and latitude in degrees.
  818. *
  819. * @param {Number} [west=0.0] The westernmost longitude in degrees in the range [-180.0, 180.0].
  820. * @param {Number} [south=0.0] The southernmost latitude in degrees in the range [-90.0, 90.0].
  821. * @param {Number} [east=0.0] The easternmost longitude in degrees in the range [-180.0, 180.0].
  822. * @param {Number} [north=0.0] The northernmost latitude in degrees in the range [-90.0, 90.0].
  823. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  824. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  825. *
  826. * @example
  827. * var rectangle = Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0);
  828. */
  829. Rectangle.fromDegrees = function(west, south, east, north, result) {
  830. west = _Math.CesiumMath.toRadians(when.defaultValue(west, 0.0));
  831. south = _Math.CesiumMath.toRadians(when.defaultValue(south, 0.0));
  832. east = _Math.CesiumMath.toRadians(when.defaultValue(east, 0.0));
  833. north = _Math.CesiumMath.toRadians(when.defaultValue(north, 0.0));
  834.  
  835. if (!when.defined(result)) {
  836. return new Rectangle(west, south, east, north);
  837. }
  838.  
  839. result.west = west;
  840. result.south = south;
  841. result.east = east;
  842. result.north = north;
  843.  
  844. return result;
  845. };
  846.  
  847. /**
  848. * Creates a rectangle given the boundary longitude and latitude in radians.
  849. *
  850. * @param {Number} [west=0.0] The westernmost longitude in radians in the range [-Math.PI, Math.PI].
  851. * @param {Number} [south=0.0] The southernmost latitude in radians in the range [-Math.PI/2, Math.PI/2].
  852. * @param {Number} [east=0.0] The easternmost longitude in radians in the range [-Math.PI, Math.PI].
  853. * @param {Number} [north=0.0] The northernmost latitude in radians in the range [-Math.PI/2, Math.PI/2].
  854. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  855. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  856. *
  857. * @example
  858. * var rectangle = Cesium.Rectangle.fromRadians(0.0, Math.PI/4, Math.PI/8, 3*Math.PI/4);
  859. */
  860. Rectangle.fromRadians = function(west, south, east, north, result) {
  861. if (!when.defined(result)) {
  862. return new Rectangle(west, south, east, north);
  863. }
  864.  
  865. result.west = when.defaultValue(west, 0.0);
  866. result.south = when.defaultValue(south, 0.0);
  867. result.east = when.defaultValue(east, 0.0);
  868. result.north = when.defaultValue(north, 0.0);
  869.  
  870. return result;
  871. };
  872.  
  873. /**
  874. * Creates the smallest possible Rectangle that encloses all positions in the provided array.
  875. *
  876. * @param {Cartographic[]} cartographics The list of Cartographic instances.
  877. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  878. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  879. */
  880. Rectangle.fromCartographicArray = function(cartographics, result) {
  881. //>>includeStart('debug', pragmas.debug);
  882. Check.Check.defined('cartographics', cartographics);
  883. //>>includeEnd('debug');
  884.  
  885. var west = Number.MAX_VALUE;
  886. var east = -Number.MAX_VALUE;
  887. var westOverIDL = Number.MAX_VALUE;
  888. var eastOverIDL = -Number.MAX_VALUE;
  889. var south = Number.MAX_VALUE;
  890. var north = -Number.MAX_VALUE;
  891.  
  892. for ( var i = 0, len = cartographics.length; i < len; i++) {
  893. var position = cartographics[i];
  894. west = Math.min(west, position.longitude);
  895. east = Math.max(east, position.longitude);
  896. south = Math.min(south, position.latitude);
  897. north = Math.max(north, position.latitude);
  898.  
  899. var lonAdjusted = position.longitude >= 0 ? position.longitude : position.longitude + _Math.CesiumMath.TWO_PI;
  900. westOverIDL = Math.min(westOverIDL, lonAdjusted);
  901. eastOverIDL = Math.max(eastOverIDL, lonAdjusted);
  902. }
  903.  
  904. if(east - west > eastOverIDL - westOverIDL) {
  905. west = westOverIDL;
  906. east = eastOverIDL;
  907.  
  908. if (east > _Math.CesiumMath.PI) {
  909. east = east - _Math.CesiumMath.TWO_PI;
  910. }
  911. if (west > _Math.CesiumMath.PI) {
  912. west = west - _Math.CesiumMath.TWO_PI;
  913. }
  914. }
  915.  
  916. if (!when.defined(result)) {
  917. return new Rectangle(west, south, east, north);
  918. }
  919.  
  920. result.west = west;
  921. result.south = south;
  922. result.east = east;
  923. result.north = north;
  924. return result;
  925. };
  926.  
  927. /**
  928. * Creates the smallest possible Rectangle that encloses all positions in the provided array.
  929. *
  930. * @param {Cartesian3[]} cartesians The list of Cartesian instances.
  931. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid the cartesians are on.
  932. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  933. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  934. */
  935. Rectangle.fromCartesianArray = function(cartesians, ellipsoid, result) {
  936. //>>includeStart('debug', pragmas.debug);
  937. Check.Check.defined('cartesians', cartesians);
  938. //>>includeEnd('debug');
  939. ellipsoid = when.defaultValue(ellipsoid, Ellipsoid.WGS84);
  940.  
  941. var west = Number.MAX_VALUE;
  942. var east = -Number.MAX_VALUE;
  943. var westOverIDL = Number.MAX_VALUE;
  944. var eastOverIDL = -Number.MAX_VALUE;
  945. var south = Number.MAX_VALUE;
  946. var north = -Number.MAX_VALUE;
  947.  
  948. for ( var i = 0, len = cartesians.length; i < len; i++) {
  949. var position = ellipsoid.cartesianToCartographic(cartesians[i]);
  950. west = Math.min(west, position.longitude);
  951. east = Math.max(east, position.longitude);
  952. south = Math.min(south, position.latitude);
  953. north = Math.max(north, position.latitude);
  954.  
  955. var lonAdjusted = position.longitude >= 0 ? position.longitude : position.longitude + _Math.CesiumMath.TWO_PI;
  956. westOverIDL = Math.min(westOverIDL, lonAdjusted);
  957. eastOverIDL = Math.max(eastOverIDL, lonAdjusted);
  958. }
  959.  
  960. if(east - west > eastOverIDL - westOverIDL) {
  961. west = westOverIDL;
  962. east = eastOverIDL;
  963.  
  964. if (east > _Math.CesiumMath.PI) {
  965. east = east - _Math.CesiumMath.TWO_PI;
  966. }
  967. if (west > _Math.CesiumMath.PI) {
  968. west = west - _Math.CesiumMath.TWO_PI;
  969. }
  970. }
  971.  
  972. if (!when.defined(result)) {
  973. return new Rectangle(west, south, east, north);
  974. }
  975.  
  976. result.west = west;
  977. result.south = south;
  978. result.east = east;
  979. result.north = north;
  980. return result;
  981. };
  982.  
  983. /**
  984. * Duplicates a Rectangle.
  985. *
  986. * @param {Rectangle} rectangle The rectangle to clone.
  987. * @param {Rectangle} [result] The object onto which to store the result, or undefined if a new instance should be created.
  988. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided. (Returns undefined if rectangle is undefined)
  989. */
  990. Rectangle.clone = function(rectangle, result) {
  991. if (!when.defined(rectangle)) {
  992. return undefined;
  993. }
  994.  
  995. if (!when.defined(result)) {
  996. return new Rectangle(rectangle.west, rectangle.south, rectangle.east, rectangle.north);
  997. }
  998.  
  999. result.west = rectangle.west;
  1000. result.south = rectangle.south;
  1001. result.east = rectangle.east;
  1002. result.north = rectangle.north;
  1003. return result;
  1004. };
  1005.  
  1006. /**
  1007. * Compares the provided Rectangles componentwise and returns
  1008. * <code>true</code> if they pass an absolute or relative tolerance test,
  1009. * <code>false</code> otherwise.
  1010. *
  1011. * @param {Rectangle} [left] The first Rectangle.
  1012. * @param {Rectangle} [right] The second Rectangle.
  1013. * @param {Number} absoluteEpsilon The absolute epsilon tolerance to use for equality testing.
  1014. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  1015. */
  1016. Rectangle.equalsEpsilon = function(left, right, absoluteEpsilon) {
  1017. //>>includeStart('debug', pragmas.debug);
  1018. Check.Check.typeOf.number('absoluteEpsilon', absoluteEpsilon);
  1019. //>>includeEnd('debug');
  1020.  
  1021. return (left === right) ||
  1022. (when.defined(left) &&
  1023. when.defined(right) &&
  1024. (Math.abs(left.west - right.west) <= absoluteEpsilon) &&
  1025. (Math.abs(left.south - right.south) <= absoluteEpsilon) &&
  1026. (Math.abs(left.east - right.east) <= absoluteEpsilon) &&
  1027. (Math.abs(left.north - right.north) <= absoluteEpsilon));
  1028. };
  1029.  
  1030. /**
  1031. * Duplicates this Rectangle.
  1032. *
  1033. * @param {Rectangle} [result] The object onto which to store the result.
  1034. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  1035. */
  1036. Rectangle.prototype.clone = function(result) {
  1037. return Rectangle.clone(this, result);
  1038. };
  1039.  
  1040. /**
  1041. * Compares the provided Rectangle with this Rectangle componentwise and returns
  1042. * <code>true</code> if they are equal, <code>false</code> otherwise.
  1043. *
  1044. * @param {Rectangle} [other] The Rectangle to compare.
  1045. * @returns {Boolean} <code>true</code> if the Rectangles are equal, <code>false</code> otherwise.
  1046. */
  1047. Rectangle.prototype.equals = function(other) {
  1048. return Rectangle.equals(this, other);
  1049. };
  1050.  
  1051. /**
  1052. * Compares the provided rectangles and returns <code>true</code> if they are equal,
  1053. * <code>false</code> otherwise.
  1054. *
  1055. * @param {Rectangle} [left] The first Rectangle.
  1056. * @param {Rectangle} [right] The second Rectangle.
  1057. * @returns {Boolean} <code>true</code> if left and right are equal; otherwise <code>false</code>.
  1058. */
  1059. Rectangle.equals = function(left, right) {
  1060. return (left === right) ||
  1061. ((when.defined(left)) &&
  1062. (when.defined(right)) &&
  1063. (left.west === right.west) &&
  1064. (left.south === right.south) &&
  1065. (left.east === right.east) &&
  1066. (left.north === right.north));
  1067. };
  1068.  
  1069. /**
  1070. * Compares the provided Rectangle with this Rectangle componentwise and returns
  1071. * <code>true</code> if they are within the provided epsilon,
  1072. * <code>false</code> otherwise.
  1073. *
  1074. * @param {Rectangle} [other] The Rectangle to compare.
  1075. * @param {Number} epsilon The epsilon to use for equality testing.
  1076. * @returns {Boolean} <code>true</code> if the Rectangles are within the provided epsilon, <code>false</code> otherwise.
  1077. */
  1078. Rectangle.prototype.equalsEpsilon = function(other, epsilon) {
  1079. //>>includeStart('debug', pragmas.debug);
  1080. Check.Check.typeOf.number('epsilon', epsilon);
  1081. //>>includeEnd('debug');
  1082.  
  1083. return Rectangle.equalsEpsilon(this, other, epsilon);
  1084. };
  1085.  
  1086. /**
  1087. * Checks a Rectangle's properties and throws if they are not in valid ranges.
  1088. *
  1089. * @param {Rectangle} rectangle The rectangle to validate
  1090. *
  1091. * @exception {DeveloperError} <code>north</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  1092. * @exception {DeveloperError} <code>south</code> must be in the interval [<code>-Pi/2</code>, <code>Pi/2</code>].
  1093. * @exception {DeveloperError} <code>east</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  1094. * @exception {DeveloperError} <code>west</code> must be in the interval [<code>-Pi</code>, <code>Pi</code>].
  1095. */
  1096. Rectangle.validate = function(rectangle) {
  1097. //>>includeStart('debug', pragmas.debug);
  1098. Check.Check.typeOf.object('rectangle', rectangle);
  1099.  
  1100. var north = rectangle.north;
  1101. Check.Check.typeOf.number.greaterThanOrEquals('north', north, -_Math.CesiumMath.PI_OVER_TWO);
  1102. Check.Check.typeOf.number.lessThanOrEquals('north', north, _Math.CesiumMath.PI_OVER_TWO);
  1103.  
  1104. var south = rectangle.south;
  1105. Check.Check.typeOf.number.greaterThanOrEquals('south', south, -_Math.CesiumMath.PI_OVER_TWO);
  1106. Check.Check.typeOf.number.lessThanOrEquals('south', south, _Math.CesiumMath.PI_OVER_TWO);
  1107.  
  1108. var west = rectangle.west;
  1109. Check.Check.typeOf.number.greaterThanOrEquals('west', west, -Math.PI);
  1110. Check.Check.typeOf.number.lessThanOrEquals('west', west, Math.PI);
  1111.  
  1112. var east = rectangle.east;
  1113. Check.Check.typeOf.number.greaterThanOrEquals('east', east, -Math.PI);
  1114. Check.Check.typeOf.number.lessThanOrEquals('east', east, Math.PI);
  1115. //>>includeEnd('debug');
  1116. };
  1117.  
  1118. /**
  1119. * Computes the southwest corner of a rectangle.
  1120. *
  1121. * @param {Rectangle} rectangle The rectangle for which to find the corner
  1122. * @param {Cartographic} [result] The object onto which to store the result.
  1123. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  1124. */
  1125. Rectangle.southwest = function(rectangle, result) {
  1126. //>>includeStart('debug', pragmas.debug);
  1127. Check.Check.typeOf.object('rectangle', rectangle);
  1128. //>>includeEnd('debug');
  1129.  
  1130. if (!when.defined(result)) {
  1131. return new Cartographic.Cartographic(rectangle.west, rectangle.south);
  1132. }
  1133. result.longitude = rectangle.west;
  1134. result.latitude = rectangle.south;
  1135. result.height = 0.0;
  1136. return result;
  1137. };
  1138.  
  1139. /**
  1140. * Computes the northwest corner of a rectangle.
  1141. *
  1142. * @param {Rectangle} rectangle The rectangle for which to find the corner
  1143. * @param {Cartographic} [result] The object onto which to store the result.
  1144. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  1145. */
  1146. Rectangle.northwest = function(rectangle, result) {
  1147. //>>includeStart('debug', pragmas.debug);
  1148. Check.Check.typeOf.object('rectangle', rectangle);
  1149. //>>includeEnd('debug');
  1150.  
  1151. if (!when.defined(result)) {
  1152. return new Cartographic.Cartographic(rectangle.west, rectangle.north);
  1153. }
  1154. result.longitude = rectangle.west;
  1155. result.latitude = rectangle.north;
  1156. result.height = 0.0;
  1157. return result;
  1158. };
  1159.  
  1160. /**
  1161. * Computes the northeast corner of a rectangle.
  1162. *
  1163. * @param {Rectangle} rectangle The rectangle for which to find the corner
  1164. * @param {Cartographic} [result] The object onto which to store the result.
  1165. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  1166. */
  1167. Rectangle.northeast = function(rectangle, result) {
  1168. //>>includeStart('debug', pragmas.debug);
  1169. Check.Check.typeOf.object('rectangle', rectangle);
  1170. //>>includeEnd('debug');
  1171.  
  1172. if (!when.defined(result)) {
  1173. return new Cartographic.Cartographic(rectangle.east, rectangle.north);
  1174. }
  1175. result.longitude = rectangle.east;
  1176. result.latitude = rectangle.north;
  1177. result.height = 0.0;
  1178. return result;
  1179. };
  1180.  
  1181. /**
  1182. * Computes the southeast corner of a rectangle.
  1183. *
  1184. * @param {Rectangle} rectangle The rectangle for which to find the corner
  1185. * @param {Cartographic} [result] The object onto which to store the result.
  1186. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  1187. */
  1188. Rectangle.southeast = function(rectangle, result) {
  1189. //>>includeStart('debug', pragmas.debug);
  1190. Check.Check.typeOf.object('rectangle', rectangle);
  1191. //>>includeEnd('debug');
  1192.  
  1193. if (!when.defined(result)) {
  1194. return new Cartographic.Cartographic(rectangle.east, rectangle.south);
  1195. }
  1196. result.longitude = rectangle.east;
  1197. result.latitude = rectangle.south;
  1198. result.height = 0.0;
  1199. return result;
  1200. };
  1201.  
  1202. /**
  1203. * Computes the center of a rectangle.
  1204. *
  1205. * @param {Rectangle} rectangle The rectangle for which to find the center
  1206. * @param {Cartographic} [result] The object onto which to store the result.
  1207. * @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
  1208. */
  1209. Rectangle.center = function(rectangle, result) {
  1210. //>>includeStart('debug', pragmas.debug);
  1211. Check.Check.typeOf.object('rectangle', rectangle);
  1212. //>>includeEnd('debug');
  1213.  
  1214. var east = rectangle.east;
  1215. var west = rectangle.west;
  1216.  
  1217. if (east < west) {
  1218. east += _Math.CesiumMath.TWO_PI;
  1219. }
  1220.  
  1221. var longitude = _Math.CesiumMath.negativePiToPi((west + east) * 0.5);
  1222. var latitude = (rectangle.south + rectangle.north) * 0.5;
  1223.  
  1224. if (!when.defined(result)) {
  1225. return new Cartographic.Cartographic(longitude, latitude);
  1226. }
  1227.  
  1228. result.longitude = longitude;
  1229. result.latitude = latitude;
  1230. result.height = 0.0;
  1231. return result;
  1232. };
  1233.  
  1234. /**
  1235. * Computes the intersection of two rectangles. This function assumes that the rectangle's coordinates are
  1236. * latitude and longitude in radians and produces a correct intersection, taking into account the fact that
  1237. * the same angle can be represented with multiple values as well as the wrapping of longitude at the
  1238. * anti-meridian. For a simple intersection that ignores these factors and can be used with projected
  1239. * coordinates, see {@link Rectangle.simpleIntersection}.
  1240. *
  1241. * @param {Rectangle} rectangle On rectangle to find an intersection
  1242. * @param {Rectangle} otherRectangle Another rectangle to find an intersection
  1243. * @param {Rectangle} [result] The object onto which to store the result.
  1244. * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.
  1245. */
  1246. Rectangle.intersection = function(rectangle, otherRectangle, result) {
  1247. //>>includeStart('debug', pragmas.debug);
  1248. Check.Check.typeOf.object('rectangle', rectangle);
  1249. Check.Check.typeOf.object('otherRectangle', otherRectangle);
  1250. //>>includeEnd('debug');
  1251.  
  1252. var rectangleEast = rectangle.east;
  1253. var rectangleWest = rectangle.west;
  1254.  
  1255. var otherRectangleEast = otherRectangle.east;
  1256. var otherRectangleWest = otherRectangle.west;
  1257.  
  1258. if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {
  1259. rectangleEast += _Math.CesiumMath.TWO_PI;
  1260. } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {
  1261. otherRectangleEast += _Math.CesiumMath.TWO_PI;
  1262. }
  1263.  
  1264. if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {
  1265. otherRectangleWest += _Math.CesiumMath.TWO_PI;
  1266. } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {
  1267. rectangleWest += _Math.CesiumMath.TWO_PI;
  1268. }
  1269.  
  1270. var west = _Math.CesiumMath.negativePiToPi(Math.max(rectangleWest, otherRectangleWest));
  1271. var east = _Math.CesiumMath.negativePiToPi(Math.min(rectangleEast, otherRectangleEast));
  1272.  
  1273. if ((rectangle.west < rectangle.east || otherRectangle.west < otherRectangle.east) && east <= west) {
  1274. return undefined;
  1275. }
  1276.  
  1277. var south = Math.max(rectangle.south, otherRectangle.south);
  1278. var north = Math.min(rectangle.north, otherRectangle.north);
  1279.  
  1280. if (south >= north) {
  1281. return undefined;
  1282. }
  1283.  
  1284. if (!when.defined(result)) {
  1285. return new Rectangle(west, south, east, north);
  1286. }
  1287. result.west = west;
  1288. result.south = south;
  1289. result.east = east;
  1290. result.north = north;
  1291. return result;
  1292. };
  1293.  
  1294. /**
  1295. * Computes a simple intersection of two rectangles. Unlike {@link Rectangle.intersection}, this function
  1296. * does not attempt to put the angular coordinates into a consistent range or to account for crossing the
  1297. * anti-meridian. As such, it can be used for rectangles where the coordinates are not simply latitude
  1298. * and longitude (i.e. projected coordinates).
  1299. *
  1300. * @param {Rectangle} rectangle On rectangle to find an intersection
  1301. * @param {Rectangle} otherRectangle Another rectangle to find an intersection
  1302. * @param {Rectangle} [result] The object onto which to store the result.
  1303. * @returns {Rectangle|undefined} The modified result parameter, a new Rectangle instance if none was provided or undefined if there is no intersection.
  1304. */
  1305. Rectangle.simpleIntersection = function(rectangle, otherRectangle, result) {
  1306. //>>includeStart('debug', pragmas.debug);
  1307. Check.Check.typeOf.object('rectangle', rectangle);
  1308. Check.Check.typeOf.object('otherRectangle', otherRectangle);
  1309. //>>includeEnd('debug');
  1310.  
  1311. var west = Math.max(rectangle.west, otherRectangle.west);
  1312. var south = Math.max(rectangle.south, otherRectangle.south);
  1313. var east = Math.min(rectangle.east, otherRectangle.east);
  1314. var north = Math.min(rectangle.north, otherRectangle.north);
  1315.  
  1316. if (south >= north || west >= east) {
  1317. return undefined;
  1318. }
  1319.  
  1320. if (!when.defined(result)) {
  1321. return new Rectangle(west, south, east, north);
  1322. }
  1323.  
  1324. result.west = west;
  1325. result.south = south;
  1326. result.east = east;
  1327. result.north = north;
  1328. return result;
  1329. };
  1330.  
  1331. /**
  1332. * Computes a rectangle that is the union of two rectangles.
  1333. *
  1334. * @param {Rectangle} rectangle A rectangle to enclose in rectangle.
  1335. * @param {Rectangle} otherRectangle A rectangle to enclose in a rectangle.
  1336. * @param {Rectangle} [result] The object onto which to store the result.
  1337. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if none was provided.
  1338. */
  1339. Rectangle.union = function(rectangle, otherRectangle, result) {
  1340. //>>includeStart('debug', pragmas.debug);
  1341. Check.Check.typeOf.object('rectangle', rectangle);
  1342. Check.Check.typeOf.object('otherRectangle', otherRectangle);
  1343. //>>includeEnd('debug');
  1344.  
  1345. if (!when.defined(result)) {
  1346. result = new Rectangle();
  1347. }
  1348.  
  1349. var rectangleEast = rectangle.east;
  1350. var rectangleWest = rectangle.west;
  1351.  
  1352. var otherRectangleEast = otherRectangle.east;
  1353. var otherRectangleWest = otherRectangle.west;
  1354.  
  1355. if (rectangleEast < rectangleWest && otherRectangleEast > 0.0) {
  1356. rectangleEast += _Math.CesiumMath.TWO_PI;
  1357. } else if (otherRectangleEast < otherRectangleWest && rectangleEast > 0.0) {
  1358. otherRectangleEast += _Math.CesiumMath.TWO_PI;
  1359. }
  1360.  
  1361. if (rectangleEast < rectangleWest && otherRectangleWest < 0.0) {
  1362. otherRectangleWest += _Math.CesiumMath.TWO_PI;
  1363. } else if (otherRectangleEast < otherRectangleWest && rectangleWest < 0.0) {
  1364. rectangleWest += _Math.CesiumMath.TWO_PI;
  1365. }
  1366.  
  1367. var west = _Math.CesiumMath.convertLongitudeRange(Math.min(rectangleWest, otherRectangleWest));
  1368. var east = _Math.CesiumMath.convertLongitudeRange(Math.max(rectangleEast, otherRectangleEast));
  1369.  
  1370. result.west = west;
  1371. result.south = Math.min(rectangle.south, otherRectangle.south);
  1372. result.east = east;
  1373. result.north = Math.max(rectangle.north, otherRectangle.north);
  1374.  
  1375. return result;
  1376. };
  1377.  
  1378. /**
  1379. * Computes a rectangle by enlarging the provided rectangle until it contains the provided cartographic.
  1380. *
  1381. * @param {Rectangle} rectangle A rectangle to expand.
  1382. * @param {Cartographic} cartographic A cartographic to enclose in a rectangle.
  1383. * @param {Rectangle} [result] The object onto which to store the result.
  1384. * @returns {Rectangle} The modified result parameter or a new Rectangle instance if one was not provided.
  1385. */
  1386. Rectangle.expand = function(rectangle, cartographic, result) {
  1387. //>>includeStart('debug', pragmas.debug);
  1388. Check.Check.typeOf.object('rectangle', rectangle);
  1389. Check.Check.typeOf.object('cartographic', cartographic);
  1390. //>>includeEnd('debug');
  1391.  
  1392. if (!when.defined(result)) {
  1393. result = new Rectangle();
  1394. }
  1395.  
  1396. result.west = Math.min(rectangle.west, cartographic.longitude);
  1397. result.south = Math.min(rectangle.south, cartographic.latitude);
  1398. result.east = Math.max(rectangle.east, cartographic.longitude);
  1399. result.north = Math.max(rectangle.north, cartographic.latitude);
  1400.  
  1401. return result;
  1402. };
  1403.  
  1404. /**
  1405. * Returns true if the cartographic is on or inside the rectangle, false otherwise.
  1406. *
  1407. * @param {Rectangle} rectangle The rectangle
  1408. * @param {Cartographic} cartographic The cartographic to test.
  1409. * @returns {Boolean} true if the provided cartographic is inside the rectangle, false otherwise.
  1410. */
  1411. Rectangle.contains = function(rectangle, cartographic) {
  1412. //>>includeStart('debug', pragmas.debug);
  1413. Check.Check.typeOf.object('rectangle', rectangle);
  1414. Check.Check.typeOf.object('cartographic', cartographic);
  1415. //>>includeEnd('debug');
  1416.  
  1417. var longitude = cartographic.longitude;
  1418. var latitude = cartographic.latitude;
  1419.  
  1420. var west = rectangle.west;
  1421. var east = rectangle.east;
  1422.  
  1423. if (east < west) {
  1424. east += _Math.CesiumMath.TWO_PI;
  1425. if (longitude < 0.0) {
  1426. longitude += _Math.CesiumMath.TWO_PI;
  1427. }
  1428. }
  1429. return (longitude > west || _Math.CesiumMath.equalsEpsilon(longitude, west, _Math.CesiumMath.EPSILON14)) &&
  1430. (longitude < east || _Math.CesiumMath.equalsEpsilon(longitude, east, _Math.CesiumMath.EPSILON14)) &&
  1431. latitude >= rectangle.south &&
  1432. latitude <= rectangle.north;
  1433. };
  1434.  
  1435. var subsampleLlaScratch = new Cartographic.Cartographic();
  1436. /**
  1437. * Samples a rectangle so that it includes a list of Cartesian points suitable for passing to
  1438. * {@link BoundingSphere#fromPoints}. Sampling is necessary to account
  1439. * for rectangles that cover the poles or cross the equator.
  1440. *
  1441. * @param {Rectangle} rectangle The rectangle to subsample.
  1442. * @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid to use.
  1443. * @param {Number} [surfaceHeight=0.0] The height of the rectangle above the ellipsoid.
  1444. * @param {Cartesian3[]} [result] The array of Cartesians onto which to store the result.
  1445. * @returns {Cartesian3[]} The modified result parameter or a new Array of Cartesians instances if none was provided.
  1446. */
  1447. Rectangle.subsample = function(rectangle, ellipsoid, surfaceHeight, result) {
  1448. //>>includeStart('debug', pragmas.debug);
  1449. Check.Check.typeOf.object('rectangle', rectangle);
  1450. //>>includeEnd('debug');
  1451.  
  1452. ellipsoid = when.defaultValue(ellipsoid, Ellipsoid.WGS84);
  1453. surfaceHeight = when.defaultValue(surfaceHeight, 0.0);
  1454.  
  1455. if (!when.defined(result)) {
  1456. result = [];
  1457. }
  1458. var length = 0;
  1459.  
  1460. var north = rectangle.north;
  1461. var south = rectangle.south;
  1462. var east = rectangle.east;
  1463. var west = rectangle.west;
  1464.  
  1465. var lla = subsampleLlaScratch;
  1466. lla.height = surfaceHeight;
  1467.  
  1468. lla.longitude = west;
  1469. lla.latitude = north;
  1470. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  1471. length++;
  1472.  
  1473. lla.longitude = east;
  1474. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  1475. length++;
  1476.  
  1477. lla.latitude = south;
  1478. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  1479. length++;
  1480.  
  1481. lla.longitude = west;
  1482. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  1483. length++;
  1484.  
  1485. if (north < 0.0) {
  1486. lla.latitude = north;
  1487. } else if (south > 0.0) {
  1488. lla.latitude = south;
  1489. } else {
  1490. lla.latitude = 0.0;
  1491. }
  1492.  
  1493. for ( var i = 1; i < 8; ++i) {
  1494. lla.longitude = -Math.PI + i * _Math.CesiumMath.PI_OVER_TWO;
  1495. if (Rectangle.contains(rectangle, lla)) {
  1496. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  1497. length++;
  1498. }
  1499. }
  1500.  
  1501. if (lla.latitude === 0.0) {
  1502. lla.longitude = west;
  1503. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  1504. length++;
  1505. lla.longitude = east;
  1506. result[length] = ellipsoid.cartographicToCartesian(lla, result[length]);
  1507. length++;
  1508. }
  1509. result.length = length;
  1510. return result;
  1511. };
  1512.  
  1513. var scratchCartographic = new Cartographic.Cartographic();
  1514. Rectangle.prototype.contains = function(rectangle) {
  1515. return Rectangle.contains(this, Rectangle.southwest(rectangle, scratchCartographic))
  1516. && Rectangle.contains(this, Rectangle.northwest(rectangle, scratchCartographic))
  1517. && Rectangle.contains(this, Rectangle.southeast(rectangle, scratchCartographic))
  1518. && Rectangle.contains(this, Rectangle.northeast(rectangle, scratchCartographic));
  1519. };
  1520.  
  1521. /**
  1522. * The largest possible rectangle.
  1523. *
  1524. * @type {Rectangle}
  1525. * @constant
  1526. */
  1527. Rectangle.MAX_VALUE = Object.freeze(new Rectangle(-Math.PI, -_Math.CesiumMath.PI_OVER_TWO, Math.PI, _Math.CesiumMath.PI_OVER_TWO));
  1528.  
  1529. /**
  1530. * A 2D Cartesian point.
  1531. * @alias Cartesian2
  1532. * @constructor
  1533. *
  1534. * @param {Number} [x=0.0] The X component.
  1535. * @param {Number} [y=0.0] The Y component.
  1536. *
  1537. * @see Cartesian3
  1538. * @see Cartesian4
  1539. * @see Packable
  1540. */
  1541. function Cartesian2(x, y) {
  1542. /**
  1543. * The X component.
  1544. * @type {Number}
  1545. * @default 0.0
  1546. */
  1547. this.x = when.defaultValue(x, 0.0);
  1548.  
  1549. /**
  1550. * The Y component.
  1551. * @type {Number}
  1552. * @default 0.0
  1553. */
  1554. this.y = when.defaultValue(y, 0.0);
  1555. }
  1556.  
  1557. /**
  1558. * Creates a Cartesian2 instance from x and y coordinates.
  1559. *
  1560. * @param {Number} x The x coordinate.
  1561. * @param {Number} y The y coordinate.
  1562. * @param {Cartesian2} [result] The object onto which to store the result.
  1563. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  1564. */
  1565. Cartesian2.fromElements = function(x, y, result) {
  1566. if (!when.defined(result)) {
  1567. return new Cartesian2(x, y);
  1568. }
  1569.  
  1570. result.x = x;
  1571. result.y = y;
  1572. return result;
  1573. };
  1574.  
  1575. /**
  1576. * Duplicates a Cartesian2 instance.
  1577. *
  1578. * @param {Cartesian2} cartesian The Cartesian to duplicate.
  1579. * @param {Cartesian2} [result] The object onto which to store the result.
  1580. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided. (Returns undefined if cartesian is undefined)
  1581. */
  1582. Cartesian2.clone = function(cartesian, result) {
  1583. if (!when.defined(cartesian)) {
  1584. return undefined;
  1585. }
  1586. if (!when.defined(result)) {
  1587. return new Cartesian2(cartesian.x, cartesian.y);
  1588. }
  1589.  
  1590. result.x = cartesian.x;
  1591. result.y = cartesian.y;
  1592. return result;
  1593. };
  1594.  
  1595. /**
  1596. * Creates a Cartesian2 instance from an existing Cartesian3. This simply takes the
  1597. * x and y properties of the Cartesian3 and drops z.
  1598. * @function
  1599. *
  1600. * @param {Cartesian3} cartesian The Cartesian3 instance to create a Cartesian2 instance from.
  1601. * @param {Cartesian2} [result] The object onto which to store the result.
  1602. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  1603. */
  1604. Cartesian2.fromCartesian3 = Cartesian2.clone;
  1605.  
  1606. /**
  1607. * Creates a Cartesian2 instance from an existing Cartesian4. This simply takes the
  1608. * x and y properties of the Cartesian4 and drops z and w.
  1609. * @function
  1610. *
  1611. * @param {Cartesian4} cartesian The Cartesian4 instance to create a Cartesian2 instance from.
  1612. * @param {Cartesian2} [result] The object onto which to store the result.
  1613. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  1614. */
  1615. Cartesian2.fromCartesian4 = Cartesian2.clone;
  1616.  
  1617. /**
  1618. * The number of elements used to pack the object into an array.
  1619. * @type {Number}
  1620. */
  1621. Cartesian2.packedLength = 2;
  1622.  
  1623. /**
  1624. * Stores the provided instance into the provided array.
  1625. *
  1626. * @param {Cartesian2} value The value to pack.
  1627. * @param {Number[]} array The array to pack into.
  1628. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  1629. *
  1630. * @returns {Number[]} The array that was packed into
  1631. */
  1632. Cartesian2.pack = function(value, array, startingIndex) {
  1633. //>>includeStart('debug', pragmas.debug);
  1634. Check.Check.typeOf.object('value', value);
  1635. Check.Check.defined('array', array);
  1636. //>>includeEnd('debug');
  1637.  
  1638. startingIndex = when.defaultValue(startingIndex, 0);
  1639.  
  1640. array[startingIndex++] = value.x;
  1641. array[startingIndex] = value.y;
  1642.  
  1643. return array;
  1644. };
  1645.  
  1646. /**
  1647. * Retrieves an instance from a packed array.
  1648. *
  1649. * @param {Number[]} array The packed array.
  1650. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  1651. * @param {Cartesian2} [result] The object into which to store the result.
  1652. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  1653. */
  1654. Cartesian2.unpack = function(array, startingIndex, result) {
  1655. //>>includeStart('debug', pragmas.debug);
  1656. Check.Check.defined('array', array);
  1657. //>>includeEnd('debug');
  1658.  
  1659. startingIndex = when.defaultValue(startingIndex, 0);
  1660.  
  1661. if (!when.defined(result)) {
  1662. result = new Cartesian2();
  1663. }
  1664. result.x = array[startingIndex++];
  1665. result.y = array[startingIndex];
  1666. return result;
  1667. };
  1668.  
  1669. /**
  1670. * Flattens an array of Cartesian2s into and array of components.
  1671. *
  1672. * @param {Cartesian2[]} array The array of cartesians to pack.
  1673. * @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.
  1674.  
  1675. * @returns {Number[]} The packed array.
  1676. */
  1677. Cartesian2.packArray = function(array, result) {
  1678. //>>includeStart('debug', pragmas.debug);
  1679. Check.Check.defined('array', array);
  1680. //>>includeEnd('debug');
  1681.  
  1682. var length = array.length;
  1683. var resultLength = length * 2;
  1684. if (!when.defined(result)) {
  1685. result = new Array(resultLength);
  1686. } else if (!Array.isArray(result) && result.length !== resultLength) {
  1687. throw new Check.DeveloperError('If result is a typed array, it must have exactly array.length * 2 elements');
  1688. } else if (result.length !== resultLength) {
  1689. result.length = resultLength;
  1690. }
  1691.  
  1692. for (var i = 0; i < length; ++i) {
  1693. Cartesian2.pack(array[i], result, i * 2);
  1694. }
  1695. return result;
  1696. };
  1697.  
  1698. /**
  1699. * Unpacks an array of cartesian components into and array of Cartesian2s.
  1700. *
  1701. * @param {Number[]} array The array of components to unpack.
  1702. * @param {Cartesian2[]} [result] The array onto which to store the result.
  1703. * @returns {Cartesian2[]} The unpacked array.
  1704. */
  1705. Cartesian2.unpackArray = function(array, result) {
  1706. //>>includeStart('debug', pragmas.debug);
  1707. Check.Check.defined('array', array);
  1708. Check.Check.typeOf.number.greaterThanOrEquals('array.length', array.length, 2);
  1709. if (array.length % 2 !== 0) {
  1710. throw new Check.DeveloperError('array length must be a multiple of 2.');
  1711. }
  1712. //>>includeEnd('debug');
  1713.  
  1714. var length = array.length;
  1715. if (!when.defined(result)) {
  1716. result = new Array(length / 2);
  1717. } else {
  1718. result.length = length / 2;
  1719. }
  1720.  
  1721. for (var i = 0; i < length; i += 2) {
  1722. var index = i / 2;
  1723. result[index] = Cartesian2.unpack(array, i, result[index]);
  1724. }
  1725. return result;
  1726. };
  1727.  
  1728. /**
  1729. * Creates a Cartesian2 from two consecutive elements in an array.
  1730. * @function
  1731. *
  1732. * @param {Number[]} array The array whose two consecutive elements correspond to the x and y components, respectively.
  1733. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to the x component.
  1734. * @param {Cartesian2} [result] The object onto which to store the result.
  1735. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  1736. *
  1737. * @example
  1738. * // Create a Cartesian2 with (1.0, 2.0)
  1739. * var v = [1.0, 2.0];
  1740. * var p = Cesium.Cartesian2.fromArray(v);
  1741. *
  1742. * // Create a Cartesian2 with (1.0, 2.0) using an offset into an array
  1743. * var v2 = [0.0, 0.0, 1.0, 2.0];
  1744. * var p2 = Cesium.Cartesian2.fromArray(v2, 2);
  1745. */
  1746. Cartesian2.fromArray = Cartesian2.unpack;
  1747.  
  1748. /**
  1749. * Computes the value of the maximum component for the supplied Cartesian.
  1750. *
  1751. * @param {Cartesian2} cartesian The cartesian to use.
  1752. * @returns {Number} The value of the maximum component.
  1753. */
  1754. Cartesian2.maximumComponent = function(cartesian) {
  1755. //>>includeStart('debug', pragmas.debug);
  1756. Check.Check.typeOf.object('cartesian', cartesian);
  1757. //>>includeEnd('debug');
  1758.  
  1759. return Math.max(cartesian.x, cartesian.y);
  1760. };
  1761.  
  1762. /**
  1763. * Computes the value of the minimum component for the supplied Cartesian.
  1764. *
  1765. * @param {Cartesian2} cartesian The cartesian to use.
  1766. * @returns {Number} The value of the minimum component.
  1767. */
  1768. Cartesian2.minimumComponent = function(cartesian) {
  1769. //>>includeStart('debug', pragmas.debug);
  1770. Check.Check.typeOf.object('cartesian', cartesian);
  1771. //>>includeEnd('debug');
  1772.  
  1773. return Math.min(cartesian.x, cartesian.y);
  1774. };
  1775.  
  1776. /**
  1777. * Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.
  1778. *
  1779. * @param {Cartesian2} first A cartesian to compare.
  1780. * @param {Cartesian2} second A cartesian to compare.
  1781. * @param {Cartesian2} result The object into which to store the result.
  1782. * @returns {Cartesian2} A cartesian with the minimum components.
  1783. */
  1784. Cartesian2.minimumByComponent = function(first, second, result) {
  1785. //>>includeStart('debug', pragmas.debug);
  1786. Check.Check.typeOf.object('first', first);
  1787. Check.Check.typeOf.object('second', second);
  1788. Check.Check.typeOf.object('result', result);
  1789. //>>includeEnd('debug');
  1790.  
  1791. result.x = Math.min(first.x, second.x);
  1792. result.y = Math.min(first.y, second.y);
  1793.  
  1794. return result;
  1795. };
  1796.  
  1797. /**
  1798. * Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.
  1799. *
  1800. * @param {Cartesian2} first A cartesian to compare.
  1801. * @param {Cartesian2} second A cartesian to compare.
  1802. * @param {Cartesian2} result The object into which to store the result.
  1803. * @returns {Cartesian2} A cartesian with the maximum components.
  1804. */
  1805. Cartesian2.maximumByComponent = function(first, second, result) {
  1806. //>>includeStart('debug', pragmas.debug);
  1807. Check.Check.typeOf.object('first', first);
  1808. Check.Check.typeOf.object('second', second);
  1809. Check.Check.typeOf.object('result', result);
  1810. //>>includeEnd('debug');
  1811.  
  1812. result.x = Math.max(first.x, second.x);
  1813. result.y = Math.max(first.y, second.y);
  1814. return result;
  1815. };
  1816.  
  1817. /**
  1818. * Computes the provided Cartesian's squared magnitude.
  1819. *
  1820. * @param {Cartesian2} cartesian The Cartesian instance whose squared magnitude is to be computed.
  1821. * @returns {Number} The squared magnitude.
  1822. */
  1823. Cartesian2.magnitudeSquared = function(cartesian) {
  1824. //>>includeStart('debug', pragmas.debug);
  1825. Check.Check.typeOf.object('cartesian', cartesian);
  1826. //>>includeEnd('debug');
  1827.  
  1828. return cartesian.x * cartesian.x + cartesian.y * cartesian.y;
  1829. };
  1830.  
  1831. /**
  1832. * Computes the Cartesian's magnitude (length).
  1833. *
  1834. * @param {Cartesian2} cartesian The Cartesian instance whose magnitude is to be computed.
  1835. * @returns {Number} The magnitude.
  1836. */
  1837. Cartesian2.magnitude = function(cartesian) {
  1838. return Math.sqrt(Cartesian2.magnitudeSquared(cartesian));
  1839. };
  1840.  
  1841. var distanceScratch = new Cartesian2();
  1842.  
  1843. /**
  1844. * Computes the distance between two points.
  1845. *
  1846. * @param {Cartesian2} left The first point to compute the distance from.
  1847. * @param {Cartesian2} right The second point to compute the distance to.
  1848. * @returns {Number} The distance between two points.
  1849. *
  1850. * @example
  1851. * // Returns 1.0
  1852. * var d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(2.0, 0.0));
  1853. */
  1854. Cartesian2.distance = function(left, right) {
  1855. //>>includeStart('debug', pragmas.debug);
  1856. Check.Check.typeOf.object('left', left);
  1857. Check.Check.typeOf.object('right', right);
  1858. //>>includeEnd('debug');
  1859.  
  1860. Cartesian2.subtract(left, right, distanceScratch);
  1861. return Cartesian2.magnitude(distanceScratch);
  1862. };
  1863.  
  1864. /**
  1865. * Computes the squared distance between two points. Comparing squared distances
  1866. * using this function is more efficient than comparing distances using {@link Cartesian2#distance}.
  1867. *
  1868. * @param {Cartesian2} left The first point to compute the distance from.
  1869. * @param {Cartesian2} right The second point to compute the distance to.
  1870. * @returns {Number} The distance between two points.
  1871. *
  1872. * @example
  1873. * // Returns 4.0, not 2.0
  1874. * var d = Cesium.Cartesian2.distance(new Cesium.Cartesian2(1.0, 0.0), new Cesium.Cartesian2(3.0, 0.0));
  1875. */
  1876. Cartesian2.distanceSquared = function(left, right) {
  1877. //>>includeStart('debug', pragmas.debug);
  1878. Check.Check.typeOf.object('left', left);
  1879. Check.Check.typeOf.object('right', right);
  1880. //>>includeEnd('debug');
  1881.  
  1882. Cartesian2.subtract(left, right, distanceScratch);
  1883. return Cartesian2.magnitudeSquared(distanceScratch);
  1884. };
  1885.  
  1886. /**
  1887. * Computes the normalized form of the supplied Cartesian.
  1888. *
  1889. * @param {Cartesian2} cartesian The Cartesian to be normalized.
  1890. * @param {Cartesian2} result The object onto which to store the result.
  1891. * @returns {Cartesian2} The modified result parameter.
  1892. */
  1893. Cartesian2.normalize = function(cartesian, result) {
  1894. //>>includeStart('debug', pragmas.debug);
  1895. Check.Check.typeOf.object('cartesian', cartesian);
  1896. Check.Check.typeOf.object('result', result);
  1897. //>>includeEnd('debug');
  1898.  
  1899. var magnitude = Cartesian2.magnitude(cartesian);
  1900.  
  1901. result.x = cartesian.x / magnitude;
  1902. result.y = cartesian.y / magnitude;
  1903.  
  1904. //>>includeStart('debug', pragmas.debug);
  1905. if (isNaN(result.x) || isNaN(result.y)) {
  1906. throw new Check.DeveloperError('normalized result is not a number');
  1907. }
  1908. //>>includeEnd('debug');
  1909.  
  1910. return result;
  1911. };
  1912.  
  1913. /**
  1914. * Computes the dot (scalar) product of two Cartesians.
  1915. *
  1916. * @param {Cartesian2} left The first Cartesian.
  1917. * @param {Cartesian2} right The second Cartesian.
  1918. * @returns {Number} The dot product.
  1919. */
  1920. Cartesian2.dot = function(left, right) {
  1921. //>>includeStart('debug', pragmas.debug);
  1922. Check.Check.typeOf.object('left', left);
  1923. Check.Check.typeOf.object('right', right);
  1924. //>>includeEnd('debug');
  1925.  
  1926. return left.x * right.x + left.y * right.y;
  1927. };
  1928.  
  1929. /**
  1930. * Computes the componentwise product of two Cartesians.
  1931. *
  1932. * @param {Cartesian2} left The first Cartesian.
  1933. * @param {Cartesian2} right The second Cartesian.
  1934. * @param {Cartesian2} result The object onto which to store the result.
  1935. * @returns {Cartesian2} The modified result parameter.
  1936. */
  1937. Cartesian2.multiplyComponents = function(left, right, result) {
  1938. //>>includeStart('debug', pragmas.debug);
  1939. Check.Check.typeOf.object('left', left);
  1940. Check.Check.typeOf.object('right', right);
  1941. Check.Check.typeOf.object('result', result);
  1942. //>>includeEnd('debug');
  1943.  
  1944. result.x = left.x * right.x;
  1945. result.y = left.y * right.y;
  1946. return result;
  1947. };
  1948.  
  1949. /**
  1950. * Computes the componentwise quotient of two Cartesians.
  1951. *
  1952. * @param {Cartesian2} left The first Cartesian.
  1953. * @param {Cartesian2} right The second Cartesian.
  1954. * @param {Cartesian2} result The object onto which to store the result.
  1955. * @returns {Cartesian2} The modified result parameter.
  1956. */
  1957. Cartesian2.divideComponents = function(left, right, result) {
  1958. //>>includeStart('debug', pragmas.debug);
  1959. Check.Check.typeOf.object('left', left);
  1960. Check.Check.typeOf.object('right', right);
  1961. Check.Check.typeOf.object('result', result);
  1962. //>>includeEnd('debug');
  1963.  
  1964. result.x = left.x / right.x;
  1965. result.y = left.y / right.y;
  1966. return result;
  1967. };
  1968.  
  1969. /**
  1970. * Computes the componentwise sum of two Cartesians.
  1971. *
  1972. * @param {Cartesian2} left The first Cartesian.
  1973. * @param {Cartesian2} right The second Cartesian.
  1974. * @param {Cartesian2} result The object onto which to store the result.
  1975. * @returns {Cartesian2} The modified result parameter.
  1976. */
  1977. Cartesian2.add = function(left, right, result) {
  1978. //>>includeStart('debug', pragmas.debug);
  1979. Check.Check.typeOf.object('left', left);
  1980. Check.Check.typeOf.object('right', right);
  1981. Check.Check.typeOf.object('result', result);
  1982. //>>includeEnd('debug');
  1983.  
  1984. result.x = left.x + right.x;
  1985. result.y = left.y + right.y;
  1986. return result;
  1987. };
  1988.  
  1989. /**
  1990. * Computes the componentwise difference of two Cartesians.
  1991. *
  1992. * @param {Cartesian2} left The first Cartesian.
  1993. * @param {Cartesian2} right The second Cartesian.
  1994. * @param {Cartesian2} result The object onto which to store the result.
  1995. * @returns {Cartesian2} The modified result parameter.
  1996. */
  1997. Cartesian2.subtract = function(left, right, result) {
  1998. //>>includeStart('debug', pragmas.debug);
  1999. Check.Check.typeOf.object('left', left);
  2000. Check.Check.typeOf.object('right', right);
  2001. Check.Check.typeOf.object('result', result);
  2002. //>>includeEnd('debug');
  2003.  
  2004. result.x = left.x - right.x;
  2005. result.y = left.y - right.y;
  2006. return result;
  2007. };
  2008.  
  2009. /**
  2010. * Multiplies the provided Cartesian componentwise by the provided scalar.
  2011. *
  2012. * @param {Cartesian2} cartesian The Cartesian to be scaled.
  2013. * @param {Number} scalar The scalar to multiply with.
  2014. * @param {Cartesian2} result The object onto which to store the result.
  2015. * @returns {Cartesian2} The modified result parameter.
  2016. */
  2017. Cartesian2.multiplyByScalar = function(cartesian, scalar, result) {
  2018. //>>includeStart('debug', pragmas.debug);
  2019. Check.Check.typeOf.object('cartesian', cartesian);
  2020. Check.Check.typeOf.number('scalar', scalar);
  2021. Check.Check.typeOf.object('result', result);
  2022. //>>includeEnd('debug');
  2023.  
  2024. result.x = cartesian.x * scalar;
  2025. result.y = cartesian.y * scalar;
  2026. return result;
  2027. };
  2028.  
  2029. /**
  2030. * Divides the provided Cartesian componentwise by the provided scalar.
  2031. *
  2032. * @param {Cartesian2} cartesian The Cartesian to be divided.
  2033. * @param {Number} scalar The scalar to divide by.
  2034. * @param {Cartesian2} result The object onto which to store the result.
  2035. * @returns {Cartesian2} The modified result parameter.
  2036. */
  2037. Cartesian2.divideByScalar = function(cartesian, scalar, result) {
  2038. //>>includeStart('debug', pragmas.debug);
  2039. Check.Check.typeOf.object('cartesian', cartesian);
  2040. Check.Check.typeOf.number('scalar', scalar);
  2041. Check.Check.typeOf.object('result', result);
  2042. //>>includeEnd('debug');
  2043.  
  2044. result.x = cartesian.x / scalar;
  2045. result.y = cartesian.y / scalar;
  2046. return result;
  2047. };
  2048.  
  2049. /**
  2050. * Negates the provided Cartesian.
  2051. *
  2052. * @param {Cartesian2} cartesian The Cartesian to be negated.
  2053. * @param {Cartesian2} result The object onto which to store the result.
  2054. * @returns {Cartesian2} The modified result parameter.
  2055. */
  2056. Cartesian2.negate = function(cartesian, result) {
  2057. //>>includeStart('debug', pragmas.debug);
  2058. Check.Check.typeOf.object('cartesian', cartesian);
  2059. Check.Check.typeOf.object('result', result);
  2060. //>>includeEnd('debug');
  2061.  
  2062. result.x = -cartesian.x;
  2063. result.y = -cartesian.y;
  2064. return result;
  2065. };
  2066.  
  2067. /**
  2068. * Computes the absolute value of the provided Cartesian.
  2069. *
  2070. * @param {Cartesian2} cartesian The Cartesian whose absolute value is to be computed.
  2071. * @param {Cartesian2} result The object onto which to store the result.
  2072. * @returns {Cartesian2} The modified result parameter.
  2073. */
  2074. Cartesian2.abs = function(cartesian, result) {
  2075. //>>includeStart('debug', pragmas.debug);
  2076. Check.Check.typeOf.object('cartesian', cartesian);
  2077. Check.Check.typeOf.object('result', result);
  2078. //>>includeEnd('debug');
  2079.  
  2080. result.x = Math.abs(cartesian.x);
  2081. result.y = Math.abs(cartesian.y);
  2082. return result;
  2083. };
  2084.  
  2085. var lerpScratch = new Cartesian2();
  2086. /**
  2087. * Computes the linear interpolation or extrapolation at t using the provided cartesians.
  2088. *
  2089. * @param {Cartesian2} start The value corresponding to t at 0.0.
  2090. * @param {Cartesian2} end The value corresponding to t at 1.0.
  2091. * @param {Number} t The point along t at which to interpolate.
  2092. * @param {Cartesian2} result The object onto which to store the result.
  2093. * @returns {Cartesian2} The modified result parameter.
  2094. */
  2095. Cartesian2.lerp = function(start, end, t, result) {
  2096. //>>includeStart('debug', pragmas.debug);
  2097. Check.Check.typeOf.object('start', start);
  2098. Check.Check.typeOf.object('end', end);
  2099. Check.Check.typeOf.number('t', t);
  2100. Check.Check.typeOf.object('result', result);
  2101. //>>includeEnd('debug');
  2102.  
  2103. Cartesian2.multiplyByScalar(end, t, lerpScratch);
  2104. result = Cartesian2.multiplyByScalar(start, 1.0 - t, result);
  2105. return Cartesian2.add(lerpScratch, result, result);
  2106. };
  2107.  
  2108. var angleBetweenScratch = new Cartesian2();
  2109. var angleBetweenScratch2 = new Cartesian2();
  2110. /**
  2111. * Returns the angle, in radians, between the provided Cartesians.
  2112. *
  2113. * @param {Cartesian2} left The first Cartesian.
  2114. * @param {Cartesian2} right The second Cartesian.
  2115. * @returns {Number} The angle between the Cartesians.
  2116. */
  2117. Cartesian2.angleBetween = function(left, right) {
  2118. //>>includeStart('debug', pragmas.debug);
  2119. Check.Check.typeOf.object('left', left);
  2120. Check.Check.typeOf.object('right', right);
  2121. //>>includeEnd('debug');
  2122.  
  2123. Cartesian2.normalize(left, angleBetweenScratch);
  2124. Cartesian2.normalize(right, angleBetweenScratch2);
  2125. return _Math.CesiumMath.acosClamped(Cartesian2.dot(angleBetweenScratch, angleBetweenScratch2));
  2126. };
  2127.  
  2128. var mostOrthogonalAxisScratch = new Cartesian2();
  2129. /**
  2130. * Returns the axis that is most orthogonal to the provided Cartesian.
  2131. *
  2132. * @param {Cartesian2} cartesian The Cartesian on which to find the most orthogonal axis.
  2133. * @param {Cartesian2} result The object onto which to store the result.
  2134. * @returns {Cartesian2} The most orthogonal axis.
  2135. */
  2136. Cartesian2.mostOrthogonalAxis = function(cartesian, result) {
  2137. //>>includeStart('debug', pragmas.debug);
  2138. Check.Check.typeOf.object('cartesian', cartesian);
  2139. Check.Check.typeOf.object('result', result);
  2140. //>>includeEnd('debug');
  2141.  
  2142. var f = Cartesian2.normalize(cartesian, mostOrthogonalAxisScratch);
  2143. Cartesian2.abs(f, f);
  2144.  
  2145. if (f.x <= f.y) {
  2146. result = Cartesian2.clone(Cartesian2.UNIT_X, result);
  2147. } else {
  2148. result = Cartesian2.clone(Cartesian2.UNIT_Y, result);
  2149. }
  2150.  
  2151. return result;
  2152. };
  2153.  
  2154. /**
  2155. * Compares the provided Cartesians componentwise and returns
  2156. * <code>true</code> if they are equal, <code>false</code> otherwise.
  2157. *
  2158. * @param {Cartesian2} [left] The first Cartesian.
  2159. * @param {Cartesian2} [right] The second Cartesian.
  2160. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  2161. */
  2162. Cartesian2.equals = function(left, right) {
  2163. return (left === right) ||
  2164. ((when.defined(left)) &&
  2165. (when.defined(right)) &&
  2166. (left.x === right.x) &&
  2167. (left.y === right.y));
  2168. };
  2169.  
  2170. /**
  2171. * @private
  2172. */
  2173. Cartesian2.equalsArray = function(cartesian, array, offset) {
  2174. return cartesian.x === array[offset] &&
  2175. cartesian.y === array[offset + 1];
  2176. };
  2177.  
  2178. /**
  2179. * Compares the provided Cartesians componentwise and returns
  2180. * <code>true</code> if they pass an absolute or relative tolerance test,
  2181. * <code>false</code> otherwise.
  2182. *
  2183. * @param {Cartesian2} [left] The first Cartesian.
  2184. * @param {Cartesian2} [right] The second Cartesian.
  2185. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  2186. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  2187. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  2188. */
  2189. Cartesian2.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
  2190. return (left === right) ||
  2191. (when.defined(left) &&
  2192. when.defined(right) &&
  2193. _Math.CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
  2194. _Math.CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon));
  2195. };
  2196.  
  2197. /**
  2198. * An immutable Cartesian2 instance initialized to (0.0, 0.0).
  2199. *
  2200. * @type {Cartesian2}
  2201. * @constant
  2202. */
  2203. Cartesian2.ZERO = Object.freeze(new Cartesian2(0.0, 0.0));
  2204.  
  2205. /**
  2206. * An immutable Cartesian2 instance initialized to (1.0, 0.0).
  2207. *
  2208. * @type {Cartesian2}
  2209. * @constant
  2210. */
  2211. Cartesian2.UNIT_X = Object.freeze(new Cartesian2(1.0, 0.0));
  2212.  
  2213. /**
  2214. * An immutable Cartesian2 instance initialized to (0.0, 1.0).
  2215. *
  2216. * @type {Cartesian2}
  2217. * @constant
  2218. */
  2219. Cartesian2.UNIT_Y = Object.freeze(new Cartesian2(0.0, 1.0));
  2220.  
  2221. /**
  2222. * Duplicates this Cartesian2 instance.
  2223. *
  2224. * @param {Cartesian2} [result] The object onto which to store the result.
  2225. * @returns {Cartesian2} The modified result parameter or a new Cartesian2 instance if one was not provided.
  2226. */
  2227. Cartesian2.prototype.clone = function(result) {
  2228. return Cartesian2.clone(this, result);
  2229. };
  2230.  
  2231. /**
  2232. * Compares this Cartesian against the provided Cartesian componentwise and returns
  2233. * <code>true</code> if they are equal, <code>false</code> otherwise.
  2234. *
  2235. * @param {Cartesian2} [right] The right hand side Cartesian.
  2236. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  2237. */
  2238. Cartesian2.prototype.equals = function(right) {
  2239. return Cartesian2.equals(this, right);
  2240. };
  2241.  
  2242. /**
  2243. * Compares this Cartesian against the provided Cartesian componentwise and returns
  2244. * <code>true</code> if they pass an absolute or relative tolerance test,
  2245. * <code>false</code> otherwise.
  2246. *
  2247. * @param {Cartesian2} [right] The right hand side Cartesian.
  2248. * @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
  2249. * @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
  2250. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  2251. */
  2252. Cartesian2.prototype.equalsEpsilon = function(right, relativeEpsilon, absoluteEpsilon) {
  2253. return Cartesian2.equalsEpsilon(this, right, relativeEpsilon, absoluteEpsilon);
  2254. };
  2255.  
  2256. /**
  2257. * Creates a string representing this Cartesian in the format '(x, y)'.
  2258. *
  2259. * @returns {String} A string representing the provided Cartesian in the format '(x, y)'.
  2260. */
  2261. Cartesian2.prototype.toString = function() {
  2262. return '(' + this.x + ', ' + this.y + ')';
  2263. };
  2264.  
  2265. exports.Cartesian2 = Cartesian2;
  2266. exports.Ellipsoid = Ellipsoid;
  2267. exports.Rectangle = Rectangle;
  2268.  
  2269. });