智慧水务管理系统 - 精河县供水工程综合管理平台

Property.js 3.5KB

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