add Range to optimize Shape#hit
parent
5e52db65d4
commit
7757b3d573
@ -0,0 +1,19 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue