/**
 *
 * @param {Sampler2D} source
 * @param {Sampler2D} target
 * @param {number} u0
 * @param {number} v0
 * @param {number} u1
 * @param {number} v1
 */
export function sampler2d_copy_rectangle(
    source, target,
    u0, v0, u1, v1
) {

    const sample = [];

    const target_height = target.height;
    const target_width = target.width;

    const v_span = v1 - v0;
    const u_span = u1 - u0;

    const v_multiplier = v_span / target_height;
    const u_multiplier = u_span / target_width;

    for (let y = 0; y < target_height; y++) {

        const source_v = y * v_multiplier + v0;

        for (let x = 0; x < target_width; x++) {

            const source_u = x * u_multiplier + u0;

            source.sampleBilinearUV(source_u, source_v, sample);

            target.write(x, y, sample);

        }
    }

}