Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | 25x 25x 25x 25x 1x 24x 1x 23x 1x 22x 22x 22x 22x 1x 17x 15x 1x 1x 1x 1x 15x 15x 13x 13x 13x 3x 10x 6x 10x | import Frozen from "./Frozen.js";
import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
import Spline from "./Spline.js";
/**
* A spline that is composed of piecewise constants representing a step function.
*
* @alias SteppedSpline
* @constructor
*
* @param {object} options Object with the following properties:
* @param {number[]} options.times An array of strictly increasing, unit-less, floating-point times at each point. The values are in no way connected to the clock time. They are the parameterization for the curve.
* @param {number[]|Cartesian3[]|Quaternion[]} options.points The array of control points.
*
* @exception {DeveloperError} points.length must be greater than or equal to 2.
* @exception {DeveloperError} times.length must be equal to points.length.
*
* @example
* const times = [ 0.0, 1.5, 3.0, 4.5, 6.0 ];
* const spline = new Cesium.SteppedSpline({
* times : times,
* points : [
* new Cesium.Cartesian3(1235398.0, -4810983.0, 4146266.0),
* new Cesium.Cartesian3(1372574.0, -5345182.0, 4606657.0),
* new Cesium.Cartesian3(-757983.0, -5542796.0, 4514323.0),
* new Cesium.Cartesian3(-2821260.0, -5248423.0, 4021290.0),
* new Cesium.Cartesian3(-2539788.0, -4724797.0, 3620093.0)
* ]
* });
*
* const p0 = spline.evaluate(times[0]);
*
* @see ConstantSpline
* @see CatmullRomSpline
* @see HermiteSpline
* @see LinearSpline
* @see QuaternionSpline
* @see MorphWeightSpline
*/
function SteppedSpline(options) {
options = options ?? Frozen.EMPTY_OBJECT;
const points = options.points;
const times = options.times;
//>>includeStart('debug', pragmas.debug);
if (!defined(points) || !defined(times)) {
throw new DeveloperError("points and times are required.");
}
if (points.length < 2) {
throw new DeveloperError(
"points.length must be greater than or equal to 2.",
);
}
if (times.length !== points.length) {
throw new DeveloperError("times.length must be equal to points.length.");
}
//>>includeEnd('debug');
this._times = times;
this._points = points;
this._pointType = Spline.getPointType(points[0]);
this._lastTimeIndex = 0;
}
Object.defineProperties(SteppedSpline.prototype, {
/**
* An array of times for the control points.
*
* @memberof SteppedSpline.prototype
*
* @type {number[]}
* @readonly
*/
times: {
get: function () {
return this._times;
},
},
/**
* An array of control points.
*
* @memberof SteppedSpline.prototype
*
* @type {number[]|Cartesian3[]|Quaternion[]}
* @readonly
*/
points: {
get: function () {
return this._points;
},
},
});
/**
* Finds an index <code>i</code> in <code>times</code> such that the parameter
* <code>time</code> is in the interval <code>[times[i], times[i + 1]]</code>.
* @function
*
* @param {number} time The time.
* @param {number} startIndex The index from which to start the search.
* @returns {number} The index for the element at the start of the interval.
*
* @exception {DeveloperError} time must be in the range <code>[t<sub>0</sub>, t<sub>n</sub>]</code>, where <code>t<sub>0</sub></code>
* is the first element in the array <code>times</code> and <code>t<sub>n</sub></code> is the last element
* in the array <code>times</code>.
*/
SteppedSpline.prototype.findTimeInterval = Spline.prototype.findTimeInterval;
/**
* Wraps the given time to the period covered by the spline.
* @function
*
* @param {number} time The time.
* @return {number} The time, wrapped around to the updated animation.
*/
SteppedSpline.prototype.wrapTime = Spline.prototype.wrapTime;
/**
* Clamps the given time to the period covered by the spline.
* @function
*
* @param {number} time The time.
* @return {number} The time, clamped to the animation period.
*/
SteppedSpline.prototype.clampTime = Spline.prototype.clampTime;
/**
* Evaluates the curve at a given time.
*
* @param {number} time The time at which to evaluate the curve.
* @param {Cartesian3|Quaternion} [result] The object onto which to store the result.
* @returns {number|Cartesian3|Quaternion} The modified result parameter or a new instance of the point on the curve at the given time.
*
* @exception {DeveloperError} time must be in the range <code>[t<sub>0</sub>, t<sub>n</sub>]</code>, where <code>t<sub>0</sub></code>
* is the first element in the array <code>times</code> and <code>t<sub>n</sub></code> is the last element
* in the array <code>times</code>.
*/
SteppedSpline.prototype.evaluate = function (time, result) {
const points = this.points;
this._lastTimeIndex = this.findTimeInterval(time, this._lastTimeIndex);
const i = this._lastTimeIndex;
const PointType = this._pointType;
if (PointType === Number) {
return points[i];
}
if (!defined(result)) {
result = new PointType();
}
return PointType.clone(points[i], result);
};
export default SteppedSpline;
|