forked from mockingbirdnest/Principia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterval_body.hpp
More file actions
46 lines (35 loc) · 984 Bytes
/
interval_body.hpp
File metadata and controls
46 lines (35 loc) · 984 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
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include "geometry/interval.hpp"
#include <algorithm>
#include "boost/multiprecision/number.hpp"
#include "glog/logging.h"
namespace principia {
namespace geometry {
namespace _interval {
namespace internal {
using namespace boost::multiprecision;
template<typename T>
Difference<T> Interval<T>::measure() const {
return max >= min ? max - min : Difference<T>{};
}
template<typename T>
bool Interval<T>::empty() const {
return max <= min;
}
template<typename T>
T Interval<T>::midpoint() const {
return max >= min ? min + measure() / 2 : min + NaN<Difference<T>>;
}
template<typename T>
void Interval<T>::Include(T const& x) {
min = std::min(min, x);
max = std::max(max, x);
}
template<typename T>
std::ostream& operator<<(std::ostream& out, Interval<T> const& interval) {
return out << interval.midpoint() << " ± " << interval.measure() / 2;
}
} // namespace internal
} // namespace _interval
} // namespace geometry
} // namespace principia