import { assert } from "../../../../core/assert.js";
import { AbstractCellFilterSampleGridLayer } from "./AbstractCellFilterSampleGridLayer.js";

export class CellFilterSampleLayerCubic extends AbstractCellFilterSampleGridLayer {

    /**
     *
     * @param {string} layer
     * @returns {CellFilterSampleLayerCubic}
     */
    static from(layer) {
        assert.isString(layer, 'layer');

        const r = new CellFilterSampleLayerCubic();

        r.layerId = layer;

        return r;
    }

    execute(grid, x, y, rotation) {

        //convert to UV
        const sampler_x = x * this.__u_scale;
        const sampler_y = y * this.__v_scale;


        /**
         *
         * @type {Sampler2D}
         */
        const sampler = this.__sampler;

        return sampler.sampleChannelBicubic(sampler_x, sampler_y, 0);
    }
}
