Skip to content

Commit c46b0b4

Browse files
committed
add extra methods to Bracket class
1 parent 94f6d88 commit c46b0b4

File tree

1 file changed

+43
-5
lines changed
  • Common/MathUtils/include/MathUtils/detail

1 file changed

+43
-5
lines changed

Common/MathUtils/include/MathUtils/detail/Bracket.h

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#define ALICEO2_BRACKET_H
1717

1818
#include <GPUCommonRtypes.h>
19+
#ifndef GPUCA_ALIGPUCODE
20+
#include <fmt/format.h>
21+
#include <string>
22+
#endif
1923

2024
namespace o2
2125
{
@@ -60,18 +64,20 @@ class Bracket
6064
T mean() const;
6165
T delta() const;
6266

63-
void scale(T c)
64-
{
65-
mMin *= c;
66-
mMax *= c;
67-
}
67+
Bracket getOverlap(const Bracket<T>& other) const;
6868

69+
void scale(T c);
70+
bool isZeroLength() const;
6971
bool isValid() const;
7072
bool isInvalid() const;
7173
void update(T v);
7274
Relation isOutside(const Bracket<T>& t) const;
7375
Relation isOutside(T t, T tErr) const;
7476

77+
#ifndef GPUCA_ALIGPUCODE
78+
std::string asString() const;
79+
#endif
80+
7581
private:
7682
T mMin{};
7783
T mMax{};
@@ -168,21 +174,31 @@ inline T Bracket<T>::mean() const
168174
{
169175
return (mMin + mMax) / 2;
170176
}
177+
171178
template <typename T>
172179
inline T Bracket<T>::delta() const
173180
{
174181
return mMax - mMin;
175182
}
183+
176184
template <typename T>
177185
inline bool Bracket<T>::isValid() const
178186
{
179187
return mMax >= mMin;
180188
}
189+
181190
template <typename T>
182191
inline bool Bracket<T>::isInvalid() const
183192
{
184193
return mMin > mMax;
185194
}
195+
196+
template <typename T>
197+
inline bool Bracket<T>::isZeroLength() const
198+
{
199+
return mMin == mMax;
200+
}
201+
186202
template <typename T>
187203
inline void Bracket<T>::update(T v)
188204
{
@@ -195,19 +211,41 @@ inline void Bracket<T>::update(T v)
195211
}
196212
}
197213

214+
template <typename T>
215+
inline void Bracket<T>::scale(T c)
216+
{
217+
mMin *= c;
218+
mMax *= c;
219+
}
220+
221+
template <typename T>
222+
inline Bracket<T> Bracket<T>::getOverlap(const Bracket<T>& other) const
223+
{
224+
return {getMin() > other.getMin() ? getMin() : other.getMin(), getMax() < other.getMax() ? getMax() : other.getMax()};
225+
}
226+
198227
template <typename T>
199228
inline typename Bracket<T>::Relation Bracket<T>::isOutside(const Bracket<T>& t) const
200229
{
201230
///< check if provided bracket is outside of this bracket
202231
return t.mMax < mMin ? Below : (t.mMin > mMax ? Above : Inside);
203232
}
233+
204234
template <typename T>
205235
inline typename Bracket<T>::Relation Bracket<T>::isOutside(T t, T tErr) const
206236
{
207237
///< check if the provided value t with error tErr is outside of the bracket
208238
return t + tErr < mMin ? Below : (t - tErr > mMax ? Above : Inside);
209239
}
210240

241+
#ifndef GPUCA_ALIGPUCODE
242+
template <typename T>
243+
std::string Bracket<T>::asString() const
244+
{
245+
return fmt::format("[{}:{}]", getMin(), getMax());
246+
}
247+
#endif
248+
211249
} // namespace detail
212250
} // namespace math_utils
213251
} // namespace o2

0 commit comments

Comments
 (0)