CMS 3D CMS Logo

Vector2DBase.h
Go to the documentation of this file.
1 #ifndef GeometryVector_Vector2DBase_h
2 #define GeometryVector_Vector2DBase_h
3 
6 
7 template <class T, class FrameTag>
8 class Vector2DBase : public PV2DBase<T, VectorTag, FrameTag> {
9 public:
12  typedef typename BaseClass::Polar Polar;
13 
19 
23  template <class U>
25 
27  Vector2DBase(const T& x, const T& y) : BaseClass(x, y) {}
28 
30  explicit Vector2DBase(const Polar& set) : BaseClass(set) {}
31 
36  template <class U>
37  explicit Vector2DBase(const Basic2DVector<U>& v) : BaseClass(v) {}
38 
42  Vector2DBase unit() const { return Vector2DBase(this->basicVector().unit()); }
43 
47  template <class U>
49  this->basicVector() += v.basicVector();
50  return *this;
51  }
52 
56  template <class U>
58  this->basicVector() -= v.basicVector();
59  return *this;
60  }
61 
63  Vector2DBase operator-() const { return Vector2DBase(-this->basicVector()); }
64 
67  this->basicVector() *= t;
68  return *this;
69  }
70 
73  this->basicVector() /= t;
74  return *this;
75  }
76 
83  template <class U>
85  return this->basicVector().dot(v.basicVector());
86  }
87 };
88 
90 template <class T, class U, class FrameTag>
92  const Vector2DBase<U, FrameTag>& v2) {
94  return RT(v1.basicVector() + v2.basicVector());
95 }
96 
97 template <class T, class U, class FrameTag>
99  const Vector2DBase<U, FrameTag>& v2) {
101  return RT(v1.basicVector() - v2.basicVector());
102 }
103 
105 template <class T, class U, class FrameTag>
107  const Vector2DBase<U, FrameTag>& v2) {
108  return v1.basicVector() * v2.basicVector();
109 }
110 
114 template <class T, class FrameTag, class Scalar>
116  return Vector2DBase<T, FrameTag>(v.basicVector() * s);
117 }
118 
120 template <class T, class FrameTag, class Scalar>
122  return Vector2DBase<T, FrameTag>(v.basicVector() * s);
123 }
124 
128 template <class T, class FrameTag, class Scalar>
130  return Vector2DBase<T, FrameTag>(v.basicVector() / s);
131 }
132 
133 #endif // GeometryVector_Vector2DBase_h
Vector2DBase & operator+=(const Vector2DBase< U, FrameTag > &v)
Definition: Vector2DBase.h:48
double Scalar
Definition: Definitions.h:25
PV2DBase< T, VectorTag, FrameTag > BaseClass
Definition: Vector2DBase.h:10
Vector2DBase & operator*=(const T &t)
Scaling by a scalar value (multiplication)
Definition: Vector2DBase.h:66
Vector2DBase & operator/=(const T &t)
Scaling by a scalar value (division)
Definition: Vector2DBase.h:72
Vector2DBase(const Vector2DBase< U, FrameTag > &p)
Definition: Vector2DBase.h:24
Vector2DBase(const T &x, const T &y)
construct from cartesian coordinates
Definition: Vector2DBase.h:27
Vector2DBase unit() const
Definition: Vector2DBase.h:42
Vector2DBase & operator-=(const Vector2DBase< U, FrameTag > &v)
Definition: Vector2DBase.h:57
Vector2DBase(const Basic2DVector< U > &v)
Definition: Vector2DBase.h:37
Vector2DBase< typename PreciseFloatType< T, U >::Type, FrameTag > operator-(const Vector2DBase< T, FrameTag > &v1, const Vector2DBase< U, FrameTag > &v2)
Definition: Vector2DBase.h:98
Vector2DBase< typename PreciseFloatType< T, U >::Type, FrameTag > operator+(const Vector2DBase< T, FrameTag > &v1, const Vector2DBase< U, FrameTag > &v2)
vector sum and subtraction of vectors of possibly different precision
Definition: Vector2DBase.h:91
Vector2DBase< T, FrameTag > operator/(const Vector2DBase< T, FrameTag > &v, const Scalar &s)
Definition: Vector2DBase.h:129
const BasicVectorType & basicVector() const
Definition: PV2DBase.h:37
Vector2DBase operator-() const
Unary minus, returns a vector with components (-x(),-y())
Definition: Vector2DBase.h:63
PreciseFloatType< T, U >::Type dot(const Vector2DBase< U, FrameTag > &v) const
Definition: Vector2DBase.h:84
T dot(const Basic2DVector &lh) const
Scalar product, or "dot" product, with a vector of same type.
Vector2DBase(const Polar &set)
construct from polar coordinates
Definition: Vector2DBase.h:30
BaseClass::Polar Polar
Definition: Vector2DBase.h:12
Basic2DVector< T > BasicVectorType
Definition: Vector2DBase.h:11
long double T
PreciseFloatType< T, U >::Type operator*(const Vector2DBase< T, FrameTag > &v1, const Vector2DBase< U, FrameTag > &v2)
scalar product of vectors of possibly different precision
Definition: Vector2DBase.h:106