Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:36

0001 // -*- C++ -*-
0002 // $Id: Point3D.h,v 1.5 2010/06/16 16:21:27 garren Exp $
0003 // ---------------------------------------------------------------------------
0004 //
0005 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
0006 //
0007 // History:
0008 // 09.09.96 E.Chernyaev - initial version
0009 // 12.06.01 E.Chernyaev - CLHEP-1.7: introduction of BasicVector3D to decouple
0010 //                        the functionality from CLHEP::Hep3Vector
0011 // 01.04.03 E.Chernyaev - CLHEP-1.9: template version
0012 //
0013 
0014 #ifndef HEP_POINT3D_H
0015 #define HEP_POINT3D_H
0016 
0017 #include <iosfwd>
0018 #include "CLHEP/Geometry/defs.h"
0019 #include "CLHEP/Vector/ThreeVector.h"
0020 #include "CLHEP/Geometry/BasicVector3D.h"
0021 
0022 namespace HepGeom {
0023 
0024   class Transform3D;
0025 
0026   /**
0027    * Geometrical 3D Point.
0028    * This is just a declaration of the class needed to define
0029    * specializations Point3D<float> and Point3D<double>.
0030    *
0031    * @ingroup geometry
0032    * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
0033    */
0034   template<class T>
0035   class Point3D : public BasicVector3D<T> {};
0036 
0037   /**
0038    * Geometrical 3D Point with components of float type.
0039    *
0040    * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
0041    * @ingroup geometry
0042    */
0043   template<>
0044   class Point3D<float> : public BasicVector3D<float> {
0045   public:
0046     /**
0047      * Default constructor. */
0048     Point3D() = default;
0049 
0050     /**
0051      * Constructor from three numbers. */
0052     Point3D(float x1, float y1, float z1) : BasicVector3D<float>(x1,y1,z1) {}
0053 
0054     /**
0055      * Constructor from array of floats. */
0056     explicit Point3D(const float * a)
0057       : BasicVector3D<float>(a[0],a[1],a[2]) {}
0058 
0059     /**
0060      * Copy constructor. */
0061     Point3D(const Point3D<float> &) = default;
0062 
0063     /**
0064      * Move constructor. */
0065     Point3D(Point3D<float> &&) = default;
0066 
0067     /**
0068      * Constructor from BasicVector3D<float>. */
0069     Point3D(const BasicVector3D<float> & v) : BasicVector3D<float>(v) {}
0070 
0071     /**
0072      * Destructor. */
0073     ~Point3D() = default;
0074 
0075     /**
0076      * Assignment. */
0077     Point3D<float> & operator=(const Point3D<float> &) = default;
0078 
0079     /**
0080      * Assignment from BasicVector3D<float>. */
0081     Point3D<float> & operator=(const BasicVector3D<float> & v) {
0082       this->BasicVector3D<float>::operator=(v);
0083       return *this;
0084     }
0085 
0086     /**
0087      * Move assignment. */
0088     Point3D<float> & operator=(Point3D<float> &&) = default;
0089 
0090     /**
0091      * Returns distance to the origin squared. */
0092     float distance2() const { return mag2(); }
0093 
0094     /**
0095      * Returns distance to the point squared. */
0096     float distance2(const Point3D<float> & p) const {
0097       float dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z();
0098       return dx*dx + dy*dy + dz*dz;
0099     }
0100 
0101     /**
0102      * Returns distance to the origin. */
0103     float distance() const { return std::sqrt(distance2()); }
0104 
0105     /**
0106      * Returns distance to the point. */
0107     float distance(const Point3D<float> & p) const {
0108       return std::sqrt(distance2(p));
0109     }
0110 
0111     /**
0112      * Transformation by Transform3D. */
0113     Point3D<float> & transform(const Transform3D & m);
0114   };
0115 
0116   /**
0117    * Transformation of Point3D<float> by Transform3D.
0118    * @relates Point3D
0119    */
0120   Point3D<float>
0121   operator*(const Transform3D & m, const Point3D<float> & p);
0122 
0123   /**
0124    * Geometrical 3D Point with components of double type.
0125    *
0126    * @author Evgeni Chernyaev <Evgueni.Tcherniaev@cern.ch>
0127    * @ingroup geometry
0128    */
0129   template<>
0130   class Point3D<double> : public BasicVector3D<double> {
0131   public:
0132     /**
0133      * Default constructor. */
0134     Point3D() = default;
0135 
0136     /**
0137      * Constructor from three numbers. */
0138     Point3D(double x1, double y1, double z1) : BasicVector3D<double>(x1,y1,z1) {}
0139 
0140     /**
0141      * Constructor from array of floats. */
0142     explicit Point3D(const float * a)
0143       : BasicVector3D<double>(a[0],a[1],a[2]) {}
0144 
0145     /**
0146      * Constructor from array of doubles. */
0147     explicit Point3D(const double * a)
0148       : BasicVector3D<double>(a[0],a[1],a[2]) {}
0149 
0150     /**
0151      * Copy constructor. */
0152     Point3D(const Point3D<double> &) = default;
0153 
0154     /**
0155      * Move constructor. */
0156     Point3D(Point3D<double> &&) = default;
0157 
0158     /**
0159      * Constructor from BasicVector3D<float>. */
0160     Point3D(const BasicVector3D<float> & v) : BasicVector3D<double>(v) {}
0161 
0162     /**
0163      * Constructor from BasicVector3D<double>. */
0164     Point3D(const BasicVector3D<double> & v) : BasicVector3D<double>(v) {}
0165 
0166     /**
0167      * Destructor. */
0168     ~Point3D() = default;
0169 
0170     /**
0171      * Constructor from CLHEP::Hep3Vector.
0172      * This constructor is needed only for backward compatibility and
0173      * in principle should be absent.
0174      */
0175     Point3D(const CLHEP::Hep3Vector & v)
0176       : BasicVector3D<double>(v.x(),v.y(),v.z()) {}
0177 
0178     /**
0179      * Conversion (cast) to CLHEP::Hep3Vector.
0180      * This operator is needed only for backward compatibility and
0181      * in principle should not exit.
0182      */
0183     operator CLHEP::Hep3Vector () const { return CLHEP::Hep3Vector(x(),y(),z()); }
0184 
0185     /**
0186      * Assignment. */
0187     Point3D<double> & operator=(const Point3D<double> &) = default;
0188 
0189     /**
0190      * Assignment from BasicVector3D<float>. */
0191     Point3D<double> & operator=(const BasicVector3D<float> & v) {
0192       this->BasicVector3D<double>::operator=(v);
0193       return *this;
0194     }
0195 
0196     /**
0197      * Assignment from BasicVector3D<double>. */
0198     Point3D<double> & operator=(const BasicVector3D<double> & v) {
0199       this->BasicVector3D<double>::operator=(v);
0200       return *this;
0201     }
0202 
0203     /**
0204      * Move assignment. */
0205     Point3D<double> & operator=(Point3D<double> &&) = default;
0206 
0207     /**
0208      * Returns distance to the origin squared. */
0209     double distance2() const { return mag2(); }
0210 
0211     /**
0212      * Returns distance to the point squared. */
0213     double distance2(const Point3D<double> & p) const {
0214       double dx = p.x()-x(), dy = p.y()-y(), dz = p.z()-z();
0215       return dx*dx + dy*dy + dz*dz;
0216     }
0217 
0218     /**
0219      * Returns distance to the origin. */
0220     double distance() const { return std::sqrt(distance2()); }
0221 
0222     /**
0223      * Returns distance to the point. */
0224     double distance(const Point3D<double> & p) const {
0225       return std::sqrt(distance2(p));
0226     }
0227 
0228     /**
0229      * Transformation by Transform3D. */
0230     Point3D<double> & transform(const Transform3D & m);
0231   };
0232 
0233   /**
0234    * Transformation of Point3D<double> by Transform3D.
0235    * @relates Point3D
0236    */
0237   Point3D<double>
0238   operator*(const Transform3D & m, const Point3D<double> & p);
0239 
0240 } /* namespace HepGeom */
0241 
0242 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0243 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0244 #include "CLHEP/config/CLHEP.h"
0245 #include "CLHEP/Geometry/Normal3D.h"
0246 #include "CLHEP/Geometry/Transform3D.h"
0247 typedef HepGeom::Point3D<double> HepPoint3D;
0248 #endif
0249 
0250 #endif /* HEP_POINT3D_H */