RectangleGeometryLibrary-36556359.js 8.2 KB

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