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 | 8x 8x | export interface Span {
start: number;
end: number;
}
/**
* Implements linear interpolation (lerp).
*
* Calculates such a linear mapping `R -> R` that `from.start` will be mapped
* into `to.start`, and `from.end` will be mapped to `to.end`. Then applies
* this mapping to `value`.
* @param from Interpolation domain
* @param to Interpolation target
* @param value Value from domain
* @returns Value from target
*/
export function lerp(from: Span, to: Span, value: number): number {
return to.start + ((value - from.start) * (to.end - to.start)) / (from.end - from.start);
}
/**
* Calculates a lerp scale coefficient
* @param from Interpolation domain
* @param to Interpolation target
* @returns Scale coefficient
*/
export function getLerpCoeff(from: Span, to: Span): number {
return (to.end - to.start) / (from.end - from.start);
}
|