createCircleOutlineGeometry.js 6.8 KB

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