package eu.jonahbauer.raytracing.scene.hittable2d;

import eu.jonahbauer.raytracing.math.BoundingBox;
import eu.jonahbauer.raytracing.math.Vec3;
import eu.jonahbauer.raytracing.render.material.Material;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

public final class Triangle extends Hittable2D {

    public Triangle(@NotNull Vec3 origin, @NotNull Vec3 u, @NotNull Vec3 v, @NotNull Material material) {
        super(origin, u, v, material);
    }

    @Override
    protected boolean isInterior(double alpha, double beta) {
        return 0 <= alpha && 0 <= beta && alpha + beta <= 1;
    }

    @Override
    public @NotNull Optional<BoundingBox> getBoundingBox() {
        var a = origin;
        var b = origin.plus(u).plus(v);
        return Optional.of(new BoundingBox(Vec3.min(a, b), Vec3.max(a, b)));
    }
}
