ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
10#include <cmath>
11#include <ostream>
12
13namespace 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 }
36
37 void set(double x, double y) {
38 m_x = x;
39 m_y = y;
40 }
41
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;
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
std::vector< size_t > vec
Implementation of 2 dimensional vector class.
Definition LocVec2D.h:16
LocVec2D operator+(const LocVec2D &lv) const
Plus and minus operators.
Definition LocVec2D.h:47
LocVec2D(LocVec2D &&)=default
LocVec2D & operator*=(double v)
Definition LocVec2D.h:75
double operator*(const LocVec2D &lv) const
Definition LocVec2D.h:68
LocVec2D & operator+=(const LocVec2D &lv)
Incrementation operator.
Definition LocVec2D.h:56
void setX(double x)
Set only x.
Definition LocVec2D.h:42
void set(const LocVec2D &vec)
Setter function using another vector.
Definition LocVec2D.h:32
LocVec2D(double x, double y)
Constructor parsing the coordinates.
Definition LocVec2D.h:19
double y() const
Returns the y coordinate of the vector.
Definition LocVec2D.h:29
double x() const
Returns the x coordinate of the vector.
Definition LocVec2D.h:27
LocVec2D operator-(const LocVec2D &lv) const
Definition LocVec2D.h:49
LocVec2D(const LocVec2D &)=default
Default copy & move constructors.
LocVec2D & operator-=(const LocVec2D &lv)
Definition LocVec2D.h:62
void set(double x, double y)
Set x & y simultaenously.
Definition LocVec2D.h:37
LocVec2D & operator=(const LocVec2D &)=default
Default assignment operators (Equivalent to the setter x)
void setY(double y)
Set only y.
Definition LocVec2D.h:44
double cross(const LocVec2D &lv) const
Definition LocVec2D.h:87
LocVec2D & operator=(LocVec2D &&)=default
LocVec2D & operator/=(double v)
Definition LocVec2D.h:81
LocVec2D operator*(double v) const
Definition LocVec2D.h:70
Function object to check whether two Segments are sub/super sets or different.
std::ostream & operator<<(std::ostream &os, const TrkDriftCircleMath::ClusterId &id)
Definition ClusterId.cxx:9