Raytracer
Loading...
Searching...
No Matches
Interval.hpp
1#include <limits>
2#include "Common.hpp"
3
4#ifndef __INTERVAL_HPP__
5 #define __INTERVAL_HPP__
6
7namespace Raytracer::Utils
8{
9 class Interval {
10 private:
11 double _min = +std::numeric_limits<double>::infinity();
12 double _max = -std::numeric_limits<double>::infinity();
13
14 public:
15 Interval() = default;
16 Interval(double min, double max);
17 Interval(const Interval &a, const Interval &b);
18 double size() const;
19 bool contains(double x) const;
20 bool surrounds(double x) const;
21 double clamp(double x) const;
22 Interval expand(double x) const;
23 static const Interval Empty;
24 static const Interval Universe;
25 GET_SET(double, min)
26 GET_SET(double, max)
27 };
28
29 Utils::Interval operator+(const Utils::Interval &value, double offset);
30 Utils::Interval operator+(double offset, const Utils::Interval &value);
31} // namespace Raytracer::Utils
32
33#endif /* __INTERVAL_HPP__ */
Definition Interval.hpp:9
bool surrounds(double x) const
Check if the interval surrounds the given value.
Definition Interval.cpp:75
double size() const
Get the minimum value of the interval.
Definition Interval.cpp:45
double clamp(double x) const
Clamp the value to the interval.
Definition Interval.cpp:90
static const Interval Empty
A constant empty interval.
Definition Interval.hpp:23
Interval expand(double x) const
Expand the interval by the given value.
Definition Interval.cpp:105
bool contains(double x) const
Check if the interval contains the given value.
Definition Interval.cpp:60
static const Interval Universe
A constant universe interval.
Definition Interval.hpp:24