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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | 1x 1215x 1215x 256x 787x 787x 270x 70x 787x 717x 717x 717x 256x 959x 959x 3484x 3484x 3603x 847x 3484x 2637x 959x 1x 1x 14x 14x 14x 14x 14x 1x 44x 1x 44x 44x 44x 134x 134x 134x 134x 316x 44x 44x 44x 100x 44x 44x 134x 316x 316x 134x 182x 182x 350x 350x 350x 350x 350x 350x 182x 28x 44x 44x 98x 98x 308x 308x 44x 1x 1x 48x 48x 1x 48x 271x 48x 48x 48x 102x 214x 48x 48x 48x 48x 48x 48x 48x 101x 400x 400x 400x 400x 1019x 1019x 1019x 48x 48x 48x 48x 48x 133x 133x 566x 566x 133x 433x 433x 433x 433x 1071x 1071x 1071x 298x 298x 298x 298x 298x 773x 773x 773x 773x 773x 1071x 433x 418x 48x | import defined from "./defined.js";
import DeveloperError from "./DeveloperError.js";
import CesiumMath from "./Math.js";
const factorial = CesiumMath.factorial;
function calculateCoefficientTerm(
x,
zIndices,
xTable,
derivOrder,
termOrder,
reservedIndices,
) {
let result = 0;
let reserved;
let i;
let j;
if (derivOrder > 0) {
for (i = 0; i < termOrder; i++) {
reserved = false;
for (j = 0; j < reservedIndices.length && !reserved; j++) {
if (i === reservedIndices[j]) {
reserved = true;
}
}
if (!reserved) {
reservedIndices.push(i);
result += calculateCoefficientTerm(
x,
zIndices,
xTable,
derivOrder - 1,
termOrder,
reservedIndices,
);
reservedIndices.splice(reservedIndices.length - 1, 1);
}
}
return result;
}
result = 1;
for (i = 0; i < termOrder; i++) {
reserved = false;
for (j = 0; j < reservedIndices.length && !reserved; j++) {
if (i === reservedIndices[j]) {
reserved = true;
}
}
if (!reserved) {
result *= x - xTable[zIndices[i]];
}
}
return result;
}
/**
* An {@link InterpolationAlgorithm} for performing Hermite interpolation.
*
* @namespace HermitePolynomialApproximation
*/
const HermitePolynomialApproximation = {
type: "Hermite",
};
/**
* Given the desired degree, returns the number of data points required for interpolation.
*
* @param {number} degree The desired degree of interpolation.
* @param {number} [inputOrder=0] The order of the inputs (0 means just the data, 1 means the data and its derivative, etc).
* @returns {number} The number of required data points needed for the desired degree of interpolation.
* @exception {DeveloperError} degree must be 0 or greater.
* @exception {DeveloperError} inputOrder must be 0 or greater.
*/
HermitePolynomialApproximation.getRequiredDataPoints = function (
degree,
inputOrder,
) {
inputOrder = inputOrder ?? 0;
//>>includeStart('debug', pragmas.debug);
Iif (!defined(degree)) {
throw new DeveloperError("degree is required.");
}
Iif (degree < 0) {
throw new DeveloperError("degree must be 0 or greater.");
}
Iif (inputOrder < 0) {
throw new DeveloperError("inputOrder must be 0 or greater.");
}
//>>includeEnd('debug');
return Math.max(Math.floor((degree + 1) / (inputOrder + 1)), 2);
};
/**
* Interpolates values using Hermite Polynomial Approximation.
*
* @param {number} x The independent variable for which the dependent variables will be interpolated.
* @param {number[]} xTable The array of independent variables to use to interpolate. The values
* in this array must be in increasing order and the same value must not occur twice in the array.
* @param {number[]} yTable The array of dependent variables to use to interpolate. For a set of three
* dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.
* @param {number} yStride The number of dependent variable values in yTable corresponding to
* each independent variable value in xTable.
* @param {number[]} [result] An existing array into which to store the result.
* @returns {number[]} The array of interpolated values, or the result parameter if one was provided.
*/
HermitePolynomialApproximation.interpolateOrderZero = function (
x,
xTable,
yTable,
yStride,
result,
) {
if (!defined(result)) {
result = new Array(yStride);
}
let i;
let j;
let d;
let s;
let len;
let index;
const length = xTable.length;
const coefficients = new Array(yStride);
for (i = 0; i < yStride; i++) {
result[i] = 0;
const l = new Array(length);
coefficients[i] = l;
for (j = 0; j < length; j++) {
l[j] = [];
}
}
const zIndicesLength = length,
zIndices = new Array(zIndicesLength);
for (i = 0; i < zIndicesLength; i++) {
zIndices[i] = i;
}
let highestNonZeroCoef = length - 1;
for (s = 0; s < yStride; s++) {
for (j = 0; j < zIndicesLength; j++) {
index = zIndices[j] * yStride + s;
coefficients[s][0].push(yTable[index]);
}
for (i = 1; i < zIndicesLength; i++) {
let nonZeroCoefficients = false;
for (j = 0; j < zIndicesLength - i; j++) {
const zj = xTable[zIndices[j]];
const zn = xTable[zIndices[j + i]];
let numerator;
Iif (zn - zj <= 0) {
index = zIndices[j] * yStride + yStride * i + s;
numerator = yTable[index];
coefficients[s][i].push(numerator / factorial(i));
} else {
numerator = coefficients[s][i - 1][j + 1] - coefficients[s][i - 1][j];
coefficients[s][i].push(numerator / (zn - zj));
}
nonZeroCoefficients = nonZeroCoefficients || numerator !== 0;
}
if (!nonZeroCoefficients) {
highestNonZeroCoef = i - 1;
}
}
}
for (d = 0, len = 0; d <= len; d++) {
for (i = d; i <= highestNonZeroCoef; i++) {
const tempTerm = calculateCoefficientTerm(x, zIndices, xTable, d, i, []);
for (s = 0; s < yStride; s++) {
const coeff = coefficients[s][i][0];
result[s + d * yStride] += coeff * tempTerm;
}
}
}
return result;
};
const arrayScratch = [];
/**
* Interpolates values using Hermite Polynomial Approximation.
*
* @param {number} x The independent variable for which the dependent variables will be interpolated.
* @param {number[]} xTable The array of independent variables to use to interpolate. The values
* in this array must be in increasing order and the same value must not occur twice in the array.
* @param {number[]} yTable The array of dependent variables to use to interpolate. For a set of three
* dependent values (p,q,w) at time 1 and time 2 this should be as follows: {p1, q1, w1, p2, q2, w2}.
* @param {number} yStride The number of dependent variable values in yTable corresponding to
* each independent variable value in xTable.
* @param {number} inputOrder The number of derivatives supplied for input.
* @param {number} outputOrder The number of derivatives desired for output.
* @param {number[]} [result] An existing array into which to store the result.
*
* @returns {number[]} The array of interpolated values, or the result parameter if one was provided.
*/
HermitePolynomialApproximation.interpolate = function (
x,
xTable,
yTable,
yStride,
inputOrder,
outputOrder,
result,
) {
const resultLength = yStride * (outputOrder + 1);
if (!defined(result)) {
result = new Array(resultLength);
}
for (let r = 0; r < resultLength; r++) {
result[r] = 0;
}
const length = xTable.length;
// The zIndices array holds copies of the addresses of the xTable values
// in the range we're looking at. Even though this just holds information already
// available in xTable this is a much more convenient format.
const zIndices = new Array(length * (inputOrder + 1));
let i;
for (i = 0; i < length; i++) {
for (let j = 0; j < inputOrder + 1; j++) {
zIndices[i * (inputOrder + 1) + j] = i;
}
}
const zIndiceslength = zIndices.length;
const coefficients = arrayScratch;
const highestNonZeroCoef = fillCoefficientList(
coefficients,
zIndices,
xTable,
yTable,
yStride,
inputOrder,
);
const reservedIndices = [];
const tmp = (zIndiceslength * (zIndiceslength + 1)) / 2;
const loopStop = Math.min(highestNonZeroCoef, outputOrder);
for (let d = 0; d <= loopStop; d++) {
for (i = d; i <= highestNonZeroCoef; i++) {
reservedIndices.length = 0;
const tempTerm = calculateCoefficientTerm(
x,
zIndices,
xTable,
d,
i,
reservedIndices,
);
const dimTwo = Math.floor((i * (1 - i)) / 2) + zIndiceslength * i;
for (let s = 0; s < yStride; s++) {
const dimOne = Math.floor(s * tmp);
const coef = coefficients[dimOne + dimTwo];
result[s + d * yStride] += coef * tempTerm;
}
}
}
return result;
};
function fillCoefficientList(
coefficients,
zIndices,
xTable,
yTable,
yStride,
inputOrder,
) {
let j;
let index;
let highestNonZero = -1;
const zIndiceslength = zIndices.length;
const tmp = (zIndiceslength * (zIndiceslength + 1)) / 2;
for (let s = 0; s < yStride; s++) {
const dimOne = Math.floor(s * tmp);
for (j = 0; j < zIndiceslength; j++) {
index = zIndices[j] * yStride * (inputOrder + 1) + s;
coefficients[dimOne + j] = yTable[index];
}
for (let i = 1; i < zIndiceslength; i++) {
let coefIndex = 0;
const dimTwo = Math.floor((i * (1 - i)) / 2) + zIndiceslength * i;
let nonZeroCoefficients = false;
for (j = 0; j < zIndiceslength - i; j++) {
const zj = xTable[zIndices[j]];
const zn = xTable[zIndices[j + i]];
let numerator;
let coefficient;
if (zn - zj <= 0) {
index = zIndices[j] * yStride * (inputOrder + 1) + yStride * i + s;
numerator = yTable[index];
coefficient = numerator / CesiumMath.factorial(i);
coefficients[dimOne + dimTwo + coefIndex] = coefficient;
coefIndex++;
} else {
const dimTwoMinusOne =
Math.floor(((i - 1) * (2 - i)) / 2) + zIndiceslength * (i - 1);
numerator =
coefficients[dimOne + dimTwoMinusOne + j + 1] -
coefficients[dimOne + dimTwoMinusOne + j];
coefficient = numerator / (zn - zj);
coefficients[dimOne + dimTwo + coefIndex] = coefficient;
coefIndex++;
}
nonZeroCoefficients = nonZeroCoefficients || numerator !== 0.0;
}
if (nonZeroCoefficients) {
highestNonZero = Math.max(highestNonZero, i);
}
}
}
return highestNonZero;
}
export default HermitePolynomialApproximation;
|