createCircleOutlineGeometry.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.97
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['./Matrix2-ab676047', './RuntimeError-1088cc64', './defaultValue-a6eb9f34', './EllipseOutlineGeometry-cfe46a59', './ComponentDatatype-e06f4e16', './WebGLConstants-d81b330d', './Transforms-c78c4637', './_commonjsHelpers-89c9b271', './combine-7cf28d88', './EllipseGeometryLibrary-b13c13df', './GeometryAttribute-4f02e2ad', './GeometryAttributes-aff51037', './GeometryOffsetAttribute-102da468', './IndexDatatype-c2232ebd'], (function (Matrix2, RuntimeError, defaultValue, EllipseOutlineGeometry, ComponentDatatype, WebGLConstants, Transforms, _commonjsHelpers, combine, EllipseGeometryLibrary, GeometryAttribute, GeometryAttributes, GeometryOffsetAttribute, IndexDatatype) { 'use strict';
  26. /**
  27. * A description of the outline of a circle on the ellipsoid.
  28. *
  29. * @alias CircleOutlineGeometry
  30. * @constructor
  31. *
  32. * @param {Object} options Object with the following properties:
  33. * @param {Cartesian3} options.center The circle's center point in the fixed frame.
  34. * @param {Number} options.radius The radius in meters.
  35. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid the circle will be on.
  36. * @param {Number} [options.height=0.0] The distance in meters between the circle and the ellipsoid surface.
  37. * @param {Number} [options.granularity=0.02] The angular distance between points on the circle in radians.
  38. * @param {Number} [options.extrudedHeight=0.0] The distance in meters between the circle's extruded face and the ellipsoid surface.
  39. * @param {Number} [options.numberOfVerticalLines=16] Number of lines to draw between the top and bottom of an extruded circle.
  40. *
  41. * @exception {DeveloperError} radius must be greater than zero.
  42. * @exception {DeveloperError} granularity must be greater than zero.
  43. *
  44. * @see CircleOutlineGeometry.createGeometry
  45. * @see Packable
  46. *
  47. * @example
  48. * // Create a circle.
  49. * const circle = new Cesium.CircleOutlineGeometry({
  50. * center : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
  51. * radius : 100000.0
  52. * });
  53. * const geometry = Cesium.CircleOutlineGeometry.createGeometry(circle);
  54. */
  55. function CircleOutlineGeometry(options) {
  56. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  57. const radius = options.radius;
  58. //>>includeStart('debug', pragmas.debug);
  59. RuntimeError.Check.typeOf.number("radius", radius);
  60. //>>includeEnd('debug');
  61. const ellipseGeometryOptions = {
  62. center: options.center,
  63. semiMajorAxis: radius,
  64. semiMinorAxis: radius,
  65. ellipsoid: options.ellipsoid,
  66. height: options.height,
  67. extrudedHeight: options.extrudedHeight,
  68. granularity: options.granularity,
  69. numberOfVerticalLines: options.numberOfVerticalLines,
  70. };
  71. this._ellipseGeometry = new EllipseOutlineGeometry.EllipseOutlineGeometry(ellipseGeometryOptions);
  72. this._workerName = "createCircleOutlineGeometry";
  73. }
  74. /**
  75. * The number of elements used to pack the object into an array.
  76. * @type {Number}
  77. */
  78. CircleOutlineGeometry.packedLength = EllipseOutlineGeometry.EllipseOutlineGeometry.packedLength;
  79. /**
  80. * Stores the provided instance into the provided array.
  81. *
  82. * @param {CircleOutlineGeometry} value The value to pack.
  83. * @param {Number[]} array The array to pack into.
  84. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  85. *
  86. * @returns {Number[]} The array that was packed into
  87. */
  88. CircleOutlineGeometry.pack = function (value, array, startingIndex) {
  89. //>>includeStart('debug', pragmas.debug);
  90. RuntimeError.Check.typeOf.object("value", value);
  91. //>>includeEnd('debug');
  92. return EllipseOutlineGeometry.EllipseOutlineGeometry.pack(
  93. value._ellipseGeometry,
  94. array,
  95. startingIndex
  96. );
  97. };
  98. const scratchEllipseGeometry = new EllipseOutlineGeometry.EllipseOutlineGeometry({
  99. center: new Matrix2.Cartesian3(),
  100. semiMajorAxis: 1.0,
  101. semiMinorAxis: 1.0,
  102. });
  103. const scratchOptions = {
  104. center: new Matrix2.Cartesian3(),
  105. radius: undefined,
  106. ellipsoid: Matrix2.Ellipsoid.clone(Matrix2.Ellipsoid.UNIT_SPHERE),
  107. height: undefined,
  108. extrudedHeight: undefined,
  109. granularity: undefined,
  110. numberOfVerticalLines: undefined,
  111. semiMajorAxis: undefined,
  112. semiMinorAxis: undefined,
  113. };
  114. /**
  115. * Retrieves an instance from a packed array.
  116. *
  117. * @param {Number[]} array The packed array.
  118. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  119. * @param {CircleOutlineGeometry} [result] The object into which to store the result.
  120. * @returns {CircleOutlineGeometry} The modified result parameter or a new CircleOutlineGeometry instance if one was not provided.
  121. */
  122. CircleOutlineGeometry.unpack = function (array, startingIndex, result) {
  123. const ellipseGeometry = EllipseOutlineGeometry.EllipseOutlineGeometry.unpack(
  124. array,
  125. startingIndex,
  126. scratchEllipseGeometry
  127. );
  128. scratchOptions.center = Matrix2.Cartesian3.clone(
  129. ellipseGeometry._center,
  130. scratchOptions.center
  131. );
  132. scratchOptions.ellipsoid = Matrix2.Ellipsoid.clone(
  133. ellipseGeometry._ellipsoid,
  134. scratchOptions.ellipsoid
  135. );
  136. scratchOptions.height = ellipseGeometry._height;
  137. scratchOptions.extrudedHeight = ellipseGeometry._extrudedHeight;
  138. scratchOptions.granularity = ellipseGeometry._granularity;
  139. scratchOptions.numberOfVerticalLines = ellipseGeometry._numberOfVerticalLines;
  140. if (!defaultValue.defined(result)) {
  141. scratchOptions.radius = ellipseGeometry._semiMajorAxis;
  142. return new CircleOutlineGeometry(scratchOptions);
  143. }
  144. scratchOptions.semiMajorAxis = ellipseGeometry._semiMajorAxis;
  145. scratchOptions.semiMinorAxis = ellipseGeometry._semiMinorAxis;
  146. result._ellipseGeometry = new EllipseOutlineGeometry.EllipseOutlineGeometry(scratchOptions);
  147. return result;
  148. };
  149. /**
  150. * Computes the geometric representation of an outline of a circle on an ellipsoid, including its vertices, indices, and a bounding sphere.
  151. *
  152. * @param {CircleOutlineGeometry} circleGeometry A description of the circle.
  153. * @returns {Geometry|undefined} The computed vertices and indices.
  154. */
  155. CircleOutlineGeometry.createGeometry = function (circleGeometry) {
  156. return EllipseOutlineGeometry.EllipseOutlineGeometry.createGeometry(circleGeometry._ellipseGeometry);
  157. };
  158. function createCircleOutlineGeometry(circleGeometry, offset) {
  159. if (defaultValue.defined(offset)) {
  160. circleGeometry = CircleOutlineGeometry.unpack(circleGeometry, offset);
  161. }
  162. circleGeometry._ellipseGeometry._center = Matrix2.Cartesian3.clone(
  163. circleGeometry._ellipseGeometry._center
  164. );
  165. circleGeometry._ellipseGeometry._ellipsoid = Matrix2.Ellipsoid.clone(
  166. circleGeometry._ellipseGeometry._ellipsoid
  167. );
  168. return CircleOutlineGeometry.createGeometry(circleGeometry);
  169. }
  170. return createCircleOutlineGeometry;
  171. }));