CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
newBasic2DVector.h
Go to the documentation of this file.
1 #ifndef GeometryVector_newBasic2DVector_h
2 #define GeometryVector_newBasic2DVector_h
3 
8 
9 
10 #include <cmath>
11 #include <iosfwd>
12 
13 
14 template < class T>
16 public:
17 
18  typedef T ScalarType;
22 
28 
30  Basic2DVector( const Basic2DVector & p) : v(p.v) {}
31 
32  template<typename U>
33  Basic2DVector( const Basic2DVector<U> & p) : v(p.v) {}
34 
35 
43  template <class Other>
44  explicit Basic2DVector( const Other& p) : v(p.x(),p.y()) {}
45 
47  Basic2DVector( const T& x, const T& y) : v(x,y) {}
48 
49  // constructor from Vec2 or vec4
50  template<typename U>
51  Basic2DVector(mathSSE::Vec2<U> const& iv) : v(iv){}
52  template<typename U>
53  Basic2DVector(mathSSE::Vec4<U> const& iv) : v(iv.xy()){}
54 
55  MathVector const & mathVector() const { return v;}
56  MathVector & mathVector() { return v;}
57 
58 
60  T x() const { return v[0];}
61 
63  T y() const { return v[1];}
64 
66  T mag2() const { return ::dot(v,v);}
67 
69  T mag() const { return std::sqrt( mag2());}
70 
72  T r() const { return mag();}
73 
78  T barePhi() const {return std::atan2(y(),x());}
79  Geom::Phi<T> phi() const {return Geom::Phi<T>(atan2(y(),x()));}
80 
84  Basic2DVector unit() const {
85  T my_mag = mag();
86  return my_mag == 0 ? *this : *this / my_mag;
87  }
88 
91  template <class U>
93  v = v + p.v;
94  return *this;
95  }
96 
99  template <class U>
101  v = v - p.v;
102  return *this;
103  }
104 
106  Basic2DVector operator-() const { return Basic2DVector(-v);}
107 
110  v = v*t;
111  return *this;
112  }
113 
116  t = T(1)/t;
117  v = v*t;
118  return *this;
119  }
120 
122  T dot( const Basic2DVector& lh) const { return ::dot(v,lh.v);}
123 
129  template <class U>
133  }
134 
136  T cross( const Basic2DVector& lh) const { return ::cross(v,lh.v);}
137 
143  template <class U>
147  }
148 
149 
150 public:
151 
153 
154 };
155 
156 
157 namespace geometryDetails {
158  std::ostream & print2D(std::ostream& s, double x, double y);
159 
160 }
161 
163 template <class T>
164 inline std::ostream & operator<<( std::ostream& s, const Basic2DVector<T>& v) {
165  return geometryDetails::print2D(s, v.x(),v.y());
166 }
167 
168 
170 template <class T>
171 inline Basic2DVector<T>
173  return a.v+b.v;
174 }
175 template <class T>
176 inline Basic2DVector<T>
178  return a.v-b.v;
179 }
180 
181 template <class T, class U>
185  return RT(a) + RT(b);
186 }
187 
188 template <class T, class U>
192  return RT(a)-RT(b);
193 }
194 
195 
196 
197 
198 // scalar product of vectors of same precision
199 template <class T>
200 inline T operator*( const Basic2DVector<T>& v1, const Basic2DVector<T>& v2) {
201  return v1.dot(v2);
202 }
203 
205 template <class T, class U>
207  const Basic2DVector<U>& v2) {
208  return v1.dot(v2);
209 }
210 
211 
215 template <class T>
217  return v.v*t;
218 }
219 
221 template <class T>
223  return v.v*t;
224 }
225 
226 
227 
228 template <class T, class Scalar>
230  T t = static_cast<T>(s);
231  return v*t;
232 }
233 
235 template <class T, class Scalar>
237  T t = static_cast<T>(s);
238  return v*t;
239 }
240 
244 template <class T>
246  return v.v/t;
247 }
248 
249 template <class T, class Scalar>
251  // T t = static_cast<T>(Scalar(1)/s); return v*t;
252  T t = static_cast<T>(s);
253  return v/t;
254 }
255 
258 
259 
260 #endif // GeometryVector_Basic2DVector_h
T cross(const Basic2DVector &lh) const
Vector product, or &quot;cross&quot; product, with a vector of same type.
Basic2DVector(const T &x, const T &y)
construct from cartesian coordinates
Basic2DVector(mathSSE::Vec2< U > const &iv)
double Scalar
Definition: Definitions.h:27
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Basic2DVector(const Basic2DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
T dot(const Basic2DVector &lh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
MathVector const & mathVector() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Basic2DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
PreciseFloatType< T, U >::Type cross(const Basic2DVector< U > &lh) const
T r() const
Radius, same as mag()
T barePhi() const
bool int lh
Definition: SSEVec.h:55
Basic2DVector(const Basic2DVector< U > &p)
Basic2DVector(const Other &p)
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Basic2DVector unit() const
PreciseFloatType< T, U >::Type dot(const Basic2DVector< U > &lh) const
Geom::Polar2Cartesian< T > Polar
Basic2DVector< float > Basic2DVectorF
T sqrt(T t)
Definition: SSEVec.h:46
Basic2DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Basic2DVector & operator/=(T t)
Scaling by a scalar value (division)
std::ostream & print2D(std::ostream &s, double x, double y)
Definition: print.cc:8
Basic2DVector & operator+=(const Basic2DVector< U > &p)
T y() const
Cartesian y coordinate.
MathVector & mathVector()
Basic2DVector & operator-=(const Basic2DVector< U > &p)
double b
Definition: hdecay.h:120
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Basic2DVector(mathSSE::Vec4< U > const &iv)
T dot(const Basic3DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
double a
Definition: hdecay.h:121
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Definition: DDAxes.h:10
Basic2DVector< double > Basic2DVectorD
mathSSE::Vec2< T > MathVector
Geom::Phi< T > phi() const
long double T
mathSSE::Vec2< T > VectorType
Definition: Phi.h:20
mathSSE::Vec4< T > v
mathSSE::Vec2< T > v
T x() const
Cartesian x coordinate.
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or &quot;cross&quot; product, with a vector of same type.