createCircleOutlineGeometry.js 8.6 KB

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