PolygonGeometryLibrary-515b324f.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './ArcType-0cf52f8c', './arrayRemoveDuplicates-87160c89', './Matrix2-69c32d33', './ComponentDatatype-b1ea011a', './defaultValue-94c3e563', './EllipsoidRhumbLine-5cb6da82', './GeometryAttribute-cb73bb3f', './GeometryAttributes-7df9bef6', './GeometryPipeline-e27e35f8', './IndexDatatype-c4099fe9', './PolygonPipeline-d1884135', './Transforms-323408fe'], (function (exports, ArcType, arrayRemoveDuplicates, Matrix2, ComponentDatatype, defaultValue, EllipsoidRhumbLine, GeometryAttribute, GeometryAttributes, GeometryPipeline, IndexDatatype, PolygonPipeline, Transforms) { '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. const array = this._array;
  48. let offset = this._offset;
  49. const 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. const PolygonGeometryLibrary = {};
  103. PolygonGeometryLibrary.computeHierarchyPackedLength = function (
  104. polygonHierarchy
  105. ) {
  106. let numComponents = 0;
  107. const stack = [polygonHierarchy];
  108. while (stack.length > 0) {
  109. const hierarchy = stack.pop();
  110. if (!defaultValue.defined(hierarchy)) {
  111. continue;
  112. }
  113. numComponents += 2;
  114. const positions = hierarchy.positions;
  115. const holes = hierarchy.holes;
  116. if (defaultValue.defined(positions)) {
  117. numComponents += positions.length * Matrix2.Cartesian3.packedLength;
  118. }
  119. if (defaultValue.defined(holes)) {
  120. const length = holes.length;
  121. for (let 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. const stack = [polygonHierarchy];
  134. while (stack.length > 0) {
  135. const hierarchy = stack.pop();
  136. if (!defaultValue.defined(hierarchy)) {
  137. continue;
  138. }
  139. const positions = hierarchy.positions;
  140. const holes = hierarchy.holes;
  141. array[startingIndex++] = defaultValue.defined(positions) ? positions.length : 0;
  142. array[startingIndex++] = defaultValue.defined(holes) ? holes.length : 0;
  143. if (defaultValue.defined(positions)) {
  144. const positionsLength = positions.length;
  145. for (let i = 0; i < positionsLength; ++i, startingIndex += 3) {
  146. Matrix2.Cartesian3.pack(positions[i], array, startingIndex);
  147. }
  148. }
  149. if (defaultValue.defined(holes)) {
  150. const holesLength = holes.length;
  151. for (let 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. const positionsLength = array[startingIndex++];
  163. const holesLength = array[startingIndex++];
  164. const positions = new Array(positionsLength);
  165. const holes = holesLength > 0 ? new Array(holesLength) : undefined;
  166. for (
  167. let i = 0;
  168. i < positionsLength;
  169. ++i, startingIndex += Matrix2.Cartesian3.packedLength
  170. ) {
  171. positions[i] = Matrix2.Cartesian3.unpack(array, startingIndex);
  172. }
  173. for (let 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. const distanceScratch = new Matrix2.Cartesian3();
  188. function getPointAtDistance(p0, p1, distance, length) {
  189. Matrix2.Cartesian3.subtract(p1, p0, distanceScratch);
  190. Matrix2.Cartesian3.multiplyByScalar(
  191. distanceScratch,
  192. distance / length,
  193. distanceScratch
  194. );
  195. Matrix2.Cartesian3.add(p0, distanceScratch, distanceScratch);
  196. return [distanceScratch.x, distanceScratch.y, distanceScratch.z];
  197. }
  198. PolygonGeometryLibrary.subdivideLineCount = function (p0, p1, minDistance) {
  199. const distance = Matrix2.Cartesian3.distance(p0, p1);
  200. const n = distance / minDistance;
  201. const countDivide = Math.max(0, Math.ceil(ComponentDatatype.CesiumMath.log2(n)));
  202. return Math.pow(2, countDivide);
  203. };
  204. const scratchCartographic0 = new Matrix2.Cartographic();
  205. const scratchCartographic1 = new Matrix2.Cartographic();
  206. const scratchCartographic2 = new Matrix2.Cartographic();
  207. const scratchCartesian0 = new Matrix2.Cartesian3();
  208. PolygonGeometryLibrary.subdivideRhumbLineCount = function (
  209. ellipsoid,
  210. p0,
  211. p1,
  212. minDistance
  213. ) {
  214. const c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);
  215. const c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);
  216. const rhumb = new EllipsoidRhumbLine.EllipsoidRhumbLine(c0, c1, ellipsoid);
  217. const n = rhumb.surfaceDistance / minDistance;
  218. const countDivide = Math.max(0, Math.ceil(ComponentDatatype.CesiumMath.log2(n)));
  219. return Math.pow(2, countDivide);
  220. };
  221. PolygonGeometryLibrary.subdivideLine = function (p0, p1, minDistance, result) {
  222. const numVertices = PolygonGeometryLibrary.subdivideLineCount(
  223. p0,
  224. p1,
  225. minDistance
  226. );
  227. const length = Matrix2.Cartesian3.distance(p0, p1);
  228. const distanceBetweenVertices = length / numVertices;
  229. if (!defaultValue.defined(result)) {
  230. result = [];
  231. }
  232. const positions = result;
  233. positions.length = numVertices * 3;
  234. let index = 0;
  235. for (let i = 0; i < numVertices; i++) {
  236. const 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. const c0 = ellipsoid.cartesianToCartographic(p0, scratchCartographic0);
  251. const c1 = ellipsoid.cartesianToCartographic(p1, scratchCartographic1);
  252. const rhumb = new EllipsoidRhumbLine.EllipsoidRhumbLine(c0, c1, ellipsoid);
  253. const n = rhumb.surfaceDistance / minDistance;
  254. const countDivide = Math.max(0, Math.ceil(ComponentDatatype.CesiumMath.log2(n)));
  255. const numVertices = Math.pow(2, countDivide);
  256. const distanceBetweenVertices = rhumb.surfaceDistance / numVertices;
  257. if (!defaultValue.defined(result)) {
  258. result = [];
  259. }
  260. const positions = result;
  261. positions.length = numVertices * 3;
  262. let index = 0;
  263. for (let i = 0; i < numVertices; i++) {
  264. const c = rhumb.interpolateUsingSurfaceDistance(
  265. i * distanceBetweenVertices,
  266. scratchCartographic2
  267. );
  268. const 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. const scaleToGeodeticHeightN1 = new Matrix2.Cartesian3();
  276. const scaleToGeodeticHeightN2 = new Matrix2.Cartesian3();
  277. const scaleToGeodeticHeightP1 = new Matrix2.Cartesian3();
  278. const scaleToGeodeticHeightP2 = new Matrix2.Cartesian3();
  279. PolygonGeometryLibrary.scaleToGeodeticHeightExtruded = function (
  280. geometry,
  281. maxHeight,
  282. minHeight,
  283. ellipsoid,
  284. perPositionHeight
  285. ) {
  286. ellipsoid = defaultValue.defaultValue(ellipsoid, Matrix2.Ellipsoid.WGS84);
  287. const n1 = scaleToGeodeticHeightN1;
  288. let n2 = scaleToGeodeticHeightN2;
  289. const p = scaleToGeodeticHeightP1;
  290. let p2 = scaleToGeodeticHeightP2;
  291. if (
  292. defaultValue.defined(geometry) &&
  293. defaultValue.defined(geometry.attributes) &&
  294. defaultValue.defined(geometry.attributes.position)
  295. ) {
  296. const positions = geometry.attributes.position.values;
  297. const length = positions.length / 2;
  298. for (let i = 0; i < length; i += 3) {
  299. Matrix2.Cartesian3.fromArray(positions, i, p);
  300. ellipsoid.geodeticSurfaceNormal(p, n1);
  301. p2 = ellipsoid.scaleToGeodeticSurface(p, p2);
  302. n2 = Matrix2.Cartesian3.multiplyByScalar(n1, minHeight, n2);
  303. n2 = Matrix2.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 = Matrix2.Cartesian3.clone(p, p2);
  309. }
  310. n2 = Matrix2.Cartesian3.multiplyByScalar(n1, maxHeight, n2);
  311. n2 = Matrix2.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. const polygons = [];
  327. const queue = new Queue();
  328. queue.enqueue(polygonHierarchy);
  329. let i;
  330. let j;
  331. let length;
  332. while (queue.length !== 0) {
  333. const outerNode = queue.dequeue();
  334. let 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. Matrix2.Cartesian3.equalsEpsilon,
  344. true
  345. );
  346. if (outerRing.length < 3) {
  347. continue;
  348. }
  349. const numChildren = outerNode.holes ? outerNode.holes.length : 0;
  350. // The outer polygon contains inner polygons
  351. for (i = 0; i < numChildren; i++) {
  352. const hole = outerNode.holes[i];
  353. let 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. Matrix2.Cartesian3.equalsEpsilon,
  363. true
  364. );
  365. if (holePositions.length < 3) {
  366. continue;
  367. }
  368. polygons.push(holePositions);
  369. let numGrandchildren = 0;
  370. if (defaultValue.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. const hierarchy = [];
  390. const polygons = [];
  391. const queue = new Queue();
  392. queue.enqueue(polygonHierarchy);
  393. while (queue.length !== 0) {
  394. const outerNode = queue.dequeue();
  395. let outerRing = outerNode.positions;
  396. const holes = outerNode.holes;
  397. let i;
  398. let 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. Matrix2.Cartesian3.equalsEpsilon,
  408. true
  409. );
  410. if (outerRing.length < 3) {
  411. continue;
  412. }
  413. let positions2D = projectPointsTo2D(outerRing);
  414. if (!defaultValue.defined(positions2D)) {
  415. continue;
  416. }
  417. const holeIndices = [];
  418. let originalWindingOrder = PolygonPipeline.PolygonPipeline.computeWindingOrder2D(
  419. positions2D
  420. );
  421. if (originalWindingOrder === PolygonPipeline.WindingOrder.CLOCKWISE) {
  422. positions2D.reverse();
  423. outerRing = outerRing.slice().reverse();
  424. }
  425. let positions = outerRing.slice();
  426. const numChildren = defaultValue.defined(holes) ? holes.length : 0;
  427. const polygonHoles = [];
  428. let j;
  429. for (i = 0; i < numChildren; i++) {
  430. const hole = holes[i];
  431. let 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. Matrix2.Cartesian3.equalsEpsilon,
  441. true
  442. );
  443. if (holePositions.length < 3) {
  444. continue;
  445. }
  446. const holePositions2D = projectPointsTo2D(holePositions);
  447. if (!defaultValue.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. let numGrandchildren = 0;
  462. if (defaultValue.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. const computeBoundingRectangleCartesian2 = new Matrix2.Cartesian2();
  485. const computeBoundingRectangleCartesian3 = new Matrix2.Cartesian3();
  486. const computeBoundingRectangleQuaternion = new Transforms.Quaternion();
  487. const computeBoundingRectangleMatrix3 = new Matrix2.Matrix3();
  488. PolygonGeometryLibrary.computeBoundingRectangle = function (
  489. planeNormal,
  490. projectPointTo2D,
  491. positions,
  492. angle,
  493. result
  494. ) {
  495. const rotation = Transforms.Quaternion.fromAxisAngle(
  496. planeNormal,
  497. angle,
  498. computeBoundingRectangleQuaternion
  499. );
  500. const textureMatrix = Matrix2.Matrix3.fromQuaternion(
  501. rotation,
  502. computeBoundingRectangleMatrix3
  503. );
  504. let minX = Number.POSITIVE_INFINITY;
  505. let maxX = Number.NEGATIVE_INFINITY;
  506. let minY = Number.POSITIVE_INFINITY;
  507. let maxY = Number.NEGATIVE_INFINITY;
  508. const length = positions.length;
  509. for (let i = 0; i < length; ++i) {
  510. const p = Matrix2.Cartesian3.clone(
  511. positions[i],
  512. computeBoundingRectangleCartesian3
  513. );
  514. Matrix2.Matrix3.multiplyByVector(textureMatrix, p, p);
  515. const st = projectPointTo2D(p, computeBoundingRectangleCartesian2);
  516. if (defaultValue.defined(st)) {
  517. minX = Math.min(minX, st.x);
  518. maxX = Math.max(maxX, st.x);
  519. minY = Math.min(minY, st.y);
  520. maxY = Math.max(maxY, st.y);
  521. }
  522. }
  523. result.x = minX;
  524. result.y = minY;
  525. result.width = maxX - minX;
  526. result.height = maxY - minY;
  527. return result;
  528. };
  529. PolygonGeometryLibrary.createGeometryFromPositions = function (
  530. ellipsoid,
  531. polygon,
  532. granularity,
  533. perPositionHeight,
  534. vertexFormat,
  535. arcType
  536. ) {
  537. let indices = PolygonPipeline.PolygonPipeline.triangulate(polygon.positions2D, polygon.holes);
  538. /* If polygon is completely unrenderable, just use the first three vertices */
  539. if (indices.length < 3) {
  540. indices = [0, 1, 2];
  541. }
  542. const positions = polygon.positions;
  543. if (perPositionHeight) {
  544. const length = positions.length;
  545. const flattenedPositions = new Array(length * 3);
  546. let index = 0;
  547. for (let i = 0; i < length; i++) {
  548. const p = positions[i];
  549. flattenedPositions[index++] = p.x;
  550. flattenedPositions[index++] = p.y;
  551. flattenedPositions[index++] = p.z;
  552. }
  553. const geometry = new GeometryAttribute.Geometry({
  554. attributes: {
  555. position: new GeometryAttribute.GeometryAttribute({
  556. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  557. componentsPerAttribute: 3,
  558. values: flattenedPositions,
  559. }),
  560. },
  561. indices: indices,
  562. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  563. });
  564. if (vertexFormat.normal) {
  565. return GeometryPipeline.GeometryPipeline.computeNormal(geometry);
  566. }
  567. return geometry;
  568. }
  569. if (arcType === ArcType.ArcType.GEODESIC) {
  570. return PolygonPipeline.PolygonPipeline.computeSubdivision(
  571. ellipsoid,
  572. positions,
  573. indices,
  574. granularity
  575. );
  576. } else if (arcType === ArcType.ArcType.RHUMB) {
  577. return PolygonPipeline.PolygonPipeline.computeRhumbLineSubdivision(
  578. ellipsoid,
  579. positions,
  580. indices,
  581. granularity
  582. );
  583. }
  584. };
  585. const computeWallIndicesSubdivided = [];
  586. const p1Scratch = new Matrix2.Cartesian3();
  587. const p2Scratch = new Matrix2.Cartesian3();
  588. PolygonGeometryLibrary.computeWallGeometry = function (
  589. positions,
  590. ellipsoid,
  591. granularity,
  592. perPositionHeight,
  593. arcType
  594. ) {
  595. let edgePositions;
  596. let topEdgeLength;
  597. let i;
  598. let p1;
  599. let p2;
  600. let length = positions.length;
  601. let index = 0;
  602. if (!perPositionHeight) {
  603. const minDistance = ComponentDatatype.CesiumMath.chordLength(
  604. granularity,
  605. ellipsoid.maximumRadius
  606. );
  607. let numVertices = 0;
  608. if (arcType === ArcType.ArcType.GEODESIC) {
  609. for (i = 0; i < length; i++) {
  610. numVertices += PolygonGeometryLibrary.subdivideLineCount(
  611. positions[i],
  612. positions[(i + 1) % length],
  613. minDistance
  614. );
  615. }
  616. } else if (arcType === ArcType.ArcType.RHUMB) {
  617. for (i = 0; i < length; i++) {
  618. numVertices += PolygonGeometryLibrary.subdivideRhumbLineCount(
  619. ellipsoid,
  620. positions[i],
  621. positions[(i + 1) % length],
  622. minDistance
  623. );
  624. }
  625. }
  626. topEdgeLength = (numVertices + length) * 3;
  627. edgePositions = new Array(topEdgeLength * 2);
  628. for (i = 0; i < length; i++) {
  629. p1 = positions[i];
  630. p2 = positions[(i + 1) % length];
  631. let tempPositions;
  632. if (arcType === ArcType.ArcType.GEODESIC) {
  633. tempPositions = PolygonGeometryLibrary.subdivideLine(
  634. p1,
  635. p2,
  636. minDistance,
  637. computeWallIndicesSubdivided
  638. );
  639. } else if (arcType === ArcType.ArcType.RHUMB) {
  640. tempPositions = PolygonGeometryLibrary.subdivideRhumbLine(
  641. ellipsoid,
  642. p1,
  643. p2,
  644. minDistance,
  645. computeWallIndicesSubdivided
  646. );
  647. }
  648. const tempPositionsLength = tempPositions.length;
  649. for (let j = 0; j < tempPositionsLength; ++j, ++index) {
  650. edgePositions[index] = tempPositions[j];
  651. edgePositions[index + topEdgeLength] = tempPositions[j];
  652. }
  653. edgePositions[index] = p2.x;
  654. edgePositions[index + topEdgeLength] = p2.x;
  655. ++index;
  656. edgePositions[index] = p2.y;
  657. edgePositions[index + topEdgeLength] = p2.y;
  658. ++index;
  659. edgePositions[index] = p2.z;
  660. edgePositions[index + topEdgeLength] = p2.z;
  661. ++index;
  662. }
  663. } else {
  664. topEdgeLength = length * 3 * 2;
  665. edgePositions = new Array(topEdgeLength * 2);
  666. for (i = 0; i < length; i++) {
  667. p1 = positions[i];
  668. p2 = positions[(i + 1) % length];
  669. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.x;
  670. ++index;
  671. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.y;
  672. ++index;
  673. edgePositions[index] = edgePositions[index + topEdgeLength] = p1.z;
  674. ++index;
  675. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.x;
  676. ++index;
  677. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.y;
  678. ++index;
  679. edgePositions[index] = edgePositions[index + topEdgeLength] = p2.z;
  680. ++index;
  681. }
  682. }
  683. length = edgePositions.length;
  684. const indices = IndexDatatype.IndexDatatype.createTypedArray(
  685. length / 3,
  686. length - positions.length * 6
  687. );
  688. let edgeIndex = 0;
  689. length /= 6;
  690. for (i = 0; i < length; i++) {
  691. const UL = i;
  692. const UR = UL + 1;
  693. const LL = UL + length;
  694. const LR = LL + 1;
  695. p1 = Matrix2.Cartesian3.fromArray(edgePositions, UL * 3, p1Scratch);
  696. p2 = Matrix2.Cartesian3.fromArray(edgePositions, UR * 3, p2Scratch);
  697. if (
  698. Matrix2.Cartesian3.equalsEpsilon(
  699. p1,
  700. p2,
  701. ComponentDatatype.CesiumMath.EPSILON10,
  702. ComponentDatatype.CesiumMath.EPSILON10
  703. )
  704. ) {
  705. //skip corner
  706. continue;
  707. }
  708. indices[edgeIndex++] = UL;
  709. indices[edgeIndex++] = LL;
  710. indices[edgeIndex++] = UR;
  711. indices[edgeIndex++] = UR;
  712. indices[edgeIndex++] = LL;
  713. indices[edgeIndex++] = LR;
  714. }
  715. return new GeometryAttribute.Geometry({
  716. attributes: new GeometryAttributes.GeometryAttributes({
  717. position: new GeometryAttribute.GeometryAttribute({
  718. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  719. componentsPerAttribute: 3,
  720. values: edgePositions,
  721. }),
  722. }),
  723. indices: indices,
  724. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  725. });
  726. };
  727. exports.PolygonGeometryLibrary = PolygonGeometryLibrary;
  728. }));