EllipseOutlineGeometry-e0a3b205.js 19 KB

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