Property.js 4.1 KB

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