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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import defined from "../Core/defined.js";
  2. import DeveloperError from "../Core/DeveloperError.js";
  3. import CesiumMath from "../Core/Math.js";
  4. /**
  5. * Represents a {@link Packable} number that always interpolates values
  6. * towards the shortest angle of rotation. This object is never used directly
  7. * but is instead passed to the constructor of {@link SampledProperty}
  8. * in order to represent a two-dimensional angle of rotation.
  9. *
  10. * @interface Rotation
  11. *
  12. *
  13. * @example
  14. * const time1 = Cesium.JulianDate.fromIso8601('2010-05-07T00:00:00');
  15. * const time2 = Cesium.JulianDate.fromIso8601('2010-05-07T00:01:00');
  16. * const time3 = Cesium.JulianDate.fromIso8601('2010-05-07T00:02:00');
  17. *
  18. * const property = new Cesium.SampledProperty(Cesium.Rotation);
  19. * property.addSample(time1, 0);
  20. * property.addSample(time3, Cesium.Math.toRadians(350));
  21. *
  22. * //Getting the value at time2 will equal 355 degrees instead
  23. * //of 175 degrees (which is what you get if you construct
  24. * //a SampledProperty(Number) instead. Note, the actual
  25. * //return value is in radians, not degrees.
  26. * property.getValue(time2);
  27. *
  28. * @see PackableForInterpolation
  29. */
  30. const Rotation = {
  31. /**
  32. * The number of elements used to pack the object into an array.
  33. * @type {number}
  34. */
  35. packedLength: 1,
  36. /**
  37. * Stores the provided instance into the provided array.
  38. *
  39. * @param {Rotation} value The value to pack.
  40. * @param {number[]} array The array to pack into.
  41. * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
  42. *
  43. * @returns {number[]} The array that was packed into
  44. */
  45. pack: function (value, array, startingIndex) {
  46. //>>includeStart('debug', pragmas.debug);
  47. if (!defined(value)) {
  48. throw new DeveloperError("value is required");
  49. }
  50. if (!defined(array)) {
  51. throw new DeveloperError("array is required");
  52. }
  53. //>>includeEnd('debug');
  54. startingIndex = startingIndex ?? 0;
  55. array[startingIndex] = value;
  56. return array;
  57. },
  58. /**
  59. * Retrieves an instance from a packed array.
  60. *
  61. * @param {number[]} array The packed array.
  62. * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
  63. * @param {Rotation} [result] The object into which to store the result.
  64. * @returns {Rotation} The modified result parameter or a new Rotation instance if one was not provided.
  65. */
  66. unpack: function (array, startingIndex, result) {
  67. //>>includeStart('debug', pragmas.debug);
  68. if (!defined(array)) {
  69. throw new DeveloperError("array is required");
  70. }
  71. //>>includeEnd('debug');
  72. startingIndex = startingIndex ?? 0;
  73. return array[startingIndex];
  74. },
  75. /**
  76. * Converts a packed array into a form suitable for interpolation.
  77. *
  78. * @param {number[]} packedArray The packed array.
  79. * @param {number} [startingIndex=0] The index of the first element to be converted.
  80. * @param {number} [lastIndex=packedArray.length] The index of the last element to be converted.
  81. * @param {number[]} [result] The object into which to store the result.
  82. */
  83. convertPackedArrayForInterpolation: function (
  84. packedArray,
  85. startingIndex,
  86. lastIndex,
  87. result,
  88. ) {
  89. //>>includeStart('debug', pragmas.debug);
  90. if (!defined(packedArray)) {
  91. throw new DeveloperError("packedArray is required");
  92. }
  93. //>>includeEnd('debug');
  94. if (!defined(result)) {
  95. result = [];
  96. }
  97. startingIndex = startingIndex ?? 0;
  98. lastIndex = lastIndex ?? packedArray.length;
  99. let previousValue;
  100. for (let i = 0, len = lastIndex - startingIndex + 1; i < len; i++) {
  101. const value = packedArray[startingIndex + i];
  102. if (i === 0 || Math.abs(previousValue - value) < Math.PI) {
  103. result[i] = value;
  104. } else {
  105. result[i] = value - CesiumMath.TWO_PI;
  106. }
  107. previousValue = value;
  108. }
  109. },
  110. /**
  111. * Retrieves an instance from a packed array converted with {@link Rotation.convertPackedArrayForInterpolation}.
  112. *
  113. * @param {number[]} array The array previously packed for interpolation.
  114. * @param {number[]} sourceArray The original packed array.
  115. * @param {number} [firstIndex=0] The firstIndex used to convert the array.
  116. * @param {number} [lastIndex=packedArray.length] The lastIndex used to convert the array.
  117. * @param {Rotation} [result] The object into which to store the result.
  118. * @returns {Rotation} The modified result parameter or a new Rotation instance if one was not provided.
  119. */
  120. unpackInterpolationResult: function (
  121. array,
  122. sourceArray,
  123. firstIndex,
  124. lastIndex,
  125. result,
  126. ) {
  127. //>>includeStart('debug', pragmas.debug);
  128. if (!defined(array)) {
  129. throw new DeveloperError("array is required");
  130. }
  131. if (!defined(sourceArray)) {
  132. throw new DeveloperError("sourceArray is required");
  133. }
  134. //>>includeEnd('debug');
  135. result = array[0];
  136. if (result < 0) {
  137. return result + CesiumMath.TWO_PI;
  138. }
  139. return result;
  140. },
  141. };
  142. export default Rotation;