import { inverseLerp } from "../../../core/math/inverseLerp.js";
import { spline3_hermite } from "../../../core/math/spline/spline3_hermite.js";

/**
 *
 * @param {number} time
 * @param {Keyframe} keyframe0
 * @param {Keyframe} keyframe1
 * @return {number}
 */
export function evaluate_two_key_curve(time, keyframe0, keyframe1) {
    // convert to 0..1 region
    const normalized_time = inverseLerp(keyframe0.time, keyframe1.time, time);

    const time_distance = keyframe1.time - keyframe0.time;

    return spline3_hermite(
        normalized_time,
        keyframe0.value, keyframe1.value,
        keyframe0.outTangent * time_distance,
        keyframe1.inTangent * time_distance
    );
}