CircleOutlineGeometry.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import Cartesian3 from './Cartesian3.js';
  2. import Check from './Check.js';
  3. import defaultValue from './defaultValue.js';
  4. import defined from './defined.js';
  5. import EllipseOutlineGeometry from './EllipseOutlineGeometry.js';
  6. import Ellipsoid from './Ellipsoid.js';
  7. /**
  8. * A description of the outline of a circle on the ellipsoid.
  9. *
  10. * @alias CircleOutlineGeometry
  11. * @constructor
  12. *
  13. * @param {Object} options Object with the following properties:
  14. * @param {Cartesian3} options.center The circle's center point in the fixed frame.
  15. * @param {Number} options.radius The radius in meters.
  16. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the circle will be on.
  17. * @param {Number} [options.height=0.0] The distance in meters between the circle and the ellipsoid surface.
  18. * @param {Number} [options.granularity=0.02] The angular distance between points on the circle in radians.
  19. * @param {Number} [options.extrudedHeight=0.0] The distance in meters between the circle's extruded face and the ellipsoid surface.
  20. * @param {Number} [options.numberOfVerticalLines=16] Number of lines to draw between the top and bottom of an extruded circle.
  21. *
  22. * @exception {DeveloperError} radius must be greater than zero.
  23. * @exception {DeveloperError} granularity must be greater than zero.
  24. *
  25. * @see CircleOutlineGeometry.createGeometry
  26. * @see Packable
  27. *
  28. * @example
  29. * // Create a circle.
  30. * var circle = new Cesium.CircleOutlineGeometry({
  31. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  32. * radius : 100000.0
  33. * });
  34. * var geometry = Cesium.CircleOutlineGeometry.createGeometry(circle);
  35. */
  36. function CircleOutlineGeometry(options) {
  37. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  38. var radius = options.radius;
  39. //>>includeStart('debug', pragmas.debug);
  40. Check.typeOf.number('radius', radius);
  41. //>>includeEnd('debug');
  42. var ellipseGeometryOptions = {
  43. center : options.center,
  44. semiMajorAxis : radius,
  45. semiMinorAxis : radius,
  46. ellipsoid : options.ellipsoid,
  47. height : options.height,
  48. extrudedHeight : options.extrudedHeight,
  49. granularity : options.granularity,
  50. numberOfVerticalLines : options.numberOfVerticalLines
  51. };
  52. this._ellipseGeometry = new EllipseOutlineGeometry(ellipseGeometryOptions);
  53. this._workerName = 'createCircleOutlineGeometry';
  54. }
  55. /**
  56. * The number of elements used to pack the object into an array.
  57. * @type {Number}
  58. */
  59. CircleOutlineGeometry.packedLength = EllipseOutlineGeometry.packedLength;
  60. /**
  61. * Stores the provided instance into the provided array.
  62. *
  63. * @param {CircleOutlineGeometry} value The value to pack.
  64. * @param {Number[]} array The array to pack into.
  65. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  66. *
  67. * @returns {Number[]} The array that was packed into
  68. */
  69. CircleOutlineGeometry.pack = function(value, array, startingIndex) {
  70. //>>includeStart('debug', pragmas.debug);
  71. Check.typeOf.object('value', value);
  72. //>>includeEnd('debug');
  73. return EllipseOutlineGeometry.pack(value._ellipseGeometry, array, startingIndex);
  74. };
  75. var scratchEllipseGeometry = new EllipseOutlineGeometry({
  76. center : new Cartesian3(),
  77. semiMajorAxis : 1.0,
  78. semiMinorAxis : 1.0
  79. });
  80. var scratchOptions = {
  81. center : new Cartesian3(),
  82. radius : undefined,
  83. ellipsoid : Ellipsoid.clone(Ellipsoid.UNIT_SPHERE),
  84. height : undefined,
  85. extrudedHeight : undefined,
  86. granularity : undefined,
  87. numberOfVerticalLines : undefined,
  88. semiMajorAxis : undefined,
  89. semiMinorAxis : undefined
  90. };
  91. /**
  92. * Retrieves an instance from a packed array.
  93. *
  94. * @param {Number[]} array The packed array.
  95. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  96. * @param {CircleOutlineGeometry} [result] The object into which to store the result.
  97. * @returns {CircleOutlineGeometry} The modified result parameter or a new CircleOutlineGeometry instance if one was not provided.
  98. */
  99. CircleOutlineGeometry.unpack = function(array, startingIndex, result) {
  100. var ellipseGeometry = EllipseOutlineGeometry.unpack(array, startingIndex, scratchEllipseGeometry);
  101. scratchOptions.center = Cartesian3.clone(ellipseGeometry._center, scratchOptions.center);
  102. scratchOptions.ellipsoid = Ellipsoid.clone(ellipseGeometry._ellipsoid, scratchOptions.ellipsoid);
  103. scratchOptions.height = ellipseGeometry._height;
  104. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  105. scratchOptions.granularity = ellipseGeometry._granularity;
  106. scratchOptions.numberOfVerticalLines = ellipseGeometry._numberOfVerticalLines;
  107. if (!defined(result)) {
  108. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  109. return new CircleOutlineGeometry(scratchOptions);
  110. }
  111. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  112. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  113. result._ellipseGeometry = new EllipseOutlineGeometry(scratchOptions);
  114. return result;
  115. };
  116. /**
  117. * Computes the geometric representation of an outline of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  118. *
  119. * @param {CircleOutlineGeometry} circleGeometry A description of the circle.
  120. * @returns {Geometry|undefined} The computed vertices and indices.
  121. */
  122. CircleOutlineGeometry.createGeometry = function(circleGeometry) {
  123. return EllipseOutlineGeometry.createGeometry(circleGeometry._ellipseGeometry);
  124. };
  125. export default CircleOutlineGeometry;