10#include <tracking/trackFindingCDC/numerics/Quadratic.h>
12#include <tracking/trackFindingCDC/numerics/EForwardBackward.h>
13#include <tracking/trackFindingCDC/numerics/ERightLeft.h>
14#include <tracking/trackFindingCDC/numerics/ERotation.h>
15#include <tracking/trackFindingCDC/numerics/ESign.h>
27 namespace TrackFindingCDC {
55 Vector2D(
const Vector2D& coordinateVec,
const double parallelCoor,
const double orthoCoor)
56 :
m_x(coordinateVec.
x() * parallelCoor - coordinateVec.
y() * orthoCoor)
57 ,
m_y(coordinateVec.
y() * parallelCoor + coordinateVec.
x() * orthoCoor)
74 compose(
const Vector2D& coordinateVec,
const double parallelCoor,
const double orthoCoor)
76 return Vector2D(coordinateVec, parallelCoor, orthoCoor);
91 return Vector2D((one.
x() + two.
x()) / 2.0, (one.
y() + two.
y()) / 2.0);
106 }
else if (two.
hasNAN()) {
108 }
else if (three.
hasNAN()) {
111 return Vector2D((one.
x() + two.
x() + three.
x()) / 3.0,
112 (one.
y() + two.
y() + three.
y()) / 3.0);
119 return x() == rhs.
x() and
y() == rhs.
y();
145 return x() == 0.0 and
y() == 0.0;
151 return std::isnan(
x()) or std::isnan(
y());
160 return x() * rhs.
x() +
y() * rhs.
y();
165 return x() * rhs.
y() -
y() * rhs.
x();
171 return x() *
x() +
y() *
y();
177 return hypot2(
x(),
y());
206 double deltaX =
x() - rhs.x();
207 double deltaY =
y() - rhs.y();
208 return hypot2(deltaX, deltaY);
221 return scale(factor);
233 return vec2D.
scaled(factor);
247 return divide(denominator);
253 return Vector2D(
x() / denominator,
y() / denominator);
297 return isValid(ccwInfo) ?
Vector2D(-
static_cast<double>(ccwInfo) *
y(),
static_cast<double>(ccwInfo) *
x()) :
Vector2D();
305 double originalLength =
norm();
306 if (originalLength != 0.0)
divide(originalLength);
307 return originalLength;
315 double originalLength =
norm();
316 if (originalLength != 0.0)
scale(toLength / originalLength);
317 return originalLength;
413 return relativTo.
dot(*
this) / relativTo.
norm();
427 return relativTo.
dot(*
this);
434 return relativTo.
cross(*
this) / relativTo.
norm();
448 return relativTo.
cross(*
this);
481 return isCCWOrCWOf(rhs) == ERotation::c_CounterClockwise;
516 return ((n1 > 0 and n2 > 0 and n3 > 0) or (n1 < 0 and n2 < 0 and n3 < 0));
533 double det = lower.
cross(upper);
538 bool flipsOrientation = det < 0;
540 double transformedX =
cross(upper);
541 double transformedY = -
cross(lower);
542 bool inFirstQuadrant =
sameSign(det, transformedX, transformedY);
543 if (flipsOrientation) {
544 inFirstQuadrant = not inFirstQuadrant;
546 return inFirstQuadrant;
559 return hypot2(
x(),
y());
571 return isNull() ? NAN : atan2(
y(),
x());
671 std::ostream& operator<<(std::ostream& output,
const Vector2D& vector2D);
A two dimensional vector which is equipped with functions for correct handling of orientation relate...
void setSecond(const double second)
Setter for the second coordinate.
double normalize()
Normalizes the vector to unit length.
void swapCoordinates()
Swaps the coordinates in place.
Vector2D & divide(const double denominator)
Divides all coordinates by a common denominator in place.
double parallelComp(const Vector2D &relativTo) const
Calculates the component parallel to the given vector.
void flipSecond()
Flips the first coordinate inplace (no difference between active and passive)
Vector2D(const Vector2D &coordinateVec, const double parallelCoor, const double orthoCoor)
Constructs a vector from a unit coordinate system vector and the coordinates in that system.
std::string __str__() const
Output operator for python.
Vector2D & operator-=(const Vector2D &rhs)
Same as subtract()
Vector2D flippedSecond() const
Makes a copy of the vector with the second coordinate flipped (no difference between active and passi...
double normalizeTo(const double toLength)
Normalizes the vector to the given length.
Vector2D(const double x, const double y)
Constructor from two coordinates.
Vector2D & scale(const double factor)
Scales the vector in place by the given factor.
static Vector2D compose(const Vector2D &coordinateVec, const double parallelCoor, const double orthoCoor)
Constructs a vector from a unit coordinate system vector and the coordinates in that system.
Vector2D operator-(const Vector2D &rhs) const
Returns a new vector as differenc of this and rhs.
double dot(const Vector2D &rhs) const
Calculates the two dimensional dot product.
static Vector2D average(const Vector2D &one, const Vector2D &two)
Constructs the average of two vectors.
Vector2D reversed() const
Returns a vector pointing in the opposite direction.
void setXY(const double x, const double y)
Setter for both coordinate.
static bool sameSign(float n1, float n2, float n3)
Check if three values have the same sign.
Vector2D & add(const Vector2D &rhs)
Adds a vector to this in place.
Vector2D scaled(const double factor) const
Returns a scaled copy of the vector.
void set(const double first, const double second)
Setter for both coordinate.
double distance(const Vector2D &rhs=Vector2D(0.0, 0.0)) const
Calculates the distance of this point to the rhs.
double cylindricalR() const
Gives the cylindrical radius of the vector. Same as norm()
double unnormalizedParallelComp(const Vector2D &relativTo) const
Same as parallelComp() but assumes the given vector to be of unit length.
double cosWith(const Vector2D &rhs) const
void flipFirst()
Flips the first coordinate inplace (no difference between active and passive)
void passiveMoveBy(const Vector2D &by)
Passivelly moves the vector inplace by the given vector.
Vector2D orthogonalVector(const Vector2D &relativTo) const
Calculates the part of this vector that is parallel to the given vector.
Vector2D operator-() const
Same as reversed()
EForwardBackward isForwardOrBackwardOf(const Vector2D &rhs) const
Indicates if the given vector is more coaligned or reverse if you looked in the direction of this vec...
ERotation isCCWOrCWOf(const Vector2D &rhs) const
Indicates if the given vector is more counterclockwise or more clockwise if you looked in the directi...
void set(const Vector2D &both)
Setter for both coordinate by an other vector.
Vector2D flippedFirst() const
Makes a copy of the vector with the first coordinate flipped (no difference between active and passiv...
friend Vector2D operator*(const Vector2D &vec2D, const double factor)
Same as scaled()
Vector2D operator+(const Vector2D &rhs) const
Returns a new vector as sum of this and rhs.
double cross(const Vector2D &rhs) const
Calculated the two dimensional cross product.
Vector2D & operator*=(const double factor)
Same as scale()
Vector2D & reverse()
Reverses the direction of the vector in place.
double m_x
Memory for the first coordinate.
Vector2D orthogonal(const ERotation ccwInfo) const
Orthogonal vector to the direction given by the counterclockwise info.
Vector2D()
Default constructor for ROOT compatibility.
ERightLeft isRightOrLeftOf(const Vector2D &rhs) const
Indicates if the given vector is more left or more right if you looked in the direction of this vecto...
Vector2D operator/(const double denominator) const
Same as divided()
double x() const
Getter for the x coordinate.
double sinWith(const Vector2D &rhs) const
Sine of the angle between this and rhs.
Vector2D & subtract(const Vector2D &rhs)
Subtracts a vector from this in place.
Vector2D conformalTransformed() const
Returns a copy of the vector transformed in conformal space.
Vector2D & operator/=(const double denominator)
Same as divide()
bool isRightOf(const Vector2D &rhs) const
Indicates if the given vector is more right if you looked in the direction of this vector.
void conformalTransform()
Transforms the vector to conformal space inplace.
bool isCCWOf(const Vector2D &rhs) const
Indicates if the given vector is more counterclockwise if you looked in the direction of this vector.
double orthogonalComp(const Vector2D &relativTo) const
Calculates the component orthogonal to the given vector.
void setCylindricalR(const double cylindricalR)
Set the cylindrical radius while keeping the azimuth angle phi the same.
Vector2D & operator+=(const Vector2D &rhs)
Same as add()
static Vector2D average(const Vector2D &one, const Vector2D &two, const Vector2D &three)
Constructs the average of three vectors.
bool isBetween(const Vector2D &lower, const Vector2D &upper) const
Checks if this vector is between two other vectors Between means here that when rotating the lower ve...
double phi() const
Gives the azimuth angle being the angle to the x axes ( range -M_PI to M_PI )
bool operator==(const Vector2D &rhs) const
Equality comparison with both coordinates.
static Vector2D getLowest()
Getter for the lowest possible vector.
Vector2D parallelVector(const Vector2D &relativTo) const
Calculates the part of this vector that is parallel to the given vector.
double second() const
Getter for the second coordinate.
void setXY(const Vector2D &xy)
Setter for both coordinate by an other vector.
double normSquared() const
Calculates .
bool isNull() const
Checks if the vector is the null vector.
Vector2D orthogonal() const
Orthogonal vector to the counterclockwise direction.
bool hasNAN() const
Checks if one of the coordinates is NAN.
Vector2D divided(const double denominator) const
Returns a copy where all coordinates got divided by a common denominator.
void setY(const double y)
Setter for the y coordinate.
double y() const
Getter for the y coordinate.
double first() const
Getter for the first coordinate.
Vector2D flippedOver(const Vector2D &reflectionLine) const
Reflects this vector over line designated by the given vector.
Vector2D flippedAlong(const Vector2D &flippingDirection) const
Reflects this vector along line designated by the given vector.
Vector2D unit() const
Returns a unit vector colaligned with this.
double angleWith(const Vector2D &rhs) const
The angle between this and rhs.
double norm() const
Calculates the length of the vector.
Vector2D passiveRotatedBy(const Vector2D &phiVec) const
Returns a transformed vector version rotated by the given vector.
double m_y
Memory for the second coordinate.
bool isLeftOf(const Vector2D &rhs) const
Indicates if the given vector is more left if you looked in the direction of this vector.
void setFirst(const double first)
Setter for the first coordinate.
bool isForwardOf(const Vector2D &rhs) const
Indicates if the given vector is more coaligned if you looked in the direction of this vector.
void setX(const double x)
Setter for the x coordinate.
bool isCWOf(const Vector2D &rhs) const
Indicates if the given vector is more clockwise if you looked in the direction of this vector.
bool isBackwardOf(const Vector2D &rhs) const
Indicates if the given vector is more Reverse if you looked in the direction of this vector.
double unnormalizedOrthogonalComp(const Vector2D &relativTo) const
Same as orthogonalComp() but assumes the given vector to be of unit length.
bool operator<(const Vector2D &rhs) const
Total ordering based on cylindrical radius first and azimuth angle second.
static Vector2D Phi(const double phi)
Constructs a unit vector with azimuth angle equal to phi.
Vector2D passiveMovedBy(const Vector2D &by) const
Returns a transformed vector passivelly moved by the given vector.
EForwardBackward
Enumeration to represent the distinct possibilities of the right left passage information.
ERightLeft
Enumeration to represent the distinct possibilities of the right left passage.
ERotation
Enumeration to represent the distinct possibilities of the right left passage information.
Abstract base class for different kinds of events.