Belle II Software  release-05-02-19
BoundingBox.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <algorithm>
13 #include <cmath>
14 
15 namespace Belle2 {
20  namespace TrackFindingCDC {
21 
23  class BoundingBox {
24 
25  public:
26 
28  BoundingBox() :
29  m_left(NAN),
30  m_bottom(NAN),
31  m_right(NAN),
32  m_top(NAN)
33  {}
34 
36  BoundingBox(float x1, float y1, float x2, float y2) :
37  m_left(std::min(x1, x2)),
38  m_bottom(std::min(y1, y2)),
39  m_right(std::max(x1, x2)),
40  m_top(std::max(y1, y2))
41  {}
42 
44  void operator&=(const BoundingBox& other)
45  {
46 
47  m_left = std::isnan(getLeft()) ? other.getLeft() : std::min(getLeft(), other.getLeft());
48  m_bottom = std::isnan(getBottom()) ? other.getBottom() : std::min(getBottom(), other.getBottom());
49 
50  m_right = std::isnan(getRight()) ? other.getRight() : std::max(getRight(), other.getRight());
51  m_top = std::isnan(getTop()) ? other.getTop() : std::max(getTop(), other.getTop());
52 
53  }
54 
56  void expand(float delta)
57  {
58  m_left -= delta;
59  m_bottom -= delta;
60  m_right += delta;
61  m_top += delta;
62  }
63 
65  float getWidth() const
66  { return getRight() - getLeft(); }
67 
69  float getHeight() const
70  { return getTop() - getBottom(); }
71 
73  float getLeft() const
74  { return m_left; }
75 
77  float getBottom() const
78  { return m_bottom; }
79 
81  float getRight() const
82  { return m_right; }
83 
85  float getTop() const
86  { return m_top; }
87 
89  void clear()
90  {
91  m_left = NAN;
92  m_bottom = NAN;
93  m_right = NAN;
94  m_top = NAN;
95  }
96 
97  private:
99  float m_left;
100 
102  float m_bottom;
103 
105  float m_right;
106 
108  float m_top;
109 
110  };
111 
112  }
114 }
Belle2::TrackFindingCDC::BoundingBox::getTop
float getTop() const
Getter for the location of the top of the bounding box rectangle (upper y bound). NAN if unset.
Definition: BoundingBox.h:93
Belle2::TrackFindingCDC::BoundingBox::operator&=
void operator&=(const BoundingBox &other)
Expands the bounding box such that it also covers the given bounding box.
Definition: BoundingBox.h:52
Belle2::TrackFindingCDC::BoundingBox::BoundingBox
BoundingBox()
Default constructor for ROOT compatibility. Cell weight defaults to 1.
Definition: BoundingBox.h:36
Belle2::TrackFindingCDC::BoundingBox::getBottom
float getBottom() const
Getter for the location of the bottom of the bounding box rectangle (lower y bound)....
Definition: BoundingBox.h:85
Belle2::TrackFindingCDC::BoundingBox::m_right
float m_right
Memory for the upper x bound of the rectangle.
Definition: BoundingBox.h:113
Belle2::TrackFindingCDC::BoundingBox::m_top
float m_top
Memory for the upper y bound of the rectangle.
Definition: BoundingBox.h:116
Belle2::TrackFindingCDC::BoundingBox::m_bottom
float m_bottom
Memory for the lower y bound of the rectangle.
Definition: BoundingBox.h:110
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::BoundingBox::getWidth
float getWidth() const
Getter for the width of the bounding box rectangle.
Definition: BoundingBox.h:73
Belle2::TrackFindingCDC::BoundingBox::getHeight
float getHeight() const
Getter for the height of the bounding box rectangle.
Definition: BoundingBox.h:77
Belle2::TrackFindingCDC::BoundingBox::m_left
float m_left
Memory for the lower x bound of the rectangle.
Definition: BoundingBox.h:107
Belle2::TrackFindingCDC::BoundingBox::getRight
float getRight() const
Getter for the location of the right of the bounding box rectangle (upper x bound)....
Definition: BoundingBox.h:89
Belle2::TrackFindingCDC::BoundingBox::getLeft
float getLeft() const
Getter for the location of the left of the bounding box rectangle (lower x bound)....
Definition: BoundingBox.h:81
Belle2::TrackFindingCDC::BoundingBox::clear
void clear()
Clears all bounds to NAN.
Definition: BoundingBox.h:97
Belle2::TrackFindingCDC::BoundingBox
A two dimensional rectangle that keeps track of the extend of a drawing.
Definition: BoundingBox.h:31
Belle2::TrackFindingCDC::BoundingBox::expand
void expand(float delta)
Expands the rectangle in each direction by the given value delta.
Definition: BoundingBox.h:64