GeometryAttribute-6d403cd9.js 51 KB

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