WallGeometryLibrary-3933dbde.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.95
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['exports', './arrayRemoveDuplicates-1af79ba4', './Matrix2-9e1c22e2', './defaultValue-97284df2', './ComponentDatatype-4eeb6d9b', './PolylinePipeline-e67c0760'], (function (exports, arrayRemoveDuplicates, Matrix2, defaultValue, ComponentDatatype, PolylinePipeline) { 'use strict';
  26. /**
  27. * @private
  28. */
  29. const WallGeometryLibrary = {};
  30. function latLonEquals(c0, c1) {
  31. return (
  32. ComponentDatatype.CesiumMath.equalsEpsilon(c0.latitude, c1.latitude, ComponentDatatype.CesiumMath.EPSILON10) &&
  33. ComponentDatatype.CesiumMath.equalsEpsilon(c0.longitude, c1.longitude, ComponentDatatype.CesiumMath.EPSILON10)
  34. );
  35. }
  36. const scratchCartographic1 = new Matrix2.Cartographic();
  37. const scratchCartographic2 = new Matrix2.Cartographic();
  38. function removeDuplicates(ellipsoid, positions, topHeights, bottomHeights) {
  39. positions = arrayRemoveDuplicates.arrayRemoveDuplicates(positions, Matrix2.Cartesian3.equalsEpsilon);
  40. const length = positions.length;
  41. if (length < 2) {
  42. return;
  43. }
  44. const hasBottomHeights = defaultValue.defined(bottomHeights);
  45. const hasTopHeights = defaultValue.defined(topHeights);
  46. const cleanedPositions = new Array(length);
  47. const cleanedTopHeights = new Array(length);
  48. const cleanedBottomHeights = new Array(length);
  49. const v0 = positions[0];
  50. cleanedPositions[0] = v0;
  51. const c0 = ellipsoid.cartesianToCartographic(v0, scratchCartographic1);
  52. if (hasTopHeights) {
  53. c0.height = topHeights[0];
  54. }
  55. cleanedTopHeights[0] = c0.height;
  56. if (hasBottomHeights) {
  57. cleanedBottomHeights[0] = bottomHeights[0];
  58. } else {
  59. cleanedBottomHeights[0] = 0.0;
  60. }
  61. const startTopHeight = cleanedTopHeights[0];
  62. const startBottomHeight = cleanedBottomHeights[0];
  63. let hasAllSameHeights = startTopHeight === startBottomHeight;
  64. let index = 1;
  65. for (let i = 1; i < length; ++i) {
  66. const v1 = positions[i];
  67. const c1 = ellipsoid.cartesianToCartographic(v1, scratchCartographic2);
  68. if (hasTopHeights) {
  69. c1.height = topHeights[i];
  70. }
  71. hasAllSameHeights = hasAllSameHeights && c1.height === 0;
  72. if (!latLonEquals(c0, c1)) {
  73. cleanedPositions[index] = v1; // Shallow copy!
  74. cleanedTopHeights[index] = c1.height;
  75. if (hasBottomHeights) {
  76. cleanedBottomHeights[index] = bottomHeights[i];
  77. } else {
  78. cleanedBottomHeights[index] = 0.0;
  79. }
  80. hasAllSameHeights =
  81. hasAllSameHeights &&
  82. cleanedTopHeights[index] === cleanedBottomHeights[index];
  83. Matrix2.Cartographic.clone(c1, c0);
  84. ++index;
  85. } else if (c0.height < c1.height) {
  86. // two adjacent positions are the same, so use whichever has the greater height
  87. cleanedTopHeights[index - 1] = c1.height;
  88. }
  89. }
  90. if (hasAllSameHeights || index < 2) {
  91. return;
  92. }
  93. cleanedPositions.length = index;
  94. cleanedTopHeights.length = index;
  95. cleanedBottomHeights.length = index;
  96. return {
  97. positions: cleanedPositions,
  98. topHeights: cleanedTopHeights,
  99. bottomHeights: cleanedBottomHeights,
  100. };
  101. }
  102. const positionsArrayScratch = new Array(2);
  103. const heightsArrayScratch = new Array(2);
  104. const generateArcOptionsScratch = {
  105. positions: undefined,
  106. height: undefined,
  107. granularity: undefined,
  108. ellipsoid: undefined,
  109. };
  110. /**
  111. * @private
  112. */
  113. WallGeometryLibrary.computePositions = function (
  114. ellipsoid,
  115. wallPositions,
  116. maximumHeights,
  117. minimumHeights,
  118. granularity,
  119. duplicateCorners
  120. ) {
  121. const o = removeDuplicates(
  122. ellipsoid,
  123. wallPositions,
  124. maximumHeights,
  125. minimumHeights
  126. );
  127. if (!defaultValue.defined(o)) {
  128. return;
  129. }
  130. wallPositions = o.positions;
  131. maximumHeights = o.topHeights;
  132. minimumHeights = o.bottomHeights;
  133. const length = wallPositions.length;
  134. const numCorners = length - 2;
  135. let topPositions;
  136. let bottomPositions;
  137. const minDistance = ComponentDatatype.CesiumMath.chordLength(
  138. granularity,
  139. ellipsoid.maximumRadius
  140. );
  141. const generateArcOptions = generateArcOptionsScratch;
  142. generateArcOptions.minDistance = minDistance;
  143. generateArcOptions.ellipsoid = ellipsoid;
  144. if (duplicateCorners) {
  145. let count = 0;
  146. let i;
  147. for (i = 0; i < length - 1; i++) {
  148. count +=
  149. PolylinePipeline.PolylinePipeline.numberOfPoints(
  150. wallPositions[i],
  151. wallPositions[i + 1],
  152. minDistance
  153. ) + 1;
  154. }
  155. topPositions = new Float64Array(count * 3);
  156. bottomPositions = new Float64Array(count * 3);
  157. const generateArcPositions = positionsArrayScratch;
  158. const generateArcHeights = heightsArrayScratch;
  159. generateArcOptions.positions = generateArcPositions;
  160. generateArcOptions.height = generateArcHeights;
  161. let offset = 0;
  162. for (i = 0; i < length - 1; i++) {
  163. generateArcPositions[0] = wallPositions[i];
  164. generateArcPositions[1] = wallPositions[i + 1];
  165. generateArcHeights[0] = maximumHeights[i];
  166. generateArcHeights[1] = maximumHeights[i + 1];
  167. const pos = PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions);
  168. topPositions.set(pos, offset);
  169. generateArcHeights[0] = minimumHeights[i];
  170. generateArcHeights[1] = minimumHeights[i + 1];
  171. bottomPositions.set(
  172. PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions),
  173. offset
  174. );
  175. offset += pos.length;
  176. }
  177. } else {
  178. generateArcOptions.positions = wallPositions;
  179. generateArcOptions.height = maximumHeights;
  180. topPositions = new Float64Array(
  181. PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions)
  182. );
  183. generateArcOptions.height = minimumHeights;
  184. bottomPositions = new Float64Array(
  185. PolylinePipeline.PolylinePipeline.generateArc(generateArcOptions)
  186. );
  187. }
  188. return {
  189. bottomPositions: bottomPositions,
  190. topPositions: topPositions,
  191. numCorners: numCorners,
  192. };
  193. };
  194. exports.WallGeometryLibrary = WallGeometryLibrary;
  195. }));
  196. //# sourceMappingURL=WallGeometryLibrary-3933dbde.js.map