Property.js 4.2 KB

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