TimeIntervalCollectionPositionProperty.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. */
  59. intervals: {
  60. get: function () {
  61. return this._intervals;
  62. },
  63. },
  64. /**
  65. * Gets the reference frame in which the position is defined.
  66. * @memberof TimeIntervalCollectionPositionProperty.prototype
  67. * @type {ReferenceFrame}
  68. * @default ReferenceFrame.FIXED;
  69. */
  70. referenceFrame: {
  71. get: function () {
  72. return this._referenceFrame;
  73. },
  74. },
  75. });
  76. /**
  77. * Gets the value of the property at the provided time in the fixed frame.
  78. *
  79. * @param {JulianDate} time The time for which to retrieve the value.
  80. * @param {Object} [result] The object to store the value into, if omitted, a new instance is created and returned.
  81. * @returns {Object} The modified result parameter or a new instance if the result parameter was not supplied.
  82. */
  83. TimeIntervalCollectionPositionProperty.prototype.getValue = function (
  84. time,
  85. result
  86. ) {
  87. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  88. };
  89. /**
  90. * Gets the value of the property at the provided time and in the provided reference frame.
  91. *
  92. * @param {JulianDate} time The time for which to retrieve the value.
  93. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
  94. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  95. * @returns {Cartesian3} The modified result parameter or a new instance if the result parameter was not supplied.
  96. */
  97. TimeIntervalCollectionPositionProperty.prototype.getValueInReferenceFrame = function (
  98. time,
  99. referenceFrame,
  100. result
  101. ) {
  102. //>>includeStart('debug', pragmas.debug);
  103. if (!defined(time)) {
  104. throw new DeveloperError("time is required.");
  105. }
  106. if (!defined(referenceFrame)) {
  107. throw new DeveloperError("referenceFrame is required.");
  108. }
  109. //>>includeEnd('debug');
  110. var position = this._intervals.findDataForIntervalContainingDate(time);
  111. if (defined(position)) {
  112. return PositionProperty.convertToReferenceFrame(
  113. time,
  114. position,
  115. this._referenceFrame,
  116. referenceFrame,
  117. result
  118. );
  119. }
  120. return undefined;
  121. };
  122. /**
  123. * Compares this property to the provided property and returns
  124. * <code>true</code> if they are equal, <code>false</code> otherwise.
  125. *
  126. * @param {Property} [other] The other property.
  127. * @returns {Boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  128. */
  129. TimeIntervalCollectionPositionProperty.prototype.equals = function (other) {
  130. return (
  131. this === other || //
  132. (other instanceof TimeIntervalCollectionPositionProperty && //
  133. this._intervals.equals(other._intervals, Property.equals) && //
  134. this._referenceFrame === other._referenceFrame)
  135. );
  136. };
  137. /**
  138. * @private
  139. */
  140. TimeIntervalCollectionPositionProperty.prototype._intervalsChanged = function () {
  141. this._definitionChanged.raiseEvent(this);
  142. };
  143. export default TimeIntervalCollectionPositionProperty;