import { CellMatcher } from "./CellMatcher.js";

export class CellMatcherFromFilter extends CellMatcher {

    /**
     *
     * @type {CellFilter|null}
     */
    filter = null;

    /**
     *
     * @param {CellFilter} f
     * @returns {CellMatcherFromFilter}
     */
    static from(f) {
        const r = new CellMatcherFromFilter();

        r.filter = f;

        return r;
    }

    initialize(grid, seed) {
        if (!this.filter.initialized) {
            this.filter.initialize(grid, seed);
        }
    }

    match(grid, x, y, rotation) {
        const v = this.filter.execute(grid, x, y, rotation);

        return v > 0;
    }
}
