EllipseOutlineGeometry-edd2c2e0.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /* This file is automatically rebuilt by the Cesium build process. */
  2. define(['exports', './when-e6985d2a', './Check-24cae389', './Math-392d0035', './Cartesian2-a5d6dde9', './Transforms-81680c41', './ComponentDatatype-cb08e294', './GeometryAttribute-6d403cd9', './GeometryAttributes-d6ea8c2b', './IndexDatatype-1be7d1f8', './GeometryOffsetAttribute-9c46b133', './EllipseGeometryLibrary-5e06d338'], function (exports, when, Check, _Math, Cartesian2, Transforms, ComponentDatatype, GeometryAttribute, GeometryAttributes, IndexDatatype, GeometryOffsetAttribute, EllipseGeometryLibrary) { 'use strict';
  3. var scratchCartesian1 = new Cartesian2.Cartesian3();
  4. var boundingSphereCenter = new Cartesian2.Cartesian3();
  5. function computeEllipse(options) {
  6. var center = options.center;
  7. boundingSphereCenter = Cartesian2.Cartesian3.multiplyByScalar(
  8. options.ellipsoid.geodeticSurfaceNormal(center, boundingSphereCenter),
  9. options.height,
  10. boundingSphereCenter
  11. );
  12. boundingSphereCenter = Cartesian2.Cartesian3.add(
  13. center,
  14. boundingSphereCenter,
  15. boundingSphereCenter
  16. );
  17. var boundingSphere = new Transforms.BoundingSphere(
  18. boundingSphereCenter,
  19. options.semiMajorAxis
  20. );
  21. var positions = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  22. options,
  23. false,
  24. true
  25. ).outerPositions;
  26. var 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. var length = positions.length / 3;
  38. var indices = IndexDatatype.IndexDatatype.createTypedArray(length, length * 2);
  39. var index = 0;
  40. for (var 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. var topBoundingSphere = new Transforms.BoundingSphere();
  51. var bottomBoundingSphere = new Transforms.BoundingSphere();
  52. function computeExtrudedEllipse(options) {
  53. var center = options.center;
  54. var ellipsoid = options.ellipsoid;
  55. var semiMajorAxis = options.semiMajorAxis;
  56. var scaledNormal = Cartesian2.Cartesian3.multiplyByScalar(
  57. ellipsoid.geodeticSurfaceNormal(center, scratchCartesian1),
  58. options.height,
  59. scratchCartesian1
  60. );
  61. topBoundingSphere.center = Cartesian2.Cartesian3.add(
  62. center,
  63. scaledNormal,
  64. topBoundingSphere.center
  65. );
  66. topBoundingSphere.radius = semiMajorAxis;
  67. scaledNormal = Cartesian2.Cartesian3.multiplyByScalar(
  68. ellipsoid.geodeticSurfaceNormal(center, scaledNormal),
  69. options.extrudedHeight,
  70. scaledNormal
  71. );
  72. bottomBoundingSphere.center = Cartesian2.Cartesian3.add(
  73. center,
  74. scaledNormal,
  75. bottomBoundingSphere.center
  76. );
  77. bottomBoundingSphere.radius = semiMajorAxis;
  78. var positions = EllipseGeometryLibrary.EllipseGeometryLibrary.computeEllipsePositions(
  79. options,
  80. false,
  81. true
  82. ).outerPositions;
  83. var 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. var boundingSphere = Transforms.BoundingSphere.union(
  96. topBoundingSphere,
  97. bottomBoundingSphere
  98. );
  99. var length = positions.length / 3;
  100. if (when.defined(options.offsetAttribute)) {
  101. var applyOffset = new Uint8Array(length);
  102. if (options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP) {
  103. applyOffset = GeometryOffsetAttribute.arrayFill(applyOffset, 1, 0, length / 2);
  104. } else {
  105. var 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. var numberOfVerticalLines = when.defaultValue(options.numberOfVerticalLines, 16);
  116. numberOfVerticalLines = _Math.CesiumMath.clamp(
  117. numberOfVerticalLines,
  118. 0,
  119. length / 2
  120. );
  121. var indices = IndexDatatype.IndexDatatype.createTypedArray(
  122. length,
  123. length * 2 + numberOfVerticalLines * 2
  124. );
  125. length /= 2;
  126. var index = 0;
  127. var 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. var numSide;
  135. if (numberOfVerticalLines > 0) {
  136. var numSideLines = Math.min(numberOfVerticalLines, length);
  137. numSide = Math.round(length / numSideLines);
  138. var 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. * var 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. * var geometry = Cesium.EllipseOutlineGeometry.createGeometry(ellipse);
  181. */
  182. function EllipseOutlineGeometry(options) {
  183. options = when.defaultValue(options, when.defaultValue.EMPTY_OBJECT);
  184. var center = options.center;
  185. var ellipsoid = when.defaultValue(options.ellipsoid, Cartesian2.Ellipsoid.WGS84);
  186. var semiMajorAxis = options.semiMajorAxis;
  187. var semiMinorAxis = options.semiMinorAxis;
  188. var granularity = when.defaultValue(
  189. options.granularity,
  190. _Math.CesiumMath.RADIANS_PER_DEGREE
  191. );
  192. //>>includeStart('debug', pragmas.debug);
  193. if (!when.defined(center)) {
  194. throw new Check.DeveloperError("center is required.");
  195. }
  196. if (!when.defined(semiMajorAxis)) {
  197. throw new Check.DeveloperError("semiMajorAxis is required.");
  198. }
  199. if (!when.defined(semiMinorAxis)) {
  200. throw new Check.DeveloperError("semiMinorAxis is required.");
  201. }
  202. if (semiMajorAxis < semiMinorAxis) {
  203. throw new Check.DeveloperError(
  204. "semiMajorAxis must be greater than or equal to the semiMinorAxis."
  205. );
  206. }
  207. if (granularity <= 0.0) {
  208. throw new Check.DeveloperError("granularity must be greater than zero.");
  209. }
  210. //>>includeEnd('debug');
  211. var height = when.defaultValue(options.height, 0.0);
  212. var extrudedHeight = when.defaultValue(options.extrudedHeight, height);
  213. this._center = Cartesian2.Cartesian3.clone(center);
  214. this._semiMajorAxis = semiMajorAxis;
  215. this._semiMinorAxis = semiMinorAxis;
  216. this._ellipsoid = Cartesian2.Ellipsoid.clone(ellipsoid);
  217. this._rotation = when.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. when.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. Cartesian2.Cartesian3.packedLength + Cartesian2.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 (!when.defined(value)) {
  246. throw new Check.DeveloperError("value is required");
  247. }
  248. if (!when.defined(array)) {
  249. throw new Check.DeveloperError("array is required");
  250. }
  251. //>>includeEnd('debug');
  252. startingIndex = when.defaultValue(startingIndex, 0);
  253. Cartesian2.Cartesian3.pack(value._center, array, startingIndex);
  254. startingIndex += Cartesian2.Cartesian3.packedLength;
  255. Cartesian2.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  256. startingIndex += Cartesian2.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] = when.defaultValue(value._offsetAttribute, -1);
  265. return array;
  266. };
  267. var scratchCenter = new Cartesian2.Cartesian3();
  268. var scratchEllipsoid = new Cartesian2.Ellipsoid();
  269. var 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 (!when.defined(array)) {
  292. throw new Check.DeveloperError("array is required");
  293. }
  294. //>>includeEnd('debug');
  295. startingIndex = when.defaultValue(startingIndex, 0);
  296. var center = Cartesian2.Cartesian3.unpack(array, startingIndex, scratchCenter);
  297. startingIndex += Cartesian2.Cartesian3.packedLength;
  298. var ellipsoid = Cartesian2.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  299. startingIndex += Cartesian2.Ellipsoid.packedLength;
  300. var semiMajorAxis = array[startingIndex++];
  301. var semiMinorAxis = array[startingIndex++];
  302. var rotation = array[startingIndex++];
  303. var height = array[startingIndex++];
  304. var granularity = array[startingIndex++];
  305. var extrudedHeight = array[startingIndex++];
  306. var numberOfVerticalLines = array[startingIndex++];
  307. var offsetAttribute = array[startingIndex];
  308. if (!when.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 = Cartesian2.Cartesian3.clone(center, result._center);
  321. result._ellipsoid = Cartesian2.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. var height = ellipseGeometry._height;
  347. var extrudedHeight = ellipseGeometry._extrudedHeight;
  348. var extrude = !_Math.CesiumMath.equalsEpsilon(
  349. height,
  350. extrudedHeight,
  351. 0,
  352. _Math.CesiumMath.EPSILON2
  353. );
  354. ellipseGeometry._center = ellipseGeometry._ellipsoid.scaleToGeodeticSurface(
  355. ellipseGeometry._center,
  356. ellipseGeometry._center
  357. );
  358. var 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. var 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 (when.defined(ellipseGeometry._offsetAttribute)) {
  376. var length = geometry.attributes.position.values.length;
  377. var applyOffset = new Uint8Array(length / 3);
  378. var 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. });