DistanceDisplayCondition.js 5.0 KB

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