/**
 * One-dimensional cubic curve conversion from Hermite to bezier
 * @param {Float32Array|number[]} result where to put results
 * @param {number} result_offset offset to start writing at in result array
 * @param {number} result_stride how far to step between each written value. Necessary for N-dimensional curves where we want to interleave multiple curves together, such as for color or quaternions
 * @param {number} p0
 * @param {number} p1
 * @param {number} m0 tangent at p0
 * @param {number} m1 tangent at p1
 * @see spline3_bezier_to_hermite
 */
export function spline3_hermite_to_bezier(
    result,
    result_offset,
    result_stride,
    p0, p1,
    m0, m1
) {

    // see https://stackoverflow.com/questions/42574940/draw-hermite-curve-on-browser-canvas-javascript
    // see https://pomax.github.io/bezierinfo/#catmullconv
    // see https://github.com/haiku/haiku/blob/eb5f74847eb9d7e1cbfa484064b35f833102f9c5/headers/libs/agg/agg_curves.h#L340

    const TENSION_FACTOR = 3;

    result[result_offset + 0 * result_stride] = p0;
    result[result_offset + 1 * result_stride] = p0 + m0 / TENSION_FACTOR;
    result[result_offset + 2 * result_stride] = p1 - m1 / TENSION_FACTOR;
    result[result_offset + 3 * result_stride] = p1;

}

