philomena/assets/js/utils/lerp.ts

16 lines
478 B
TypeScript
Raw Permalink Normal View History

2024-06-03 23:43:51 +02:00
// Simple linear interpolation.
// Returns a value between min and max based on a delta.
// The delta is a number between 0 and 1.
// If the delta is not within the 0-1 range, this function will
// clamp the value between min and max, depending on whether
// the delta >= 1 or <= 0.
export function lerp(delta: number, from: number, to: number): number {
2024-07-03 22:54:14 +02:00
if (delta >= 1) {
return to;
} else if (delta <= 0) {
return from;
}
2024-06-03 23:43:51 +02:00
return from + (to - from) * delta;
}