-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterval.h
More file actions
33 lines (23 loc) · 724 Bytes
/
interval.h
File metadata and controls
33 lines (23 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef RAYTRACER_INTERVAL_H
#define RAYTRACER_INTERVAL_H
#include <functional>
#include "mathutils.h"
class Interval {
public:
double min, max;
Interval(double _min, double _max) : min(_min), max(_max) {}
Interval() : min(+infinity), max(-infinity) {}
[[nodiscard]] bool contains(double x) const {
return min <= x && x <= max;
}
[[nodiscard]] bool surrounds(double x) const {
return min < x && x < max;
}
double clamp(double x) const {
return std::clamp(x, min, max);
}
static const Interval empty, universe;
};
const static Interval empty (+infinity, -infinity);
const static Interval universe (-infinity, +infinity);
#endif //RAYTRACER_INTERVAL_H