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

SampledPositionProperty.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import Cartesian3 from "../Core/Cartesian3.js";
  2. import Check from "../Core/Check.js";
  3. import defined from "../Core/defined.js";
  4. import DeveloperError from "../Core/DeveloperError.js";
  5. import Event from "../Core/Event.js";
  6. import JulianDate from "../Core/JulianDate.js";
  7. import ReferenceFrame from "../Core/ReferenceFrame.js";
  8. import PositionProperty from "./PositionProperty.js";
  9. import Property from "./Property.js";
  10. import SampledProperty from "./SampledProperty.js";
  11. /**
  12. * A {@link SampledProperty} which is also a {@link PositionProperty}.
  13. *
  14. * @alias SampledPositionProperty
  15. * @constructor
  16. *
  17. * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined.
  18. * @param {number} [numberOfDerivatives=0] The number of derivatives that accompany each position; i.e. velocity, acceleration, etc...
  19. */
  20. function SampledPositionProperty(referenceFrame, numberOfDerivatives) {
  21. numberOfDerivatives = numberOfDerivatives ?? 0;
  22. let derivativeTypes;
  23. if (numberOfDerivatives > 0) {
  24. derivativeTypes = new Array(numberOfDerivatives);
  25. for (let i = 0; i < numberOfDerivatives; i++) {
  26. derivativeTypes[i] = Cartesian3;
  27. }
  28. }
  29. this._numberOfDerivatives = numberOfDerivatives;
  30. this._property = new SampledProperty(Cartesian3, derivativeTypes);
  31. this._definitionChanged = new Event();
  32. this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED;
  33. this._property._definitionChanged.addEventListener(function () {
  34. this._definitionChanged.raiseEvent(this);
  35. }, this);
  36. }
  37. Object.defineProperties(SampledPositionProperty.prototype, {
  38. /**
  39. * Gets a value indicating if this property is constant. A property is considered
  40. * constant if getValue always returns the same result for the current definition.
  41. * @memberof SampledPositionProperty.prototype
  42. *
  43. * @type {boolean}
  44. * @readonly
  45. */
  46. isConstant: {
  47. get: function () {
  48. return this._property.isConstant;
  49. },
  50. },
  51. /**
  52. * Gets the event that is raised whenever the definition of this property changes.
  53. * The definition is considered to have changed if a call to getValue would return
  54. * a different result for the same time.
  55. * @memberof SampledPositionProperty.prototype
  56. *
  57. * @type {Event}
  58. * @readonly
  59. */
  60. definitionChanged: {
  61. get: function () {
  62. return this._definitionChanged;
  63. },
  64. },
  65. /**
  66. * Gets the reference frame in which the position is defined.
  67. * @memberof SampledPositionProperty.prototype
  68. * @type {ReferenceFrame}
  69. * @default ReferenceFrame.FIXED;
  70. */
  71. referenceFrame: {
  72. get: function () {
  73. return this._referenceFrame;
  74. },
  75. },
  76. /**
  77. * Gets the degree of interpolation to perform when retrieving a value. Call <code>setInterpolationOptions</code> to set this.
  78. * @memberof SampledPositionProperty.prototype
  79. *
  80. * @type {number}
  81. * @default 1
  82. * @readonly
  83. */
  84. interpolationDegree: {
  85. get: function () {
  86. return this._property.interpolationDegree;
  87. },
  88. },
  89. /**
  90. * Gets the interpolation algorithm to use when retrieving a value. Call <code>setInterpolationOptions</code> to set this.
  91. * @memberof SampledPositionProperty.prototype
  92. *
  93. * @type {InterpolationAlgorithm}
  94. * @default LinearApproximation
  95. * @readonly
  96. */
  97. interpolationAlgorithm: {
  98. get: function () {
  99. return this._property.interpolationAlgorithm;
  100. },
  101. },
  102. /**
  103. * The number of derivatives contained by this property; i.e. 0 for just position, 1 for velocity, etc.
  104. * @memberof SampledPositionProperty.prototype
  105. *
  106. * @type {number}
  107. * @default 0
  108. */
  109. numberOfDerivatives: {
  110. get: function () {
  111. return this._numberOfDerivatives;
  112. },
  113. },
  114. /**
  115. * Gets or sets the type of extrapolation to perform when a value
  116. * is requested at a time after any available samples.
  117. * @memberof SampledPositionProperty.prototype
  118. * @type {ExtrapolationType}
  119. * @default ExtrapolationType.NONE
  120. */
  121. forwardExtrapolationType: {
  122. get: function () {
  123. return this._property.forwardExtrapolationType;
  124. },
  125. set: function (value) {
  126. this._property.forwardExtrapolationType = value;
  127. },
  128. },
  129. /**
  130. * Gets or sets the amount of time to extrapolate forward before
  131. * the property becomes undefined. A value of 0 will extrapolate forever.
  132. * @memberof SampledPositionProperty.prototype
  133. * @type {number}
  134. * @default 0
  135. */
  136. forwardExtrapolationDuration: {
  137. get: function () {
  138. return this._property.forwardExtrapolationDuration;
  139. },
  140. set: function (value) {
  141. this._property.forwardExtrapolationDuration = value;
  142. },
  143. },
  144. /**
  145. * Gets or sets the type of extrapolation to perform when a value
  146. * is requested at a time before any available samples.
  147. * @memberof SampledPositionProperty.prototype
  148. * @type {ExtrapolationType}
  149. * @default ExtrapolationType.NONE
  150. */
  151. backwardExtrapolationType: {
  152. get: function () {
  153. return this._property.backwardExtrapolationType;
  154. },
  155. set: function (value) {
  156. this._property.backwardExtrapolationType = value;
  157. },
  158. },
  159. /**
  160. * Gets or sets the amount of time to extrapolate backward
  161. * before the property becomes undefined. A value of 0 will extrapolate forever.
  162. * @memberof SampledPositionProperty.prototype
  163. * @type {number}
  164. * @default 0
  165. */
  166. backwardExtrapolationDuration: {
  167. get: function () {
  168. return this._property.backwardExtrapolationDuration;
  169. },
  170. set: function (value) {
  171. this._property.backwardExtrapolationDuration = value;
  172. },
  173. },
  174. });
  175. const timeScratch = new JulianDate();
  176. /**
  177. * Gets the position at the provided time.
  178. *
  179. * @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
  180. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  181. * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.
  182. */
  183. SampledPositionProperty.prototype.getValue = function (time, result) {
  184. if (!defined(time)) {
  185. time = JulianDate.now(timeScratch);
  186. }
  187. return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
  188. };
  189. /**
  190. * Gets the position at the provided time and in the provided reference frame.
  191. *
  192. * @param {JulianDate} time The time for which to retrieve the value.
  193. * @param {ReferenceFrame} referenceFrame The desired referenceFrame of the result.
  194. * @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
  195. * @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.
  196. */
  197. SampledPositionProperty.prototype.getValueInReferenceFrame = function (
  198. time,
  199. referenceFrame,
  200. result,
  201. ) {
  202. //>>includeStart('debug', pragmas.debug);
  203. Check.defined("time", time);
  204. Check.defined("referenceFrame", referenceFrame);
  205. //>>includeEnd('debug');
  206. result = this._property.getValue(time, result);
  207. if (defined(result)) {
  208. return PositionProperty.convertToReferenceFrame(
  209. time,
  210. result,
  211. this._referenceFrame,
  212. referenceFrame,
  213. result,
  214. );
  215. }
  216. return undefined;
  217. };
  218. /**
  219. * Sets the algorithm and degree to use when interpolating a position.
  220. *
  221. * @param {object} [options] Object with the following properties:
  222. * @param {InterpolationAlgorithm} [options.interpolationAlgorithm] The new interpolation algorithm. If undefined, the existing property will be unchanged.
  223. * @param {number} [options.interpolationDegree] The new interpolation degree. If undefined, the existing property will be unchanged.
  224. */
  225. SampledPositionProperty.prototype.setInterpolationOptions = function (options) {
  226. this._property.setInterpolationOptions(options);
  227. };
  228. /**
  229. * Adds a new sample.
  230. *
  231. * @param {JulianDate} time The sample time.
  232. * @param {Cartesian3} position The position at the provided time.
  233. * @param {Cartesian3[]} [derivatives] The array of derivative values at the provided time.
  234. */
  235. SampledPositionProperty.prototype.addSample = function (
  236. time,
  237. position,
  238. derivatives,
  239. ) {
  240. const numberOfDerivatives = this._numberOfDerivatives;
  241. //>>includeStart('debug', pragmas.debug);
  242. if (
  243. numberOfDerivatives > 0 &&
  244. (!defined(derivatives) || derivatives.length !== numberOfDerivatives)
  245. ) {
  246. throw new DeveloperError(
  247. "derivatives length must be equal to the number of derivatives.",
  248. );
  249. }
  250. //>>includeEnd('debug');
  251. this._property.addSample(time, position, derivatives);
  252. };
  253. /**
  254. * Adds multiple samples via parallel arrays.
  255. *
  256. * @param {JulianDate[]} times An array of JulianDate instances where each index is a sample time.
  257. * @param {Cartesian3[]} positions An array of Cartesian3 position instances, where each value corresponds to the provided time index.
  258. * @param {Array[]} [derivatives] An array where each value is another array containing derivatives for the corresponding time index.
  259. *
  260. * @exception {DeveloperError} All arrays must be the same length.
  261. */
  262. SampledPositionProperty.prototype.addSamples = function (
  263. times,
  264. positions,
  265. derivatives,
  266. ) {
  267. this._property.addSamples(times, positions, derivatives);
  268. };
  269. /**
  270. * Adds samples as a single packed array where each new sample is represented as a date,
  271. * followed by the packed representation of the corresponding value and derivatives.
  272. *
  273. * @param {number[]} packedSamples The array of packed samples.
  274. * @param {JulianDate} [epoch] If any of the dates in packedSamples are numbers, they are considered an offset from this epoch, in seconds.
  275. */
  276. SampledPositionProperty.prototype.addSamplesPackedArray = function (
  277. packedSamples,
  278. epoch,
  279. ) {
  280. this._property.addSamplesPackedArray(packedSamples, epoch);
  281. };
  282. /**
  283. * Removes a sample at the given time, if present.
  284. *
  285. * @param {JulianDate} time The sample time.
  286. * @returns {boolean} <code>true</code> if a sample at time was removed, <code>false</code> otherwise.
  287. */
  288. SampledPositionProperty.prototype.removeSample = function (time) {
  289. return this._property.removeSample(time);
  290. };
  291. /**
  292. * Removes all samples for the given time interval.
  293. *
  294. * @param {TimeInterval} time The time interval for which to remove all samples.
  295. */
  296. SampledPositionProperty.prototype.removeSamples = function (timeInterval) {
  297. this._property.removeSamples(timeInterval);
  298. };
  299. /**
  300. * Compares this property to the provided property and returns
  301. * <code>true</code> if they are equal, <code>false</code> otherwise.
  302. *
  303. * @param {Property} [other] The other property.
  304. * @returns {boolean} <code>true</code> if left and right are equal, <code>false</code> otherwise.
  305. */
  306. SampledPositionProperty.prototype.equals = function (other) {
  307. return (
  308. this === other || //
  309. (other instanceof SampledPositionProperty &&
  310. Property.equals(this._property, other._property) && //
  311. this._referenceFrame === other._referenceFrame)
  312. );
  313. };
  314. export default SampledPositionProperty;