RectangleGeometryLibrary-a23c9ebe.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. define(['exports', './Matrix3-41c58dde', './defaultValue-fe22d8c0', './Check-6ede7e26', './Transforms-bc45e707', './Math-0a2ac845', './Matrix2-e1298525'], (function (exports, Matrix3, defaultValue, Check, Transforms, Math$1, Matrix2) { 'use strict';
  2. const cos = Math.cos;
  3. const sin = Math.sin;
  4. const sqrt = Math.sqrt;
  5. /**
  6. * @private
  7. */
  8. const RectangleGeometryLibrary = {};
  9. /**
  10. * @private
  11. */
  12. RectangleGeometryLibrary.computePosition = function (
  13. computedOptions,
  14. ellipsoid,
  15. computeST,
  16. row,
  17. col,
  18. position,
  19. st
  20. ) {
  21. const radiiSquared = ellipsoid.radiiSquared;
  22. const nwCorner = computedOptions.nwCorner;
  23. const rectangle = computedOptions.boundingRectangle;
  24. let stLatitude =
  25. nwCorner.latitude -
  26. computedOptions.granYCos * row +
  27. col * computedOptions.granXSin;
  28. const cosLatitude = cos(stLatitude);
  29. const nZ = sin(stLatitude);
  30. const kZ = radiiSquared.z * nZ;
  31. let stLongitude =
  32. nwCorner.longitude +
  33. row * computedOptions.granYSin +
  34. col * computedOptions.granXCos;
  35. const nX = cosLatitude * cos(stLongitude);
  36. const nY = cosLatitude * sin(stLongitude);
  37. const kX = radiiSquared.x * nX;
  38. const kY = radiiSquared.y * nY;
  39. const gamma = sqrt(kX * nX + kY * nY + kZ * nZ);
  40. position.x = kX / gamma;
  41. position.y = kY / gamma;
  42. position.z = kZ / gamma;
  43. if (computeST) {
  44. const stNwCorner = computedOptions.stNwCorner;
  45. if (defaultValue.defined(stNwCorner)) {
  46. stLatitude =
  47. stNwCorner.latitude -
  48. computedOptions.stGranYCos * row +
  49. col * computedOptions.stGranXSin;
  50. stLongitude =
  51. stNwCorner.longitude +
  52. row * computedOptions.stGranYSin +
  53. col * computedOptions.stGranXCos;
  54. st.x = (stLongitude - computedOptions.stWest) * computedOptions.lonScalar;
  55. st.y = (stLatitude - computedOptions.stSouth) * computedOptions.latScalar;
  56. } else {
  57. st.x = (stLongitude - rectangle.west) * computedOptions.lonScalar;
  58. st.y = (stLatitude - rectangle.south) * computedOptions.latScalar;
  59. }
  60. }
  61. };
  62. const rotationMatrixScratch = new Matrix2.Matrix2();
  63. let nwCartesian = new Matrix3.Cartesian3();
  64. const centerScratch = new Matrix3.Cartographic();
  65. let centerCartesian = new Matrix3.Cartesian3();
  66. const proj = new Transforms.GeographicProjection();
  67. function getRotationOptions(
  68. nwCorner,
  69. rotation,
  70. granularityX,
  71. granularityY,
  72. center,
  73. width,
  74. height
  75. ) {
  76. const cosRotation = Math.cos(rotation);
  77. const granYCos = granularityY * cosRotation;
  78. const granXCos = granularityX * cosRotation;
  79. const sinRotation = Math.sin(rotation);
  80. const granYSin = granularityY * sinRotation;
  81. const granXSin = granularityX * sinRotation;
  82. nwCartesian = proj.project(nwCorner, nwCartesian);
  83. nwCartesian = Matrix3.Cartesian3.subtract(nwCartesian, centerCartesian, nwCartesian);
  84. const rotationMatrix = Matrix2.Matrix2.fromRotation(rotation, rotationMatrixScratch);
  85. nwCartesian = Matrix2.Matrix2.multiplyByVector(
  86. rotationMatrix,
  87. nwCartesian,
  88. nwCartesian
  89. );
  90. nwCartesian = Matrix3.Cartesian3.add(nwCartesian, centerCartesian, nwCartesian);
  91. nwCorner = proj.unproject(nwCartesian, nwCorner);
  92. width -= 1;
  93. height -= 1;
  94. const latitude = nwCorner.latitude;
  95. const latitude0 = latitude + width * granXSin;
  96. const latitude1 = latitude - granYCos * height;
  97. const latitude2 = latitude - granYCos * height + width * granXSin;
  98. const north = Math.max(latitude, latitude0, latitude1, latitude2);
  99. const south = Math.min(latitude, latitude0, latitude1, latitude2);
  100. const longitude = nwCorner.longitude;
  101. const longitude0 = longitude + width * granXCos;
  102. const longitude1 = longitude + height * granYSin;
  103. const longitude2 = longitude + height * granYSin + width * granXCos;
  104. const east = Math.max(longitude, longitude0, longitude1, longitude2);
  105. const west = Math.min(longitude, longitude0, longitude1, longitude2);
  106. return {
  107. north: north,
  108. south: south,
  109. east: east,
  110. west: west,
  111. granYCos: granYCos,
  112. granYSin: granYSin,
  113. granXCos: granXCos,
  114. granXSin: granXSin,
  115. nwCorner: nwCorner,
  116. };
  117. }
  118. /**
  119. * @private
  120. */
  121. RectangleGeometryLibrary.computeOptions = function (
  122. rectangle,
  123. granularity,
  124. rotation,
  125. stRotation,
  126. boundingRectangleScratch,
  127. nwCornerResult,
  128. stNwCornerResult
  129. ) {
  130. let east = rectangle.east;
  131. let west = rectangle.west;
  132. let north = rectangle.north;
  133. let south = rectangle.south;
  134. let northCap = false;
  135. let southCap = false;
  136. if (north === Math$1.CesiumMath.PI_OVER_TWO) {
  137. northCap = true;
  138. }
  139. if (south === -Math$1.CesiumMath.PI_OVER_TWO) {
  140. southCap = true;
  141. }
  142. let dx;
  143. const dy = north - south;
  144. if (west > east) {
  145. dx = Math$1.CesiumMath.TWO_PI - west + east;
  146. } else {
  147. dx = east - west;
  148. }
  149. const width = Math.ceil(dx / granularity) + 1;
  150. const height = Math.ceil(dy / granularity) + 1;
  151. const granularityX = dx / (width - 1);
  152. const granularityY = dy / (height - 1);
  153. const nwCorner = Matrix2.Rectangle.northwest(rectangle, nwCornerResult);
  154. const center = Matrix2.Rectangle.center(rectangle, centerScratch);
  155. if (rotation !== 0 || stRotation !== 0) {
  156. if (center.longitude < nwCorner.longitude) {
  157. center.longitude += Math$1.CesiumMath.TWO_PI;
  158. }
  159. centerCartesian = proj.project(center, centerCartesian);
  160. }
  161. const granYCos = granularityY;
  162. const granXCos = granularityX;
  163. const granYSin = 0.0;
  164. const granXSin = 0.0;
  165. const boundingRectangle = Matrix2.Rectangle.clone(
  166. rectangle,
  167. boundingRectangleScratch
  168. );
  169. const computedOptions = {
  170. granYCos: granYCos,
  171. granYSin: granYSin,
  172. granXCos: granXCos,
  173. granXSin: granXSin,
  174. nwCorner: nwCorner,
  175. boundingRectangle: boundingRectangle,
  176. width: width,
  177. height: height,
  178. northCap: northCap,
  179. southCap: southCap,
  180. };
  181. if (rotation !== 0) {
  182. const rotationOptions = getRotationOptions(
  183. nwCorner,
  184. rotation,
  185. granularityX,
  186. granularityY,
  187. center,
  188. width,
  189. height
  190. );
  191. north = rotationOptions.north;
  192. south = rotationOptions.south;
  193. east = rotationOptions.east;
  194. west = rotationOptions.west;
  195. //>>includeStart('debug', pragmas.debug);
  196. if (
  197. north < -Math$1.CesiumMath.PI_OVER_TWO ||
  198. north > Math$1.CesiumMath.PI_OVER_TWO ||
  199. south < -Math$1.CesiumMath.PI_OVER_TWO ||
  200. south > Math$1.CesiumMath.PI_OVER_TWO
  201. ) {
  202. throw new Check.DeveloperError(
  203. "Rotated rectangle is invalid. It crosses over either the north or south pole."
  204. );
  205. }
  206. //>>includeEnd('debug')
  207. computedOptions.granYCos = rotationOptions.granYCos;
  208. computedOptions.granYSin = rotationOptions.granYSin;
  209. computedOptions.granXCos = rotationOptions.granXCos;
  210. computedOptions.granXSin = rotationOptions.granXSin;
  211. boundingRectangle.north = north;
  212. boundingRectangle.south = south;
  213. boundingRectangle.east = east;
  214. boundingRectangle.west = west;
  215. }
  216. if (stRotation !== 0) {
  217. rotation = rotation - stRotation;
  218. const stNwCorner = Matrix2.Rectangle.northwest(boundingRectangle, stNwCornerResult);
  219. const stRotationOptions = getRotationOptions(
  220. stNwCorner,
  221. rotation,
  222. granularityX,
  223. granularityY,
  224. center,
  225. width,
  226. height
  227. );
  228. computedOptions.stGranYCos = stRotationOptions.granYCos;
  229. computedOptions.stGranXCos = stRotationOptions.granXCos;
  230. computedOptions.stGranYSin = stRotationOptions.granYSin;
  231. computedOptions.stGranXSin = stRotationOptions.granXSin;
  232. computedOptions.stNwCorner = stNwCorner;
  233. computedOptions.stWest = stRotationOptions.west;
  234. computedOptions.stSouth = stRotationOptions.south;
  235. }
  236. return computedOptions;
  237. };
  238. var RectangleGeometryLibrary$1 = RectangleGeometryLibrary;
  239. exports.RectangleGeometryLibrary = RectangleGeometryLibrary$1;
  240. }));