PolygonGeometryLibrary-a0562073.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './when-e6985d2a', './Math-392d0035', './Cartesian2-a5d6dde9', './Transforms-81680c41', './ComponentDatatype-cb08e294', './GeometryAttribute-6d403cd9', './GeometryAttributes-d6ea8c2b', './GeometryPipeline-e8a01ba6', './IndexDatatype-1be7d1f8', './arrayRemoveDuplicates-1ded18d8', './ArcType-13a53523', './EllipsoidRhumbLine-5f1ab81f', './PolygonPipeline-197b7d5c'], function (exports, when, _Math, Cartesian2, Transforms, ComponentDatatype, GeometryAttribute, GeometryAttributes, GeometryPipeline, IndexDatatype, arrayRemoveDuplicates, ArcType, EllipsoidRhumbLine, PolygonPipeline) { 'use strict';
  3. /**
  4. * A queue that can enqueue items at the end, and dequeue items from the front.
  5. *
  6. * @alias Queue
  7. * @constructor
  8. */
  9. function Queue() {
  10. this._array = [];
  11. this._offset = 0;
  12. this._length = 0;
  13. }
  14. Object.defineProperties(Queue.prototype, {
  15. /**
  16. * The length of the queue.
  17. *
  18. * @memberof Queue.prototype
  19. *
  20. * @type {Number}
  21. * @readonly
  22. */
  23. length: {
  24. get: function () {
  25. return this._length;
  26. },
  27. },
  28. });
  29. /**
  30. * Enqueues the specified item.
  31. *
  32. * @param {*} item The item to enqueue.
  33. */
  34. Queue.prototype.enqueue = function (item) {
  35. this._array.push(item);
  36. this._length++;
  37. };
  38. /**
  39. * Dequeues an item. Returns undefined if the queue is empty.
  40. *
  41. * @returns {*} The the dequeued item.
  42. */
  43. Queue.prototype.dequeue = function () {
  44. if (this._length === 0) {
  45. return undefined;
  46. }
  47. var array = this._array;
  48. var offset = this._offset;
  49. var item = array[offset];
  50. array[offset] = undefined;
  51. offset++;
  52. if (offset > 10 && offset * 2 > array.length) {
  53. //compact array
  54. this._array = array.slice(offset);
  55. offset = 0;
  56. }
  57. this._offset = offset;
  58. this._length--;
  59. return item;
  60. };
  61. /**
  62. * Returns the item at the front of the queue. Returns undefined if the queue is empty.
  63. *
  64. * @returns {*} The item at the front of the queue.
  65. */
  66. Queue.prototype.peek = function () {
  67. if (this._length === 0) {
  68. return undefined;
  69. }
  70. return this._array[this._offset];
  71. };
  72. /**
  73. * Check whether this queue contains the specified item.
  74. *
  75. * @param {*} item The item to search for.
  76. */
  77. Queue.prototype.contains = function (item) {
  78. return this._array.indexOf(item) !== -1;
  79. };
  80. /**
  81. * Remove all items from the queue.
  82. */
  83. Queue.prototype.clear = function () {
  84. this._array.length = this._offset = this._length = 0;
  85. };
  86. /**
  87. * Sort the items in the queue in-place.
  88. *
  89. * @param {Queue.Comparator} compareFunction A function that defines the sort order.
  90. */
  91. Queue.prototype.sort = function (compareFunction) {
  92. if (this._offset > 0) {
  93. //compact array
  94. this._array = this._array.slice(this._offset);
  95. this._offset = 0;
  96. }
  97. this._array.sort(compareFunction);
  98. };
  99. /**
  100. * @private
  101. */
  102. var PolygonGeometryLibrary = {};
  103. PolygonGeometryLibrary.computeHierarchyPackedLength = function (
  104. polygonHierarchy
  105. ) {
  106. var numComponents = 0;
  107. var stack = [polygonHierarchy];
  108. while (stack.length > 0) {
  109. var hierarchy = stack.pop();
  110. if (!when.defined(hierarchy)) {
  111. continue;
  112. }
  113. numComponents += 2;
  114. var positions = hierarchy.positions;
  115. var holes = hierarchy.holes;
  116. if (when.defined(positions)) {
  117. numComponents += positions.length * Cartesian2.Cartesian3.packedLength;
  118. }
  119. if (when.defined(holes)) {
  120. var length = holes.length;
  121. for (var i = 0; i < length; ++i) {
  122. stack.push(holes[i]);
  123. }
  124. }
  125. }
  126. return numComponents;
  127. };
  128. PolygonGeometryLibrary.packPolygonHierarchy = function (
  129. polygonHierarchy,
  130. array,
  131. startingIndex
  132. ) {
  133. var stack = [polygonHierarchy];
  134. while (stack.length > 0) {
  135. var hierarchy = stack.pop();
  136. if (!when.defined(hierarchy)) {
  137. continue;
  138. }
  139. var positions = hierarchy.positions;
  140. var holes = hierarchy.holes;
  141. array[startingIndex++] = when.defined(positions) ? positions.length : 0;
  142. array[startingIndex++] = when.defined(holes) ? holes.length : 0;
  143. if (when.defined(positions)) {
  144. var positionsLength = positions.length;
  145. for (var i = 0; i < positionsLength; ++i, startingIndex += 3) {
  146. Cartesian2.Cartesian3.pack(positions[i], array, startingIndex);
  147. }
  148. }
  149. if (when.defined(holes)) {
  150. var holesLength = holes.length;
  151. for (var j = 0; j < holesLength; ++j) {
  152. stack.push(holes[j]);
  153. }
  154. }
  155. }
  156. return startingIndex;
  157. };
  158. PolygonGeometryLibrary.unpackPolygonHierarchy = function (
  159. array,
  160. startingIndex
  161. ) {
  162. var positionsLength = array[startingIndex++];
  163. var holesLength = array[startingIndex++];
  164. var positions = new Array(positionsLength);
  165. var holes = holesLength > 0 ? new Array(holesLength) : undefined;
  166. for (
  167. var i = 0;
  168. i < positionsLength;
  169. ++i, startingIndex += Cartesian2.Cartesian3.packedLength
  170. ) {
  171. positions[i] = Cartesian2.Cartesian3.unpack(array, startingIndex);
  172. }
  173. for (var j = 0; j < holesLength; ++j) {
  174. holes[j] = PolygonGeometryLibrary.unpackPolygonHierarchy(
  175. array,
  176. startingIndex
  177. );
  178. startingIndex = holes[j].startingIndex;
  179. delete holes[j].startingIndex;
  180. }
  181. return {
  182. positions: positions,
  183. holes: holes,
  184. startingIndex: startingIndex,
  185. };
  186. };
  187. var distanceScratch = new Cartesian2.Cartesian3();
  188. function getPointAtDistance(p0, p1, distance, length) {
  189. Cartesian2.Cartesian3.subtract(p1, p0, distanceScratch);
  190. Cartesian2.Cartesian3.multiplyByScalar(
  191. distanceScratch,
  192. distance / length,
  193. distanceScratch
  194. );
  195. Cartesian2.Cartesian3.add(p0, distanceScratch, distanceScratch);
  196. return [distanceScratch.x, distanceScratch.y, distanceScratch.z];
  197. }
  198. PolygonGeometryLibrary.subdivideLineCount = function (p0, p1, minDistance) {
  199. var distance = Cartesian2.Cartesian3.distance(p0, p1);
  200. var n = distance / minDistance;
  201. var countDivide = Math.max(0, Math.ceil(_Math.CesiumMath.log2(n)));
  202. return Math.pow(2, countDivide);
  203. };
  204. var scratchCartographic0 = new Cartesian2.Cartographic();
  205. var scratchCartographic1 = new Cartesian2.Cartographic();
  206. var scratchCartographic2 = new Cartesian2.Cartographic();
  207. var scratchCartesian0 = new Cartesian2.Cartesian3();
  208. PolygonGeometryLibrary.subdivideRhumbLineCount = function (
  209. ellipsoid,
  210. p0,
  211. p1,
  212. minDistance
  213. ) {
  214. var c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);
  215. var c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);
  216. var rhumb = new EllipsoidRhumbLine.EllipsoidRhumbLine(c0, c1, ellipsoid);
  217. var n = rhumb.surfaceDistance / minDistance;
  218. var countDivide = Math.max(0, Math.ceil(_Math.CesiumMath.log2(n)));
  219. return Math.pow(2, countDivide);
  220. };
  221. PolygonGeometryLibrary.subdivideLine = function (p0, p1, minDistance, result) {
  222. var numVertices = PolygonGeometryLibrary.subdivideLineCount(
  223. p0,
  224. p1,
  225. minDistance
  226. );
  227. var length = Cartesian2.Cartesian3.distance(p0, p1);
  228. var distanceBetweenVertices = length / numVertices;
  229. if (!when.defined(result)) {
  230. result = [];
  231. }
  232. var positions = result;
  233. positions.length = numVertices * 3;
  234. var index = 0;
  235. for (var i = 0; i < numVertices; i++) {
  236. var p = getPointAtDistance(p0, p1, i * distanceBetweenVertices, length);
  237. positions[index++] = p[0];
  238. positions[index++] = p[1];
  239. positions[index++] = p[2];
  240. }
  241. return positions;
  242. };
  243. PolygonGeometryLibrary.subdivideRhumbLine = function (
  244. ellipsoid,
  245. p0,
  246. p1,
  247. minDistance,
  248. result
  249. ) {
  250. var c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);
  251. var c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);
  252. var rhumb = new EllipsoidRhumbLine.EllipsoidRhumbLine(c0, c1, ellipsoid);
  253. var n = rhumb.surfaceDistance / minDistance;
  254. var countDivide = Math.max(0, Math.ceil(_Math.CesiumMath.log2(n)));
  255. var numVertices = Math.pow(2, countDivide);
  256. var distanceBetweenVertices = rhumb.surfaceDistance / numVertices;
  257. if (!when.defined(result)) {
  258. result = [];
  259. }
  260. var positions = result;
  261. positions.length = numVertices * 3;
  262. var index = 0;
  263. for (var i = 0; i < numVertices; i++) {
  264. var c = rhumb.interpolateUsingSurfaceDistance(
  265. i * distanceBetweenVertices,
  266. scratchCartographic2
  267. );
  268. var p = ellipsoid.cartographicToCartesian(c, scratchCartesian0);
  269. positions[index++] = p.x;
  270. positions[index++] = p.y;
  271. positions[index++] = p.z;
  272. }
  273. return positions;
  274. };
  275. var scaleToGeodeticHeightN1 = new Cartesian2.Cartesian3();
  276. var scaleToGeodeticHeightN2 = new Cartesian2.Cartesian3();
  277. var scaleToGeodeticHeightP1 = new Cartesian2.Cartesian3();
  278. var scaleToGeodeticHeightP2 = new Cartesian2.Cartesian3();
  279. PolygonGeometryLibrary.scaleToGeodeticHeightExtruded = function (
  280. geometry,
  281. maxHeight,
  282. minHeight,
  283. ellipsoid,
  284. perPositionHeight
  285. ) {
  286. ellipsoid = when.defaultValue(ellipsoid, Cartesian2.Ellipsoid.WGS84);
  287. var n1 = scaleToGeodeticHeightN1;
  288. var n2 = scaleToGeodeticHeightN2;
  289. var p = scaleToGeodeticHeightP1;
  290. var p2 = scaleToGeodeticHeightP2;
  291. if (
  292. when.defined(geometry) &&
  293. when.defined(geometry.attributes) &&
  294. when.defined(geometry.attributes.position)
  295. ) {
  296. var positions = geometry.attributes.position.values;
  297. var length = positions.length / 2;
  298. for (var i = 0; i < length; i += 3) {
  299. Cartesian2.Cartesian3.fromArray(positions, i, p);
  300. ellipsoid.geodeticSurfaceNormal(p, n1);
  301. p2 = ellipsoid.scaleToGeodeticSurface(p, p2);
  302. n2 = Cartesian2.Cartesian3.multiplyByScalar(n1, minHeight, n2);
  303. n2 = Cartesian2.Cartesian3.add(p2, n2, n2);
  304. positions[i + length] = n2.x;
  305. positions[i + 1 + length] = n2.y;
  306. positions[i + 2 + length] = n2.z;
  307. if (perPositionHeight) {
  308. p2 = Cartesian2.Cartesian3.clone(p, p2);
  309. }
  310. n2 = Cartesian2.Cartesian3.multiplyByScalar(n1, maxHeight, n2);
  311. n2 = Cartesian2.Cartesian3.add(p2, n2, n2);
  312. positions[i] = n2.x;
  313. positions[i + 1] = n2.y;
  314. positions[i + 2] = n2.z;
  315. }
  316. }
  317. return geometry;
  318. };
  319. PolygonGeometryLibrary.polygonOutlinesFromHierarchy = function (
  320. polygonHierarchy,
  321. scaleToEllipsoidSurface,
  322. ellipsoid
  323. ) {
  324. // create from a polygon hierarchy
  325. // Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
  326. var polygons = [];
  327. var queue = new Queue();
  328. queue.enqueue(polygonHierarchy);
  329. var i;
  330. var j;
  331. var length;
  332. while (queue.length !== 0) {
  333. var outerNode = queue.dequeue();
  334. var outerRing = outerNode.positions;
  335. if (scaleToEllipsoidSurface) {
  336. length = outerRing.length;
  337. for (i = 0; i < length; i++) {
  338. ellipsoid.scaleToGeodeticSurface(outerRing[i], outerRing[i]);
  339. }
  340. }
  341. outerRing = arrayRemoveDuplicates.arrayRemoveDuplicates(
  342. outerRing,
  343. Cartesian2.Cartesian3.equalsEpsilon,
  344. true
  345. );
  346. if (outerRing.length < 3) {
  347. continue;
  348. }
  349. var numChildren = outerNode.holes ? outerNode.holes.length : 0;
  350. // The outer polygon contains inner polygons
  351. for (i = 0; i < numChildren; i++) {
  352. var hole = outerNode.holes[i];
  353. var holePositions = hole.positions;
  354. if (scaleToEllipsoidSurface) {
  355. length = holePositions.length;
  356. for (j = 0; j < length; ++j) {
  357. ellipsoid.scaleToGeodeticSurface(holePositions[j], holePositions[j]);
  358. }
  359. }
  360. holePositions = arrayRemoveDuplicates.arrayRemoveDuplicates(
  361. holePositions,
  362. Cartesian2.Cartesian3.equalsEpsilon,
  363. true
  364. );
  365. if (holePositions.length < 3) {
  366. continue;
  367. }
  368. polygons.push(holePositions);
  369. var numGrandchildren = 0;
  370. if (when.defined(hole.holes)) {
  371. numGrandchildren = hole.holes.length;
  372. }
  373. for (j = 0; j < numGrandchildren; j++) {
  374. queue.enqueue(hole.holes[j]);
  375. }
  376. }
  377. polygons.push(outerRing);
  378. }
  379. return polygons;
  380. };
  381. PolygonGeometryLibrary.polygonsFromHierarchy = function (
  382. polygonHierarchy,
  383. projectPointsTo2D,
  384. scaleToEllipsoidSurface,
  385. ellipsoid
  386. ) {
  387. // create from a polygon hierarchy
  388. // Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
  389. var hierarchy = [];
  390. var polygons = [];
  391. var queue = new Queue();
  392. queue.enqueue(polygonHierarchy);
  393. while (queue.length !== 0) {
  394. var outerNode = queue.dequeue();
  395. var outerRing = outerNode.positions;
  396. var holes = outerNode.holes;
  397. var i;
  398. var length;
  399. if (scaleToEllipsoidSurface) {
  400. length = outerRing.length;
  401. for (i = 0; i < length; i++) {
  402. ellipsoid.scaleToGeodeticSurface(outerRing[i], outerRing[i]);
  403. }
  404. }
  405. outerRing = arrayRemoveDuplicates.arrayRemoveDuplicates(
  406. outerRing,
  407. Cartesian2.Cartesian3.equalsEpsilon,
  408. true
  409. );
  410. if (outerRing.length < 3) {
  411. continue;
  412. }
  413. var positions2D = projectPointsTo2D(outerRing);
  414. if (!when.defined(positions2D)) {
  415. continue;
  416. }
  417. var holeIndices = [];
  418. var originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(
  419. positions2D
  420. );
  421. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  422. positions2D.reverse();
  423. outerRing = outerRing.slice().reverse();
  424. }
  425. var positions = outerRing.slice();
  426. var numChildren = when.defined(holes) ? holes.length : 0;
  427. var polygonHoles = [];
  428. var j;
  429. for (i = 0; i < numChildren; i++) {
  430. var hole = holes[i];
  431. var holePositions = hole.positions;
  432. if (scaleToEllipsoidSurface) {
  433. length = holePositions.length;
  434. for (j = 0; j < length; ++j) {
  435. ellipsoid.scaleToGeodeticSurface(holePositions[j], holePositions[j]);
  436. }
  437. }
  438. holePositions = arrayRemoveDuplicates.arrayRemoveDuplicates(
  439. holePositions,
  440. Cartesian2.Cartesian3.equalsEpsilon,
  441. true
  442. );
  443. if (holePositions.length < 3) {
  444. continue;
  445. }
  446. var holePositions2D = projectPointsTo2D(holePositions);
  447. if (!when.defined(holePositions2D)) {
  448. continue;
  449. }
  450. originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(
  451. holePositions2D
  452. );
  453. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  454. holePositions2D.reverse();
  455. holePositions = holePositions.slice().reverse();
  456. }
  457. polygonHoles.push(holePositions);
  458. holeIndices.push(positions.length);
  459. positions = positions.concat(holePositions);
  460. positions2D = positions2D.concat(holePositions2D);
  461. var numGrandchildren = 0;
  462. if (when.defined(hole.holes)) {
  463. numGrandchildren = hole.holes.length;
  464. }
  465. for (j = 0; j < numGrandchildren; j++) {
  466. queue.enqueue(hole.holes[j]);
  467. }
  468. }
  469. hierarchy.push({
  470. outerRing: outerRing,
  471. holes: polygonHoles,
  472. });
  473. polygons.push({
  474. positions: positions,
  475. positions2D: positions2D,
  476. holes: holeIndices,
  477. });
  478. }
  479. return {
  480. hierarchy: hierarchy,
  481. polygons: polygons,
  482. };
  483. };
  484. var computeBoundingRectangleCartesian2 = new Cartesian2.Cartesian2();
  485. var computeBoundingRectangleCartesian3 = new Cartesian2.Cartesian3();
  486. var computeBoundingRectangleQuaternion = new Transforms.Quaternion();
  487. var computeBoundingRectangleMatrix3 = new Transforms.Matrix3();
  488. PolygonGeometryLibrary.computeBoundingRectangle = function (
  489. planeNormal,
  490. projectPointTo2D,
  491. positions,
  492. angle,
  493. result
  494. ) {
  495. var rotation = Transforms.Quaternion.fromAxisAngle(
  496. planeNormal,
  497. angle,
  498. computeBoundingRectangleQuaternion
  499. );
  500. var textureMatrix = Transforms.Matrix3.fromQuaternion(
  501. rotation,
  502. computeBoundingRectangleMatrix3
  503. );
  504. var minX = Number.POSITIVE_INFINITY;
  505. var maxX = Number.NEGATIVE_INFINITY;
  506. var minY = Number.POSITIVE_INFINITY;
  507. var maxY = Number.NEGATIVE_INFINITY;
  508. var length = positions.length;
  509. for (var i = 0; i < length; ++i) {
  510. var p = Cartesian2.Cartesian3.clone(positions[i], computeBoundingRectangleCartesian3);
  511. Transforms.Matrix3.multiplyByVector(textureMatrix, p, p);
  512. var st = projectPointTo2D(p, computeBoundingRectangleCartesian2);
  513. if (when.defined(st)) {
  514. minX = Math.min(minX, st.x);
  515. maxX = Math.max(maxX, st.x);
  516. minY = Math.min(minY, st.y);
  517. maxY = Math.max(maxY, st.y);
  518. }
  519. }
  520. result.x = minX;
  521. result.y = minY;
  522. result.width = maxX - minX;
  523. result.height = maxY - minY;
  524. return result;
  525. };
  526. PolygonGeometryLibrary.createGeometryFromPositions = function (
  527. ellipsoid,
  528. polygon,
  529. granularity,
  530. perPositionHeight,
  531. vertexFormat,
  532. arcType
  533. ) {
  534. var indices = PolygonPipeline.PolygonPipeline.triangulate(polygon.positions2D, polygon.holes);
  535. /* If polygon is completely unrenderable, just use the first three vertices */
  536. if (indices.length < 3) {
  537. indices = [0, 1, 2];
  538. }
  539. var positions = polygon.positions;
  540. if (perPositionHeight) {
  541. var length = positions.length;
  542. var flattenedPositions = new Array(length * 3);
  543. var index = 0;
  544. for (var i = 0; i < length; i++) {
  545. var p = positions[i];
  546. flattenedPositions[index++] = p.x;
  547. flattenedPositions[index++] = p.y;
  548. flattenedPositions[index++] = p.z;
  549. }
  550. var geometry = new GeometryAttribute.Geometry({
  551. attributes: {
  552. position: new GeometryAttribute.GeometryAttribute({
  553. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  554. componentsPerAttribute: 3,
  555. values: flattenedPositions,
  556. }),
  557. },
  558. indices: indices,
  559. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  560. });
  561. if (vertexFormat.normal) {
  562. return GeometryPipeline.GeometryPipeline.computeNormal(geometry);
  563. }
  564. return geometry;
  565. }
  566. if (arcType === ArcType.ArcType.GEODESIC) {
  567. return PolygonPipeline.PolygonPipeline.computeSubdivision(
  568. ellipsoid,
  569. positions,
  570. indices,
  571. granularity
  572. );
  573. } else if (arcType === ArcType.ArcType.RHUMB) {
  574. return PolygonPipeline.PolygonPipeline.computeRhumbLineSubdivision(
  575. ellipsoid,
  576. positions,
  577. indices,
  578. granularity
  579. );
  580. }
  581. };
  582. var computeWallIndicesSubdivided = [];
  583. var p1Scratch = new Cartesian2.Cartesian3();
  584. var p2Scratch = new Cartesian2.Cartesian3();
  585. PolygonGeometryLibrary.computeWallGeometry = function (
  586. positions,
  587. ellipsoid,
  588. granularity,
  589. perPositionHeight,
  590. arcType
  591. ) {
  592. var edgePositions;
  593. var topEdgeLength;
  594. var i;
  595. var p1;
  596. var p2;
  597. var length = positions.length;
  598. var index = 0;
  599. if (!perPositionHeight) {
  600. var minDistance = _Math.CesiumMath.chordLength(
  601. granularity,
  602. ellipsoid.maximumRadius
  603. );
  604. var numVertices = 0;
  605. if (arcType === ArcType.ArcType.GEODESIC) {
  606. for (i = 0; i < length; i++) {
  607. numVertices += PolygonGeometryLibrary.subdivideLineCount(
  608. positions[i],
  609. positions[(i + 1) % length],
  610. minDistance
  611. );
  612. }
  613. } else if (arcType === ArcType.ArcType.RHUMB) {
  614. for (i = 0; i < length; i++) {
  615. numVertices += PolygonGeometryLibrary.subdivideRhumbLineCount(
  616. ellipsoid,
  617. positions[i],
  618. positions[(i + 1) % length],
  619. minDistance
  620. );
  621. }
  622. }
  623. topEdgeLength = (numVertices + length) * 3;
  624. edgePositions = new Array(topEdgeLength * 2);
  625. for (i = 0; i < length; i++) {
  626. p1 = positions[i];
  627. p2 = positions[(i + 1) % length];
  628. var tempPositions;
  629. if (arcType === ArcType.ArcType.GEODESIC) {
  630. tempPositions = PolygonGeometryLibrary.subdivideLine(
  631. p1,
  632. p2,
  633. minDistance,
  634. computeWallIndicesSubdivided
  635. );
  636. } else if (arcType === ArcType.ArcType.RHUMB) {
  637. tempPositions = PolygonGeometryLibrary.subdivideRhumbLine(
  638. ellipsoid,
  639. p1,
  640. p2,
  641. minDistance,
  642. computeWallIndicesSubdivided
  643. );
  644. }
  645. var tempPositionsLength = tempPositions.length;
  646. for (var j = 0; j < tempPositionsLength; ++j, ++index) {
  647. edgePositions[index] = tempPositions[j];
  648. edgePositions[index + topEdgeLength] = tempPositions[j];
  649. }
  650. edgePositions[index] = p2.x;
  651. edgePositions[index + topEdgeLength] = p2.x;
  652. ++index;
  653. edgePositions[index] = p2.y;
  654. edgePositions[index + topEdgeLength] = p2.y;
  655. ++index;
  656. edgePositions[index] = p2.z;
  657. edgePositions[index + topEdgeLength] = p2.z;
  658. ++index;
  659. }
  660. } else {
  661. topEdgeLength = length * 3 * 2;
  662. edgePositions = new Array(topEdgeLength * 2);
  663. for (i = 0; i < length; i++) {
  664. p1 = positions[i];
  665. p2 = positions[(i + 1) % length];
  666. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.x;
  667. ++index;
  668. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.y;
  669. ++index;
  670. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.z;
  671. ++index;
  672. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.x;
  673. ++index;
  674. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.y;
  675. ++index;
  676. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.z;
  677. ++index;
  678. }
  679. }
  680. length = edgePositions.length;
  681. var indices = IndexDatatype.IndexDatatype.createTypedArray(
  682. length / 3,
  683. length - positions.length * 6
  684. );
  685. var edgeIndex = 0;
  686. length /= 6;
  687. for (i = 0; i < length; i++) {
  688. var UL = i;
  689. var UR = UL + 1;
  690. var LL = UL + length;
  691. var LR = LL + 1;
  692. p1 = Cartesian2.Cartesian3.fromArray(edgePositions, UL * 3, p1Scratch);
  693. p2 = Cartesian2.Cartesian3.fromArray(edgePositions, UR * 3, p2Scratch);
  694. if (
  695. Cartesian2.Cartesian3.equalsEpsilon(
  696. p1,
  697. p2,
  698. _Math.CesiumMath.EPSILON10,
  699. _Math.CesiumMath.EPSILON10
  700. )
  701. ) {
  702. //skip corner
  703. continue;
  704. }
  705. indices[edgeIndex++] = UL;
  706. indices[edgeIndex++] = LL;
  707. indices[edgeIndex++] = UR;
  708. indices[edgeIndex++] = UR;
  709. indices[edgeIndex++] = LL;
  710. indices[edgeIndex++] = LR;
  711. }
  712. return new GeometryAttribute.Geometry({
  713. attributes: new GeometryAttributes.GeometryAttributes({
  714. position: new GeometryAttribute.GeometryAttribute({
  715. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  716. componentsPerAttribute: 3,
  717. values: edgePositions,
  718. }),
  719. }),
  720. indices: indices,
  721. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  722. });
  723. };
  724. exports.PolygonGeometryLibrary = PolygonGeometryLibrary;
  725. });