Horizon
Loading...
Searching...
No Matches
bbox_accumulator.hpp
1#pragma once
2#include "common/common.hpp"
3#include <optional>
4
5namespace horizon {
6template <typename T> class BBoxAccumulator {
7 using TCoord = Coord<T>;
8 using TBB = std::pair<TCoord, TCoord>;
9
10public:
11 void accumulate(const TCoord &c)
12 {
13 if (bbox) {
14 bbox->first = TCoord::min(bbox->first, c);
15 bbox->second = TCoord::max(bbox->second, c);
16 }
17 else {
18 bbox.emplace(c, c);
19 }
20 }
21
22 void accumulate(const TBB &bb)
23 {
24 accumulate(bb.first);
25 accumulate(bb.second);
26 }
27
28 const auto &get() const
29 {
30 return bbox.value();
31 }
32
33 const TBB get_or_0() const
34 {
35 if (bbox)
36 return bbox.value();
37 else
38 return {};
39 }
40
41 const TBB get_or(const TBB &other) const
42 {
43 if (bbox)
44 return bbox.value();
45 else
46 return other;
47 }
48
49private:
50 std::optional<TBB> bbox;
51};
52} // namespace horizon
Definition bbox_accumulator.hpp:6
Your typical coordinate class.
Definition common.hpp:88
static Coord< T > min(const Coord< T > &a, const Coord< T > &b)
Definition common.hpp:158
static Coord< T > max(const Coord< T > &a, const Coord< T > &b)
Definition common.hpp:166