GeometryAttribute-91704ebb.js 57 KB

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