package eu.jonahbauer.raytracing.math;

public record Range(double min, double max) {
    public static final Range EMPTY = new Range(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY);
    public static final Range UNIVERSE = new Range(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    public static final Range NON_NEGATIVE = new Range(0, Double.POSITIVE_INFINITY);

    public Range {
        if (Double.isNaN(min) || Double.isNaN(max)) throw new IllegalArgumentException("min and max must not be NaN");
    }

    public boolean contains(double value) {
        return min <= value && value <= max;
    }

    public boolean surrounds(double value) {
        return min < value && value < max;
    }
}
