Property.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import defaultValue from "../Core/defaultValue.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. /**
  5. * The interface for all properties, which represent a value that can optionally vary over time.
  6. * This type defines an interface and cannot be instantiated directly.
  7. *
  8. * @alias Property
  9. * @constructor
  10. * @abstract
  11. *
  12. * @see CompositeProperty
  13. * @see ConstantProperty
  14. * @see SampledProperty
  15. * @see TimeIntervalCollectionProperty
  16. * @see MaterialProperty
  17. * @see PositionProperty
  18. * @see ReferenceProperty
  19. */
  20. function Property() {
  21. DeveloperError.throwInstantiationError();
  22. }
  23. Object.defineProperties(Property.prototype, {
  24. /**
  25. * Gets a value indicating if this property is constant. A property is considered
  26. * constant if getValue always returns the same result for the current definition.
  27. * @memberof Property.prototype
  28. *
  29. * @type {Boolean}
  30. * @readonly
  31. */
  32. isConstant: {
  33. get: DeveloperError.throwInstantiationError,
  34. },
  35. /**
  36. * Gets the event that is raised whenever the definition of this property changes.
  37. * The definition is considered to have changed if a call to getValue would return
  38. * a different result for the same time.
  39. * @memberof Property.prototype
  40. *
  41. * @type {Event}
  42. * @readonly
  43. */
  44. definitionChanged: {
  45. get: DeveloperError.throwInstantiationError,
  46. },
  47. });
  48. /**
  49. * Gets the value of the property at the provided time.
  50. * @function
  51. *
  52. * @param {JulianDate} time The time for which to retrieve the value.
  53. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  54. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  55. */
  56. Property.prototype.getValue = DeveloperError.throwInstantiationError;
  57. /**
  58. * Compares this property to the provided property and returns
  59. * <code>true</code> if they are equal, <code>false</code> otherwise.
  60. * @function
  61. *
  62. * @param {Property} [other] The other property.
  63. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  64. */
  65. Property.prototype.equals = DeveloperError.throwInstantiationError;
  66. /**
  67. * @private
  68. */
  69. Property.equals = function (left, right) {
  70. return left === right || (defined(left) && left.equals(right));
  71. };
  72. /**
  73. * @private
  74. */
  75. Property.arrayEquals = function (left, right) {
  76. if (left === right) {
  77. return true;
  78. }
  79. if (!defined(left) || !defined(right) || left.length !== right.length) {
  80. return false;
  81. }
  82. const length = left.length;
  83. for (let i = 0; i < length; i++) {
  84. if (!Property.equals(left[i], right[i])) {
  85. return false;
  86. }
  87. }
  88. return true;
  89. };
  90. /**
  91. * @private
  92. */
  93. Property.isConstant = function (property) {
  94. return !defined(property) || property.isConstant;
  95. };
  96. /**
  97. * @private
  98. */
  99. Property.getValueOrUndefined = function (property, time, result) {
  100. return defined(property) ? property.getValue(time, result) : undefined;
  101. };
  102. /**
  103. * @private
  104. */
  105. Property.getValueOrDefault = function (property, time, valueDefault, result) {
  106. return defined(property)
  107. ? defaultValue(property.getValue(time, result), valueDefault)
  108. : valueDefault;
  109. };
  110. /**
  111. * @private
  112. */
  113. Property.getValueOrClonedDefault = function (
  114. property,
  115. time,
  116. valueDefault,
  117. result
  118. ) {
  119. let value;
  120. if (defined(property)) {
  121. value = property.getValue(time, result);
  122. }
  123. if (!defined(value)) {
  124. value = valueDefault.clone(value);
  125. }
  126. return value;
  127. };
  128. export default Property;