package eu.jonahbauer.raytracing.render.texture;

import eu.jonahbauer.raytracing.math.Vec3;
import org.jetbrains.annotations.NotNull;

public record CheckerTexture(double scale, @NotNull Texture even, @NotNull Texture odd) implements Texture {


    @Override
    public @NotNull Color get(double u, double v, @NotNull Vec3 p) {
        var x = (int) Math.floor(p.x() / scale);
        var y = (int) Math.floor(p.y() / scale);
        var z = (int) Math.floor(p.z() / scale);
        var even = (x + y + z) % 2 == 0;
        return even ? even().get(u, v, p) : odd().get(u, v, p);
    }
}
