-
Notifications
You must be signed in to change notification settings - Fork 945
Closed
Description
A class that operates on ranges of double
values. Use cases:
- aabb class (Refactor AABB class to use interval class #796)
- time interval (Convert time start/end to use interval class #795)
- clamp (Convert clamp() to interval::clamp() #793)
- hittable::hit() (Introduce interval class for hit() methods #786)
- moving_sphere time range (Refactor moving_sphere to use new interval class #797)
- moving_sphere center range (Refactor moving_sphere to use new interval class #797)
Here's a sketch of an interval class (not all methods below need be implemented; only those actually needed):
struct interval {
double min, max;
interval() : min(0), max(0) {}
interval(double x) : min(x), max(x) {}
interval(double _min, double _max) : min(_min), max(_max) {}
double size() const {
return max - min;
}
bool contains(double x) const {
return min <= x && x <= max;
}
double clamp(double x) const {
return (x < min) ? min
: (x > max) ? max
: x;
}
interval hull(const interval& other) const {
return interval(std::min(min, other.min), std::max(max, other.max));
}
interval intersect(const interval& other) const {
return interval(std::max(min, other.min), std::min(max, other.max));
}
static interval empty = interval(+std::numeric_limits::infinity, -std::numeric_limits::infinity);
static interval universe = interval(-std::numeric_limits::infinity, +std::numeric_limits::infinity);
}
This class could also support transforms, such as scale, translate, whatever.