CMS 3D CMS Logo

sseBasic2DVector.h
Go to the documentation of this file.
1 #ifndef GeometryVector_newBasic2DVector_h
2 #define GeometryVector_newBasic2DVector_h
3 
8 
9 #include <cmath>
10 #include <iosfwd>
11 
12 template <class T>
13 class Basic2DVector {
14 public:
15  typedef T ScalarType;
19 
25 
27  Basic2DVector(const Basic2DVector& p) : v(p.v) {}
28 
29  template <typename U>
31 
39  template <class Other>
40  explicit Basic2DVector(const Other& p) : v(p.x(), p.y()) {}
41 
43  Basic2DVector(const T& x, const T& y) : v(x, y) {}
44 
45  // constructor from Vec2 or vec4
46  template <typename U>
48  template <typename U>
50 
51  MathVector const& mathVector() const { return v; }
52  MathVector& mathVector() { return v; }
53 
54  T operator[](int i) const { return v[i]; }
55  T& operator[](int i) { return v[i]; }
56 
58  T x() const { return v[0]; }
59 
61  T y() const { return v[1]; }
62 
64  T mag2() const { return ::dot(v, v); }
65 
67  T mag() const { return std::sqrt(mag2()); }
68 
70  T r() const { return mag(); }
71 
76  T barePhi() const { return std::atan2(y(), x()); }
77  Geom::Phi<T> phi() const { return Geom::Phi<T>(atan2(y(), x())); }
78 
82  Basic2DVector unit() const {
83  T my_mag = mag();
84  return my_mag == 0 ? *this : *this / my_mag;
85  }
86 
89  template <class U>
91  v = v + p.v;
92  return *this;
93  }
94 
97  template <class U>
99  v = v - p.v;
100  return *this;
101  }
102 
104  Basic2DVector operator-() const { return Basic2DVector(-v); }
105 
108  v = v * t;
109  return *this;
110  }
111 
114  t = T(1) / t;
115  v = v * t;
116  return *this;
117  }
118 
120  T dot(const Basic2DVector& lh) const { return ::dot(v, lh.v); }
121 
127  template <class U>
131  }
132 
134  T cross(const Basic2DVector& lh) const { return ::cross(v, lh.v); }
135 
141  template <class U>
145  }
146 
147 public:
149 };
150 
151 namespace geometryDetails {
152  std::ostream& print2D(std::ostream& s, double x, double y);
153 
154 }
155 
157 template <class T>
158 inline std::ostream& operator<<(std::ostream& s, const Basic2DVector<T>& v) {
159  return geometryDetails::print2D(s, v.x(), v.y());
160 }
161 
163 template <class T>
165  return a.v + b.v;
166 }
167 template <class T>
169  return a.v - b.v;
170 }
171 
172 template <class T, class U>
174  const Basic2DVector<U>& b) {
176  return RT(a) + RT(b);
177 }
178 
179 template <class T, class U>
181  const Basic2DVector<U>& b) {
183  return RT(a) - RT(b);
184 }
185 
186 // scalar product of vectors of same precision
187 template <class T>
188 inline T operator*(const Basic2DVector<T>& v1, const Basic2DVector<T>& v2) {
189  return v1.dot(v2);
190 }
191 
193 template <class T, class U>
195  return v1.dot(v2);
196 }
197 
201 template <class T>
203  return v.v * t;
204 }
205 
207 template <class T>
209  return v.v * t;
210 }
211 
212 template <class T, class Scalar>
214  T t = static_cast<T>(s);
215  return v * t;
216 }
217 
219 template <class T, class Scalar>
221  T t = static_cast<T>(s);
222  return v * t;
223 }
224 
228 template <class T>
230  return v.v / t;
231 }
232 
233 template <class T, class Scalar>
235  // T t = static_cast<T>(Scalar(1)/s); return v*t;
236  T t = static_cast<T>(s);
237  return v / t;
238 }
239 
242 
243 #endif // GeometryVector_Basic2DVector_h
dot
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
Definition: Basic3DVectorLD.h:212
Phi.h
Basic2DVector::Basic2DVector
Basic2DVector(mathSSE::Vec2< U > const &iv)
Definition: sseBasic2DVector.h:47
mps_fire.i
i
Definition: mps_fire.py:428
Basic2DVector::phi
Geom::Phi< T > phi() const
Definition: sseBasic2DVector.h:77
Basic2DVector::operator+=
Basic2DVector & operator+=(const Basic2DVector< U > &p)
Definition: sseBasic2DVector.h:90
operator+
Basic2DVector< T > operator+(const Basic2DVector< T > &a, const Basic2DVector< T > &b)
vector sum and subtraction of vectors of possibly different precision
Definition: sseBasic2DVector.h:164
Basic2DVector::operator[]
T operator[](int i) const
Definition: sseBasic2DVector.h:54
Basic2DVector::Basic2DVector
Basic2DVector(mathSSE::Vec4< U > const &iv)
Definition: sseBasic2DVector.h:49
SSEVec.h
gpuVertexFinder::iv
int32_t *__restrict__ iv
Definition: gpuClusterTracksDBSCAN.h:42
Basic2DVector::v
Vec2< T > v
Definition: extBasic2DVector.h:156
CoordinateSets.h
Basic2DVector::Basic2DVector
Basic2DVector(const Basic2DVector< U > &p)
Definition: sseBasic2DVector.h:30
mathSSE::lh
bool int lh
Definition: SIMDVec.h:20
findQualityFiles.v
v
Definition: findQualityFiles.py:179
operator*
T operator*(const Basic2DVector< T > &v1, const Basic2DVector< T > &v2)
Definition: sseBasic2DVector.h:188
Basic2DVector::mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: sseBasic2DVector.h:67
Basic2DVector::operator-
Basic2DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
Definition: sseBasic2DVector.h:104
Basic2DVector::dot
PreciseFloatType< T, U >::Type dot(const Basic2DVector< U > &lh) const
Definition: sseBasic2DVector.h:128
operator<<
std::ostream & operator<<(std::ostream &s, const Basic2DVector< T > &v)
simple text output to standard streams
Definition: sseBasic2DVector.h:158
align::Scalar
double Scalar
Definition: Definitions.h:25
Basic2DVector::r
T r() const
Radius, same as mag()
Definition: sseBasic2DVector.h:70
Basic2DVector< float >::MathVector
Vec2< float > MathVector
Definition: extBasic2DVector.h:20
Basic2DVector::operator[]
T & operator[](int i)
Definition: sseBasic2DVector.h:55
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
Basic2DVector::cross
T cross(const Basic2DVector &lh) const
Vector product, or "cross" product, with a vector of same type.
Definition: sseBasic2DVector.h:134
PreciseFloatType.h
Basic2DVector::Basic2DVector
Basic2DVector(const T &x, const T &y)
construct from cartesian coordinates
Definition: sseBasic2DVector.h:43
Basic2DVector::operator-=
Basic2DVector & operator-=(const Basic2DVector< U > &p)
Definition: sseBasic2DVector.h:98
Basic2DVector::dot
T dot(const Basic2DVector &lh) const
Scalar product, or "dot" product, with a vector of same type.
Definition: sseBasic2DVector.h:120
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Basic2DVector::MathVector
mathSSE::Vec2< T > MathVector
Definition: sseBasic2DVector.h:17
mathSSE::Vec2
Definition: SSEVec.h:118
Basic2DVector::v
mathSSE::Vec2< T > v
Definition: sseBasic2DVector.h:148
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: sseBasic2DVector.h:107
Basic2DVector::operator/=
Basic2DVector & operator/=(T t)
Scaling by a scalar value (division)
Definition: sseBasic2DVector.h:113
b
double b
Definition: hdecay.h:118
Basic2DVector::mathVector
MathVector const & mathVector() const
Definition: sseBasic2DVector.h:51
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
Basic2DVector
Definition: extBasic2DVector.h:15
operator/
Basic2DVector< T > operator/(const Basic2DVector< T > &v, T t)
Definition: sseBasic2DVector.h:229
cross
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
Definition: Basic3DVectorLD.h:225
Basic2DVectorD
Basic2DVector< double > Basic2DVectorD
Definition: sseBasic2DVector.h:241
a
double a
Definition: hdecay.h:119
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
mathSSE::Vec4
Definition: SSEVec.h:115
Basic2DVector::VectorType
mathSSE::Vec2< T > VectorType
Definition: sseBasic2DVector.h:16
Geom::Phi
Definition: Phi.h:52
PreciseFloatType::Type
double Type
Definition: PreciseFloatType.h:24
geometryDetails
Definition: extTkRotation.h:21
Basic2DVector::unit
Basic2DVector unit() const
Definition: sseBasic2DVector.h:82
Basic2DVector::Polar
Geom::Polar2Cartesian< T > Polar
Definition: sseBasic2DVector.h:18
T
long double T
Definition: Basic3DVectorLD.h:48
Basic2DVector::Basic2DVector
Basic2DVector(const Other &p)
Definition: sseBasic2DVector.h:40
Basic2DVector::mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: sseBasic2DVector.h:64
Basic2DVector::Basic2DVector
Basic2DVector()
Definition: sseBasic2DVector.h:24
Basic2DVector::cross
PreciseFloatType< T, U >::Type cross(const Basic2DVector< U > &lh) const
Definition: sseBasic2DVector.h:142
Basic2DVector::Basic2DVector
Basic2DVector(const Basic2DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
Definition: sseBasic2DVector.h:27
Basic2DVector::mathVector
MathVector & mathVector()
Definition: sseBasic2DVector.h:52
Basic2DVector::barePhi
T barePhi() const
Definition: sseBasic2DVector.h:76
Basic2DVector::ScalarType
T ScalarType
Definition: sseBasic2DVector.h:15
operator-
Basic2DVector< T > operator-(const Basic2DVector< T > &a, const Basic2DVector< T > &b)
Definition: sseBasic2DVector.h:168
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
Basic2DVectorF
Basic2DVector< float > Basic2DVectorF
Definition: sseBasic2DVector.h:240
geometryDetails::print2D
std::ostream & print2D(std::ostream &s, double x, double y)
Definition: print.cc:8