qupid 0.2
Quasi-Signal Generation Model for Pixelized Detector
Loading...
Searching...
No Matches
QPVector.hpp
1#ifndef __QPVECTOR__
2#define __QPVECTOR__ 1
3
4#include <string>
5#include <iostream>
6
14 public:
16 QPVector();
20 QPVector(double x, double y);
24 QPVector(double x, double y, double z);
27 QPVector(const QPVector& other);
28
29 //Get
31 double X();
33 double Y();
35 double Z();
40 void Get(double& x, double& y, double& z);
44 QPVector Unit();
45
46 //Operator, returning result
50 inline double Dot(QPVector other) const;
55 inline QPVector Cross(QPVector other) const;
59 QPVector Scale(double& number);
61 double Norm();
63 double Norm2();
64
65 //Operator, Self operation
69 void AddThis(const QPVector& other);
73 void SubstractThis(const QPVector& other);
77 void CrossThis(const QPVector& other);
80 void ScaleThis(const double& number);
81
82 //Operator, Coveniences
83 // QPVector& operator+(const QPVector& other); //Add
84 // QPVector& operator-(const QPVector& other); //Substract
85 // double operator*(const QPVector& other); //Dot product
86 // QPVector& operator*(const double& other); //Scaling
87 // QPVector& operator^(const QPVector& other); //Cross product
88
92 inline QPVector & operator=(const QPVector& other);
93
107 friend QPVector operator+(QPVector a, QPVector b);
108 // friend QPVector operator-(QPVector& a, QPVector& b);
113 friend QPVector operator-(QPVector a, QPVector b);
114 // friend QPVector operator^(QPVector& a, QPVector& b);
119 friend QPVector operator^(QPVector a, QPVector b);
120 // friend QPVector operator* (QPVector &vec, double other);
121 // friend QPVector operator* (double other, QPVector& vec);
126 friend QPVector operator* (QPVector vec, double other);
131 friend QPVector operator* (double other, QPVector vec);
132 // friend double operator* (QPVector& other, QPVector& vec);
137 friend double operator* (QPVector other, QPVector vec);
138
145 inline QPVector& operator+=(const QPVector& other); //Add
151 inline QPVector& operator-=(const QPVector& other); //Substract
155 inline QPVector& operator*=(const double& other); //Scaling
163 inline QPVector& operator^=(const QPVector& other); //Cross product
164
171 inline double& operator()(const int& i);
176 inline double& operator[](const int& i);
177
182 double GetAngle(QPVector other);
186 double GetAngleDegree(QPVector other);
187
192 std::string Print(bool quite=false);
193
194 protected:
195 private:
196 double fX=0., fY=0., fZ=0;
197
198};
199
201 fX = other.fX;
202 fY = other.fY;
203 fZ = other.fZ;
204 return *this;
205}
206
208 fX += other.fX;
209 fY += other.fY;
210 fZ += other.fX;
211 return (*this);
212}
213
215 fX -= other.fX;
216 fY -= other.fY;
217 fZ -= other.fX;
218 return (*this);
219}
220
221inline QPVector& QPVector::operator*=(const double& other){
222 fX *= other;
223 fY *= other;
224 fZ *= other;
225 return (*this);
226}
227
229 fX = fY*other.fZ-fY*other.fZ;
230 fY = fZ*other.fX-fX*other.fZ;
231 fZ = fX*other.fY-fY*other.fX;
232 return (*this);
233}
234
235inline double& QPVector::operator()(const int& i){
236 if(i>2) std::cout<<"QPVector::operator() - Index is over 3\t:\t" << i <<std::endl;
237 double * val[3] = {&fX, &fY, &fZ};
238 return *(val[i]);
239}
240
241inline double& QPVector::operator[](const int& i){
242 if(i>2) std::cout<<"QPVector::operator[] - Index is over 3\t:\t" << i <<std::endl;
243 double * val[3] = {&fX, &fY, &fZ};
244 return *(val[i]);
245}
246
247
248inline double QPVector::Dot(QPVector other) const{
249 return fX*other.fX + fY*other.fY + fZ*other.fZ;
250}
251
253 return QPVector(fY*other.fZ-other.fY*fZ, fZ*other.fX-other.fZ*fX, fX*other.fY-other.fX*fY);
254}
255
256// QPVector operator+ ( QPVector &, QPVector & );
257QPVector operator+ ( QPVector , QPVector );
258// QPVector operator- ( QPVector &, QPVector & );
259QPVector operator- ( QPVector , QPVector );
260// QPVector operator^ ( QPVector &, QPVector & );
261QPVector operator^ ( QPVector , QPVector );
262
263// QPVector operator* ( QPVector & , double a );
264// QPVector operator* ( double a , QPVector & );
265// double operator* ( QPVector & , QPVector & );
266
267QPVector operator* ( QPVector , double a );
268QPVector operator* ( double a , QPVector );
269double operator* ( QPVector , QPVector );
270
271#endif
3-component double vector with hand-rolled operations.
Definition QPVector.hpp:13
void AddThis(const QPVector &other)
In-place add; delegates to operator+= and inherits its z-component defect (see operator+=).
Definition QPVector.cpp:42
void CrossThis(const QPVector &other)
In-place cross product; delegates to operator^= and inherits its overwrite defect (see operator^=).
Definition QPVector.cpp:54
void ScaleThis(const double &number)
Multiply all components in place.
Definition QPVector.cpp:58
QPVector Cross(QPVector other) const
Cross product (correct, unlike operator^=).
Definition QPVector.hpp:252
QPVector & operator^=(const QPVector &other)
In-place cross product.
Definition QPVector.hpp:228
double & operator()(const int &i)
Reference to component i (0 = x, 1 = y, 2 = z).
Definition QPVector.hpp:235
double Dot(QPVector other) const
Dot product .
Definition QPVector.hpp:248
double Z()
Definition QPVector.cpp:18
QPVector Scale(double &number)
Scaled copy .
Definition QPVector.cpp:28
QPVector Unit()
Unit vector .
Definition QPVector.cpp:21
friend QPVector operator^(QPVector a, QPVector b)
Cross product .
Definition QPVector.cpp:124
friend QPVector operator*(QPVector vec, double other)
Scaled copy.
Definition QPVector.cpp:135
QPVector()
Zero vector.
Definition QPVector.cpp:10
QPVector & operator=(const QPVector &other)
Component-wise copy assignment.
Definition QPVector.hpp:200
QPVector & operator-=(const QPVector &other)
In-place subtract.
Definition QPVector.hpp:214
double Y()
Definition QPVector.cpp:17
QPVector & operator+=(const QPVector &other)
In-place add.
Definition QPVector.hpp:207
double GetAngle(QPVector other)
Angle between this vector and other, .
Definition QPVector.cpp:79
double X()
Definition QPVector.cpp:16
friend QPVector operator+(QPVector &a, QPVector &b)
Component-wise sum (lvalue overload).
std::string Print(bool quite=false)
Formats the vector as "[x,y,z]".
Definition QPVector.cpp:87
double & operator[](const int &i)
Reference to component i (0 = x, 1 = y, 2 = z); same behavior and warning as operator().
Definition QPVector.hpp:241
double Norm2()
Definition QPVector.cpp:37
double Norm()
Definition QPVector.cpp:33
void SubstractThis(const QPVector &other)
In-place subtract; delegates to operator-= and inherits its z-component defect (see operator-=).
Definition QPVector.cpp:48
QPVector & operator*=(const double &other)
Multiply all components in place.
Definition QPVector.hpp:221
friend QPVector operator-(QPVector a, QPVector b)
Component-wise difference.
Definition QPVector.cpp:113
double GetAngleDegree(QPVector other)
GetAngle converted to degrees.
Definition QPVector.cpp:83
void Get(double &x, double &y, double &z)
Writes the components into the given references.
Definition QPVector.cpp:19