PolygonGeometryLibrary-7f7b74b5.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './defaultValue-f2e68450', './Math-fa6e45cb', './Cartesian2-2a723276', './defineProperties-6f7a50f2', './Transforms-65aba0a4', './ComponentDatatype-69643096', './GeometryAttribute-ed359d71', './GeometryAttributes-eecc9f43', './GeometryPipeline-f0b16df6', './IndexDatatype-3de60176', './arrayRemoveDuplicates-dd708d81', './ArcType-d521909b', './EllipsoidRhumbLine-c6cdbfd3', './PolygonPipeline-e486c11c'], function (exports, defined, defaultValue, _Math, Cartesian2, defineProperties, 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. defineProperties.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(polygonHierarchy) {
  104. var numComponents = 0;
  105. var stack = [polygonHierarchy];
  106. while (stack.length > 0) {
  107. var hierarchy = stack.pop();
  108. if (!defined.defined(hierarchy)) {
  109. continue;
  110. }
  111. numComponents += 2;
  112. var positions = hierarchy.positions;
  113. var holes = hierarchy.holes;
  114. if (defined.defined(positions)) {
  115. numComponents += positions.length * Cartesian2.Cartesian3.packedLength;
  116. }
  117. if (defined.defined(holes)) {
  118. var length = holes.length;
  119. for (var i = 0; i < length; ++i) {
  120. stack.push(holes[i]);
  121. }
  122. }
  123. }
  124. return numComponents;
  125. };
  126. PolygonGeometryLibrary.packPolygonHierarchy = function(polygonHierarchy, array, startingIndex) {
  127. var stack = [polygonHierarchy];
  128. while (stack.length > 0) {
  129. var hierarchy = stack.pop();
  130. if (!defined.defined(hierarchy)) {
  131. continue;
  132. }
  133. var positions = hierarchy.positions;
  134. var holes = hierarchy.holes;
  135. array[startingIndex++] = defined.defined(positions) ? positions.length : 0;
  136. array[startingIndex++] = defined.defined(holes) ? holes.length : 0;
  137. if (defined.defined(positions)) {
  138. var positionsLength = positions.length;
  139. for (var i = 0; i < positionsLength; ++i, startingIndex += 3) {
  140. Cartesian2.Cartesian3.pack(positions[i], array, startingIndex);
  141. }
  142. }
  143. if (defined.defined(holes)) {
  144. var holesLength = holes.length;
  145. for (var j = 0; j < holesLength; ++j) {
  146. stack.push(holes[j]);
  147. }
  148. }
  149. }
  150. return startingIndex;
  151. };
  152. PolygonGeometryLibrary.unpackPolygonHierarchy = function(array, startingIndex) {
  153. var positionsLength = array[startingIndex++];
  154. var holesLength = array[startingIndex++];
  155. var positions = new Array(positionsLength);
  156. var holes = holesLength > 0 ? new Array(holesLength) : undefined;
  157. for (var i = 0; i < positionsLength; ++i, startingIndex += Cartesian2.Cartesian3.packedLength) {
  158. positions[i] = Cartesian2.Cartesian3.unpack(array, startingIndex);
  159. }
  160. for (var j = 0; j < holesLength; ++j) {
  161. holes[j] = PolygonGeometryLibrary.unpackPolygonHierarchy(array, startingIndex);
  162. startingIndex = holes[j].startingIndex;
  163. delete holes[j].startingIndex;
  164. }
  165. return {
  166. positions : positions,
  167. holes : holes,
  168. startingIndex : startingIndex
  169. };
  170. };
  171. var distanceScratch = new Cartesian2.Cartesian3();
  172. function getPointAtDistance(p0, p1, distance, length) {
  173. Cartesian2.Cartesian3.subtract(p1, p0, distanceScratch);
  174. Cartesian2.Cartesian3.multiplyByScalar(distanceScratch, distance / length, distanceScratch);
  175. Cartesian2.Cartesian3.add(p0, distanceScratch, distanceScratch);
  176. return [distanceScratch.x, distanceScratch.y, distanceScratch.z];
  177. }
  178. PolygonGeometryLibrary.subdivideLineCount = function(p0, p1, minDistance) {
  179. var distance = Cartesian2.Cartesian3.distance(p0, p1);
  180. var n = distance / minDistance;
  181. var countDivide = Math.max(0, Math.ceil(_Math.CesiumMath.log2(n)));
  182. return Math.pow(2, countDivide);
  183. };
  184. var scratchCartographic0 = new Cartesian2.Cartographic();
  185. var scratchCartographic1 = new Cartesian2.Cartographic();
  186. var scratchCartographic2 = new Cartesian2.Cartographic();
  187. var scratchCartesian0 = new Cartesian2.Cartesian3();
  188. PolygonGeometryLibrary.subdivideRhumbLineCount = function(ellipsoid, p0, p1, minDistance) {
  189. var c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);
  190. var c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);
  191. var rhumb = new EllipsoidRhumbLine.EllipsoidRhumbLine(c0, c1, ellipsoid);
  192. var n = rhumb.surfaceDistance / minDistance;
  193. var countDivide = Math.max(0, Math.ceil(_Math.CesiumMath.log2(n)));
  194. return Math.pow(2, countDivide);
  195. };
  196. PolygonGeometryLibrary.subdivideLine = function(p0, p1, minDistance, result) {
  197. var numVertices = PolygonGeometryLibrary.subdivideLineCount(p0, p1, minDistance);
  198. var length = Cartesian2.Cartesian3.distance(p0, p1);
  199. var distanceBetweenVertices = length / numVertices;
  200. if (!defined.defined(result)) {
  201. result = [];
  202. }
  203. var positions = result;
  204. positions.length = numVertices * 3;
  205. var index = 0;
  206. for ( var i = 0; i < numVertices; i++) {
  207. var p = getPointAtDistance(p0, p1, i * distanceBetweenVertices, length);
  208. positions[index++] = p[0];
  209. positions[index++] = p[1];
  210. positions[index++] = p[2];
  211. }
  212. return positions;
  213. };
  214. PolygonGeometryLibrary.subdivideRhumbLine = function(ellipsoid, p0, p1, minDistance, result) {
  215. var c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);
  216. var c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);
  217. var rhumb = new EllipsoidRhumbLine.EllipsoidRhumbLine(c0, c1, ellipsoid);
  218. var n = rhumb.surfaceDistance / minDistance;
  219. var countDivide = Math.max(0, Math.ceil(_Math.CesiumMath.log2(n)));
  220. var numVertices = Math.pow(2, countDivide);
  221. var distanceBetweenVertices = rhumb.surfaceDistance / numVertices;
  222. if (!defined.defined(result)) {
  223. result = [];
  224. }
  225. var positions = result;
  226. positions.length = numVertices * 3;
  227. var index = 0;
  228. for ( var i = 0; i < numVertices; i++) {
  229. var c = rhumb.interpolateUsingSurfaceDistance(i * distanceBetweenVertices, scratchCartographic2);
  230. var p = ellipsoid.cartographicToCartesian(c, scratchCartesian0);
  231. positions[index++] = p.x;
  232. positions[index++] = p.y;
  233. positions[index++] = p.z;
  234. }
  235. return positions;
  236. };
  237. var scaleToGeodeticHeightN1 = new Cartesian2.Cartesian3();
  238. var scaleToGeodeticHeightN2 = new Cartesian2.Cartesian3();
  239. var scaleToGeodeticHeightP1 = new Cartesian2.Cartesian3();
  240. var scaleToGeodeticHeightP2 = new Cartesian2.Cartesian3();
  241. PolygonGeometryLibrary.scaleToGeodeticHeightExtruded = function(geometry, maxHeight, minHeight, ellipsoid, perPositionHeight) {
  242. ellipsoid = defaultValue.defaultValue(ellipsoid, Cartesian2.Ellipsoid.WGS84);
  243. var n1 = scaleToGeodeticHeightN1;
  244. var n2 = scaleToGeodeticHeightN2;
  245. var p = scaleToGeodeticHeightP1;
  246. var p2 = scaleToGeodeticHeightP2;
  247. if (defined.defined(geometry) && defined.defined(geometry.attributes) && defined.defined(geometry.attributes.position)) {
  248. var positions = geometry.attributes.position.values;
  249. var length = positions.length / 2;
  250. for ( var i = 0; i < length; i += 3) {
  251. Cartesian2.Cartesian3.fromArray(positions, i, p);
  252. ellipsoid.geodeticSurfaceNormal(p, n1);
  253. p2 = ellipsoid.scaleToGeodeticSurface(p, p2);
  254. n2 = Cartesian2.Cartesian3.multiplyByScalar(n1, minHeight, n2);
  255. n2 = Cartesian2.Cartesian3.add(p2, n2, n2);
  256. positions[i + length] = n2.x;
  257. positions[i + 1 + length] = n2.y;
  258. positions[i + 2 + length] = n2.z;
  259. if (perPositionHeight) {
  260. p2 = Cartesian2.Cartesian3.clone(p, p2);
  261. }
  262. n2 = Cartesian2.Cartesian3.multiplyByScalar(n1, maxHeight, n2);
  263. n2 = Cartesian2.Cartesian3.add(p2, n2, n2);
  264. positions[i] = n2.x;
  265. positions[i + 1] = n2.y;
  266. positions[i + 2] = n2.z;
  267. }
  268. }
  269. return geometry;
  270. };
  271. PolygonGeometryLibrary.polygonOutlinesFromHierarchy = function(polygonHierarchy, scaleToEllipsoidSurface, ellipsoid) {
  272. // create from a polygon hierarchy
  273. // Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
  274. var polygons = [];
  275. var queue = new Queue();
  276. queue.enqueue(polygonHierarchy);
  277. var i;
  278. var j;
  279. var length;
  280. while (queue.length !== 0) {
  281. var outerNode = queue.dequeue();
  282. var outerRing = outerNode.positions;
  283. if (scaleToEllipsoidSurface) {
  284. length = outerRing.length;
  285. for (i = 0; i < length; i++) {
  286. ellipsoid.scaleToGeodeticSurface(outerRing[i], outerRing[i]);
  287. }
  288. }
  289. outerRing = arrayRemoveDuplicates.arrayRemoveDuplicates(outerRing, Cartesian2.Cartesian3.equalsEpsilon, true);
  290. if (outerRing.length < 3) {
  291. continue;
  292. }
  293. var numChildren = outerNode.holes ? outerNode.holes.length : 0;
  294. // The outer polygon contains inner polygons
  295. for (i = 0; i < numChildren; i++) {
  296. var hole = outerNode.holes[i];
  297. var holePositions = hole.positions;
  298. if (scaleToEllipsoidSurface) {
  299. length = holePositions.length;
  300. for (j = 0; j < length; ++j) {
  301. ellipsoid.scaleToGeodeticSurface(holePositions[j], holePositions[j]);
  302. }
  303. }
  304. holePositions = arrayRemoveDuplicates.arrayRemoveDuplicates(holePositions, Cartesian2.Cartesian3.equalsEpsilon, true);
  305. if (holePositions.length < 3) {
  306. continue;
  307. }
  308. polygons.push(holePositions);
  309. var numGrandchildren = 0;
  310. if (defined.defined(hole.holes)) {
  311. numGrandchildren = hole.holes.length;
  312. }
  313. for (j = 0; j < numGrandchildren; j++) {
  314. queue.enqueue(hole.holes[j]);
  315. }
  316. }
  317. polygons.push(outerRing);
  318. }
  319. return polygons;
  320. };
  321. PolygonGeometryLibrary.polygonsFromHierarchy = function(polygonHierarchy, projectPointsTo2D, scaleToEllipsoidSurface, ellipsoid) {
  322. // create from a polygon hierarchy
  323. // Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
  324. var hierarchy = [];
  325. var polygons = [];
  326. var queue = new Queue();
  327. queue.enqueue(polygonHierarchy);
  328. while (queue.length !== 0) {
  329. var outerNode = queue.dequeue();
  330. var outerRing = outerNode.positions;
  331. var holes = outerNode.holes;
  332. var i;
  333. var length;
  334. if (scaleToEllipsoidSurface) {
  335. length = outerRing.length;
  336. for (i = 0; i < length; i++) {
  337. ellipsoid.scaleToGeodeticSurface(outerRing[i], outerRing[i]);
  338. }
  339. }
  340. outerRing = arrayRemoveDuplicates.arrayRemoveDuplicates(outerRing, Cartesian2.Cartesian3.equalsEpsilon, true);
  341. if (outerRing.length < 3) {
  342. continue;
  343. }
  344. var positions2D = projectPointsTo2D(outerRing);
  345. if (!defined.defined(positions2D)) {
  346. continue;
  347. }
  348. var holeIndices = [];
  349. var originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(positions2D);
  350. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  351. positions2D.reverse();
  352. outerRing = outerRing.slice().reverse();
  353. }
  354. var positions = outerRing.slice();
  355. var numChildren = defined.defined(holes) ? holes.length : 0;
  356. var polygonHoles = [];
  357. var j;
  358. for (i = 0; i < numChildren; i++) {
  359. var hole = holes[i];
  360. var holePositions = hole.positions;
  361. if (scaleToEllipsoidSurface) {
  362. length = holePositions.length;
  363. for (j = 0; j < length; ++j) {
  364. ellipsoid.scaleToGeodeticSurface(holePositions[j], holePositions[j]);
  365. }
  366. }
  367. holePositions = arrayRemoveDuplicates.arrayRemoveDuplicates(holePositions, Cartesian2.Cartesian3.equalsEpsilon, true);
  368. if (holePositions.length < 3) {
  369. continue;
  370. }
  371. var holePositions2D = projectPointsTo2D(holePositions);
  372. if (!defined.defined(holePositions2D)) {
  373. continue;
  374. }
  375. originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(holePositions2D);
  376. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  377. holePositions2D.reverse();
  378. holePositions = holePositions.slice().reverse();
  379. }
  380. polygonHoles.push(holePositions);
  381. holeIndices.push(positions.length);
  382. positions = positions.concat(holePositions);
  383. positions2D = positions2D.concat(holePositions2D);
  384. var numGrandchildren = 0;
  385. if (defined.defined(hole.holes)) {
  386. numGrandchildren = hole.holes.length;
  387. }
  388. for (j = 0; j < numGrandchildren; j++) {
  389. queue.enqueue(hole.holes[j]);
  390. }
  391. }
  392. hierarchy.push({
  393. outerRing : outerRing,
  394. holes : polygonHoles
  395. });
  396. polygons.push({
  397. positions : positions,
  398. positions2D : positions2D,
  399. holes : holeIndices
  400. });
  401. }
  402. return {
  403. hierarchy : hierarchy,
  404. polygons : polygons
  405. };
  406. };
  407. var computeBoundingRectangleCartesian2 = new Cartesian2.Cartesian2();
  408. var computeBoundingRectangleCartesian3 = new Cartesian2.Cartesian3();
  409. var computeBoundingRectangleQuaternion = new Transforms.Quaternion();
  410. var computeBoundingRectangleMatrix3 = new Transforms.Matrix3();
  411. PolygonGeometryLibrary.computeBoundingRectangle = function (planeNormal, projectPointTo2D, positions, angle, result) {
  412. var rotation = Transforms.Quaternion.fromAxisAngle(planeNormal, angle, computeBoundingRectangleQuaternion);
  413. var textureMatrix = Transforms.Matrix3.fromQuaternion(rotation, computeBoundingRectangleMatrix3);
  414. var minX = Number.POSITIVE_INFINITY;
  415. var maxX = Number.NEGATIVE_INFINITY;
  416. var minY = Number.POSITIVE_INFINITY;
  417. var maxY = Number.NEGATIVE_INFINITY;
  418. var length = positions.length;
  419. for ( var i = 0; i < length; ++i) {
  420. var p = Cartesian2.Cartesian3.clone(positions[i], computeBoundingRectangleCartesian3);
  421. Transforms.Matrix3.multiplyByVector(textureMatrix, p, p);
  422. var st = projectPointTo2D(p, computeBoundingRectangleCartesian2);
  423. if (defined.defined(st)) {
  424. minX = Math.min(minX, st.x);
  425. maxX = Math.max(maxX, st.x);
  426. minY = Math.min(minY, st.y);
  427. maxY = Math.max(maxY, st.y);
  428. }
  429. }
  430. result.x = minX;
  431. result.y = minY;
  432. result.width = maxX - minX;
  433. result.height = maxY - minY;
  434. return result;
  435. };
  436. PolygonGeometryLibrary.createGeometryFromPositions = function(ellipsoid, polygon, granularity, perPositionHeight, vertexFormat, arcType) {
  437. var indices = PolygonPipeline.PolygonPipeline.triangulate(polygon.positions2D, polygon.holes);
  438. /* If polygon is completely unrenderable, just use the first three vertices */
  439. if (indices.length < 3) {
  440. indices = [0, 1, 2];
  441. }
  442. var positions = polygon.positions;
  443. if (perPositionHeight) {
  444. var length = positions.length;
  445. var flattenedPositions = new Array(length * 3);
  446. var index = 0;
  447. for ( var i = 0; i < length; i++) {
  448. var p = positions[i];
  449. flattenedPositions[index++] = p.x;
  450. flattenedPositions[index++] = p.y;
  451. flattenedPositions[index++] = p.z;
  452. }
  453. var geometry = new GeometryAttribute.Geometry({
  454. attributes : {
  455. position : new GeometryAttribute.GeometryAttribute({
  456. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  457. componentsPerAttribute : 3,
  458. values : flattenedPositions
  459. })
  460. },
  461. indices : indices,
  462. primitiveType : GeometryAttribute.PrimitiveType.TRIANGLES
  463. });
  464. if (vertexFormat.normal) {
  465. return GeometryPipeline.GeometryPipeline.computeNormal(geometry);
  466. }
  467. return geometry;
  468. }
  469. if (arcType === ArcType.ArcType.GEODESIC) {
  470. return PolygonPipeline.PolygonPipeline.computeSubdivision(ellipsoid, positions, indices, granularity);
  471. } else if (arcType === ArcType.ArcType.RHUMB) {
  472. return PolygonPipeline.PolygonPipeline.computeRhumbLineSubdivision(ellipsoid, positions, indices, granularity);
  473. }
  474. };
  475. var computeWallIndicesSubdivided = [];
  476. var p1Scratch = new Cartesian2.Cartesian3();
  477. var p2Scratch = new Cartesian2.Cartesian3();
  478. PolygonGeometryLibrary.computeWallGeometry = function(positions, ellipsoid, granularity, perPositionHeight, arcType) {
  479. var edgePositions;
  480. var topEdgeLength;
  481. var i;
  482. var p1;
  483. var p2;
  484. var length = positions.length;
  485. var index = 0;
  486. if (!perPositionHeight) {
  487. var minDistance = _Math.CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
  488. var numVertices = 0;
  489. if (arcType === ArcType.ArcType.GEODESIC) {
  490. for (i = 0; i < length; i++) {
  491. numVertices += PolygonGeometryLibrary.subdivideLineCount(positions[i], positions[(i + 1) % length], minDistance);
  492. }
  493. } else if (arcType === ArcType.ArcType.RHUMB) {
  494. for (i = 0; i < length; i++) {
  495. numVertices += PolygonGeometryLibrary.subdivideRhumbLineCount(ellipsoid, positions[i], positions[(i + 1) % length], minDistance);
  496. }
  497. }
  498. topEdgeLength = (numVertices + length) * 3;
  499. edgePositions = new Array(topEdgeLength * 2);
  500. for (i = 0; i < length; i++) {
  501. p1 = positions[i];
  502. p2 = positions[(i + 1) % length];
  503. var tempPositions;
  504. if (arcType === ArcType.ArcType.GEODESIC) {
  505. tempPositions = PolygonGeometryLibrary.subdivideLine(p1, p2, minDistance, computeWallIndicesSubdivided);
  506. } else if (arcType === ArcType.ArcType.RHUMB) {
  507. tempPositions = PolygonGeometryLibrary.subdivideRhumbLine(ellipsoid, p1, p2, minDistance, computeWallIndicesSubdivided);
  508. }
  509. var tempPositionsLength = tempPositions.length;
  510. for (var j = 0; j < tempPositionsLength; ++j, ++index) {
  511. edgePositions[index] = tempPositions[j];
  512. edgePositions[index + topEdgeLength] = tempPositions[j];
  513. }
  514. edgePositions[index] = p2.x;
  515. edgePositions[index + topEdgeLength] = p2.x;
  516. ++index;
  517. edgePositions[index] = p2.y;
  518. edgePositions[index + topEdgeLength] = p2.y;
  519. ++index;
  520. edgePositions[index] = p2.z;
  521. edgePositions[index + topEdgeLength] = p2.z;
  522. ++index;
  523. }
  524. } else {
  525. topEdgeLength = length * 3 * 2;
  526. edgePositions = new Array(topEdgeLength * 2);
  527. for (i = 0; i < length; i++) {
  528. p1 = positions[i];
  529. p2 = positions[(i + 1) % length];
  530. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.x;
  531. ++index;
  532. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.y;
  533. ++index;
  534. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.z;
  535. ++index;
  536. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.x;
  537. ++index;
  538. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.y;
  539. ++index;
  540. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.z;
  541. ++index;
  542. }
  543. }
  544. length = edgePositions.length;
  545. var indices = IndexDatatype.IndexDatatype.createTypedArray(length / 3, length - positions.length * 6);
  546. var edgeIndex = 0;
  547. length /= 6;
  548. for (i = 0; i < length; i++) {
  549. var UL = i;
  550. var UR = UL + 1;
  551. var LL = UL + length;
  552. var LR = LL + 1;
  553. p1 = Cartesian2.Cartesian3.fromArray(edgePositions, UL * 3, p1Scratch);
  554. p2 = Cartesian2.Cartesian3.fromArray(edgePositions, UR * 3, p2Scratch);
  555. if (Cartesian2.Cartesian3.equalsEpsilon(p1, p2, _Math.CesiumMath.EPSILON10, _Math.CesiumMath.EPSILON10)) {
  556. //skip corner
  557. continue;
  558. }
  559. indices[edgeIndex++] = UL;
  560. indices[edgeIndex++] = LL;
  561. indices[edgeIndex++] = UR;
  562. indices[edgeIndex++] = UR;
  563. indices[edgeIndex++] = LL;
  564. indices[edgeIndex++] = LR;
  565. }
  566. return new GeometryAttribute.Geometry({
  567. attributes : new GeometryAttributes.GeometryAttributes({
  568. position : new GeometryAttribute.GeometryAttribute({
  569. componentDatatype : ComponentDatatype.ComponentDatatype.DOUBLE,
  570. componentsPerAttribute : 3,
  571. values : edgePositions
  572. })
  573. }),
  574. indices : indices,
  575. primitiveType : GeometryAttribute.PrimitiveType.TRIANGLES
  576. });
  577. };
  578. exports.PolygonGeometryLibrary = PolygonGeometryLibrary;
  579. });