9#include <tracking/trackFindingCDC/geometry/GeneralizedCircle.h>
10#include <tracking/trackFindingCDC/geometry/Vector2D.h>
12#include <gtest/gtest.h>
15using namespace TrackFindingCDC;
17TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_Getters)
19 float absError = 10e-6;
28 EXPECT_NEAR(n0, circle.n0(), absError);
29 EXPECT_NEAR(n1, circle.n1(), absError);
30 EXPECT_NEAR(n2, circle.n2(), absError);
31 EXPECT_NEAR(n3, circle.n3(), absError);
33 EXPECT_NEAR(2.0 * n3, circle.curvature(), absError);
34 EXPECT_NEAR(1.0 / (2.0 * n3), circle.radius(), absError);
36 EXPECT_NEAR(M_PI / 2.0, circle.tangentialPhi(), absError);
38 EXPECT_NEAR(0, circle.impact(), absError);
41TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_orientation)
44 EXPECT_EQ(ERotation::c_CounterClockwise, circle.orientation());
47 EXPECT_EQ(ERotation::c_Clockwise, reversedCircle.orientation());
50 EXPECT_EQ(ERotation::c_CounterClockwise, line.orientation());
53 EXPECT_EQ(ERotation::c_Clockwise, reversedLine.orientation());
56TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_conformalTranform)
66 EXPECT_NEAR(1.0, circle.
curvature(), 10e-7);
68 EXPECT_NEAR(0.0, circle.
impact(), 10e-7);
69 EXPECT_NEAR(0.0, circle.
distance(firstPos), 10e-7);
70 EXPECT_NEAR(0.0, circle.
distance(secondPos), 10e-7);
76 EXPECT_NEAR(0.0, circle.
curvature(), 10e-7);
78 EXPECT_NEAR(-1.0 / 2.0, circle.
impact(), 10e-7);
80 double firstConformalArcLength = circle.
arcLengthTo(firstPos);
81 double secondConformalArcLength = circle.
arcLengthTo(secondPos);
82 EXPECT_TRUE(firstConformalArcLength < secondConformalArcLength);
83 EXPECT_LT(firstConformalArcLength, secondConformalArcLength);
85 EXPECT_NEAR(0.0, circle.
distance(firstPos), 10e-7);
86 EXPECT_NEAR(0.0, circle.
distance(secondPos), 10e-7);
90 EXPECT_NEAR(1.0, conformalCopy.
curvature(), 10e-7);
91 EXPECT_NEAR(-M_PI / 2.0, conformalCopy.
tangentialPhi(), 10e-7);
92 EXPECT_NEAR(0.0, conformalCopy.
impact(), 10e-7);
95TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_closest)
105 double smallAngle = M_PI / 100;
106 Vector2D near(1.0 - cos(smallAngle), sin(smallAngle));
109 EXPECT_NEAR(near.x(), closestOfNear.
x(), 10e-7);
110 EXPECT_NEAR(near.y(), closestOfNear.
y(), 10e-7);
113TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_arcLengthFactor)
116 double smallAngle = M_PI / 100;
117 Vector2D near(1.0 - cos(smallAngle), sin(smallAngle));
119 double expectedArcLengthFactor = smallAngle / near.cylindricalR();
120 EXPECT_NEAR(expectedArcLengthFactor, circle.
arcLengthFactor(near.cylindricalR()), 10e-7);
123TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_arcLengthBetween)
131 double smallAngle = M_PI / 100;
132 Vector2D close(1.0 - cos(smallAngle), sin(smallAngle));
146 EXPECT_NEAR(-2, line.arcLengthBetween(origin, up), 10e-7);
147 EXPECT_NEAR(2, line.arcLengthBetween(origin, down), 10e-7);
148 EXPECT_NEAR(0, line.arcLengthBetween(origin, far), 10e-7);
151 EXPECT_NEAR(2, reverseLine.arcLengthBetween(origin, up), 10e-7);
152 EXPECT_NEAR(-2, reverseLine.arcLengthBetween(origin, down), 10e-7);
153 EXPECT_NEAR(0, reverseLine.arcLengthBetween(origin, far), 10e-7);
156TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_passiveMoveBy)
164 EXPECT_NEAR(5.0, circle.
radius(), 10e-7);
165 EXPECT_NEAR(1.0, circle.
center().
x(), 10e-7);
166 EXPECT_NEAR(-1.0, circle.
center().
y(), 10e-7);
169TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_intersections)
175 std::pair<Vector2D, Vector2D> intersections = circle.
intersections(line);
180 EXPECT_NEAR(1 -
sqrt(2.0) / 2.0, intersection1.
x(), 10e-7);
181 EXPECT_NEAR(1 +
sqrt(2.0) / 2.0, intersection1.
y(), 10e-7);
183 EXPECT_NEAR(1 +
sqrt(2.0) / 2.0, intersection2.
x(), 10e-7);
184 EXPECT_NEAR(1 -
sqrt(2.0) / 2.0, intersection2.
y(), 10e-7);
187TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_atArcLength)
194 double smallAngle = M_PI / 100;
195 Vector2D near(2.0 - cos(smallAngle), sin(smallAngle));
197 double nearArcLength =
198 -smallAngle * radius;
202 EXPECT_NEAR(near.x(), atNear.
x(), 10e-7);
203 EXPECT_NEAR(near.y(), atNear.
y(), 10e-7);
206 double downArcLength =
207 +M_PI / 2.0 * radius;
211 EXPECT_NEAR(down.x(), atDown.
x(), 10e-7);
212 EXPECT_NEAR(down.y(), atDown.
y(), 10e-7);
215TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_arcLengthToCylindricalR)
223 EXPECT_NEAR(0, closestArcLength, 10e-7);
226 EXPECT_NEAR(M_PI, widestArcLength, 10e-7);
229 EXPECT_NEAR(M_PI / 2, halfArcLength, 10e-7);
232 EXPECT_TRUE(std::isnan(unreachableHighArcLength));
235 EXPECT_TRUE(std::isnan(unreachableLowArcLength));
241 EXPECT_NEAR(0, closestArcLength, 10e-7);
244 EXPECT_NEAR(M_PI, widestArcLength, 10e-7);
247 EXPECT_NEAR(M_PI / 2, halfArcLength, 10e-7);
250 EXPECT_TRUE(std::isnan(unreachableHighArcLength));
253 EXPECT_TRUE(std::isnan(unreachableLowArcLength));
257TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_atCylindricalR)
265 EXPECT_NEAR(2, solutions.first.x(), 10e-7);
266 EXPECT_NEAR(1, solutions.first.y(), 10e-7);
268 EXPECT_NEAR(2, solutions.second.x(), 10e-7);
269 EXPECT_NEAR(-1, solutions.second.y(), 10e-7);
272TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_isLine)
278 EXPECT_FALSE(circle.
isLine());
281 float phi0 = M_PI / 2;
285 EXPECT_TRUE(line.isLine());
288TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_isCircle)
297 float phi0 = M_PI / 2;
301 EXPECT_FALSE(line.isCircle());
304TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_perigeeConversion)
306 float curvature = -0.5;
307 float phi0 = M_PI / 2;
311 EXPECT_NEAR(impact, circle.
impact(), 10e-7);
313 EXPECT_NEAR(curvature, circle.
curvature(), 10e-7);
316TEST(TrackFindingCDCTest, geometry_GeneralizedCircle_distance)
318 float absError = 10e-6;
327 EXPECT_NEAR(1, circle.
distance(testPoint), absError);
328 EXPECT_NEAR(1, circle.
absDistance(testPoint), absError);
331 EXPECT_NEAR(1.33333, circle.
fastDistance(testPoint), absError);
336 EXPECT_NEAR(-1, circle.
distance(testPoint), absError);
337 EXPECT_NEAR(1, circle.
absDistance(testPoint), absError);
338 EXPECT_NEAR(-1.33333, circle.
fastDistance(testPoint), absError);
Vector2D atArcLength(double arcLength) const
Calculates the point, which lies at the give perpendicular travel distance (counted from the perigee)
double fastDistance(const Vector2D &point) const
Approximate distance.
double absDistance(const Vector2D &point) const
Gives the proper absolute distance of the point to the circle line.
bool isLine() const
Indicates if the generalized circle is actually a line.
GeneralizedCircle reversed() const
Returns a copy of the circle with opposite orientation.
double arcLengthBetween(const Vector2D &from, const Vector2D &to) const
Calculates the arc length between two points of closest approach on the circle.
void reverse()
Flips the orientation of the circle in place.
double radius() const
Gives the signed radius of the circle. If it was a line this will be infinity.
double distance(const Vector2D &point) const
Gives the proper distance of the point to the circle line retaining the sign of the fast distance.
void passiveMoveBy(const Vector2D &by)
Moves the coordinate system by the given vector.
double impact() const
Gives the signed distance of the origin to the circle.
Vector2D center() const
Gives the center of the circle. If it was a line both components will be infinity.
static GeneralizedCircle fromPerigeeParameters(double curvature, const Vector2D &tangential, double impact)
Constructor of a generalized circle from perigee parameters.
void conformalTransform()
Transforms the generalized circle to conformal space inplace Applies the conformal map in the self-in...
static GeneralizedCircle fromCenterAndRadius(const Vector2D ¢er, double absRadius, ERotation orientation=ERotation::c_CounterClockwise)
Constructor from center, radius and a optional orientation.
bool isCircle() const
Indicates if the generalized circle is actually a circle.
double arcLengthTo(const Vector2D &to) const
Calculates the arc length between the perigee and the given point.
double curvature() const
Gives the signed curvature of the generalized circle.
Vector2D closest(const Vector2D &point) const
Closest approach on the circle to the point.
double arcLengthFactor(const double directDistance) const
Helper function the calculate the factor between the length of a secant line and the length on the ar...
std::pair< Belle2::TrackFindingCDC::Vector2D, Belle2::TrackFindingCDC::Vector2D > atCylindricalR(double cylindricalR) const
Calculates the two points with the given cylindrical radius on the generalised circle.
double tangentialPhi() const
Gives to azimuth angle phi of the direction of flight at the perigee.
double arcLengthToCylindricalR(double cylindricalR) const
Calculates the two dimensional arc length till the cylindrical radius is reached If the radius can no...
std::pair< Vector2D, Vector2D > intersections(const GeneralizedCircle &generalizedCircle) const
Calculates the two points common to both circles.
GeneralizedCircle conformalTransformed() const
Returns a copy of the circle in conformal space.
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
double x() const
Getter for the x coordinate.
void conformalTransform()
Transforms the vector to conformal space inplace.
double second() const
Getter for the second coordinate.
double y() const
Getter for the y coordinate.
double first() const
Getter for the first coordinate.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.