Geant4 Cross Reference |
1 // -*- C++ -*- 2 // --------------------------------------------------------------------------- 3 // 4 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 5 // 6 // History: 7 // 09.09.96 E.Chernyaev - initial version 8 // 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple 9 // the functionality from CLHEP::Hep3Vector 10 // 01.04.03 E.Chernyaev - CLHEP-1.9: template version 11 // 12 13 #ifndef HEP_POINT3D_H 14 #define HEP_POINT3D_H 15 16 #include <iosfwd> 17 #include "CLHEP/Vector/ThreeVector.h" 18 #include "CLHEP/Geometry/BasicVector3D.h" 19 20 namespace HepGeom { 21 22 class Transform3D; 23 24 /** 25 * Geometrical 3D Point. 26 * This is just a declaration of the class needed to define 27 * specializations Point3D<float> and Point3D<double>. 28 * 29 * @ingroup geometry 30 * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> 31 */ 32 template<class T> 33 class Point3D : public BasicVector3D<T> {}; 34 35 /** 36 * Geometrical 3D Point with components of float type. 37 * 38 * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> 39 * @ingroup geometry 40 */ 41 template<> 42 class Point3D<float> : public BasicVector3D<float> { 43 public: 44 /** 45 * Default constructor. */ 46 Point3D() = default; 47 48 /** 49 * Constructor from three numbers. */ 50 Point3D(float x1, float y1, float z1) : BasicVector3D<float>(x1,y1,z1) {} 51 52 /** 53 * Constructor from array of floats. */ 54 explicit Point3D(const float * a) 55 : BasicVector3D<float>(a[0],a[1],a[2]) {} 56 57 /** 58 * Copy constructor. */ 59 Point3D(const Point3D<float> &) = default; 60 61 /** 62 * Move constructor. */ 63 Point3D(Point3D<float> &&) = default; 64 65 /** 66 * Constructor from BasicVector3D<float>. */ 67 Point3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {} 68 69 /** 70 * Destructor. */ 71 ~Point3D() = default; 72 73 /** 74 * Assignment. */ 75 Point3D<float> & operator=(const Point3D<float> &) = default; 76 77 /** 78 * Assignment from BasicVector3D<float>. */ 79 Point3D<float> & operator=(const BasicVector3D<float> & v) { 80 this->BasicVector3D<float>::operator=(v); 81 return *this; 82 } 83 84 /** 85 * Move assignment. */ 86 Point3D<float> & operator=(Point3D<float> &&) = default; 87 88 /** 89 * Returns distance to the origin squared. */ 90 float distance2() const { return mag2(); } 91 92 /** 93 * Returns distance to the point squared. */ 94 float distance2(const Point3D<float> & p) const { 95 float dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z(); 96 return dx*dx + dy*dy + dz*dz; 97 } 98 99 /** 100 * Returns distance to the origin. */ 101 float distance() const { return std::sqrt(distance2()); } 102 103 /** 104 * Returns distance to the point. */ 105 float distance(const Point3D<float> & p) const { 106 return std::sqrt(distance2(p)); 107 } 108 109 /** 110 * Transformation by Transform3D. */ 111 Point3D<float> & transform(const Transform3D & m); 112 }; 113 114 /** 115 * Transformation of Point3D<float> by Transform3D. 116 * @relates Point3D 117 */ 118 Point3D<float> 119 operator*(const Transform3D & m, const Point3D<float> & p); 120 121 /** 122 * Geometrical 3D Point with components of double type. 123 * 124 * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch> 125 * @ingroup geometry 126 */ 127 template<> 128 class Point3D<double> : public BasicVector3D<double> { 129 public: 130 /** 131 * Default constructor. */ 132 Point3D() = default; 133 134 /** 135 * Constructor from three numbers. */ 136 Point3D(double x1, double y1, double z1) : BasicVector3D<double>(x1,y1,z1) {} 137 138 /** 139 * Constructor from array of floats. */ 140 explicit Point3D(const float * a) 141 : BasicVector3D<double>(a[0],a[1],a[2]) {} 142 143 /** 144 * Constructor from array of doubles. */ 145 explicit Point3D(const double * a) 146 : BasicVector3D<double>(a[0],a[1],a[2]) {} 147 148 /** 149 * Copy constructor. */ 150 Point3D(const Point3D<double> &) = default; 151 152 /** 153 * Move constructor. */ 154 Point3D(Point3D<double> &&) = default; 155 156 /** 157 * Constructor from BasicVector3D<float>. */ 158 Point3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {} 159 160 /** 161 * Constructor from BasicVector3D<double>. */ 162 Point3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {} 163 164 /** 165 * Destructor. */ 166 ~Point3D() = default; 167 168 /** 169 * Constructor from CLHEP::Hep3Vector. 170 * This constructor is needed only for backward compatibility and 171 * in principle should be absent. 172 */ 173 Point3D(const CLHEP::Hep3Vector & v) 174 : BasicVector3D<double>(v.x(),v.y(),v.z()) {} 175 176 /** 177 * Conversion (cast) to CLHEP::Hep3Vector. 178 * This operator is needed only for backward compatibility and 179 * in principle should not exit. 180 */ 181 operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); } 182 183 /** 184 * Assignment. */ 185 Point3D<double> & operator=(const Point3D<double> &) = default; 186 187 /** 188 * Assignment from BasicVector3D<float>. */ 189 Point3D<double> & operator=(const BasicVector3D<float> & v) { 190 this->BasicVector3D<double>::operator=(v); 191 return *this; 192 } 193 194 /** 195 * Assignment from BasicVector3D<double>. */ 196 Point3D<double> & operator=(const BasicVector3D<double> & v) { 197 this->BasicVector3D<double>::operator=(v); 198 return *this; 199 } 200 201 /** 202 * Move assignment. */ 203 Point3D<double> & operator=(Point3D<double> &&) = default; 204 205 /** 206 * Returns distance to the origin squared. */ 207 double distance2() const { return mag2(); } 208 209 /** 210 * Returns distance to the point squared. */ 211 double distance2(const Point3D<double> & p) const { 212 double dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z(); 213 return dx*dx + dy*dy + dz*dz; 214 } 215 216 /** 217 * Returns distance to the origin. */ 218 double distance() const { return std::sqrt(distance2()); } 219 220 /** 221 * Returns distance to the point. */ 222 double distance(const Point3D<double> & p) const { 223 return std::sqrt(distance2(p)); 224 } 225 226 /** 227 * Transformation by Transform3D. */ 228 Point3D<double> & transform(const Transform3D & m); 229 }; 230 231 /** 232 * Transformation of Point3D<double> by Transform3D. 233 * @relates Point3D 234 */ 235 Point3D<double> 236 operator*(const Transform3D & m, const Point3D<double> & p); 237 238 } /* namespace HepGeom */ 239 240 #endif /* HEP_POINT3D_H */ 241