WallGeometryLibrary-9abfba7e.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './arrayRemoveDuplicates-06991c15', './Matrix2-fc7e9822', './defaultValue-94c3e563', './ComponentDatatype-4a60b8d6', './PolylinePipeline-7608e667'], (function (exports, arrayRemoveDuplicates, Matrix2, defaultValue, ComponentDatatype, PolylinePipeline) { 'use strict';
  3. /**
  4. * @private
  5. */
  6. const WallGeometryLibrary = {};
  7. function latLonEquals(c0, c1) {
  8. return (
  9. ComponentDatatype.CesiumMath.equalsEpsilon(c0.latitude, c1.latitude, ComponentDatatype.CesiumMath.EPSILON10) &&
  10. ComponentDatatype.CesiumMath.equalsEpsilon(c0.longitude, c1.longitude, ComponentDatatype.CesiumMath.EPSILON10)
  11. );
  12. }
  13. const scratchCartographic1 = new Matrix2.Cartographic();
  14. const scratchCartographic2 = new Matrix2.Cartographic();
  15. function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) {
  16. positions = arrayRemoveDuplicates.arrayRemoveDuplicates(positions, Matrix2.Cartesian3.equalsEpsilon);
  17. const length = positions.length;
  18. if (length < 2) {
  19. return;
  20. }
  21. const hasBottomHeights = defaultValue.defined(bottomHeights);
  22. const hasTopHeights = defaultValue.defined(topHeights);
  23. const cleanedPositions = new Array(length);
  24. const cleanedTopHeights = new Array(length);
  25. const cleanedBottomHeights = new Array(length);
  26. const v0 = positions[0];
  27. cleanedPositions[0] = v0;
  28. const c0 = ellipsoid.cartesianToCartographic(v0, scratchCartographic1);
  29. if (hasTopHeights) {
  30. c0.height = topHeights[0];
  31. }
  32. cleanedTopHeights[0] = c0.height;
  33. if (hasBottomHeights) {
  34. cleanedBottomHeights[0] = bottomHeights[0];
  35. } else {
  36. cleanedBottomHeights[0] = 0.0;
  37. }
  38. const startTopHeight = cleanedTopHeights[0];
  39. const startBottomHeight = cleanedBottomHeights[0];
  40. let hasAllSameHeights = startTopHeight === startBottomHeight;
  41. let index = 1;
  42. for (let i = 1; i < length; ++i) {
  43. const v1 = positions[i];
  44. const c1 = ellipsoid.cartesianToCartographic(v1, scratchCartographic2);
  45. if (hasTopHeights) {
  46. c1.height = topHeights[i];
  47. }
  48. hasAllSameHeights = hasAllSameHeights && c1.height === 0;
  49. if (!latLonEquals(c0, c1)) {
  50. cleanedPositions[index] = v1; // Shallow copy!
  51. cleanedTopHeights[index] = c1.height;
  52. if (hasBottomHeights) {
  53. cleanedBottomHeights[index] = bottomHeights[i];
  54. } else {
  55. cleanedBottomHeights[index] = 0.0;
  56. }
  57. hasAllSameHeights =
  58. hasAllSameHeights &&
  59. cleanedTopHeights[index] === cleanedBottomHeights[index];
  60. Matrix2.Cartographic.clone(c1, c0);
  61. ++index;
  62. } else if (c0.height < c1.height) {
  63. // two adjacent positions are the same, so use whichever has the greater height
  64. cleanedTopHeights[index - 1] = c1.height;
  65. }
  66. }
  67. if (hasAllSameHeights || index < 2) {
  68. return;
  69. }
  70. cleanedPositions.length = index;
  71. cleanedTopHeights.length = index;
  72. cleanedBottomHeights.length = index;
  73. return {
  74. positions: cleanedPositions,
  75. topHeights: cleanedTopHeights,
  76. bottomHeights: cleanedBottomHeights,
  77. };
  78. }
  79. const positionsArrayScratch = new Array(2);
  80. const heightsArrayScratch = new Array(2);
  81. const generateArcOptionsScratch = {
  82. positions: undefined,
  83. height: undefined,
  84. granularity: undefined,
  85. ellipsoid: undefined,
  86. };
  87. /**
  88. * @private
  89. */
  90. WallGeometryLibrary.computePositions = function (
  91. ellipsoid,
  92. wallPositions,
  93. maximumHeights,
  94. minimumHeights,
  95. granularity,
  96. duplicateCorners
  97. ) {
  98. const o = removeDuplicates(
  99. ellipsoid,
  100. wallPositions,
  101. maximumHeights,
  102. minimumHeights
  103. );
  104. if (!defaultValue.defined(o)) {
  105. return;
  106. }
  107. wallPositions = o.positions;
  108. maximumHeights = o.topHeights;
  109. minimumHeights = o.bottomHeights;
  110. const length = wallPositions.length;
  111. const numCorners = length - 2;
  112. let topPositions;
  113. let bottomPositions;
  114. const minDistance = ComponentDatatype.CesiumMath.chordLength(
  115. granularity,
  116. ellipsoid.maximumRadius
  117. );
  118. const generateArcOptions = generateArcOptionsScratch;
  119. generateArcOptions.minDistance = minDistance;
  120. generateArcOptions.ellipsoid = ellipsoid;
  121. if (duplicateCorners) {
  122. let count = 0;
  123. let i;
  124. for (i = 0; i < length - 1; i++) {
  125. count +=
  126. PolylinePipeline.PolylinePipeline.numberOfPoints(
  127. wallPositions[i],
  128. wallPositions[i + 1],
  129. minDistance
  130. ) + 1;
  131. }
  132. topPositions = new Float64Array(count * 3);
  133. bottomPositions = new Float64Array(count * 3);
  134. const generateArcPositions = positionsArrayScratch;
  135. const generateArcHeights = heightsArrayScratch;
  136. generateArcOptions.positions = generateArcPositions;
  137. generateArcOptions.height = generateArcHeights;
  138. let offset = 0;
  139. for (i = 0; i < length - 1; i++) {
  140. generateArcPositions[0] = wallPositions[i];
  141. generateArcPositions[1] = wallPositions[i + 1];
  142. generateArcHeights[0] = maximumHeights[i];
  143. generateArcHeights[1] = maximumHeights[i + 1];
  144. const pos = PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions);
  145. topPositions.set(pos, offset);
  146. generateArcHeights[0] = minimumHeights[i];
  147. generateArcHeights[1] = minimumHeights[i + 1];
  148. bottomPositions.set(
  149. PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions),
  150. offset
  151. );
  152. offset += pos.length;
  153. }
  154. } else {
  155. generateArcOptions.positions = wallPositions;
  156. generateArcOptions.height = maximumHeights;
  157. topPositions = new Float64Array(
  158. PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions)
  159. );
  160. generateArcOptions.height = minimumHeights;
  161. bottomPositions = new Float64Array(
  162. PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions)
  163. );
  164. }
  165. return {
  166. bottomPositions: bottomPositions,
  167. topPositions: topPositions,
  168. numCorners: numCorners,
  169. };
  170. };
  171. exports.WallGeometryLibrary = WallGeometryLibrary;
  172. }));