EllipseOutlineGeometry-ca2110e2.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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', './Transforms-273eeb44', './Matrix2-9e1c22e2', './ComponentDatatype-4eeb6d9b', './defaultValue-97284df2', './RuntimeError-4f8ec8a2', './EllipseGeometryLibrary-dac95924', './GeometryAttribute-9be2d2e5', './GeometryAttributes-734a3446', './GeometryOffsetAttribute-59b14f45', './IndexDatatype-f228f5fd'], (function (exports, Transforms, Matrix2, ComponentDatatype, defaultValue, RuntimeError, EllipseGeometryLibrary, GeometryAttribute, GeometryAttributes, GeometryOffsetAttribute, IndexDatatype) { 'use strict';
  26. const scratchCartesian1 = new Matrix2.Cartesian3();
  27. let boundingSphereCenter = new Matrix2.Cartesian3();
  28. function computeEllipse(options) {
  29. const center = options.center;
  30. boundingSphereCenter = Matrix2.Cartesian3.multiplyByScalar(
  31. options.ellipsoid.geodeticSurfaceNormal(center, boundingSphereCenter),
  32. options.height,
  33. boundingSphereCenter
  34. );
  35. boundingSphereCenter = Matrix2.Cartesian3.add(
  36. center,
  37. boundingSphereCenter,
  38. boundingSphereCenter
  39. );
  40. const boundingSphere = new Transforms.BoundingSphere(
  41. boundingSphereCenter,
  42. options.semiMajorAxis
  43. );
  44. const positions = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  45. options,
  46. false,
  47. true
  48. ).outerPositions;
  49. const attributes = new GeometryAttributes.GeometryAttributes({
  50. position: new GeometryAttribute.GeometryAttribute({
  51. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  52. componentsPerAttribute: 3,
  53. values: EllipseGeometryLibrary.EllipseGeometryLibrary.raisePositionsToHeight(
  54. positions,
  55. options,
  56. false
  57. ),
  58. }),
  59. });
  60. const length = positions.length / 3;
  61. const indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 2);
  62. let index = 0;
  63. for (let i = 0; i < length; ++i) {
  64. indices[index++] = i;
  65. indices[index++] = (i + 1) % length;
  66. }
  67. return {
  68. boundingSphere: boundingSphere,
  69. attributes: attributes,
  70. indices: indices,
  71. };
  72. }
  73. const topBoundingSphere = new Transforms.BoundingSphere();
  74. const bottomBoundingSphere = new Transforms.BoundingSphere();
  75. function computeExtrudedEllipse(options) {
  76. const center = options.center;
  77. const ellipsoid = options.ellipsoid;
  78. const semiMajorAxis = options.semiMajorAxis;
  79. let scaledNormal = Matrix2.Cartesian3.multiplyByScalar(
  80. ellipsoid.geodeticSurfaceNormal(center, scratchCartesian1),
  81. options.height,
  82. scratchCartesian1
  83. );
  84. topBoundingSphere.center = Matrix2.Cartesian3.add(
  85. center,
  86. scaledNormal,
  87. topBoundingSphere.center
  88. );
  89. topBoundingSphere.radius = semiMajorAxis;
  90. scaledNormal = Matrix2.Cartesian3.multiplyByScalar(
  91. ellipsoid.geodeticSurfaceNormal(center, scaledNormal),
  92. options.extrudedHeight,
  93. scaledNormal
  94. );
  95. bottomBoundingSphere.center = Matrix2.Cartesian3.add(
  96. center,
  97. scaledNormal,
  98. bottomBoundingSphere.center
  99. );
  100. bottomBoundingSphere.radius = semiMajorAxis;
  101. let positions = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  102. options,
  103. false,
  104. true
  105. ).outerPositions;
  106. const attributes = new GeometryAttributes.GeometryAttributes({
  107. position: new GeometryAttribute.GeometryAttribute({
  108. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  109. componentsPerAttribute: 3,
  110. values: EllipseGeometryLibrary.EllipseGeometryLibrary.raisePositionsToHeight(
  111. positions,
  112. options,
  113. true
  114. ),
  115. }),
  116. });
  117. positions = attributes.position.values;
  118. const boundingSphere = Transforms.BoundingSphere.union(
  119. topBoundingSphere,
  120. bottomBoundingSphere
  121. );
  122. let length = positions.length / 3;
  123. if (defaultValue.defined(options.offsetAttribute)) {
  124. let applyOffset = new Uint8Array(length);
  125. if (options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  126. applyOffset = applyOffset.fill(1, 0, length / 2);
  127. } else {
  128. const offsetValue =
  129. options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  130. applyOffset = applyOffset.fill(offsetValue);
  131. }
  132. attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  133. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  134. componentsPerAttribute: 1,
  135. values: applyOffset,
  136. });
  137. }
  138. let numberOfVerticalLines = defaultValue.defaultValue(options.numberOfVerticalLines, 16);
  139. numberOfVerticalLines = ComponentDatatype.CesiumMath.clamp(
  140. numberOfVerticalLines,
  141. 0,
  142. length / 2
  143. );
  144. const indices = IndexDatatype.IndexDatatype.createTypedArray(
  145. length,
  146. length * 2 + numberOfVerticalLines * 2
  147. );
  148. length /= 2;
  149. let index = 0;
  150. let i;
  151. for (i = 0; i < length; ++i) {
  152. indices[index++] = i;
  153. indices[index++] = (i + 1) % length;
  154. indices[index++] = i + length;
  155. indices[index++] = ((i + 1) % length) + length;
  156. }
  157. let numSide;
  158. if (numberOfVerticalLines > 0) {
  159. const numSideLines = Math.min(numberOfVerticalLines, length);
  160. numSide = Math.round(length / numSideLines);
  161. const maxI = Math.min(numSide * numberOfVerticalLines, length);
  162. for (i = 0; i < maxI; i += numSide) {
  163. indices[index++] = i;
  164. indices[index++] = i + length;
  165. }
  166. }
  167. return {
  168. boundingSphere: boundingSphere,
  169. attributes: attributes,
  170. indices: indices,
  171. };
  172. }
  173. /**
  174. * A description of the outline of an ellipse on an ellipsoid.
  175. *
  176. * @alias EllipseOutlineGeometry
  177. * @constructor
  178. *
  179. * @param {Object} options Object with the following properties:
  180. * @param {Cartesian3} options.center The ellipse's center point in the fixed frame.
  181. * @param {Number} options.semiMajorAxis The length of the ellipse's semi-major axis in meters.
  182. * @param {Number} options.semiMinorAxis The length of the ellipse's semi-minor axis in meters.
  183. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the ellipse will be on.
  184. * @param {Number} [options.height=0.0] The distance in meters between the ellipse and the ellipsoid surface.
  185. * @param {Number} [options.extrudedHeight] The distance in meters between the ellipse's extruded face and the ellipsoid surface.
  186. * @param {Number} [options.rotation=0.0] The angle from north (counter-clockwise) in radians.
  187. * @param {Number} [options.granularity=0.02] The angular distance between points on the ellipse in radians.
  188. * @param {Number} [options.numberOfVerticalLines=16] Number of lines to draw between the top and bottom surface of an extruded ellipse.
  189. *
  190. * @exception {DeveloperError} semiMajorAxis and semiMinorAxis must be greater than zero.
  191. * @exception {DeveloperError} semiMajorAxis must be greater than or equal to the semiMinorAxis.
  192. * @exception {DeveloperError} granularity must be greater than zero.
  193. *
  194. * @see EllipseOutlineGeometry.createGeometry
  195. *
  196. * @example
  197. * const ellipse = new Cesium.EllipseOutlineGeometry({
  198. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  199. * semiMajorAxis : 500000.0,
  200. * semiMinorAxis : 300000.0,
  201. * rotation : Cesium.Math.toRadians(60.0)
  202. * });
  203. * const geometry = Cesium.EllipseOutlineGeometry.createGeometry(ellipse);
  204. */
  205. function EllipseOutlineGeometry(options) {
  206. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  207. const center = options.center;
  208. const ellipsoid = defaultValue.defaultValue(options.ellipsoid, Matrix2.Ellipsoid.WGS84);
  209. const semiMajorAxis = options.semiMajorAxis;
  210. const semiMinorAxis = options.semiMinorAxis;
  211. const granularity = defaultValue.defaultValue(
  212. options.granularity,
  213. ComponentDatatype.CesiumMath.RADIANS_PER_DEGREE
  214. );
  215. //>>includeStart('debug', pragmas.debug);
  216. if (!defaultValue.defined(center)) {
  217. throw new RuntimeError.DeveloperError("center is required.");
  218. }
  219. if (!defaultValue.defined(semiMajorAxis)) {
  220. throw new RuntimeError.DeveloperError("semiMajorAxis is required.");
  221. }
  222. if (!defaultValue.defined(semiMinorAxis)) {
  223. throw new RuntimeError.DeveloperError("semiMinorAxis is required.");
  224. }
  225. if (semiMajorAxis < semiMinorAxis) {
  226. throw new RuntimeError.DeveloperError(
  227. "semiMajorAxis must be greater than or equal to the semiMinorAxis."
  228. );
  229. }
  230. if (granularity <= 0.0) {
  231. throw new RuntimeError.DeveloperError("granularity must be greater than zero.");
  232. }
  233. //>>includeEnd('debug');
  234. const height = defaultValue.defaultValue(options.height, 0.0);
  235. const extrudedHeight = defaultValue.defaultValue(options.extrudedHeight, height);
  236. this._center = Matrix2.Cartesian3.clone(center);
  237. this._semiMajorAxis = semiMajorAxis;
  238. this._semiMinorAxis = semiMinorAxis;
  239. this._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid);
  240. this._rotation = defaultValue.defaultValue(options.rotation, 0.0);
  241. this._height = Math.max(extrudedHeight, height);
  242. this._granularity = granularity;
  243. this._extrudedHeight = Math.min(extrudedHeight, height);
  244. this._numberOfVerticalLines = Math.max(
  245. defaultValue.defaultValue(options.numberOfVerticalLines, 16),
  246. 0
  247. );
  248. this._offsetAttribute = options.offsetAttribute;
  249. this._workerName = "createEllipseOutlineGeometry";
  250. }
  251. /**
  252. * The number of elements used to pack the object into an array.
  253. * @type {Number}
  254. */
  255. EllipseOutlineGeometry.packedLength =
  256. Matrix2.Cartesian3.packedLength + Matrix2.Ellipsoid.packedLength + 8;
  257. /**
  258. * Stores the provided instance into the provided array.
  259. *
  260. * @param {EllipseOutlineGeometry} value The value to pack.
  261. * @param {Number[]} array The array to pack into.
  262. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  263. *
  264. * @returns {Number[]} The array that was packed into
  265. */
  266. EllipseOutlineGeometry.pack = function (value, array, startingIndex) {
  267. //>>includeStart('debug', pragmas.debug);
  268. if (!defaultValue.defined(value)) {
  269. throw new RuntimeError.DeveloperError("value is required");
  270. }
  271. if (!defaultValue.defined(array)) {
  272. throw new RuntimeError.DeveloperError("array is required");
  273. }
  274. //>>includeEnd('debug');
  275. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  276. Matrix2.Cartesian3.pack(value._center, array, startingIndex);
  277. startingIndex += Matrix2.Cartesian3.packedLength;
  278. Matrix2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  279. startingIndex += Matrix2.Ellipsoid.packedLength;
  280. array[startingIndex++] = value._semiMajorAxis;
  281. array[startingIndex++] = value._semiMinorAxis;
  282. array[startingIndex++] = value._rotation;
  283. array[startingIndex++] = value._height;
  284. array[startingIndex++] = value._granularity;
  285. array[startingIndex++] = value._extrudedHeight;
  286. array[startingIndex++] = value._numberOfVerticalLines;
  287. array[startingIndex] = defaultValue.defaultValue(value._offsetAttribute, -1);
  288. return array;
  289. };
  290. const scratchCenter = new Matrix2.Cartesian3();
  291. const scratchEllipsoid = new Matrix2.Ellipsoid();
  292. const scratchOptions = {
  293. center: scratchCenter,
  294. ellipsoid: scratchEllipsoid,
  295. semiMajorAxis: undefined,
  296. semiMinorAxis: undefined,
  297. rotation: undefined,
  298. height: undefined,
  299. granularity: undefined,
  300. extrudedHeight: undefined,
  301. numberOfVerticalLines: undefined,
  302. offsetAttribute: undefined,
  303. };
  304. /**
  305. * Retrieves an instance from a packed array.
  306. *
  307. * @param {Number[]} array The packed array.
  308. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  309. * @param {EllipseOutlineGeometry} [result] The object into which to store the result.
  310. * @returns {EllipseOutlineGeometry} The modified result parameter or a new EllipseOutlineGeometry instance if one was not provided.
  311. */
  312. EllipseOutlineGeometry.unpack = function (array, startingIndex, result) {
  313. //>>includeStart('debug', pragmas.debug);
  314. if (!defaultValue.defined(array)) {
  315. throw new RuntimeError.DeveloperError("array is required");
  316. }
  317. //>>includeEnd('debug');
  318. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  319. const center = Matrix2.Cartesian3.unpack(array, startingIndex, scratchCenter);
  320. startingIndex += Matrix2.Cartesian3.packedLength;
  321. const ellipsoid = Matrix2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  322. startingIndex += Matrix2.Ellipsoid.packedLength;
  323. const semiMajorAxis = array[startingIndex++];
  324. const semiMinorAxis = array[startingIndex++];
  325. const rotation = array[startingIndex++];
  326. const height = array[startingIndex++];
  327. const granularity = array[startingIndex++];
  328. const extrudedHeight = array[startingIndex++];
  329. const numberOfVerticalLines = array[startingIndex++];
  330. const offsetAttribute = array[startingIndex];
  331. if (!defaultValue.defined(result)) {
  332. scratchOptions.height = height;
  333. scratchOptions.extrudedHeight = extrudedHeight;
  334. scratchOptions.granularity = granularity;
  335. scratchOptions.rotation = rotation;
  336. scratchOptions.semiMajorAxis = semiMajorAxis;
  337. scratchOptions.semiMinorAxis = semiMinorAxis;
  338. scratchOptions.numberOfVerticalLines = numberOfVerticalLines;
  339. scratchOptions.offsetAttribute =
  340. offsetAttribute === -1 ? undefined : offsetAttribute;
  341. return new EllipseOutlineGeometry(scratchOptions);
  342. }
  343. result._center = Matrix2.Cartesian3.clone(center, result._center);
  344. result._ellipsoid = Matrix2.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  345. result._semiMajorAxis = semiMajorAxis;
  346. result._semiMinorAxis = semiMinorAxis;
  347. result._rotation = rotation;
  348. result._height = height;
  349. result._granularity = granularity;
  350. result._extrudedHeight = extrudedHeight;
  351. result._numberOfVerticalLines = numberOfVerticalLines;
  352. result._offsetAttribute =
  353. offsetAttribute === -1 ? undefined : offsetAttribute;
  354. return result;
  355. };
  356. /**
  357. * Computes the geometric representation of an outline of an ellipse on an ellipsoid, including its vertices, indices, and a bounding sphere.
  358. *
  359. * @param {EllipseOutlineGeometry} ellipseGeometry A description of the ellipse.
  360. * @returns {Geometry|undefined} The computed vertices and indices.
  361. */
  362. EllipseOutlineGeometry.createGeometry = function (ellipseGeometry) {
  363. if (
  364. ellipseGeometry._semiMajorAxis <= 0.0 ||
  365. ellipseGeometry._semiMinorAxis <= 0.0
  366. ) {
  367. return;
  368. }
  369. const height = ellipseGeometry._height;
  370. const extrudedHeight = ellipseGeometry._extrudedHeight;
  371. const extrude = !ComponentDatatype.CesiumMath.equalsEpsilon(
  372. height,
  373. extrudedHeight,
  374. 0,
  375. ComponentDatatype.CesiumMath.EPSILON2
  376. );
  377. ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(
  378. ellipseGeometry._center,
  379. ellipseGeometry._center
  380. );
  381. const options = {
  382. center: ellipseGeometry._center,
  383. semiMajorAxis: ellipseGeometry._semiMajorAxis,
  384. semiMinorAxis: ellipseGeometry._semiMinorAxis,
  385. ellipsoid: ellipseGeometry._ellipsoid,
  386. rotation: ellipseGeometry._rotation,
  387. height: height,
  388. granularity: ellipseGeometry._granularity,
  389. numberOfVerticalLines: ellipseGeometry._numberOfVerticalLines,
  390. };
  391. let geometry;
  392. if (extrude) {
  393. options.extrudedHeight = extrudedHeight;
  394. options.offsetAttribute = ellipseGeometry._offsetAttribute;
  395. geometry = computeExtrudedEllipse(options);
  396. } else {
  397. geometry = computeEllipse(options);
  398. if (defaultValue.defined(ellipseGeometry._offsetAttribute)) {
  399. const length = geometry.attributes.position.values.length;
  400. const offsetValue =
  401. ellipseGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE
  402. ? 0
  403. : 1;
  404. const applyOffset = new Uint8Array(length / 3).fill(offsetValue);
  405. geometry.attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  406. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  407. componentsPerAttribute: 1,
  408. values: applyOffset,
  409. });
  410. }
  411. }
  412. return new GeometryAttribute.Geometry({
  413. attributes: geometry.attributes,
  414. indices: geometry.indices,
  415. primitiveType: GeometryAttribute.PrimitiveType.LINES,
  416. boundingSphere: geometry.boundingSphere,
  417. offsetAttribute: ellipseGeometry._offsetAttribute,
  418. });
  419. };
  420. exports.EllipseOutlineGeometry = EllipseOutlineGeometry;
  421. }));
  422. //# sourceMappingURL=EllipseOutlineGeometry-ca2110e2.js.map