Belle II Software development
BoundingBox.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <algorithm>
11#include <cmath>
12
13namespace Belle2 {
18 namespace TrackFindingCDC {
19
22
23 public:
24
27 m_left(NAN),
28 m_bottom(NAN),
29 m_right(NAN),
30 m_top(NAN)
31 {}
32
34 BoundingBox(float x1, float y1, float x2, float y2) :
35 m_left(std::min(x1, x2)),
36 m_bottom(std::min(y1, y2)),
37 m_right(std::max(x1, x2)),
38 m_top(std::max(y1, y2))
39 {}
40
42 void operator&=(const BoundingBox& other)
43 {
44
45 m_left = std::isnan(getLeft()) ? other.getLeft() : std::min(getLeft(), other.getLeft());
46 m_bottom = std::isnan(getBottom()) ? other.getBottom() : std::min(getBottom(), other.getBottom());
47
48 m_right = std::isnan(getRight()) ? other.getRight() : std::max(getRight(), other.getRight());
49 m_top = std::isnan(getTop()) ? other.getTop() : std::max(getTop(), other.getTop());
50
51 }
52
54 void expand(float delta)
55 {
56 m_left -= delta;
57 m_bottom -= delta;
58 m_right += delta;
59 m_top += delta;
60 }
61
63 float getWidth() const
64 { return getRight() - getLeft(); }
65
67 float getHeight() const
68 { return getTop() - getBottom(); }
69
71 float getLeft() const
72 { return m_left; }
73
75 float getBottom() const
76 { return m_bottom; }
77
79 float getRight() const
80 { return m_right; }
81
83 float getTop() const
84 { return m_top; }
85
87 void clear()
88 {
89 m_left = NAN;
90 m_bottom = NAN;
91 m_right = NAN;
92 m_top = NAN;
93 }
94
95 private:
97 float m_left;
98
100 float m_bottom;
101
103 float m_right;
104
106 float m_top;
107
108 };
109
110 }
112}
A two dimensional rectangle that keeps track of the extend of a drawing.
Definition: BoundingBox.h:21
float m_left
Memory for the lower x bound of the rectangle.
Definition: BoundingBox.h:97
BoundingBox(float x1, float y1, float x2, float y2)
Initialises the bounds of the rectangle to the given values. Automatically swaps the x or y values if...
Definition: BoundingBox.h:34
BoundingBox()
Default constructor for ROOT compatibility. Cell weight defaults to 1.
Definition: BoundingBox.h:26
void expand(float delta)
Expands the rectangle in each direction by the given value delta.
Definition: BoundingBox.h:54
float getBottom() const
Getter for the location of the bottom of the bounding box rectangle (lower y bound)....
Definition: BoundingBox.h:75
float getRight() const
Getter for the location of the right of the bounding box rectangle (upper x bound)....
Definition: BoundingBox.h:79
float getTop() const
Getter for the location of the top of the bounding box rectangle (upper y bound). NAN if unset.
Definition: BoundingBox.h:83
void operator&=(const BoundingBox &other)
Expands the bounding box such that it also covers the given bounding box.
Definition: BoundingBox.h:42
float getWidth() const
Getter for the width of the bounding box rectangle.
Definition: BoundingBox.h:63
float m_bottom
Memory for the lower y bound of the rectangle.
Definition: BoundingBox.h:100
void clear()
Clears all bounds to NAN.
Definition: BoundingBox.h:87
float getLeft() const
Getter for the location of the left of the bounding box rectangle (lower x bound)....
Definition: BoundingBox.h:71
float m_top
Memory for the upper y bound of the rectangle.
Definition: BoundingBox.h:106
float getHeight() const
Getter for the height of the bounding box rectangle.
Definition: BoundingBox.h:67
float m_right
Memory for the upper x bound of the rectangle.
Definition: BoundingBox.h:103
Abstract base class for different kinds of events.
STL namespace.