Skip to content

Commit 85b7201

Browse files
MichaelLettrichdavidrohr
authored andcommitted
[math_utils] Refactor CircleXY and IntervalXY
turn `CircleXY` and `IntervalXY` into template classes with respective aliases for float and double versions of each. Change affected code accordingly. Primitive2D only includes the headers containing the CircleXY and IntervalXY implementations.
1 parent abebfd1 commit 85b7201

File tree

12 files changed

+400
-186
lines changed

12 files changed

+400
-186
lines changed

Common/MathUtils/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ o2_add_library(
1616
src/Chebyshev3DCalc.cxx
1717
src/MathBase.cxx
1818
src/RandomRing.cxx
19-
src/Primitive2D.cxx
2019
PUBLIC_LINK_LIBRARIES
2120
ROOT::Hist
2221
FairRoot::Base

Common/MathUtils/include/MathUtils/Primitive2D.h

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,22 @@
1616
#define ALICEO2_COMMON_MATH_PRIMITIVE2D_H
1717

1818
#include "GPUCommonRtypes.h"
19+
#include "MathUtils/detail/CircleXY.h"
20+
#include "MathUtils/detail/IntervalXY.h"
1921

2022
namespace o2
2123
{
2224
namespace math_utils
2325
{
24-
25-
struct CircleXY {
26-
float rC, xC, yC; // circle radius, x-center, y-center
27-
CircleXY(float r = 0., float x = 0., float y = 0.) : rC(r), xC(x), yC(y) {}
28-
float getCenterD2() const { return xC * xC + yC * yC; }
29-
ClassDefNV(CircleXY, 1);
30-
};
31-
32-
struct IntervalXY {
33-
///< 2D interval in lab frame defined by its one edge and signed projection lengths on X,Y axes
34-
float xP, yP; ///< one of edges
35-
float dxP, dyP; ///< other edge minus provided
36-
IntervalXY(float x = 0, float y = 0, float dx = 0, float dy = 0) : xP(x), yP(y), dxP(dx), dyP(dy) {}
37-
float getX0() const { return xP; }
38-
float getY0() const { return yP; }
39-
float getX1() const { return xP + dxP; }
40-
float getY1() const { return yP + dyP; }
41-
float getDX() const { return dxP; }
42-
float getDY() const { return dyP; }
43-
void eval(float t, float& x, float& y) const
44-
{
45-
x = xP + t * dxP;
46-
y = yP + t * dyP;
47-
}
48-
void getLineCoefs(float& a, float& b, float& c) const;
49-
50-
void setEdges(float x0, float y0, float x1, float y1)
51-
{
52-
xP = x0;
53-
yP = y0;
54-
dxP = x1 - x0;
55-
dyP = y1 - y0;
56-
}
57-
bool seenByCircle(const CircleXY& circle, float eps) const;
58-
bool circleCrossParam(const CircleXY& cicle, float& t) const;
59-
60-
bool seenByLine(const IntervalXY& other, float eps) const;
61-
bool lineCrossParam(const IntervalXY& other, float& t) const;
62-
63-
ClassDefNV(IntervalXY, 1);
64-
};
26+
template <typename T>
27+
using CircleXY = detail::CircleXY<T>;
28+
using CircleXYf_t = CircleXY<float>;
29+
using CircleXYd_t = CircleXY<double>;
30+
31+
template <typename T>
32+
using IntervalXY = detail::IntervalXY<T>;
33+
using IntervalXYf_t = IntervalXY<float>;
34+
using IntervalXYd_t = IntervalXY<double>;
6535

6636
} // namespace math_utils
6737
} // namespace o2
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @file CircleXY.h
12+
/// @author ruben.shahoyan@cern.ch, michael.lettrich@cern.ch
13+
/// @since Oct 10, 2020
14+
/// @brief
15+
16+
#ifndef MATHUTILS_INCLUDE_MATHUTILS_DETAIL_CIRCLEXY_H_
17+
#define MATHUTILS_INCLUDE_MATHUTILS_DETAIL_CIRCLEXY_H_
18+
19+
#include "GPUCommonRtypes.h"
20+
21+
namespace o2
22+
{
23+
namespace math_utils
24+
{
25+
namespace detail
26+
{
27+
28+
template <typename T>
29+
struct CircleXY {
30+
using value_t = T;
31+
32+
T rC; // circle radius
33+
T xC; // x-center
34+
T yC; // y-center
35+
CircleXY(T r = T(), T x = T(), T y = T());
36+
T getCenterD2() const;
37+
ClassDefNV(CircleXY, 2);
38+
};
39+
40+
template <typename T>
41+
CircleXY<T>::CircleXY(T r, T x, T y) : rC(std::move(r)), xC(std::move(x)), yC(std::move(y))
42+
{
43+
}
44+
45+
template <typename T>
46+
inline T CircleXY<T>::getCenterD2() const
47+
{
48+
return xC * xC + yC * yC;
49+
}
50+
} // namespace detail
51+
} // namespace math_utils
52+
} // namespace o2
53+
54+
#endif /* MATHUTILS_INCLUDE_MATHUTILS_DETAIL_CIRCLEXY_H_ */

0 commit comments

Comments
 (0)