CMS 3D CMS Logo

oldBasic2DVector.h
Go to the documentation of this file.
1 #ifndef GeometryVector_oldBasic2DVector_h
2 #define GeometryVector_oldBasic2DVector_h
3 
7 #if (!defined(__CLING__))
9 #endif
10 
11 
12 #include <cmath>
13 #include <iosfwd>
14 
15 
16 template < class T>
17 class Basic2DVector {
18 public:
20 
21  typedef T ScalarType;
23 
28  Basic2DVector() : theX(0), theY(0) {}
29 
32  theX(p.x()), theY(p.y()) {}
33 
41  template <class Other>
42  explicit Basic2DVector( const Other& p) : theX(p.x()), theY(p.y()) {}
43 
45  Basic2DVector( const T& x, const T& y) : theX(x), theY(y) {}
46 
47 
48 #if defined(USE_EXTVECT)
49  // constructor from Vec2 or vec4
50  template<typename U>
51  Basic2DVector(Vec2<U> const& iv) :
52  theX(iv[0]), theY(iv[1]) {}
53  template<typename U>
54  Basic2DVector(Vec4<U> const& iv) :
55  theX(iv.arr[0]), theY(iv.arr[1]) {}
56 #elif defined(USE_SSEVECT)
57  // constructor from Vec2 or vec4
58  template<typename U>
59  Basic2DVector(mathSSE::Vec2<U> const& iv) :
60  theX(iv.arr[0]), theY(iv.arr[1]) {}
61  template<typename U>
62  Basic2DVector(mathSSE::Vec4<U> const& iv) :
63  theX(iv.arr[0]), theY(iv.arr[1]) {}
64 #endif
65 
66  T operator[](int i) const { return i==0 ? theX : theY ;}
67  T & operator[](int i) { return i==0 ? theX : theY ;}
68 
70  T x() const { return theX;}
71 
73  T y() const { return theY;}
74 
76  T mag2() const { return theX*theX + theY*theY;}
77 
79  T mag() const { return std::sqrt( mag2());}
80 
82  T r() const { return mag();}
83 
88  T barePhi() const {return std::atan2(theY,theX);}
89  Geom::Phi<T> phi() const {return Geom::Phi<T>(atan2(theY,theX));}
90 
94  Basic2DVector unit() const {
95  T my_mag = mag();
96  return my_mag == 0 ? *this : *this / my_mag;
97  }
98 
101  template <class U>
103  theX += p.x();
104  theY += p.y();
105  return *this;
106  }
107 
110  template <class U>
112  theX -= p.x();
113  theY -= p.y();
114  return *this;
115  }
116 
118  Basic2DVector operator-() const { return Basic2DVector(-x(),-y());}
119 
122  theX *= t;
123  theY *= t;
124  return *this;
125  }
126 
129  theX /= t;
130  theY /= t;
131  return *this;
132  }
133 
135  T dot( const Basic2DVector& v) const { return x()*v.x() + y()*v.y();}
136 
142  template <class U>
144  return x()*v.x() + y()*v.y();
145  }
146 
147 
148 
150  T cross( const Basic2DVector& v) const { return x()*v.y() - y()*v.x();}
151 
157  template <class U>
159  return x()*v.y() - y()*v.x();
160  }
161 
162 
163 private:
166 };
167 
168 
169 namespace geometryDetails {
170  std::ostream & print2D(std::ostream& s, double x, double y);
171 
172 }
173 
175 template <class T>
176 inline std::ostream & operator<<( std::ostream& s, const Basic2DVector<T>& v) {
177  return geometryDetails::print2D(s, v.x(),v.y());
178 }
179 
180 
182 template <class T, class U>
186  return RT(a.x()+b.x(), a.y()+b.y());
187 }
188 
189 template <class T, class U>
193  return RT(a.x()-b.x(), a.y()-b.y());
194 }
195 
196 
197 
198 
199 // scalar product of vectors of same precision
200 template <class T>
201 inline T operator*( const Basic2DVector<T>& v1, const Basic2DVector<T>& v2) {
202  return v1.dot(v2);
203 }
204 
206 template <class T, class U>
208  const Basic2DVector<U>& v2) {
209  return v1.x()*v2.x() + v1.y()*v2.y();
210 }
211 
215 template <class T, class Scalar>
217  T t = static_cast<T>(s);
218  return Basic2DVector<T>(v.x()*t, v.y()*t);
219 }
220 
222 template <class T, class Scalar>
224  T t = static_cast<T>(s);
225  return Basic2DVector<T>(v.x()*t, v.y()*t);
226 }
227 
231 template <class T, class Scalar>
233  T t = static_cast<T>(s);
234  return Basic2DVector<T>(v.x()/t, v.y()/t);
235 }
236 
237 
240 
241 #endif // GeometryVector_Basic2DVector_h
Phi.h
mps_fire.i
i
Definition: mps_fire.py:355
Basic2DVector::phi
Geom::Phi< T > phi() const
Definition: oldBasic2DVector.h:89
Basic2DVector::operator+=
Basic2DVector & operator+=(const Basic2DVector< U > &p)
Definition: extBasic2DVector.h:96
SIMDVec.h
operator+
Basic2DVector< typename PreciseFloatType< T, U >::Type > operator+(const Basic2DVector< T > &a, const Basic2DVector< U > &b)
vector sum and subtraction of vectors of possibly different precision
Definition: oldBasic2DVector.h:184
Basic2DVector::operator[]
T operator[](int i) const
Definition: oldBasic2DVector.h:66
Vec2
ExtVec< T, 2 > Vec2
Definition: ExtVec.h:66
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Basic2DVector::theX
T theX
Definition: oldBasic2DVector.h:164
Basic2DVector::dot
PreciseFloatType< T, U >::Type dot(const Basic2DVector< U > &v) const
Definition: oldBasic2DVector.h:143
Basic2DVector::v
Vec2< T > v
Definition: extBasic2DVector.h:156
CoordinateSets.h
Vec4
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:64
Basic2DVector::cross
PreciseFloatType< T, U >::Type cross(const Basic2DVector< U > &v) const
Definition: oldBasic2DVector.h:158
findQualityFiles.v
v
Definition: findQualityFiles.py:179
Basic2DVector::mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: oldBasic2DVector.h:79
Basic2DVector::operator-
Basic2DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: oldBasic2DVector.h:118
align::Scalar
double Scalar
Definition: Definitions.h:25
Basic2DVector::r
T r() const
Radius, same as mag()
Definition: oldBasic2DVector.h:82
Basic2DVector::dot
T dot(const Basic2DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Definition: oldBasic2DVector.h:135
Basic2DVector::MathVector
Basic2DVector< T > MathVector
Definition: oldBasic2DVector.h:19
Basic2DVector::operator[]
T & operator[](int i)
Definition: oldBasic2DVector.h:67
operator*
T operator*(const Basic2DVector< T > &v1, const Basic2DVector< T > &v2)
Definition: oldBasic2DVector.h:201
alignCSCRings.s
s
Definition: alignCSCRings.py:92
Geom::Polar2Cartesian
Definition: CoordinateSets.h:14
Basic2DVector::y
T y() const
Cartesian y coordinate.
Definition: extBasic2DVector.h:67
operator/
Basic2DVector< T > operator/(const Basic2DVector< T > &v, const Scalar &s)
Definition: oldBasic2DVector.h:232
PreciseFloatType.h
Basic2DVector::Basic2DVector
Basic2DVector(const T &x, const T &y)
construct from cartesian coordinates
Definition: oldBasic2DVector.h:45
Basic2DVector::operator-=
Basic2DVector & operator-=(const Basic2DVector< U > &p)
Definition: extBasic2DVector.h:104
Basic2DVector::dot
T dot(const Basic2DVector &lh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: extBasic2DVector.h:126
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
mathSSE::Vec2
Definition: SSEVec.h:118
Basic2DVector::x
T x() const
Cartesian x coordinate.
Definition: extBasic2DVector.h:64
Basic2DVector::operator*=
Basic2DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Definition: extBasic2DVector.h:113
operator-
Basic2DVector< typename PreciseFloatType< T, U >::Type > operator-(const Basic2DVector< T > &a, const Basic2DVector< U > &b)
Definition: oldBasic2DVector.h:191
Basic2DVector::operator/=
Basic2DVector & operator/=(T t)
Scaling by a scalar value (division)
Definition: extBasic2DVector.h:119
OrderedSet.t
t
Definition: OrderedSet.py:90
b
double b
Definition: hdecay.h:118
Basic2DVectorF
Basic2DVector< float > Basic2DVectorF
Definition: oldBasic2DVector.h:238
Basic2DVector
Definition: extBasic2DVector.h:15
a
double a
Definition: hdecay.h:119
mathSSE::Vec4
Definition: SSEVec.h:115
Geom::Phi
Definition: Phi.h:52
PreciseFloatType::Type
double Type
Definition: PreciseFloatType.h:24
geometryDetails
Definition: extTkRotation.h:21
Basic2DVectorD
Basic2DVector< double > Basic2DVectorD
Definition: oldBasic2DVector.h:239
Basic2DVector::unit
Basic2DVector unit() const
Definition: oldBasic2DVector.h:94
Basic2DVector::Polar
Geom::Polar2Cartesian< T > Polar
Definition: oldBasic2DVector.h:22
T
long double T
Definition: Basic3DVectorLD.h:48
Basic2DVector::Basic2DVector
Basic2DVector(const Other &p)
Definition: oldBasic2DVector.h:42
Basic2DVector::cross
T cross(const Basic2DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Definition: oldBasic2DVector.h:150
Basic2DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: oldBasic2DVector.h:76
Basic2DVector::Basic2DVector
Basic2DVector()
Definition: oldBasic2DVector.h:28
Basic2DVector::Basic2DVector
Basic2DVector(const Basic2DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: oldBasic2DVector.h:31
operator<<
std::ostream & operator<<(std::ostream &s, const Basic2DVector< T > &v)
simple text output to standard streams
Definition: oldBasic2DVector.h:176
Basic2DVector::barePhi
T barePhi() const
Definition: oldBasic2DVector.h:88
Basic2DVector::ScalarType
T ScalarType
Definition: oldBasic2DVector.h:21
Basic2DVector::theY
T theY
Definition: oldBasic2DVector.h:165
geometryDetails::print2D
std::ostream & print2D(std::ostream &s, double x, double y)
Definition: print.cc:8