DistanceDisplayCondition.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import defaultValue from './defaultValue.js';
  2. import defined from './defined.js';
  3. import defineProperties from './defineProperties.js';
  4. import DeveloperError from './DeveloperError.js';
  5. /**
  6. * Determines visibility based on the distance to the camera.
  7. *
  8. * @alias DistanceDisplayCondition
  9. * @constructor
  10. *
  11. * @param {Number} [near=0.0] The smallest distance in the interval where the object is visible.
  12. * @param {Number} [far=Number.MAX_VALUE] The largest distance in the interval where the object is visible.
  13. *
  14. * @example
  15. * // Make a billboard that is only visible when the distance to the camera is between 10 and 20 meters.
  16. * billboard.distanceDisplayCondition = new Cesium.DistanceDisplayCondition(10.0, 20.0);
  17. */
  18. function DistanceDisplayCondition(near, far) {
  19. near = defaultValue(near, 0.0);
  20. this._near = near;
  21. far = defaultValue(far, Number.MAX_VALUE);
  22. this._far = far;
  23. }
  24. defineProperties(DistanceDisplayCondition.prototype, {
  25. /**
  26. * The smallest distance in the interval where the object is visible.
  27. * @memberof DistanceDisplayCondition.prototype
  28. * @type {Number}
  29. * @default 0.0
  30. */
  31. near: {
  32. get: function() {
  33. return this._near;
  34. },
  35. set: function(value) {
  36. this._near = value;
  37. }
  38. },
  39. /**
  40. * The largest distance in the interval where the object is visible.
  41. * @memberof DistanceDisplayCondition.prototype
  42. * @type {Number}
  43. * @default Number.MAX_VALUE
  44. */
  45. far: {
  46. get: function() {
  47. return this._far;
  48. },
  49. set: function(value) {
  50. this._far = value;
  51. }
  52. }
  53. });
  54. /**
  55. * The number of elements used to pack the object into an array.
  56. * @type {Number}
  57. */
  58. DistanceDisplayCondition.packedLength = 2;
  59. /**
  60. * Stores the provided instance into the provided array.
  61. *
  62. * @param {DistanceDisplayCondition} value The value to pack.
  63. * @param {Number[]} array The array to pack into.
  64. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  65. *
  66. * @returns {Number[]} The array that was packed into
  67. */
  68. DistanceDisplayCondition.pack = function(value, array, startingIndex) {
  69. //>>includeStart('debug', pragmas.debug);
  70. if (!defined(value)) {
  71. throw new DeveloperError('value is required');
  72. }
  73. if (!defined(array)) {
  74. throw new DeveloperError('array is required');
  75. }
  76. //>>includeEnd('debug');
  77. startingIndex = defaultValue(startingIndex, 0);
  78. array[startingIndex++] = value.near;
  79. array[startingIndex] = value.far;
  80. return array;
  81. };
  82. /**
  83. * Retrieves an instance from a packed array.
  84. *
  85. * @param {Number[]} array The packed array.
  86. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  87. * @param {DistanceDisplayCondition} [result] The object into which to store the result.
  88. * @returns {DistanceDisplayCondition} The modified result parameter or a new DistanceDisplayCondition instance if one was not provided.
  89. */
  90. DistanceDisplayCondition.unpack = function(array, startingIndex, result) {
  91. //>>includeStart('debug', pragmas.debug);
  92. if (!defined(array)) {
  93. throw new DeveloperError('array is required');
  94. }
  95. //>>includeEnd('debug');
  96. startingIndex = defaultValue(startingIndex, 0);
  97. if (!defined(result)) {
  98. result = new DistanceDisplayCondition();
  99. }
  100. result.near = array[startingIndex++];
  101. result.far = array[startingIndex];
  102. return result;
  103. };
  104. /**
  105. * Determines if two distance display conditions are equal.
  106. *
  107. * @param {DistanceDisplayCondition} left A distance display condition.
  108. * @param {DistanceDisplayCondition} right Another distance display condition.
  109. * @return {Boolean} Whether the two distance display conditions are equal.
  110. */
  111. DistanceDisplayCondition.equals = function(left, right) {
  112. return left === right ||
  113. (defined(left) &&
  114. defined(right) &&
  115. left.near === right.near &&
  116. left.far === right.far);
  117. };
  118. /**
  119. * Duplicates a distance display condition instance.
  120. *
  121. * @param {DistanceDisplayCondition} [value] The distance display condition to duplicate.
  122. * @param {DistanceDisplayCondition} [result] The result onto which to store the result.
  123. * @return {DistanceDisplayCondition} The duplicated instance.
  124. */
  125. DistanceDisplayCondition.clone = function(value, result) {
  126. if (!defined(value)) {
  127. return undefined;
  128. }
  129. if (!defined(result)) {
  130. result = new DistanceDisplayCondition();
  131. }
  132. result.near = value.near;
  133. result.far = value.far;
  134. return result;
  135. };
  136. /**
  137. * Duplicates this instance.
  138. *
  139. * @param {DistanceDisplayCondition} [result] The result onto which to store the result.
  140. * @return {DistanceDisplayCondition} The duplicated instance.
  141. */
  142. DistanceDisplayCondition.prototype.clone = function(result) {
  143. return DistanceDisplayCondition.clone(this, result);
  144. };
  145. /**
  146. * Determines if this distance display condition is equal to another.
  147. *
  148. * @param {DistanceDisplayCondition} other Another distance display condition.
  149. * @return {Boolean} Whether this distance display condition is equal to the other.
  150. */
  151. DistanceDisplayCondition.prototype.equals = function(other) {
  152. return DistanceDisplayCondition.equals(this, other);
  153. };
  154. export default DistanceDisplayCondition;