WallGeometryLibrary-f30761f4.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './defined-26bd4a03', './Math-fa6e45cb', './Cartesian2-2a723276', './EllipsoidTangentPlane-10c6053a', './PolygonPipeline-e486c11c', './PolylinePipeline-b4161aaf'], function (exports, defined, _Math, Cartesian2, EllipsoidTangentPlane, PolygonPipeline, PolylinePipeline) { 'use strict';
  3. /**
  4. * private
  5. */
  6. var WallGeometryLibrary = {};
  7. function latLonEquals(c0, c1) {
  8. return ((_Math.CesiumMath.equalsEpsilon(c0.latitude, c1.latitude, _Math.CesiumMath.EPSILON14)) && (_Math.CesiumMath.equalsEpsilon(c0.longitude, c1.longitude, _Math.CesiumMath.EPSILON14)));
  9. }
  10. var scratchCartographic1 = new Cartesian2.Cartographic();
  11. var scratchCartographic2 = new Cartesian2.Cartographic();
  12. function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) {
  13. var length = positions.length;
  14. if (length < 2) {
  15. return;
  16. }
  17. var hasBottomHeights = defined.defined(bottomHeights);
  18. var hasTopHeights = defined.defined(topHeights);
  19. var hasAllZeroHeights = true;
  20. var cleanedPositions = new Array(length);
  21. var cleanedTopHeights = new Array(length);
  22. var cleanedBottomHeights = new Array(length);
  23. var v0 = positions[0];
  24. cleanedPositions[0] = v0;
  25. var c0 = ellipsoid.cartesianToCartographic(v0, scratchCartographic1);
  26. if (hasTopHeights) {
  27. c0.height = topHeights[0];
  28. }
  29. hasAllZeroHeights = hasAllZeroHeights && c0.height <= 0;
  30. cleanedTopHeights[0] = c0.height;
  31. if (hasBottomHeights) {
  32. cleanedBottomHeights[0] = bottomHeights[0];
  33. } else {
  34. cleanedBottomHeights[0] = 0.0;
  35. }
  36. var index = 1;
  37. for (var i = 1; i < length; ++i) {
  38. var v1 = positions[i];
  39. var c1 = ellipsoid.cartesianToCartographic(v1, scratchCartographic2);
  40. if (hasTopHeights) {
  41. c1.height = topHeights[i];
  42. }
  43. hasAllZeroHeights = hasAllZeroHeights && c1.height <= 0;
  44. if (!latLonEquals(c0, c1)) {
  45. cleanedPositions[index] = v1; // Shallow copy!
  46. cleanedTopHeights[index] = c1.height;
  47. if (hasBottomHeights) {
  48. cleanedBottomHeights[index] = bottomHeights[i];
  49. } else {
  50. cleanedBottomHeights[index] = 0.0;
  51. }
  52. Cartesian2.Cartographic.clone(c1, c0);
  53. ++index;
  54. } else if (c0.height < c1.height) {
  55. cleanedTopHeights[index - 1] = c1.height;
  56. }
  57. }
  58. if (hasAllZeroHeights || index < 2) {
  59. return;
  60. }
  61. cleanedPositions.length = index;
  62. cleanedTopHeights.length = index;
  63. cleanedBottomHeights.length = index;
  64. return {
  65. positions: cleanedPositions,
  66. topHeights: cleanedTopHeights,
  67. bottomHeights: cleanedBottomHeights
  68. };
  69. }
  70. var positionsArrayScratch = new Array(2);
  71. var heightsArrayScratch = new Array(2);
  72. var generateArcOptionsScratch = {
  73. positions : undefined,
  74. height : undefined,
  75. granularity : undefined,
  76. ellipsoid : undefined
  77. };
  78. /**
  79. * @private
  80. */
  81. WallGeometryLibrary.computePositions = function(ellipsoid, wallPositions, maximumHeights, minimumHeights, granularity, duplicateCorners) {
  82. var o = removeDuplicates(ellipsoid, wallPositions, maximumHeights, minimumHeights);
  83. if (!defined.defined(o)) {
  84. return;
  85. }
  86. wallPositions = o.positions;
  87. maximumHeights = o.topHeights;
  88. minimumHeights = o.bottomHeights;
  89. if (wallPositions.length >= 3) {
  90. // Order positions counter-clockwise
  91. var tangentPlane = EllipsoidTangentPlane.EllipsoidTangentPlane.fromPoints(wallPositions, ellipsoid);
  92. var positions2D = tangentPlane.projectPointsOntoPlane(wallPositions);
  93. if (PolygonPipeline.PolygonPipeline.computeWindingOrder2D(positions2D) === PolygonPipeline.WindingOrder.CLOCKWISE) {
  94. wallPositions.reverse();
  95. maximumHeights.reverse();
  96. minimumHeights.reverse();
  97. }
  98. }
  99. var length = wallPositions.length;
  100. var numCorners = length - 2;
  101. var topPositions;
  102. var bottomPositions;
  103. var minDistance = _Math.CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);
  104. var generateArcOptions = generateArcOptionsScratch;
  105. generateArcOptions.minDistance = minDistance;
  106. generateArcOptions.ellipsoid = ellipsoid;
  107. if (duplicateCorners) {
  108. var count = 0;
  109. var i;
  110. for (i = 0; i < length - 1; i++) {
  111. count += PolylinePipeline.PolylinePipeline.numberOfPoints(wallPositions[i], wallPositions[i+1], minDistance) + 1;
  112. }
  113. topPositions = new Float64Array(count * 3);
  114. bottomPositions = new Float64Array(count * 3);
  115. var generateArcPositions = positionsArrayScratch;
  116. var generateArcHeights = heightsArrayScratch;
  117. generateArcOptions.positions = generateArcPositions;
  118. generateArcOptions.height = generateArcHeights;
  119. var offset = 0;
  120. for (i = 0; i < length - 1; i++) {
  121. generateArcPositions[0] = wallPositions[i];
  122. generateArcPositions[1] = wallPositions[i + 1];
  123. generateArcHeights[0] = maximumHeights[i];
  124. generateArcHeights[1] = maximumHeights[i + 1];
  125. var pos = PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions);
  126. topPositions.set(pos, offset);
  127. generateArcHeights[0] = minimumHeights[i];
  128. generateArcHeights[1] = minimumHeights[i + 1];
  129. bottomPositions.set(PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions), offset);
  130. offset += pos.length;
  131. }
  132. } else {
  133. generateArcOptions.positions = wallPositions;
  134. generateArcOptions.height = maximumHeights;
  135. topPositions = new Float64Array(PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions));
  136. generateArcOptions.height = minimumHeights;
  137. bottomPositions = new Float64Array(PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions));
  138. }
  139. return {
  140. bottomPositions: bottomPositions,
  141. topPositions: topPositions,
  142. numCorners: numCorners
  143. };
  144. };
  145. exports.WallGeometryLibrary = WallGeometryLibrary;
  146. });