BoundingBox.h
Go to the documentation of this file.
1 #ifndef WIRECELL_BOUNDINGBOX
2 #define WIRECELL_BOUNDINGBOX
3 
4 #include "WireCellUtil/Point.h"
5 
6 
7 namespace WireCell {
8 
9  /** A bounding box parallel to the Cartesian axes.
10  */
11  class BoundingBox {
13  bool m_initialized = false;
14 
15  public:
16 
17  /// Create a bounding box without an initial point or ray
18  BoundingBox(){ m_bounds = Ray();}
19 
20  /// Create a bounding box bounding an initial point.
21  BoundingBox(const Point& initial);
22 
23  /// Create a bounding box bounding an initial ray.
24  BoundingBox(const Ray& initial);
25 
26  /// Create a bounding box from an iterator pair.
27  template<typename RayOrPointIterator>
28  BoundingBox(const RayOrPointIterator& begin, const RayOrPointIterator& end) {
29  for (auto it = begin; it != end; ++it) { (*this)(*it); }
30  }
31 
32  /// Return true if point is inside bounding box
33  bool inside(const Point& point) const;
34 
35  /// Return the ray representing the bounds.
36  const Ray& bounds() const { return m_bounds; }
37 
38  /// Enlarge bounds to hold point.
39  void operator()(const Point& p);
40 
41  /// Enlarge bounds to hold ray.
42  void operator()(const Ray& r);
43 
44  template<typename RayOrPointIterator>
45  void operator()(const RayOrPointIterator& begin, const RayOrPointIterator& end) {
46  for (auto it = begin; it != end; ++it) { (*this)(*it); }
47  }
48 
49  bool empty() const { return !m_initialized; }
50  };
51 
52 
53 }
54 
55 #endif
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:72
bool empty() const
Definition: BoundingBox.h:49
bool inside(const Point &point) const
Return true if point is inside bounding box.
Definition: BoundingBox.cxx:29
Definition: Main.h:22
p
Definition: test.py:223
BoundingBox(const RayOrPointIterator &begin, const RayOrPointIterator &end)
Create a bounding box from an iterator pair.
Definition: BoundingBox.h:28
BoundingBox()
Create a bounding box without an initial point or ray.
Definition: BoundingBox.h:18
void operator()(const RayOrPointIterator &begin, const RayOrPointIterator &end)
Definition: BoundingBox.h:45
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:67
const Ray & bounds() const
Return the ray representing the bounds.
Definition: BoundingBox.h:36
void operator()(const Point &p)
Enlarge bounds to hold point.
Definition: BoundingBox.cxx:10