//


/**
 * Sample entire animation curve into a flat array with discrete equal intervals
 * @param {number[]|Float32Array} out
 * @param {number} out_offset
 * @param {AnimationCurve} curve
 * @param {number} sample_count
 */
export function sample_animation_curve_to_float_array(
    out,
    out_offset,
    curve,
    sample_count = out.length
) {
    const keyframes = curve.keys;
    const keyframe_count = keyframes.length;

    if (keyframe_count === 0) {
        // not data
        out.fill(0, out_offset, out_offset + sample_count);
        return;
    }

    const key_first = keyframes[0];
    const key_last = keyframes[keyframe_count - 1];

    const time_start = key_first.time;
    const time_end = key_last.time;
    const time_span = time_end - time_start;

    const multiplier = sample_count > 1 ? 1 / (sample_count - 1) : 0;

    for (let i = 0; i < sample_count; i++) {
        const f = i * multiplier;

        const t = time_start + (f * time_span);

        out[i + out_offset] = curve.evaluate(t);
    }
}
