TimeIntervalCollectionPositionProperty.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import defaultValue from "../Core/defaultValue.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import Event from "../Core/Event.js";
  5. import ReferenceFrame from "../Core/ReferenceFrame.js";
  6. import TimeIntervalCollection from "../Core/TimeIntervalCollection.js";
  7. import PositionProperty from "./PositionProperty.js";
  8. import Property from "./Property.js";
  9. /**
  10. * A {@link TimeIntervalCollectionProperty} which is also a {@link PositionProperty}.
  11. *
  12. * @alias TimeIntervalCollectionPositionProperty
  13. * @constructor
  14. *
  15. * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.
  16. */
  17. function TimeIntervalCollectionPositionProperty(referenceFrame) {
  18. this._definitionChanged = new Event();
  19. this._intervals = new TimeIntervalCollection();
  20. this._intervals.changedEvent.addEventListener(
  21. TimeIntervalCollectionPositionProperty.prototype._intervalsChanged,
  22. this
  23. );
  24. this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);
  25. }
  26. Object.defineProperties(TimeIntervalCollectionPositionProperty.prototype, {
  27. /**
  28. * Gets a value indicating if this property is constant. A property is considered
  29. * constant if getValue always returns the same result for the current definition.
  30. * @memberof TimeIntervalCollectionPositionProperty.prototype
  31. *
  32. * @type {Boolean}
  33. * @readonly
  34. */
  35. isConstant: {
  36. get: function () {
  37. return this._intervals.isEmpty;
  38. },
  39. },
  40. /**
  41. * Gets the event that is raised whenever the definition of this property changes.
  42. * The definition is considered to have changed if a call to getValue would return
  43. * a different result for the same time.
  44. * @memberof TimeIntervalCollectionPositionProperty.prototype
  45. *
  46. * @type {Event}
  47. * @readonly
  48. */
  49. definitionChanged: {
  50. get: function () {
  51. return this._definitionChanged;
  52. },
  53. },
  54. /**
  55. * Gets the interval collection.
  56. * @memberof TimeIntervalCollectionPositionProperty.prototype
  57. * @type {TimeIntervalCollection}
  58. * @readonly
  59. */
  60. intervals: {
  61. get: function () {
  62. return this._intervals;
  63. },
  64. },
  65. /**
  66. * Gets the reference frame in which the position is defined.
  67. * @memberof TimeIntervalCollectionPositionProperty.prototype
  68. * @type {ReferenceFrame}
  69. * @readonly
  70. * @default ReferenceFrame.FIXED;
  71. */
  72. referenceFrame: {
  73. get: function () {
  74. return this._referenceFrame;
  75. },
  76. },
  77. });
  78. /**
  79. * Gets the value of the property at the provided time in the fixed frame.
  80. *
  81. * @param {JulianDate} time The time for which to retrieve the value.
  82. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  83. * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.
  84. */
  85. TimeIntervalCollectionPositionProperty.prototype.getValue = function (
  86. time,
  87. result
  88. ) {
  89. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  90. };
  91. /**
  92. * Gets the value of the property at the provided time and in the provided reference frame.
  93. *
  94. * @param {JulianDate} time The time for which to retrieve the value.
  95. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
  96. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  97. * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.
  98. */
  99. TimeIntervalCollectionPositionProperty.prototype.getValueInReferenceFrame = function (
  100. time,
  101. referenceFrame,
  102. result
  103. ) {
  104. //>>includeStart('debug', pragmas.debug);
  105. if (!defined(time)) {
  106. throw new DeveloperError("time is required.");
  107. }
  108. if (!defined(referenceFrame)) {
  109. throw new DeveloperError("referenceFrame is required.");
  110. }
  111. //>>includeEnd('debug');
  112. const position = this._intervals.findDataForIntervalContainingDate(time);
  113. if (defined(position)) {
  114. return PositionProperty.convertToReferenceFrame(
  115. time,
  116. position,
  117. this._referenceFrame,
  118. referenceFrame,
  119. result
  120. );
  121. }
  122. return undefined;
  123. };
  124. /**
  125. * Compares this property to the provided property and returns
  126. * <code>true</code> if they are equal, <code>false</code> otherwise.
  127. *
  128. * @param {Property} [other] The other property.
  129. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  130. */
  131. TimeIntervalCollectionPositionProperty.prototype.equals = function (other) {
  132. return (
  133. this === other || //
  134. (other instanceof TimeIntervalCollectionPositionProperty && //
  135. this._intervals.equals(other._intervals, Property.equals) && //
  136. this._referenceFrame === other._referenceFrame)
  137. );
  138. };
  139. /**
  140. * @private
  141. */
  142. TimeIntervalCollectionPositionProperty.prototype._intervalsChanged = function () {
  143. this._definitionChanged.raiseEvent(this);
  144. };
  145. export default TimeIntervalCollectionPositionProperty;