CircleOutlineGeometry.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. * const circle = new Cesium.CircleOutlineGeometry({
  31. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  32. * radius : 100000.0
  33. * });
  34. * const geometry = Cesium.CircleOutlineGeometry.createGeometry(circle);
  35. */
  36. function CircleOutlineGeometry(options) {
  37. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  38. const radius = options.radius;
  39. //>>includeStart('debug', pragmas.debug);
  40. Check.typeOf.number("radius", radius);
  41. //>>includeEnd('debug');
  42. const 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(
  74. value._ellipseGeometry,
  75. array,
  76. startingIndex
  77. );
  78. };
  79. const scratchEllipseGeometry = new EllipseOutlineGeometry({
  80. center: new Cartesian3(),
  81. semiMajorAxis: 1.0,
  82. semiMinorAxis: 1.0,
  83. });
  84. const scratchOptions = {
  85. center: new Cartesian3(),
  86. radius: undefined,
  87. ellipsoid: Ellipsoid.clone(Ellipsoid.UNIT_SPHERE),
  88. height: undefined,
  89. extrudedHeight: undefined,
  90. granularity: undefined,
  91. numberOfVerticalLines: undefined,
  92. semiMajorAxis: undefined,
  93. semiMinorAxis: undefined,
  94. };
  95. /**
  96. * Retrieves an instance from a packed array.
  97. *
  98. * @param {Number[]} array The packed array.
  99. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  100. * @param {CircleOutlineGeometry} [result] The object into which to store the result.
  101. * @returns {CircleOutlineGeometry} The modified result parameter or a new CircleOutlineGeometry instance if one was not provided.
  102. */
  103. CircleOutlineGeometry.unpack = function (array, startingIndex, result) {
  104. const ellipseGeometry = EllipseOutlineGeometry.unpack(
  105. array,
  106. startingIndex,
  107. scratchEllipseGeometry
  108. );
  109. scratchOptions.center = Cartesian3.clone(
  110. ellipseGeometry._center,
  111. scratchOptions.center
  112. );
  113. scratchOptions.ellipsoid = Ellipsoid.clone(
  114. ellipseGeometry._ellipsoid,
  115. scratchOptions.ellipsoid
  116. );
  117. scratchOptions.height = ellipseGeometry._height;
  118. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  119. scratchOptions.granularity = ellipseGeometry._granularity;
  120. scratchOptions.numberOfVerticalLines = ellipseGeometry._numberOfVerticalLines;
  121. if (!defined(result)) {
  122. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  123. return new CircleOutlineGeometry(scratchOptions);
  124. }
  125. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  126. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  127. result._ellipseGeometry = new EllipseOutlineGeometry(scratchOptions);
  128. return result;
  129. };
  130. /**
  131. * Computes the geometric representation of an outline of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  132. *
  133. * @param {CircleOutlineGeometry} circleGeometry A description of the circle.
  134. * @returns {Geometry|undefined} The computed vertices and indices.
  135. */
  136. CircleOutlineGeometry.createGeometry = function (circleGeometry) {
  137. return EllipseOutlineGeometry.createGeometry(circleGeometry._ellipseGeometry);
  138. };
  139. export default CircleOutlineGeometry;