RectangleGeometryLibrary-93ca0888.js 9.0 KB

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