Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Interval.hpp
Go to the documentation of this file.
1#ifndef PHYTH_INTERVAL_HPP
2#define PHYTH_INTERVAL_HPP
3
4#include <stdexcept>
5
6#include "Quantity.hpp"
7#include "Unit.hpp"
8
9namespace Phyth {
19 template<typename UnitT>
20 struct Interval {
21 static_assert(is_unit_v<UnitT>, "Interval requires a Unit type as template parameter");
22
29 : min_(value), max_(value) {
30 }
31
40 : min_(min), max_(max) {
41 if (min_ > max_) {
42 throw std::invalid_argument("Interval: min must be less than max");
43 }
44 }
45
52 bool Contains(Quantity<UnitT> x) const noexcept {
53 return min_ <= x && x <= max_;
54 }
55
62 bool Contains(const Interval &interval) const noexcept {
63 return interval.max_ <= max_ && interval.min_ >= min_;
64 }
65
68
71
72 private:
75 };
76}
77
78#endif // PHYTH_INTERVAL_HPP
constexpr bool is_unit_v
Definition Unit.hpp:79
Closed interval [min, max] of physical quantities.
Definition Interval.hpp:20
Quantity< UnitT > max_
Definition Interval.hpp:74
bool Contains(const Interval &interval) const noexcept
Check if another interval is fully contained in this one.
Definition Interval.hpp:62
Interval(Quantity< UnitT > min, Quantity< UnitT > max)
Construct a closed interval [min, max].
Definition Interval.hpp:39
Quantity< UnitT > GetMaximum() const noexcept
Definition Interval.hpp:70
Interval(Quantity< UnitT > value) noexcept
Construct a zero-length interval containing a single value.
Definition Interval.hpp:28
bool Contains(Quantity< UnitT > x) const noexcept
Check if a value lies within the interval.
Definition Interval.hpp:52
Quantity< UnitT > GetMinimum() const noexcept
Definition Interval.hpp:67
Quantity< UnitT > min_
Definition Interval.hpp:73
Physical quantity with a value and a compile-time unit.
Definition Quantity.hpp:27