test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
sseBasic2DVector.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>
15 class Basic2DVector {
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  T operator[](int i) const { return v[i];}
59  T & operator[](int i) { return v[i];}
60 
62  T x() const { return v[0];}
63 
65  T y() const { return v[1];}
66 
68  T mag2() const { return ::dot(v,v);}
69 
71  T mag() const { return std::sqrt( mag2());}
72 
74  T r() const { return mag();}
75 
80  T barePhi() const {return std::atan2(y(),x());}
81  Geom::Phi<T> phi() const {return Geom::Phi<T>(atan2(y(),x()));}
82 
86  Basic2DVector unit() const {
87  T my_mag = mag();
88  return my_mag == 0 ? *this : *this / my_mag;
89  }
90 
93  template <class U>
95  v = v + p.v;
96  return *this;
97  }
98 
101  template <class U>
103  v = v - p.v;
104  return *this;
105  }
106 
108  Basic2DVector operator-() const { return Basic2DVector(-v);}
109 
112  v = v*t;
113  return *this;
114  }
115 
118  t = T(1)/t;
119  v = v*t;
120  return *this;
121  }
122 
124  T dot( const Basic2DVector& lh) const { return ::dot(v,lh.v);}
125 
131  template <class U>
135  }
136 
138  T cross( const Basic2DVector& lh) const { return ::cross(v,lh.v);}
139 
145  template <class U>
149  }
150 
151 
152 public:
153 
155 
156 };
157 
158 
159 namespace geometryDetails {
160  std::ostream & print2D(std::ostream& s, double x, double y);
161 
162 }
163 
165 template <class T>
166 inline std::ostream & operator<<( std::ostream& s, const Basic2DVector<T>& v) {
167  return geometryDetails::print2D(s, v.x(),v.y());
168 }
169 
170 
172 template <class T>
173 inline Basic2DVector<T>
175  return a.v+b.v;
176 }
177 template <class T>
178 inline Basic2DVector<T>
180  return a.v-b.v;
181 }
182 
183 template <class T, class U>
187  return RT(a) + RT(b);
188 }
189 
190 template <class T, class U>
194  return RT(a)-RT(b);
195 }
196 
197 
198 
199 
200 // scalar product of vectors of same precision
201 template <class T>
202 inline T operator*( const Basic2DVector<T>& v1, const Basic2DVector<T>& v2) {
203  return v1.dot(v2);
204 }
205 
207 template <class T, class U>
209  const Basic2DVector<U>& v2) {
210  return v1.dot(v2);
211 }
212 
213 
217 template <class T>
219  return v.v*t;
220 }
221 
223 template <class T>
225  return v.v*t;
226 }
227 
228 
229 
230 template <class T, class Scalar>
232  T t = static_cast<T>(s);
233  return v*t;
234 }
235 
237 template <class T, class Scalar>
239  T t = static_cast<T>(s);
240  return v*t;
241 }
242 
246 template <class T>
248  return v.v/t;
249 }
250 
251 template <class T, class Scalar>
253  // T t = static_cast<T>(Scalar(1)/s); return v*t;
254  T t = static_cast<T>(s);
255  return v/t;
256 }
257 
260 
261 
262 #endif // GeometryVector_Basic2DVector_h
int i
Definition: DBlmapReader.cc:9
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: SIMDVec.h:21
Basic2DVector(const Basic2DVector< U > &p)
Basic2DVector(const Other &p)
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Basic2DVector< double > Basic2DVectorD
Basic2DVector unit() const
PreciseFloatType< T, U >::Type dot(const Basic2DVector< U > &lh) const
T x() const
Cartesian x coordinate.
Basic2DVector< float > Basic2DVectorF
Geom::Polar2Cartesian< T > Polar
T sqrt(T t)
Definition: SSEVec.h:18
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()
T & operator[](int i)
Basic2DVector & operator-=(const Basic2DVector< U > &p)
double b
Definition: hdecay.h:120
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T operator[](int i) const
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)
mathSSE::Vec2< T > MathVector
Geom::Phi< T > phi() const
long double T
mathSSE::Vec2< T > VectorType
Definition: Phi.h:20
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.