package eu.jonahbauer.raytracing.scene;

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

import java.util.Objects;

public record HitResult(
        double t, @NotNull Vec3 position, @NotNull Vec3 normal,
        @NotNull Material material, double u, double v, boolean isFrontFace
) implements Comparable<HitResult> {
    public HitResult {
        Objects.requireNonNull(position, "position");
        normal = normal.unit();
    }

    public @NotNull HitResult withPositionAndNormal(@NotNull Vec3 position, @NotNull Vec3 normal) {
        return new HitResult(t, position, normal, material, u, v, isFrontFace);
    }

    @Override
    public int compareTo(@NotNull HitResult o) {
        return Double.compare(t, o.t);
    }
}
