2 // ---------------------------------------------------------------------------
4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
6 // This is the definitions of the inline member functions of the
14 inline double Hep2Vector::x() const {
18 inline double Hep2Vector::y() const {
22 inline Hep2Vector::Hep2Vector(double x1, double y1)
25 inline Hep2Vector::Hep2Vector( const Hep3Vector & p)
26 : dx(p.x()), dy(p.y()) {}
28 inline void Hep2Vector::setX(double x1) {
32 inline void Hep2Vector::setY(double y1) {
36 inline void Hep2Vector::set(double x1, double y1) {
41 double & Hep2Vector::operator[] (int i) { return operator()(i); }
42 double Hep2Vector::operator[] (int i) const { return operator()(i); }
44 inline Hep2Vector::Hep2Vector(const Hep2Vector & p)
45 : dx(p.x()), dy(p.y()) {}
47 inline Hep2Vector::~Hep2Vector() {}
49 inline Hep2Vector & Hep2Vector::operator = (const Hep2Vector & p) {
55 inline bool Hep2Vector::operator == (const Hep2Vector& v) const {
56 return (v.x()==x() && v.y()==y()) ? true : false;
59 inline bool Hep2Vector::operator != (const Hep2Vector& v) const {
60 return (v.x()!=x() || v.y()!=y()) ? true : false;
63 inline Hep2Vector& Hep2Vector::operator += (const Hep2Vector & p) {
69 inline Hep2Vector& Hep2Vector::operator -= (const Hep2Vector & p) {
75 inline Hep2Vector Hep2Vector::operator - () const {
76 return Hep2Vector(-dx, -dy);
79 inline Hep2Vector& Hep2Vector::operator *= (double a) {
85 inline double Hep2Vector::dot(const Hep2Vector & p) const {
86 return dx*p.x() + dy*p.y();
89 inline double Hep2Vector::mag2() const {
93 inline double Hep2Vector::mag() const {
94 return std::sqrt(mag2());
97 inline double Hep2Vector::r() const {
98 return std::sqrt(mag2());
101 inline Hep2Vector Hep2Vector::unit() const {
104 return tot > 0.0 ? p *= (1.0/std::sqrt(tot)) : Hep2Vector(1,0);
107 inline Hep2Vector Hep2Vector::orthogonal() const {
108 double x1 = std::fabs(dx), y1 = std::fabs(dy);
110 return Hep2Vector(dy,-dx);
112 return Hep2Vector(-dy,dx);
116 inline double Hep2Vector::phi() const {
117 return dx == 0.0 && dy == 0.0 ? 0.0 : std::atan2(dy,dx);
120 inline double Hep2Vector::angle(const Hep2Vector & q) const {
121 double ptot2 = mag2()*q.mag2();
122 return ptot2 <= 0.0 ? 0.0 : std::acos(dot(q)/std::sqrt(ptot2));
125 inline void Hep2Vector::setMag(double r1){
127 setX( r1 * std::cos(ph) );
128 setY( r1 * std::sin(ph) );
131 inline void Hep2Vector::setR(double r1){
135 inline void Hep2Vector::setPhi(double phi1){
137 setX( ma * std::cos(phi1) );
138 setY( ma * std::sin(phi1) );
141 inline void Hep2Vector::setPolar(double r1, double phi1){
142 setX( r1 * std::cos(phi1) );
143 setY( r1 * std::sin(phi1) );
146 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b) {
147 return Hep2Vector(a.x() + b.x(), a.y() + b.y());
150 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b) {
151 return Hep2Vector(a.x() - b.x(), a.y() - b.y());
154 inline Hep2Vector operator * (const Hep2Vector & p, double a) {
155 return Hep2Vector(a*p.x(), a*p.y());
158 inline Hep2Vector operator * (double a, const Hep2Vector & p) {
159 return Hep2Vector(a*p.x(), a*p.y());
162 inline double operator * (const Hep2Vector & a, const Hep2Vector & b) {
166 inline double Hep2Vector::getTolerance () {