import { assert } from "../../../core/assert.js";
import { Keyframe } from "../curve/Keyframe.js";

/**
 *
 * @param {AnimationCurve} curve
 * @param {number[]} values
 * @param {number[]} times
 * @param {number} component_count
 * @param {number} component_index
 */
export function curve_from_track_data_linear(
    curve,
    values,
    times,
    component_count,
    component_index
) {

    assert.isNonNegativeInteger(component_count, 'component_count');
    assert.isNonNegativeInteger(component_index, 'component_index');

    const key_count = times.length;

    for (let k = 0; k < key_count; k++) {
        const value = values[k * component_count + component_index];
        const time = times[k];

        curve.add(Keyframe.from(time, value));
    }

    for (let k = 0; k < key_count; k++) {
        curve.alignTangents(k);
    }
}