GeometryAttribute-ed359d71.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Check-da037458', './freezeObject-2d83f591', './defaultValue-f2e68450', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './WebGLConstants-497deb20'], function (exports, defined, Check, freezeObject, defaultValue, Cartesian2, defineProperties, Transforms, WebGLConstants) { 'use strict';
  3. /**
  4. * @private
  5. */
  6. var GeometryType = {
  7. NONE : 0,
  8. TRIANGLES : 1,
  9. LINES : 2,
  10. POLYLINES : 3
  11. };
  12. var GeometryType$1 = freezeObject.freezeObject(GeometryType);
  13. /**
  14. * A 2x2 matrix, indexable as a column-major order array.
  15. * Constructor parameters are in row-major order for code readability.
  16. * @alias Matrix2
  17. * @constructor
  18. *
  19. * @param {Number} [column0Row0=0.0] The value for column 0, row 0.
  20. * @param {Number} [column1Row0=0.0] The value for column 1, row 0.
  21. * @param {Number} [column0Row1=0.0] The value for column 0, row 1.
  22. * @param {Number} [column1Row1=0.0] The value for column 1, row 1.
  23. *
  24. * @see Matrix2.fromColumnMajorArray
  25. * @see Matrix2.fromRowMajorArray
  26. * @see Matrix2.fromScale
  27. * @see Matrix2.fromUniformScale
  28. * @see Matrix3
  29. * @see Matrix4
  30. */
  31. function Matrix2(column0Row0, column1Row0, column0Row1, column1Row1) {
  32. this[0] = defaultValue.defaultValue(column0Row0, 0.0);
  33. this[1] = defaultValue.defaultValue(column0Row1, 0.0);
  34. this[2] = defaultValue.defaultValue(column1Row0, 0.0);
  35. this[3] = defaultValue.defaultValue(column1Row1, 0.0);
  36. }
  37. /**
  38. * The number of elements used to pack the object into an array.
  39. * @type {Number}
  40. */
  41. Matrix2.packedLength = 4;
  42. /**
  43. * Stores the provided instance into the provided array.
  44. *
  45. * @param {Matrix2} value The value to pack.
  46. * @param {Number[]} array The array to pack into.
  47. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  48. *
  49. * @returns {Number[]} The array that was packed into
  50. */
  51. Matrix2.pack = function(value, array, startingIndex) {
  52. //>>includeStart('debug', pragmas.debug);
  53. Check.Check.typeOf.object('value', value);
  54. Check.Check.defined('array', array);
  55. //>>includeEnd('debug');
  56. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  57. array[startingIndex++] = value[0];
  58. array[startingIndex++] = value[1];
  59. array[startingIndex++] = value[2];
  60. array[startingIndex++] = value[3];
  61. return array;
  62. };
  63. /**
  64. * Retrieves an instance from a packed array.
  65. *
  66. * @param {Number[]} array The packed array.
  67. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  68. * @param {Matrix2} [result] The object into which to store the result.
  69. * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided.
  70. */
  71. Matrix2.unpack = function(array, startingIndex, result) {
  72. //>>includeStart('debug', pragmas.debug);
  73. Check.Check.defined('array', array);
  74. //>>includeEnd('debug');
  75. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  76. if (!defined.defined(result)) {
  77. result = new Matrix2();
  78. }
  79. result[0] = array[startingIndex++];
  80. result[1] = array[startingIndex++];
  81. result[2] = array[startingIndex++];
  82. result[3] = array[startingIndex++];
  83. return result;
  84. };
  85. /**
  86. * Duplicates a Matrix2 instance.
  87. *
  88. * @param {Matrix2} matrix The matrix to duplicate.
  89. * @param {Matrix2} [result] The object onto which to store the result.
  90. * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided. (Returns undefined if matrix is undefined)
  91. */
  92. Matrix2.clone = function(matrix, result) {
  93. if (!defined.defined(matrix)) {
  94. return undefined;
  95. }
  96. if (!defined.defined(result)) {
  97. return new Matrix2(matrix[0], matrix[2],
  98. matrix[1], matrix[3]);
  99. }
  100. result[0] = matrix[0];
  101. result[1] = matrix[1];
  102. result[2] = matrix[2];
  103. result[3] = matrix[3];
  104. return result;
  105. };
  106. /**
  107. * Creates a Matrix2 from 4 consecutive elements in an array.
  108. *
  109. * @param {Number[]} array The array whose 4 consecutive elements correspond to the positions of the matrix. Assumes column-major order.
  110. * @param {Number} [startingIndex=0] The offset into the array of the first element, which corresponds to first column first row position in the matrix.
  111. * @param {Matrix2} [result] The object onto which to store the result.
  112. * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided.
  113. *
  114. * @example
  115. * // Create the Matrix2:
  116. * // [1.0, 2.0]
  117. * // [1.0, 2.0]
  118. *
  119. * var v = [1.0, 1.0, 2.0, 2.0];
  120. * var m = Cesium.Matrix2.fromArray(v);
  121. *
  122. * // Create same Matrix2 with using an offset into an array
  123. * var v2 = [0.0, 0.0, 1.0, 1.0, 2.0, 2.0];
  124. * var m2 = Cesium.Matrix2.fromArray(v2, 2);
  125. */
  126. Matrix2.fromArray = function(array, startingIndex, result) {
  127. //>>includeStart('debug', pragmas.debug);
  128. Check.Check.defined('array', array);
  129. //>>includeEnd('debug');
  130. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  131. if (!defined.defined(result)) {
  132. result = new Matrix2();
  133. }
  134. result[0] = array[startingIndex];
  135. result[1] = array[startingIndex + 1];
  136. result[2] = array[startingIndex + 2];
  137. result[3] = array[startingIndex + 3];
  138. return result;
  139. };
  140. /**
  141. * Creates a Matrix2 instance from a column-major order array.
  142. *
  143. * @param {Number[]} values The column-major order array.
  144. * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.
  145. * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.
  146. */
  147. Matrix2.fromColumnMajorArray = function(values, result) {
  148. //>>includeStart('debug', pragmas.debug);
  149. Check.Check.defined('values', values);
  150. //>>includeEnd('debug');
  151. return Matrix2.clone(values, result);
  152. };
  153. /**
  154. * Creates a Matrix2 instance from a row-major order array.
  155. * The resulting matrix will be in column-major order.
  156. *
  157. * @param {Number[]} values The row-major order array.
  158. * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.
  159. * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.
  160. */
  161. Matrix2.fromRowMajorArray = function(values, result) {
  162. //>>includeStart('debug', pragmas.debug);
  163. Check.Check.defined('values', values);
  164. //>>includeEnd('debug');
  165. if (!defined.defined(result)) {
  166. return new Matrix2(values[0], values[1],
  167. values[2], values[3]);
  168. }
  169. result[0] = values[0];
  170. result[1] = values[2];
  171. result[2] = values[1];
  172. result[3] = values[3];
  173. return result;
  174. };
  175. /**
  176. * Computes a Matrix2 instance representing a non-uniform scale.
  177. *
  178. * @param {Cartesian2} scale The x and y scale factors.
  179. * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.
  180. * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.
  181. *
  182. * @example
  183. * // Creates
  184. * // [7.0, 0.0]
  185. * // [0.0, 8.0]
  186. * var m = Cesium.Matrix2.fromScale(new Cesium.Cartesian2(7.0, 8.0));
  187. */
  188. Matrix2.fromScale = function(scale, result) {
  189. //>>includeStart('debug', pragmas.debug);
  190. Check.Check.typeOf.object('scale', scale);
  191. //>>includeEnd('debug');
  192. if (!defined.defined(result)) {
  193. return new Matrix2(
  194. scale.x, 0.0,
  195. 0.0, scale.y);
  196. }
  197. result[0] = scale.x;
  198. result[1] = 0.0;
  199. result[2] = 0.0;
  200. result[3] = scale.y;
  201. return result;
  202. };
  203. /**
  204. * Computes a Matrix2 instance representing a uniform scale.
  205. *
  206. * @param {Number} scale The uniform scale factor.
  207. * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.
  208. * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.
  209. *
  210. * @example
  211. * // Creates
  212. * // [2.0, 0.0]
  213. * // [0.0, 2.0]
  214. * var m = Cesium.Matrix2.fromUniformScale(2.0);
  215. */
  216. Matrix2.fromUniformScale = function(scale, result) {
  217. //>>includeStart('debug', pragmas.debug);
  218. Check.Check.typeOf.number('scale', scale);
  219. //>>includeEnd('debug');
  220. if (!defined.defined(result)) {
  221. return new Matrix2(
  222. scale, 0.0,
  223. 0.0, scale);
  224. }
  225. result[0] = scale;
  226. result[1] = 0.0;
  227. result[2] = 0.0;
  228. result[3] = scale;
  229. return result;
  230. };
  231. /**
  232. * Creates a rotation matrix.
  233. *
  234. * @param {Number} angle The angle, in radians, of the rotation. Positive angles are counterclockwise.
  235. * @param {Matrix2} [result] The object in which the result will be stored, if undefined a new instance will be created.
  236. * @returns {Matrix2} The modified result parameter, or a new Matrix2 instance if one was not provided.
  237. *
  238. * @example
  239. * // Rotate a point 45 degrees counterclockwise.
  240. * var p = new Cesium.Cartesian2(5, 6);
  241. * var m = Cesium.Matrix2.fromRotation(Cesium.Math.toRadians(45.0));
  242. * var rotated = Cesium.Matrix2.multiplyByVector(m, p, new Cesium.Cartesian2());
  243. */
  244. Matrix2.fromRotation = function(angle, result) {
  245. //>>includeStart('debug', pragmas.debug);
  246. Check.Check.typeOf.number('angle', angle);
  247. //>>includeEnd('debug');
  248. var cosAngle = Math.cos(angle);
  249. var sinAngle = Math.sin(angle);
  250. if (!defined.defined(result)) {
  251. return new Matrix2(
  252. cosAngle, -sinAngle,
  253. sinAngle, cosAngle);
  254. }
  255. result[0] = cosAngle;
  256. result[1] = sinAngle;
  257. result[2] = -sinAngle;
  258. result[3] = cosAngle;
  259. return result;
  260. };
  261. /**
  262. * Creates an Array from the provided Matrix2 instance.
  263. * The array will be in column-major order.
  264. *
  265. * @param {Matrix2} matrix The matrix to use..
  266. * @param {Number[]} [result] The Array onto which to store the result.
  267. * @returns {Number[]} The modified Array parameter or a new Array instance if one was not provided.
  268. */
  269. Matrix2.toArray = function(matrix, result) {
  270. //>>includeStart('debug', pragmas.debug);
  271. Check.Check.typeOf.object('matrix', matrix);
  272. //>>includeEnd('debug');
  273. if (!defined.defined(result)) {
  274. return [matrix[0], matrix[1], matrix[2], matrix[3]];
  275. }
  276. result[0] = matrix[0];
  277. result[1] = matrix[1];
  278. result[2] = matrix[2];
  279. result[3] = matrix[3];
  280. return result;
  281. };
  282. /**
  283. * Computes the array index of the element at the provided row and column.
  284. *
  285. * @param {Number} row The zero-based index of the row.
  286. * @param {Number} column The zero-based index of the column.
  287. * @returns {Number} The index of the element at the provided row and column.
  288. *
  289. * @exception {DeveloperError} row must be 0 or 1.
  290. * @exception {DeveloperError} column must be 0 or 1.
  291. *
  292. * @example
  293. * var myMatrix = new Cesium.Matrix2();
  294. * var column1Row0Index = Cesium.Matrix2.getElementIndex(1, 0);
  295. * var column1Row0 = myMatrix[column1Row0Index]
  296. * myMatrix[column1Row0Index] = 10.0;
  297. */
  298. Matrix2.getElementIndex = function(column, row) {
  299. //>>includeStart('debug', pragmas.debug);
  300. Check.Check.typeOf.number.greaterThanOrEquals('row', row, 0);
  301. Check.Check.typeOf.number.lessThanOrEquals('row', row, 1);
  302. Check.Check.typeOf.number.greaterThanOrEquals('column', column, 0);
  303. Check.Check.typeOf.number.lessThanOrEquals('column', column, 1);
  304. //>>includeEnd('debug');
  305. return column * 2 + row;
  306. };
  307. /**
  308. * Retrieves a copy of the matrix column at the provided index as a Cartesian2 instance.
  309. *
  310. * @param {Matrix2} matrix The matrix to use.
  311. * @param {Number} index The zero-based index of the column to retrieve.
  312. * @param {Cartesian2} result The object onto which to store the result.
  313. * @returns {Cartesian2} The modified result parameter.
  314. *
  315. * @exception {DeveloperError} index must be 0 or 1.
  316. */
  317. Matrix2.getColumn = function(matrix, index, result) {
  318. //>>includeStart('debug', pragmas.debug);
  319. Check.Check.typeOf.object('matrix', matrix);
  320. Check.Check.typeOf.number.greaterThanOrEquals('index', index, 0);
  321. Check.Check.typeOf.number.lessThanOrEquals('index', index, 1);
  322. Check.Check.typeOf.object('result', result);
  323. //>>includeEnd('debug');
  324. var startIndex = index * 2;
  325. var x = matrix[startIndex];
  326. var y = matrix[startIndex + 1];
  327. result.x = x;
  328. result.y = y;
  329. return result;
  330. };
  331. /**
  332. * Computes a new matrix that replaces the specified column in the provided matrix with the provided Cartesian2 instance.
  333. *
  334. * @param {Matrix2} matrix The matrix to use.
  335. * @param {Number} index The zero-based index of the column to set.
  336. * @param {Cartesian2} cartesian The Cartesian whose values will be assigned to the specified column.
  337. * @param {Cartesian2} result The object onto which to store the result.
  338. * @returns {Matrix2} The modified result parameter.
  339. *
  340. * @exception {DeveloperError} index must be 0 or 1.
  341. */
  342. Matrix2.setColumn = function(matrix, index, cartesian, result) {
  343. //>>includeStart('debug', pragmas.debug);
  344. Check.Check.typeOf.object('matrix', matrix);
  345. Check.Check.typeOf.number.greaterThanOrEquals('index', index, 0);
  346. Check.Check.typeOf.number.lessThanOrEquals('index', index, 1);
  347. Check.Check.typeOf.object('cartesian', cartesian);
  348. Check.Check.typeOf.object('result', result);
  349. //>>includeEnd('debug');
  350. result = Matrix2.clone(matrix, result);
  351. var startIndex = index * 2;
  352. result[startIndex] = cartesian.x;
  353. result[startIndex + 1] = cartesian.y;
  354. return result;
  355. };
  356. /**
  357. * Retrieves a copy of the matrix row at the provided index as a Cartesian2 instance.
  358. *
  359. * @param {Matrix2} matrix The matrix to use.
  360. * @param {Number} index The zero-based index of the row to retrieve.
  361. * @param {Cartesian2} result The object onto which to store the result.
  362. * @returns {Cartesian2} The modified result parameter.
  363. *
  364. * @exception {DeveloperError} index must be 0 or 1.
  365. */
  366. Matrix2.getRow = function(matrix, index, result) {
  367. //>>includeStart('debug', pragmas.debug);
  368. Check.Check.typeOf.object('matrix', matrix);
  369. Check.Check.typeOf.number.greaterThanOrEquals('index', index, 0);
  370. Check.Check.typeOf.number.lessThanOrEquals('index', index, 1);
  371. Check.Check.typeOf.object('result', result);
  372. //>>includeEnd('debug');
  373. var x = matrix[index];
  374. var y = matrix[index + 2];
  375. result.x = x;
  376. result.y = y;
  377. return result;
  378. };
  379. /**
  380. * Computes a new matrix that replaces the specified row in the provided matrix with the provided Cartesian2 instance.
  381. *
  382. * @param {Matrix2} matrix The matrix to use.
  383. * @param {Number} index The zero-based index of the row to set.
  384. * @param {Cartesian2} cartesian The Cartesian whose values will be assigned to the specified row.
  385. * @param {Matrix2} result The object onto which to store the result.
  386. * @returns {Matrix2} The modified result parameter.
  387. *
  388. * @exception {DeveloperError} index must be 0 or 1.
  389. */
  390. Matrix2.setRow = function(matrix, index, cartesian, result) {
  391. //>>includeStart('debug', pragmas.debug);
  392. Check.Check.typeOf.object('matrix', matrix);
  393. Check.Check.typeOf.number.greaterThanOrEquals('index', index, 0);
  394. Check.Check.typeOf.number.lessThanOrEquals('index', index, 1);
  395. Check.Check.typeOf.object('cartesian', cartesian);
  396. Check.Check.typeOf.object('result', result);
  397. //>>includeEnd('debug');
  398. result = Matrix2.clone(matrix, result);
  399. result[index] = cartesian.x;
  400. result[index + 2] = cartesian.y;
  401. return result;
  402. };
  403. var scratchColumn = new Cartesian2.Cartesian2();
  404. /**
  405. * Extracts the non-uniform scale assuming the matrix is an affine transformation.
  406. *
  407. * @param {Matrix2} matrix The matrix.
  408. * @param {Cartesian2} result The object onto which to store the result.
  409. * @returns {Cartesian2} The modified result parameter.
  410. */
  411. Matrix2.getScale = function(matrix, result) {
  412. //>>includeStart('debug', pragmas.debug);
  413. Check.Check.typeOf.object('matrix', matrix);
  414. Check.Check.typeOf.object('result', result);
  415. //>>includeEnd('debug');
  416. result.x = Cartesian2.Cartesian2.magnitude(Cartesian2.Cartesian2.fromElements(matrix[0], matrix[1], scratchColumn));
  417. result.y = Cartesian2.Cartesian2.magnitude(Cartesian2.Cartesian2.fromElements(matrix[2], matrix[3], scratchColumn));
  418. return result;
  419. };
  420. var scratchScale = new Cartesian2.Cartesian2();
  421. /**
  422. * Computes the maximum scale assuming the matrix is an affine transformation.
  423. * The maximum scale is the maximum length of the column vectors.
  424. *
  425. * @param {Matrix2} matrix The matrix.
  426. * @returns {Number} The maximum scale.
  427. */
  428. Matrix2.getMaximumScale = function(matrix) {
  429. Matrix2.getScale(matrix, scratchScale);
  430. return Cartesian2.Cartesian2.maximumComponent(scratchScale);
  431. };
  432. /**
  433. * Computes the product of two matrices.
  434. *
  435. * @param {Matrix2} left The first matrix.
  436. * @param {Matrix2} right The second matrix.
  437. * @param {Matrix2} result The object onto which to store the result.
  438. * @returns {Matrix2} The modified result parameter.
  439. */
  440. Matrix2.multiply = function(left, right, result) {
  441. //>>includeStart('debug', pragmas.debug);
  442. Check.Check.typeOf.object('left', left);
  443. Check.Check.typeOf.object('right', right);
  444. Check.Check.typeOf.object('result', result);
  445. //>>includeEnd('debug');
  446. var column0Row0 = left[0] * right[0] + left[2] * right[1];
  447. var column1Row0 = left[0] * right[2] + left[2] * right[3];
  448. var column0Row1 = left[1] * right[0] + left[3] * right[1];
  449. var column1Row1 = left[1] * right[2] + left[3] * right[3];
  450. result[0] = column0Row0;
  451. result[1] = column0Row1;
  452. result[2] = column1Row0;
  453. result[3] = column1Row1;
  454. return result;
  455. };
  456. /**
  457. * Computes the sum of two matrices.
  458. *
  459. * @param {Matrix2} left The first matrix.
  460. * @param {Matrix2} right The second matrix.
  461. * @param {Matrix2} result The object onto which to store the result.
  462. * @returns {Matrix2} The modified result parameter.
  463. */
  464. Matrix2.add = function(left, right, result) {
  465. //>>includeStart('debug', pragmas.debug);
  466. Check.Check.typeOf.object('left', left);
  467. Check.Check.typeOf.object('right', right);
  468. Check.Check.typeOf.object('result', result);
  469. //>>includeEnd('debug');
  470. result[0] = left[0] + right[0];
  471. result[1] = left[1] + right[1];
  472. result[2] = left[2] + right[2];
  473. result[3] = left[3] + right[3];
  474. return result;
  475. };
  476. /**
  477. * Computes the difference of two matrices.
  478. *
  479. * @param {Matrix2} left The first matrix.
  480. * @param {Matrix2} right The second matrix.
  481. * @param {Matrix2} result The object onto which to store the result.
  482. * @returns {Matrix2} The modified result parameter.
  483. */
  484. Matrix2.subtract = function(left, right, result) {
  485. //>>includeStart('debug', pragmas.debug);
  486. Check.Check.typeOf.object('left', left);
  487. Check.Check.typeOf.object('right', right);
  488. Check.Check.typeOf.object('result', result);
  489. //>>includeEnd('debug');
  490. result[0] = left[0] - right[0];
  491. result[1] = left[1] - right[1];
  492. result[2] = left[2] - right[2];
  493. result[3] = left[3] - right[3];
  494. return result;
  495. };
  496. /**
  497. * Computes the product of a matrix and a column vector.
  498. *
  499. * @param {Matrix2} matrix The matrix.
  500. * @param {Cartesian2} cartesian The column.
  501. * @param {Cartesian2} result The object onto which to store the result.
  502. * @returns {Cartesian2} The modified result parameter.
  503. */
  504. Matrix2.multiplyByVector = function(matrix, cartesian, result) {
  505. //>>includeStart('debug', pragmas.debug);
  506. Check.Check.typeOf.object('matrix', matrix);
  507. Check.Check.typeOf.object('cartesian', cartesian);
  508. Check.Check.typeOf.object('result', result);
  509. //>>includeEnd('debug');
  510. var x = matrix[0] * cartesian.x + matrix[2] * cartesian.y;
  511. var y = matrix[1] * cartesian.x + matrix[3] * cartesian.y;
  512. result.x = x;
  513. result.y = y;
  514. return result;
  515. };
  516. /**
  517. * Computes the product of a matrix and a scalar.
  518. *
  519. * @param {Matrix2} matrix The matrix.
  520. * @param {Number} scalar The number to multiply by.
  521. * @param {Matrix2} result The object onto which to store the result.
  522. * @returns {Matrix2} The modified result parameter.
  523. */
  524. Matrix2.multiplyByScalar = function(matrix, scalar, result) {
  525. //>>includeStart('debug', pragmas.debug);
  526. Check.Check.typeOf.object('matrix', matrix);
  527. Check.Check.typeOf.number('scalar', scalar);
  528. Check.Check.typeOf.object('result', result);
  529. //>>includeEnd('debug');
  530. result[0] = matrix[0] * scalar;
  531. result[1] = matrix[1] * scalar;
  532. result[2] = matrix[2] * scalar;
  533. result[3] = matrix[3] * scalar;
  534. return result;
  535. };
  536. /**
  537. * Computes the product of a matrix times a (non-uniform) scale, as if the scale were a scale matrix.
  538. *
  539. * @param {Matrix2} matrix The matrix on the left-hand side.
  540. * @param {Cartesian2} scale The non-uniform scale on the right-hand side.
  541. * @param {Matrix2} result The object onto which to store the result.
  542. * @returns {Matrix2} The modified result parameter.
  543. *
  544. *
  545. * @example
  546. * // Instead of Cesium.Matrix2.multiply(m, Cesium.Matrix2.fromScale(scale), m);
  547. * Cesium.Matrix2.multiplyByScale(m, scale, m);
  548. *
  549. * @see Matrix2.fromScale
  550. * @see Matrix2.multiplyByUniformScale
  551. */
  552. Matrix2.multiplyByScale = function(matrix, scale, result) {
  553. //>>includeStart('debug', pragmas.debug);
  554. Check.Check.typeOf.object('matrix', matrix);
  555. Check.Check.typeOf.object('scale', scale);
  556. Check.Check.typeOf.object('result', result);
  557. //>>includeEnd('debug');
  558. result[0] = matrix[0] * scale.x;
  559. result[1] = matrix[1] * scale.x;
  560. result[2] = matrix[2] * scale.y;
  561. result[3] = matrix[3] * scale.y;
  562. return result;
  563. };
  564. /**
  565. * Creates a negated copy of the provided matrix.
  566. *
  567. * @param {Matrix2} matrix The matrix to negate.
  568. * @param {Matrix2} result The object onto which to store the result.
  569. * @returns {Matrix2} The modified result parameter.
  570. */
  571. Matrix2.negate = function(matrix, result) {
  572. //>>includeStart('debug', pragmas.debug);
  573. Check.Check.typeOf.object('matrix', matrix);
  574. Check.Check.typeOf.object('result', result);
  575. //>>includeEnd('debug');
  576. result[0] = -matrix[0];
  577. result[1] = -matrix[1];
  578. result[2] = -matrix[2];
  579. result[3] = -matrix[3];
  580. return result;
  581. };
  582. /**
  583. * Computes the transpose of the provided matrix.
  584. *
  585. * @param {Matrix2} matrix The matrix to transpose.
  586. * @param {Matrix2} result The object onto which to store the result.
  587. * @returns {Matrix2} The modified result parameter.
  588. */
  589. Matrix2.transpose = function(matrix, result) {
  590. //>>includeStart('debug', pragmas.debug);
  591. Check.Check.typeOf.object('matrix', matrix);
  592. Check.Check.typeOf.object('result', result);
  593. //>>includeEnd('debug');
  594. var column0Row0 = matrix[0];
  595. var column0Row1 = matrix[2];
  596. var column1Row0 = matrix[1];
  597. var column1Row1 = matrix[3];
  598. result[0] = column0Row0;
  599. result[1] = column0Row1;
  600. result[2] = column1Row0;
  601. result[3] = column1Row1;
  602. return result;
  603. };
  604. /**
  605. * Computes a matrix, which contains the absolute (unsigned) values of the provided matrix's elements.
  606. *
  607. * @param {Matrix2} matrix The matrix with signed elements.
  608. * @param {Matrix2} result The object onto which to store the result.
  609. * @returns {Matrix2} The modified result parameter.
  610. */
  611. Matrix2.abs = function(matrix, result) {
  612. //>>includeStart('debug', pragmas.debug);
  613. Check.Check.typeOf.object('matrix', matrix);
  614. Check.Check.typeOf.object('result', result);
  615. //>>includeEnd('debug');
  616. result[0] = Math.abs(matrix[0]);
  617. result[1] = Math.abs(matrix[1]);
  618. result[2] = Math.abs(matrix[2]);
  619. result[3] = Math.abs(matrix[3]);
  620. return result;
  621. };
  622. /**
  623. * Compares the provided matrices componentwise and returns
  624. * <code>true</code> if they are equal, <code>false</code> otherwise.
  625. *
  626. * @param {Matrix2} [left] The first matrix.
  627. * @param {Matrix2} [right] The second matrix.
  628. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  629. */
  630. Matrix2.equals = function(left, right) {
  631. return (left === right) ||
  632. (defined.defined(left) &&
  633. defined.defined(right) &&
  634. left[0] === right[0] &&
  635. left[1] === right[1] &&
  636. left[2] === right[2] &&
  637. left[3] === right[3]);
  638. };
  639. /**
  640. * @private
  641. */
  642. Matrix2.equalsArray = function(matrix, array, offset) {
  643. return matrix[0] === array[offset] &&
  644. matrix[1] === array[offset + 1] &&
  645. matrix[2] === array[offset + 2] &&
  646. matrix[3] === array[offset + 3];
  647. };
  648. /**
  649. * Compares the provided matrices componentwise and returns
  650. * <code>true</code> if they are within the provided epsilon,
  651. * <code>false</code> otherwise.
  652. *
  653. * @param {Matrix2} [left] The first matrix.
  654. * @param {Matrix2} [right] The second matrix.
  655. * @param {Number} epsilon The epsilon to use for equality testing.
  656. * @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
  657. */
  658. Matrix2.equalsEpsilon = function(left, right, epsilon) {
  659. //>>includeStart('debug', pragmas.debug);
  660. Check.Check.typeOf.number('epsilon', epsilon);
  661. //>>includeEnd('debug');
  662. return (left === right) ||
  663. (defined.defined(left) &&
  664. defined.defined(right) &&
  665. Math.abs(left[0] - right[0]) <= epsilon &&
  666. Math.abs(left[1] - right[1]) <= epsilon &&
  667. Math.abs(left[2] - right[2]) <= epsilon &&
  668. Math.abs(left[3] - right[3]) <= epsilon);
  669. };
  670. /**
  671. * An immutable Matrix2 instance initialized to the identity matrix.
  672. *
  673. * @type {Matrix2}
  674. * @constant
  675. */
  676. Matrix2.IDENTITY = freezeObject.freezeObject(new Matrix2(1.0, 0.0,
  677. 0.0, 1.0));
  678. /**
  679. * An immutable Matrix2 instance initialized to the zero matrix.
  680. *
  681. * @type {Matrix2}
  682. * @constant
  683. */
  684. Matrix2.ZERO = freezeObject.freezeObject(new Matrix2(0.0, 0.0,
  685. 0.0, 0.0));
  686. /**
  687. * The index into Matrix2 for column 0, row 0.
  688. *
  689. * @type {Number}
  690. * @constant
  691. *
  692. * @example
  693. * var matrix = new Cesium.Matrix2();
  694. * matrix[Cesium.Matrix2.COLUMN0ROW0] = 5.0; // set column 0, row 0 to 5.0
  695. */
  696. Matrix2.COLUMN0ROW0 = 0;
  697. /**
  698. * The index into Matrix2 for column 0, row 1.
  699. *
  700. * @type {Number}
  701. * @constant
  702. *
  703. * @example
  704. * var matrix = new Cesium.Matrix2();
  705. * matrix[Cesium.Matrix2.COLUMN0ROW1] = 5.0; // set column 0, row 1 to 5.0
  706. */
  707. Matrix2.COLUMN0ROW1 = 1;
  708. /**
  709. * The index into Matrix2 for column 1, row 0.
  710. *
  711. * @type {Number}
  712. * @constant
  713. *
  714. * @example
  715. * var matrix = new Cesium.Matrix2();
  716. * matrix[Cesium.Matrix2.COLUMN1ROW0] = 5.0; // set column 1, row 0 to 5.0
  717. */
  718. Matrix2.COLUMN1ROW0 = 2;
  719. /**
  720. * The index into Matrix2 for column 1, row 1.
  721. *
  722. * @type {Number}
  723. * @constant
  724. *
  725. * @example
  726. * var matrix = new Cesium.Matrix2();
  727. * matrix[Cesium.Matrix2.COLUMN1ROW1] = 5.0; // set column 1, row 1 to 5.0
  728. */
  729. Matrix2.COLUMN1ROW1 = 3;
  730. defineProperties.defineProperties(Matrix2.prototype, {
  731. /**
  732. * Gets the number of items in the collection.
  733. * @memberof Matrix2.prototype
  734. *
  735. * @type {Number}
  736. */
  737. length : {
  738. get : function() {
  739. return Matrix2.packedLength;
  740. }
  741. }
  742. });
  743. /**
  744. * Duplicates the provided Matrix2 instance.
  745. *
  746. * @param {Matrix2} [result] The object onto which to store the result.
  747. * @returns {Matrix2} The modified result parameter or a new Matrix2 instance if one was not provided.
  748. */
  749. Matrix2.prototype.clone = function(result) {
  750. return Matrix2.clone(this, result);
  751. };
  752. /**
  753. * Compares this matrix to the provided matrix componentwise and returns
  754. * <code>true</code> if they are equal, <code>false</code> otherwise.
  755. *
  756. * @param {Matrix2} [right] The right hand side matrix.
  757. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  758. */
  759. Matrix2.prototype.equals = function(right) {
  760. return Matrix2.equals(this, right);
  761. };
  762. /**
  763. * Compares this matrix to the provided matrix componentwise and returns
  764. * <code>true</code> if they are within the provided epsilon,
  765. * <code>false</code> otherwise.
  766. *
  767. * @param {Matrix2} [right] The right hand side matrix.
  768. * @param {Number} epsilon The epsilon to use for equality testing.
  769. * @returns {Boolean} <code>true</code> if they are within the provided epsilon, <code>false</code> otherwise.
  770. */
  771. Matrix2.prototype.equalsEpsilon = function(right, epsilon) {
  772. return Matrix2.equalsEpsilon(this, right, epsilon);
  773. };
  774. /**
  775. * Creates a string representing this Matrix with each row being
  776. * on a separate line and in the format '(column0, column1)'.
  777. *
  778. * @returns {String} A string representing the provided Matrix with each row being on a separate line and in the format '(column0, column1)'.
  779. */
  780. Matrix2.prototype.toString = function() {
  781. return '(' + this[0] + ', ' + this[2] + ')\n' +
  782. '(' + this[1] + ', ' + this[3] + ')';
  783. };
  784. /**
  785. * The type of a geometric primitive, i.e., points, lines, and triangles.
  786. *
  787. * @exports PrimitiveType
  788. */
  789. var PrimitiveType = {
  790. /**
  791. * Points primitive where each vertex (or index) is a separate point.
  792. *
  793. * @type {Number}
  794. * @constant
  795. */
  796. POINTS : WebGLConstants.WebGLConstants.POINTS,
  797. /**
  798. * Lines primitive where each two vertices (or indices) is a line segment. Line segments are not necessarily connected.
  799. *
  800. * @type {Number}
  801. * @constant
  802. */
  803. LINES : WebGLConstants.WebGLConstants.LINES,
  804. /**
  805. * Line loop primitive where each vertex (or index) after the first connects a line to
  806. * the previous vertex, and the last vertex implicitly connects to the first.
  807. *
  808. * @type {Number}
  809. * @constant
  810. */
  811. LINE_LOOP : WebGLConstants.WebGLConstants.LINE_LOOP,
  812. /**
  813. * Line strip primitive where each vertex (or index) after the first connects a line to the previous vertex.
  814. *
  815. * @type {Number}
  816. * @constant
  817. */
  818. LINE_STRIP : WebGLConstants.WebGLConstants.LINE_STRIP,
  819. /**
  820. * Triangles primitive where each three vertices (or indices) is a triangle. Triangles do not necessarily share edges.
  821. *
  822. * @type {Number}
  823. * @constant
  824. */
  825. TRIANGLES : WebGLConstants.WebGLConstants.TRIANGLES,
  826. /**
  827. * Triangle strip primitive where each vertex (or index) after the first two connect to
  828. * the previous two vertices forming a triangle. For example, this can be used to model a wall.
  829. *
  830. * @type {Number}
  831. * @constant
  832. */
  833. TRIANGLE_STRIP : WebGLConstants.WebGLConstants.TRIANGLE_STRIP,
  834. /**
  835. * Triangle fan primitive where each vertex (or index) after the first two connect to
  836. * the previous vertex and the first vertex forming a triangle. For example, this can be used
  837. * to model a cone or circle.
  838. *
  839. * @type {Number}
  840. * @constant
  841. */
  842. TRIANGLE_FAN : WebGLConstants.WebGLConstants.TRIANGLE_FAN,
  843. /**
  844. * @private
  845. */
  846. validate : function(primitiveType) {
  847. return primitiveType === PrimitiveType.POINTS ||
  848. primitiveType === PrimitiveType.LINES ||
  849. primitiveType === PrimitiveType.LINE_LOOP ||
  850. primitiveType === PrimitiveType.LINE_STRIP ||
  851. primitiveType === PrimitiveType.TRIANGLES ||
  852. primitiveType === PrimitiveType.TRIANGLE_STRIP ||
  853. primitiveType === PrimitiveType.TRIANGLE_FAN;
  854. }
  855. };
  856. var PrimitiveType$1 = freezeObject.freezeObject(PrimitiveType);
  857. /**
  858. * A geometry representation with attributes forming vertices and optional index data
  859. * defining primitives. Geometries and an {@link Appearance}, which describes the shading,
  860. * can be assigned to a {@link Primitive} for visualization. A <code>Primitive</code> can
  861. * be created from many heterogeneous - in many cases - geometries for performance.
  862. * <p>
  863. * Geometries can be transformed and optimized using functions in {@link GeometryPipeline}.
  864. * </p>
  865. *
  866. * @alias Geometry
  867. * @constructor
  868. *
  869. * @param {Object} options Object with the following properties:
  870. * @param {GeometryAttributes} options.attributes Attributes, which make up the geometry's vertices.
  871. * @param {PrimitiveType} [options.primitiveType=PrimitiveType.TRIANGLES] The type of primitives in the geometry.
  872. * @param {Uint16Array|Uint32Array} [options.indices] Optional index data that determines the primitives in the geometry.
  873. * @param {BoundingSphere} [options.boundingSphere] An optional bounding sphere that fully enclosed the geometry.
  874. *
  875. * @see PolygonGeometry
  876. * @see RectangleGeometry
  877. * @see EllipseGeometry
  878. * @see CircleGeometry
  879. * @see WallGeometry
  880. * @see SimplePolylineGeometry
  881. * @see BoxGeometry
  882. * @see EllipsoidGeometry
  883. *
  884. * @demo {@link https://sandcastle.cesium.com/index.html?src=Geometry%20and%20Appearances.html|Geometry and Appearances Demo}
  885. *
  886. * @example
  887. * // Create geometry with a position attribute and indexed lines.
  888. * var positions = new Float64Array([
  889. * 0.0, 0.0, 0.0,
  890. * 7500000.0, 0.0, 0.0,
  891. * 0.0, 7500000.0, 0.0
  892. * ]);
  893. *
  894. * var geometry = new Cesium.Geometry({
  895. * attributes : {
  896. * position : new Cesium.GeometryAttribute({
  897. * componentDatatype : Cesium.ComponentDatatype.DOUBLE,
  898. * componentsPerAttribute : 3,
  899. * values : positions
  900. * })
  901. * },
  902. * indices : new Uint16Array([0, 1, 1, 2, 2, 0]),
  903. * primitiveType : Cesium.PrimitiveType.LINES,
  904. * boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
  905. * });
  906. */
  907. function Geometry(options) {
  908. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  909. //>>includeStart('debug', pragmas.debug);
  910. Check.Check.typeOf.object('options.attributes', options.attributes);
  911. //>>includeEnd('debug');
  912. /**
  913. * Attributes, which make up the geometry's vertices. Each property in this object corresponds to a
  914. * {@link GeometryAttribute} containing the attribute's data.
  915. * <p>
  916. * Attributes are always stored non-interleaved in a Geometry.
  917. * </p>
  918. * <p>
  919. * There are reserved attribute names with well-known semantics. The following attributes
  920. * are created by a Geometry (depending on the provided {@link VertexFormat}.
  921. * <ul>
  922. * <li><code>position</code> - 3D vertex position. 64-bit floating-point (for precision). 3 components per attribute. See {@link VertexFormat#position}.</li>
  923. * <li><code>normal</code> - Normal (normalized), commonly used for lighting. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#normal}.</li>
  924. * <li><code>st</code> - 2D texture coordinate. 32-bit floating-point. 2 components per attribute. See {@link VertexFormat#st}.</li>
  925. * <li><code>bitangent</code> - Bitangent (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#bitangent}.</li>
  926. * <li><code>tangent</code> - Tangent (normalized), used for tangent-space effects like bump mapping. 32-bit floating-point. 3 components per attribute. See {@link VertexFormat#tangent}.</li>
  927. * </ul>
  928. * </p>
  929. * <p>
  930. * The following attribute names are generally not created by a Geometry, but are added
  931. * to a Geometry by a {@link Primitive} or {@link GeometryPipeline} functions to prepare
  932. * the geometry for rendering.
  933. * <ul>
  934. * <li><code>position3DHigh</code> - High 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  935. * <li><code>position3DLow</code> - Low 32 bits for encoded 64-bit position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  936. * <li><code>position3DHigh</code> - High 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  937. * <li><code>position2DLow</code> - Low 32 bits for encoded 64-bit 2D (Columbus view) position computed with {@link GeometryPipeline.encodeAttribute}. 32-bit floating-point. 4 components per attribute.</li>
  938. * <li><code>color</code> - RGBA color (normalized) usually from {@link GeometryInstance#color}. 32-bit floating-point. 4 components per attribute.</li>
  939. * <li><code>pickColor</code> - RGBA color used for picking. 32-bit floating-point. 4 components per attribute.</li>
  940. * </ul>
  941. * </p>
  942. *
  943. * @type GeometryAttributes
  944. *
  945. * @default undefined
  946. *
  947. *
  948. * @example
  949. * geometry.attributes.position = new Cesium.GeometryAttribute({
  950. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  951. * componentsPerAttribute : 3,
  952. * values : new Float32Array(0)
  953. * });
  954. *
  955. * @see GeometryAttribute
  956. * @see VertexFormat
  957. */
  958. this.attributes = options.attributes;
  959. /**
  960. * Optional index data that - along with {@link Geometry#primitiveType} -
  961. * determines the primitives in the geometry.
  962. *
  963. * @type Array
  964. *
  965. * @default undefined
  966. */
  967. this.indices = options.indices;
  968. /**
  969. * The type of primitives in the geometry. This is most often {@link PrimitiveType.TRIANGLES},
  970. * but can varying based on the specific geometry.
  971. *
  972. * @type PrimitiveType
  973. *
  974. * @default undefined
  975. */
  976. this.primitiveType = defaultValue.defaultValue(options.primitiveType, PrimitiveType$1.TRIANGLES);
  977. /**
  978. * An optional bounding sphere that fully encloses the geometry. This is
  979. * commonly used for culling.
  980. *
  981. * @type BoundingSphere
  982. *
  983. * @default undefined
  984. */
  985. this.boundingSphere = options.boundingSphere;
  986. /**
  987. * @private
  988. */
  989. this.geometryType = defaultValue.defaultValue(options.geometryType, GeometryType$1.NONE);
  990. /**
  991. * @private
  992. */
  993. this.boundingSphereCV = options.boundingSphereCV;
  994. /**
  995. * @private
  996. * Used for computing the bounding sphere for geometry using the applyOffset vertex attribute
  997. */
  998. this.offsetAttribute = options.offsetAttribute;
  999. }
  1000. /**
  1001. * Computes the number of vertices in a geometry. The runtime is linear with
  1002. * respect to the number of attributes in a vertex, not the number of vertices.
  1003. *
  1004. * @param {Geometry} geometry The geometry.
  1005. * @returns {Number} The number of vertices in the geometry.
  1006. *
  1007. * @example
  1008. * var numVertices = Cesium.Geometry.computeNumberOfVertices(geometry);
  1009. */
  1010. Geometry.computeNumberOfVertices = function(geometry) {
  1011. //>>includeStart('debug', pragmas.debug);
  1012. Check.Check.typeOf.object('geometry', geometry);
  1013. //>>includeEnd('debug');
  1014. var numberOfVertices = -1;
  1015. for ( var property in geometry.attributes) {
  1016. if (geometry.attributes.hasOwnProperty(property) &&
  1017. defined.defined(geometry.attributes[property]) &&
  1018. defined.defined(geometry.attributes[property].values)) {
  1019. var attribute = geometry.attributes[property];
  1020. var num = attribute.values.length / attribute.componentsPerAttribute;
  1021. //>>includeStart('debug', pragmas.debug);
  1022. if ((numberOfVertices !== num) && (numberOfVertices !== -1)) {
  1023. throw new Check.DeveloperError('All attribute lists must have the same number of attributes.');
  1024. }
  1025. //>>includeEnd('debug');
  1026. numberOfVertices = num;
  1027. }
  1028. }
  1029. return numberOfVertices;
  1030. };
  1031. var rectangleCenterScratch = new Cartesian2.Cartographic();
  1032. var enuCenterScratch = new Cartesian2.Cartesian3();
  1033. var fixedFrameToEnuScratch = new Transforms.Matrix4();
  1034. var boundingRectanglePointsCartographicScratch = [new Cartesian2.Cartographic(), new Cartesian2.Cartographic(), new Cartesian2.Cartographic()];
  1035. var boundingRectanglePointsEnuScratch = [new Cartesian2.Cartesian2(), new Cartesian2.Cartesian2(), new Cartesian2.Cartesian2()];
  1036. var points2DScratch = [new Cartesian2.Cartesian2(), new Cartesian2.Cartesian2(), new Cartesian2.Cartesian2()];
  1037. var pointEnuScratch = new Cartesian2.Cartesian3();
  1038. var enuRotationScratch = new Transforms.Quaternion();
  1039. var enuRotationMatrixScratch = new Transforms.Matrix4();
  1040. var rotation2DScratch = new Matrix2();
  1041. /**
  1042. * For remapping texture coordinates when rendering GroundPrimitives with materials.
  1043. * GroundPrimitive texture coordinates are computed to align with the cartographic coordinate system on the globe.
  1044. * However, EllipseGeometry, RectangleGeometry, and PolygonGeometry all bake rotations to per-vertex texture coordinates
  1045. * using different strategies.
  1046. *
  1047. * This method is used by EllipseGeometry and PolygonGeometry to approximate the same visual effect.
  1048. * We encapsulate rotation and scale by computing a "transformed" texture coordinate system and computing
  1049. * a set of reference points from which "cartographic" texture coordinates can be remapped to the "transformed"
  1050. * system using distances to lines in 2D.
  1051. *
  1052. * This approximation becomes less accurate as the covered area increases, especially for GroundPrimitives near the poles,
  1053. * but is generally reasonable for polygons and ellipses around the size of USA states.
  1054. *
  1055. * RectangleGeometry has its own version of this method that computes remapping coordinates using cartographic space
  1056. * as an intermediary instead of local ENU, which is more accurate for large-area rectangles.
  1057. *
  1058. * @param {Cartesian3[]} positions Array of positions outlining the geometry
  1059. * @param {Number} stRotation Texture coordinate rotation.
  1060. * @param {Ellipsoid} ellipsoid Ellipsoid for projecting and generating local vectors.
  1061. * @param {Rectangle} boundingRectangle Bounding rectangle around the positions.
  1062. * @returns {Number[]} An array of 6 numbers specifying [minimum point, u extent, v extent] as points in the "cartographic" system.
  1063. * @private
  1064. */
  1065. Geometry._textureCoordinateRotationPoints = function(positions, stRotation, ellipsoid, boundingRectangle) {
  1066. var i;
  1067. // Create a local east-north-up coordinate system centered on the polygon's bounding rectangle.
  1068. // Project the southwest, northwest, and southeast corners of the bounding rectangle into the plane of ENU as 2D points.
  1069. // These are the equivalents of (0,0), (0,1), and (1,0) in the texture coordiante system computed in ShadowVolumeAppearanceFS,
  1070. // aka "ENU texture space."
  1071. var rectangleCenter = Cartesian2.Rectangle.center(boundingRectangle, rectangleCenterScratch);
  1072. var enuCenter = Cartesian2.Cartographic.toCartesian(rectangleCenter, ellipsoid, enuCenterScratch);
  1073. var enuToFixedFrame = Transforms.Transforms.eastNorthUpToFixedFrame(enuCenter, ellipsoid, fixedFrameToEnuScratch);
  1074. var fixedFrameToEnu = Transforms.Matrix4.inverse(enuToFixedFrame, fixedFrameToEnuScratch);
  1075. var boundingPointsEnu = boundingRectanglePointsEnuScratch;
  1076. var boundingPointsCarto = boundingRectanglePointsCartographicScratch;
  1077. boundingPointsCarto[0].longitude = boundingRectangle.west;
  1078. boundingPointsCarto[0].latitude = boundingRectangle.south;
  1079. boundingPointsCarto[1].longitude = boundingRectangle.west;
  1080. boundingPointsCarto[1].latitude = boundingRectangle.north;
  1081. boundingPointsCarto[2].longitude = boundingRectangle.east;
  1082. boundingPointsCarto[2].latitude = boundingRectangle.south;
  1083. var posEnu = pointEnuScratch;
  1084. for (i = 0; i < 3; i++) {
  1085. Cartesian2.Cartographic.toCartesian(boundingPointsCarto[i], ellipsoid, posEnu);
  1086. posEnu = Transforms.Matrix4.multiplyByPointAsVector(fixedFrameToEnu, posEnu, posEnu);
  1087. boundingPointsEnu[i].x = posEnu.x;
  1088. boundingPointsEnu[i].y = posEnu.y;
  1089. }
  1090. // Rotate each point in the polygon around the up vector in the ENU by -stRotation and project into ENU as 2D.
  1091. // Compute the bounding box of these rotated points in the 2D ENU plane.
  1092. // Rotate the corners back by stRotation, then compute their equivalents in the ENU texture space using the corners computed earlier.
  1093. var rotation = Transforms.Quaternion.fromAxisAngle(Cartesian2.Cartesian3.UNIT_Z, -stRotation, enuRotationScratch);
  1094. var textureMatrix = Transforms.Matrix3.fromQuaternion(rotation, enuRotationMatrixScratch);
  1095. var positionsLength = positions.length;
  1096. var enuMinX = Number.POSITIVE_INFINITY;
  1097. var enuMinY = Number.POSITIVE_INFINITY;
  1098. var enuMaxX = Number.NEGATIVE_INFINITY;
  1099. var enuMaxY = Number.NEGATIVE_INFINITY;
  1100. for (i = 0; i < positionsLength; i++) {
  1101. posEnu = Transforms.Matrix4.multiplyByPointAsVector(fixedFrameToEnu, positions[i], posEnu);
  1102. posEnu = Transforms.Matrix3.multiplyByVector(textureMatrix, posEnu, posEnu);
  1103. enuMinX = Math.min(enuMinX, posEnu.x);
  1104. enuMinY = Math.min(enuMinY, posEnu.y);
  1105. enuMaxX = Math.max(enuMaxX, posEnu.x);
  1106. enuMaxY = Math.max(enuMaxY, posEnu.y);
  1107. }
  1108. var toDesiredInComputed = Matrix2.fromRotation(stRotation, rotation2DScratch);
  1109. var points2D = points2DScratch;
  1110. points2D[0].x = enuMinX;
  1111. points2D[0].y = enuMinY;
  1112. points2D[1].x = enuMinX;
  1113. points2D[1].y = enuMaxY;
  1114. points2D[2].x = enuMaxX;
  1115. points2D[2].y = enuMinY;
  1116. var boundingEnuMin = boundingPointsEnu[0];
  1117. var boundingPointsWidth = boundingPointsEnu[2].x - boundingEnuMin.x;
  1118. var boundingPointsHeight = boundingPointsEnu[1].y - boundingEnuMin.y;
  1119. for (i = 0; i < 3; i++) {
  1120. var point2D = points2D[i];
  1121. // rotate back
  1122. Matrix2.multiplyByVector(toDesiredInComputed, point2D, point2D);
  1123. // Convert point into east-north texture coordinate space
  1124. point2D.x = (point2D.x - boundingEnuMin.x) / boundingPointsWidth;
  1125. point2D.y = (point2D.y - boundingEnuMin.y) / boundingPointsHeight;
  1126. }
  1127. var minXYCorner = points2D[0];
  1128. var maxYCorner = points2D[1];
  1129. var maxXCorner = points2D[2];
  1130. var result = new Array(6);
  1131. Cartesian2.Cartesian2.pack(minXYCorner, result);
  1132. Cartesian2.Cartesian2.pack(maxYCorner, result, 2);
  1133. Cartesian2.Cartesian2.pack(maxXCorner, result, 4);
  1134. return result;
  1135. };
  1136. /**
  1137. * Values and type information for geometry attributes. A {@link Geometry}
  1138. * generally contains one or more attributes. All attributes together form
  1139. * the geometry's vertices.
  1140. *
  1141. * @alias GeometryAttribute
  1142. * @constructor
  1143. *
  1144. * @param {Object} [options] Object with the following properties:
  1145. * @param {ComponentDatatype} [options.componentDatatype] The datatype of each component in the attribute, e.g., individual elements in values.
  1146. * @param {Number} [options.componentsPerAttribute] A number between 1 and 4 that defines the number of components in an attributes.
  1147. * @param {Boolean} [options.normalize=false] When <code>true</code> and <code>componentDatatype</code> is an integer format, indicate that the components should be mapped to the range [0, 1] (unsigned) or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  1148. * @param {TypedArray} [options.values] The values for the attributes stored in a typed array.
  1149. *
  1150. * @exception {DeveloperError} options.componentsPerAttribute must be between 1 and 4.
  1151. *
  1152. *
  1153. * @example
  1154. * var geometry = new Cesium.Geometry({
  1155. * attributes : {
  1156. * position : new Cesium.GeometryAttribute({
  1157. * componentDatatype : Cesium.ComponentDatatype.FLOAT,
  1158. * componentsPerAttribute : 3,
  1159. * values : new Float32Array([
  1160. * 0.0, 0.0, 0.0,
  1161. * 7500000.0, 0.0, 0.0,
  1162. * 0.0, 7500000.0, 0.0
  1163. * ])
  1164. * })
  1165. * },
  1166. * primitiveType : Cesium.PrimitiveType.LINE_LOOP
  1167. * });
  1168. *
  1169. * @see Geometry
  1170. */
  1171. function GeometryAttribute(options) {
  1172. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  1173. //>>includeStart('debug', pragmas.debug);
  1174. if (!defined.defined(options.componentDatatype)) {
  1175. throw new Check.DeveloperError('options.componentDatatype is required.');
  1176. }
  1177. if (!defined.defined(options.componentsPerAttribute)) {
  1178. throw new Check.DeveloperError('options.componentsPerAttribute is required.');
  1179. }
  1180. if (options.componentsPerAttribute < 1 || options.componentsPerAttribute > 4) {
  1181. throw new Check.DeveloperError('options.componentsPerAttribute must be between 1 and 4.');
  1182. }
  1183. if (!defined.defined(options.values)) {
  1184. throw new Check.DeveloperError('options.values is required.');
  1185. }
  1186. //>>includeEnd('debug');
  1187. /**
  1188. * The datatype of each component in the attribute, e.g., individual elements in
  1189. * {@link GeometryAttribute#values}.
  1190. *
  1191. * @type ComponentDatatype
  1192. *
  1193. * @default undefined
  1194. */
  1195. this.componentDatatype = options.componentDatatype;
  1196. /**
  1197. * A number between 1 and 4 that defines the number of components in an attributes.
  1198. * For example, a position attribute with x, y, and z components would have 3 as
  1199. * shown in the code example.
  1200. *
  1201. * @type Number
  1202. *
  1203. * @default undefined
  1204. *
  1205. * @example
  1206. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  1207. * attribute.componentsPerAttribute = 3;
  1208. * attribute.values = new Float32Array([
  1209. * 0.0, 0.0, 0.0,
  1210. * 7500000.0, 0.0, 0.0,
  1211. * 0.0, 7500000.0, 0.0
  1212. * ]);
  1213. */
  1214. this.componentsPerAttribute = options.componentsPerAttribute;
  1215. /**
  1216. * When <code>true</code> and <code>componentDatatype</code> is an integer format,
  1217. * indicate that the components should be mapped to the range [0, 1] (unsigned)
  1218. * or [-1, 1] (signed) when they are accessed as floating-point for rendering.
  1219. * <p>
  1220. * This is commonly used when storing colors using {@link ComponentDatatype.UNSIGNED_BYTE}.
  1221. * </p>
  1222. *
  1223. * @type Boolean
  1224. *
  1225. * @default false
  1226. *
  1227. * @example
  1228. * attribute.componentDatatype = Cesium.ComponentDatatype.UNSIGNED_BYTE;
  1229. * attribute.componentsPerAttribute = 4;
  1230. * attribute.normalize = true;
  1231. * attribute.values = new Uint8Array([
  1232. * Cesium.Color.floatToByte(color.red),
  1233. * Cesium.Color.floatToByte(color.green),
  1234. * Cesium.Color.floatToByte(color.blue),
  1235. * Cesium.Color.floatToByte(color.alpha)
  1236. * ]);
  1237. */
  1238. this.normalize = defaultValue.defaultValue(options.normalize, false);
  1239. /**
  1240. * The values for the attributes stored in a typed array. In the code example,
  1241. * every three elements in <code>values</code> defines one attributes since
  1242. * <code>componentsPerAttribute</code> is 3.
  1243. *
  1244. * @type TypedArray
  1245. *
  1246. * @default undefined
  1247. *
  1248. * @example
  1249. * attribute.componentDatatype = Cesium.ComponentDatatype.FLOAT;
  1250. * attribute.componentsPerAttribute = 3;
  1251. * attribute.values = new Float32Array([
  1252. * 0.0, 0.0, 0.0,
  1253. * 7500000.0, 0.0, 0.0,
  1254. * 0.0, 7500000.0, 0.0
  1255. * ]);
  1256. */
  1257. this.values = options.values;
  1258. }
  1259. exports.Geometry = Geometry;
  1260. exports.GeometryAttribute = GeometryAttribute;
  1261. exports.GeometryType = GeometryType$1;
  1262. exports.Matrix2 = Matrix2;
  1263. exports.PrimitiveType = PrimitiveType$1;
  1264. });