ATLAS Offline Software
LocVec2D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef DCMATH_LOCVEC2D_H
6 #define DCMATH_LOCVEC2D_H
7 
10 #include <cmath>
11 #include <ostream>
12 
13 namespace TrkDriftCircleMath {
16  class LocVec2D {
17  public:
19  LocVec2D(double x, double y) : m_x{x}, m_y{y} {}
21  LocVec2D(const LocVec2D&) = default;
22  LocVec2D(LocVec2D&&) = default;
23  LocVec2D() = default;
24 
25  ~LocVec2D() = default;
27  double x() const { return m_x; }
29  double y() const { return m_y; }
30 
32  void set(const LocVec2D& vec) {
33  m_x = vec.x();
34  m_y = vec.y();
35  }
37  void set(double x, double y) {
38  m_x = x;
39  m_y = y;
40  }
42  void setX(double x) { m_x = x; }
44  void setY(double y) { m_y = y; }
45 
47  LocVec2D operator+(const LocVec2D& lv) const { return LocVec2D(x() + lv.x(), y() + lv.y()); }
48 
49  LocVec2D operator-(const LocVec2D& lv) const { return LocVec2D(x() - lv.x(), y() - lv.y()); }
50 
52  LocVec2D& operator=(const LocVec2D&) = default;
53  LocVec2D& operator=(LocVec2D&&) = default;
54 
57  m_x += lv.x();
58  m_y += lv.y();
59  return *this;
60  }
61 
63  m_x -= lv.x();
64  m_y -= lv.y();
65  return *this;
66  }
67 
68  double operator*(const LocVec2D& lv) const { return x() * lv.x() + y() * lv.y(); }
69 
70  LocVec2D operator*(double v) const {
71  LocVec2D n(*this);
72  return n *= v;
73  }
74 
75  LocVec2D& operator*=(double v) {
76  m_x *= v;
77  m_y *= v;
78  return *this;
79  }
80 
81  LocVec2D& operator/=(double v) {
82  m_x /= v;
83  m_y /= v;
84  return *this;
85  }
86 
87  double cross(const LocVec2D& lv) const { return y() * lv.x() - x() * lv.y(); }
88 
89  double mag() const { return std::hypot(m_x, m_y); }
90 
91  private:
92  double m_x{0};
93  double m_y{0};
94  };
95 
96  std::ostream& operator<<(std::ostream& os, const TrkDriftCircleMath::LocVec2D& lv);
97 } // namespace TrkDriftCircleMath
98 
99 #endif
TrkDriftCircleMath::LocVec2D::setY
void setY(double y)
Set only y.
Definition: LocVec2D.h:44
TrkDriftCircleMath::LocVec2D::mag
double mag() const
Definition: LocVec2D.h:89
TrkDriftCircleMath
Function object to check whether two Segments are sub/super sets or different.
Definition: IMdtSegmentFinder.h:13
TrkDriftCircleMath::LocVec2D::operator*
LocVec2D operator*(double v) const
Definition: LocVec2D.h:70
TrkDriftCircleMath::LocVec2D::x
double x() const
Returns the x coordinate of the vector.
Definition: LocVec2D.h:27
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
TrkDriftCircleMath::LocVec2D::set
void set(const LocVec2D &vec)
Setter function using another vector.
Definition: LocVec2D.h:32
TrkDriftCircleMath::LocVec2D
Implementation of 2 dimensional vector class.
Definition: LocVec2D.h:16
TrkDriftCircleMath::LocVec2D::setX
void setX(double x)
Set only x.
Definition: LocVec2D.h:42
TrkDriftCircleMath::LocVec2D::LocVec2D
LocVec2D(double x, double y)
Constructor parsing the coordinates.
Definition: LocVec2D.h:19
TrkDriftCircleMath::LocVec2D::operator-
LocVec2D operator-(const LocVec2D &lv) const
Definition: LocVec2D.h:49
TrkDriftCircleMath::LocVec2D::set
void set(double x, double y)
Set x & y simultaenously.
Definition: LocVec2D.h:37
TrkDriftCircleMath::LocVec2D::~LocVec2D
~LocVec2D()=default
TrkDriftCircleMath::operator<<
std::ostream & operator<<(std::ostream &os, const TrkDriftCircleMath::ClusterId &id)
Definition: ClusterId.cxx:9
beamspotman.n
n
Definition: beamspotman.py:731
TrkDriftCircleMath::LocVec2D::operator*
double operator*(const LocVec2D &lv) const
Definition: LocVec2D.h:68
TrkDriftCircleMath::LocVec2D::operator+=
LocVec2D & operator+=(const LocVec2D &lv)
Incrementation operator.
Definition: LocVec2D.h:56
TrkDriftCircleMath::LocVec2D::y
double y() const
Returns the y coordinate of the vector.
Definition: LocVec2D.h:29
TrkDriftCircleMath::LocVec2D::m_y
double m_y
Definition: LocVec2D.h:93
TrkDriftCircleMath::LocVec2D::LocVec2D
LocVec2D(const LocVec2D &)=default
Default copy & move constructors.
TrkDriftCircleMath::LocVec2D::m_x
double m_x
Definition: LocVec2D.h:92
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
TrkDriftCircleMath::LocVec2D::operator-=
LocVec2D & operator-=(const LocVec2D &lv)
Definition: LocVec2D.h:62
TrkDriftCircleMath::LocVec2D::LocVec2D
LocVec2D()=default
TrkDriftCircleMath::LocVec2D::operator=
LocVec2D & operator=(const LocVec2D &)=default
Default assignment operators (Equivalent to the setter x)
TrkDriftCircleMath::LocVec2D::cross
double cross(const LocVec2D &lv) const
Definition: LocVec2D.h:87
TrkDriftCircleMath::LocVec2D::LocVec2D
LocVec2D(LocVec2D &&)=default
python.PyAthena.v
v
Definition: PyAthena.py:154
TrkDriftCircleMath::LocVec2D::operator*=
LocVec2D & operator*=(double v)
Definition: LocVec2D.h:75
TrkDriftCircleMath::LocVec2D::operator/=
LocVec2D & operator/=(double v)
Definition: LocVec2D.h:81
TrkDriftCircleMath::LocVec2D::operator=
LocVec2D & operator=(LocVec2D &&)=default
TrkDriftCircleMath::LocVec2D::operator+
LocVec2D operator+(const LocVec2D &lv) const
Plus and minus operators.
Definition: LocVec2D.h:47