EllipseOutlineGeometry-6390e496.js 17 KB

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