PolygonGeometryLibrary-6e68e6b6.js 24 KB

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