CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
TPoint2D.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TPoint2D.h,v 1.6 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TPoint2D.h
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A class to represent a point in 2D.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#ifndef TPOINT2D_FLAG_
14#define TPOINT2D_FLAG_
15
16#ifdef TRKRECO_DEBUG_DETAIL
17#ifndef TRKRECO_DEBUG
18#define TRKRECO_DEBUG
19#endif
20#endif
21#include <math.h>
22#define HEP_SHORT_NAMES
23#include "CLHEP/Geometry/Vector3D.h"
24#ifndef ENABLE_BACKWARDS_COMPATIBILITY
26#endif
27#ifndef CLHEP_POINT3D_H
28#include "CLHEP/Geometry/Point3D.h"
29#endif
30#ifndef ENABLE_BACKWARDS_COMPATIBILITY
32#endif
33
34//class HepPoint3D;
35
36/// A class to represent a point in 2D.
37class TPoint2D {
38
39 public:
40 /// Constructors
41 TPoint2D();
42 TPoint2D(double, double);
43 TPoint2D(const HepPoint3D &);
44 TPoint2D(const HepVector3D &);
45
46 /// Destructor
47 virtual ~TPoint2D();
48
49 public:// Selectors
50 double x(void) const;
51 double y(void) const;
52 double mag(void) const;
53 double mag2(void) const;
54 double phi(void) const;
55
56 public:// Modifiers
57 double x(double);
58 double y(double);
59
60 public:// Operators
61 double dot(const TPoint2D &) const;
62 double cross(const TPoint2D &) const;
63 TPoint2D unit(void) const;
64 TPoint2D operator + (const TPoint2D &) const;
65 TPoint2D operator - (const TPoint2D &) const;
66 TPoint2D operator - () const;
67 bool operator == (const TPoint2D &) const;
68
69 private:
70 double _p[2];
71};
72
73std::ostream &
74operator << (std::ostream &, const TPoint2D &);
75
76//-----------------------------------------------------------------------------
77
78#ifdef TPOINT2D_NO_INLINE
79#define inline
80#else
81#undef inline
82#define TPOINT2D_INLINE_DEFINE_HERE
83#endif
84#ifdef TPOINT2D_INLINE_DEFINE_HERE
85
86inline
87double
88TPoint2D::x(void) const {
89 return _p[0];
90}
91
92inline
93double
94TPoint2D::y(void) const {
95 return _p[1];
96}
97
98inline
99double
100TPoint2D::x(double a) {
101 return _p[0] = a;
102}
103
104inline
105double
106TPoint2D::y(double a) {
107 return _p[1] = a;
108}
109
110inline
111double
112TPoint2D::mag(void) const {
113 return sqrt(_p[0] * _p[0] + _p[1] * _p[1]);
114}
115
116inline
117double
118TPoint2D::mag2(void) const {
119 return _p[0] * _p[0] + _p[1] * _p[1];
120}
121
122inline
123double
124TPoint2D::phi(void) const {
125 if (_p[0] == 0.0 && _p[1] == 0.0) return 0.;
126 double a = atan2(_p[1], _p[0]);
127 if (a > 0) return a;
128 return a + 2. * M_PI;
129}
130
131inline
132double
133TPoint2D::dot(const TPoint2D & a) const {
134 return _p[0] * a.x() + _p[1] * a.y();
135}
136
137inline
138double
139TPoint2D::cross(const TPoint2D & a) const {
140 return _p[0] * a.y() - a.x() * _p[1];
141}
142
143inline
146 return TPoint2D(_p[0] + a.x(), _p[1] + a.y());
147}
148
149inline
152 return TPoint2D(_p[0] - a.x(), _p[1] - a.y());
153}
154
155inline
158 return TPoint2D(- _p[0], - _p[1]);
159}
160
161inline
162bool
164 if (a.x() == _p[0] && a.y() == _p[1]) return true;
165 return false;
166}
167
168inline
170TPoint2D::unit(void) const {
171 double sum2 = _p[0] * _p[0] + _p[1] * _p[1];
172 if (sum2 == 0.) return TPoint2D(0., 0.);
173 double sum = sqrt(sum2);
174 return TPoint2D(_p[0] / sum, _p[1] / sum);
175}
176
177#endif
178#undef inline
179
180#endif /* TPOINT2D_FLAG_ */
#define M_PI
Definition: TConstant.h:4
std::ostream & operator<<(std::ostream &, const TPoint2D &)
Definition: TPoint2D.cxx:43
HepGeom::Point3D< double > HepPoint3D
Definition: TPoint2D.h:31
HepGeom::Vector3D< double > HepVector3D
Definition: TPoint2D.h:25
A class to represent a point in 2D.
Definition: TPoint2D.h:37
double mag2(void) const
Definition: TPoint2D.h:118
TPoint2D operator-() const
Definition: TPoint2D.h:157
double dot(const TPoint2D &) const
Definition: TPoint2D.h:133
double cross(const TPoint2D &) const
Definition: TPoint2D.h:139
double phi(void) const
Definition: TPoint2D.h:124
double y(void) const
Definition: TPoint2D.h:94
bool operator==(const TPoint2D &) const
Definition: TPoint2D.h:163
virtual ~TPoint2D()
Destructor.
Definition: TPoint2D.cxx:39
double mag(void) const
Definition: TPoint2D.h:112
double x(void) const
Definition: TPoint2D.h:88
TPoint2D()
Constructors.
Definition: TPoint2D.cxx:19
TPoint2D unit(void) const
Definition: TPoint2D.h:170
TPoint2D operator+(const TPoint2D &) const
Definition: TPoint2D.h:145