-
Notifications
You must be signed in to change notification settings - Fork 7
/
interval.h
40 lines (28 loc) · 959 Bytes
/
interval.h
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
#pragma once
#include <optional>
#include <string>
namespace cz {
struct Interval {
static Interval Lower(double other_lower);
static Interval Upper(double other_upper);
void IntersectLower(double other_lower);
void IntersectUpper(double other_upper);
void Intersect(const Interval&);
// Both |has_value()| && same |value()|.
bool HasSameUpper(const Interval&) const;
bool HasSameLower(const Interval&) const;
bool operator==(const Interval&) const;
bool HasStricterUpper(const Interval&) const;
bool HasStricterLower(const Interval&) const;
bool HasValue() const;
bool Contains(double v) const;
// Has non-empty intersection.
bool Overlaps(const Interval&) const;
// Has empty intersection but the same lower-upper.
bool Adjacents(const Interval&) const;
double ClosestTo(double v) const;
std::string ToDebugString() const;
std::optional<double> lower;
std::optional<double> upper;
};
} // namespace cz