Project
Loading...
Searching...
No Matches
BBox.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef O2_MCH_CONTOUR_BBOX_H
16#define O2_MCH_CONTOUR_BBOX_H
17
18#include "Helper.h"
19#include <stdexcept>
20#include <ostream>
21
22namespace o2
23{
24namespace mch
25{
26namespace contour
27{
28
29template <typename T>
30class BBox
31{
32 public:
33 BBox(T xmin, T ymin, T xmax, T ymax) : mXmin{xmin}, mXmax{xmax}, mYmin{ymin}, mYmax{ymax}
34 {
35 if (xmin >= xmax || ymin >= ymax) {
36 throw std::invalid_argument("BBox should be created valid (xmin<xmax and ymin<ymax)");
37 }
38 }
39
40 T xmin() const { return mXmin; }
41
42 T xmax() const { return mXmax; }
43
44 T ymin() const { return mYmin; }
45
46 T ymax() const { return mYmax; }
47
48 T xcenter() const { return (xmin() + xmax()) / T{2}; }
49
50 T ycenter() const { return (ymin() + ymax()) / T{2}; }
51
52 T width() const { return xmax() - xmin(); }
53
54 T height() const { return ymax() - ymin(); }
55
56 friend bool operator==(const BBox& lhs, const BBox& rhs)
57 {
58 return impl::areEqual(lhs.xmin(), rhs.xmin()) && impl::areEqual(lhs.ymin(), rhs.ymin()) &&
59 impl::areEqual(lhs.xmax(), rhs.xmax()) && impl::areEqual(lhs.ymax(), rhs.ymax());
60 }
61
62 friend bool operator!=(const BBox& lhs, const BBox& rhs) { return !(rhs == lhs); }
63
64 friend std::ostream& operator<<(std::ostream& os, const BBox& box)
65 {
66 os << "mTopLeft: " << box.xmin() << "," << box.ymax() << " mBottomRight: " << box.xmax() << "," << box.ymin();
67 return os;
68 }
69
70 bool contains(const BBox<T>& a) const
71 {
72 return !(a.xmin() < xmin() || a.xmax() > xmax() || a.ymin() < ymin() || a.ymax() > ymax());
73 }
74
75 private:
76 T mXmin;
77 T mXmax;
78 T mYmin;
79 T mYmax;
80};
81
82template <typename T>
83BBox<T> enlarge(const BBox<T>& box, T extraWidth, T extraHeight)
84{
85 return BBox<T>(box.xmin() - extraWidth / 2.0, box.ymin() - extraHeight / 2.0, box.xmax() + extraWidth / 2.0,
86 box.ymax() + extraHeight / 2.0);
87}
88
89template <typename T>
91{
92 return BBox<T>{std::max(a.xmin(), b.xmin()), std::max(a.ymin(), b.ymin()), std::min(a.xmax(), b.xmax()),
93 std::min(a.ymax(), b.ymax())};
94}
95
96} // namespace contour
97} // namespace mch
98} // namespace o2
99
100#endif
friend bool operator==(const BBox &lhs, const BBox &rhs)
Definition BBox.h:56
T xmin() const
Definition BBox.h:40
friend std::ostream & operator<<(std::ostream &os, const BBox &box)
Definition BBox.h:64
T ymin() const
Definition BBox.h:44
friend bool operator!=(const BBox &lhs, const BBox &rhs)
Definition BBox.h:62
T xmax() const
Definition BBox.h:42
T height() const
Definition BBox.h:54
bool contains(const BBox< T > &a) const
Definition BBox.h:70
T width() const
Definition BBox.h:52
T ycenter() const
Definition BBox.h:50
T xcenter() const
Definition BBox.h:48
BBox(T xmin, T ymin, T xmax, T ymax)
Definition BBox.h:33
T ymax() const
Definition BBox.h:46
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLsizei const GLint * box
Definition glcorearb.h:4697
bool areEqual(double a, double b)
Definition Helper.h:41
BBox< T > intersect(const BBox< T > &a, const BBox< T > &b)
Definition BBox.h:90
BBox< T > enlarge(const BBox< T > &box, T extraWidth, T extraHeight)
Definition BBox.h:83
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...