Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:16

0001 #ifndef GeometryVector_Point3DBase_h
0002 #define GeometryVector_Point3DBase_h
0003 
0004 #include "DataFormats/GeometryVector/interface/PointTag.h"
0005 #include "DataFormats/GeometryVector/interface/PV3DBase.h"
0006 #include "DataFormats/GeometryVector/interface/Point2DBase.h"
0007 #include "DataFormats/GeometryVector/interface/Vector3DBase.h"
0008 
0009 template <class T, class FrameTag>
0010 class Point3DBase : public PV3DBase<T, PointTag, FrameTag> {
0011 public:
0012   typedef PV3DBase<T, PointTag, FrameTag> BaseClass;
0013   typedef Vector3DBase<T, FrameTag> VectorType;
0014   typedef typename BaseClass::Cylindrical Cylindrical;
0015   typedef typename BaseClass::Spherical Spherical;
0016   typedef typename BaseClass::Polar Polar;
0017   typedef typename BaseClass::BasicVectorType BasicVectorType;
0018 
0019   /** default constructor uses default constructor of T to initialize the 
0020    *  components. For built-in floating-point types this means initialization 
0021    * to zero
0022    */
0023   Point3DBase() {}
0024 
0025   /** Construct from another point in the same reference frame, possiblly
0026    *  with different precision
0027    */
0028   template <class U>
0029   Point3DBase(const Point3DBase<U, FrameTag>& p) : BaseClass(p.basicVector()) {}
0030 
0031   /// construct from cartesian coordinates
0032   Point3DBase(const T& x, const T& y, const T& z) : BaseClass(x, y, z) {}
0033 
0034   /** Construct from cylindrical coordinates.
0035    */
0036   explicit Point3DBase(const Cylindrical& set) : BaseClass(set) {}
0037 
0038   /// construct from polar coordinates
0039   explicit Point3DBase(const Polar& set) : BaseClass(set) {}
0040 
0041   /** Deprecated construct from polar coordinates, use 
0042    *  constructor from Polar( theta, phi, r) instead. 
0043    */
0044   Point3DBase(const Geom::Theta<T>& th, const Geom::Phi<T>& ph, const T& r) : BaseClass(th, ph, r) {}
0045 
0046   /** Mimick 2D point. This constructor is convenient for points on a plane,
0047    *  since the z component for them is zero. 
0048    */
0049   Point3DBase(const T& x, const T& y) : BaseClass(x, y, 0) {}
0050   explicit Point3DBase(Point2DBase<T, FrameTag> p) : BaseClass(p.x(), p.y(), 0) {}
0051 
0052   /** Explicit constructor from BasicVectorType, bypasses consistency checks
0053    *  for point/vector and for coordinate frame. To be used as carefully as
0054    *  e.g. const_cast.
0055    */
0056   template <class U>
0057   explicit Point3DBase(const Basic3DVector<U>& v) : BaseClass(v) {}
0058 
0059   // equality
0060   bool operator==(const Point3DBase& rh) const { return this->basicVector() == rh.basicVector(); }
0061 
0062   /** A Point can be shifted by a Vector of possibly different precision,
0063    *  defined in the same coordinate frame
0064    */
0065   template <class U>
0066   Point3DBase& operator+=(const Vector3DBase<U, FrameTag>& v) {
0067     this->theVector += v.basicVector();
0068     return *this;
0069   }
0070 
0071   template <class U>
0072   Point3DBase& operator-=(const Vector3DBase<U, FrameTag>& v) {
0073     this->theVector -= v.basicVector();
0074     return *this;
0075   }
0076 };
0077 
0078 /** The sum of a Point and a Vector is a Point. The arguments must be defined
0079  *  in the same reference frame. The resulting point has the higher precision
0080  *  of the precisions of the two arguments.
0081  */
0082 template <typename T, typename U, class Frame>
0083 inline Point3DBase<typename PreciseFloatType<T, U>::Type, Frame> operator+(const Point3DBase<T, Frame>& p,
0084                                                                            const Vector3DBase<U, Frame>& v) {
0085   typedef Point3DBase<typename PreciseFloatType<T, U>::Type, Frame> RT;
0086   return RT(p.basicVector() + v.basicVector());
0087 }
0088 
0089 /** Same as operator+(Point,Vector) (see above)
0090  */
0091 template <typename T, typename U, class Frame>
0092 inline Point3DBase<typename PreciseFloatType<T, U>::Type, Frame> operator+(const Vector3DBase<T, Frame>& p,
0093                                                                            const Point3DBase<U, Frame>& v) {
0094   typedef Point3DBase<typename PreciseFloatType<T, U>::Type, Frame> RT;
0095   return RT(p.basicVector() + v.basicVector());
0096 }
0097 
0098 /** The difference of two points is a vector. The arguments must be defined
0099  *  in the same reference frame. The resulting vector has the higher precision
0100  *  of the precisions of the two arguments.
0101  */
0102 template <typename T, typename U, class Frame>
0103 inline Vector3DBase<typename PreciseFloatType<T, U>::Type, Frame> operator-(const Point3DBase<T, Frame>& p1,
0104                                                                             const Point3DBase<U, Frame>& p2) {
0105   typedef Vector3DBase<typename PreciseFloatType<T, U>::Type, Frame> RT;
0106   return RT(p1.basicVector() - p2.basicVector());
0107 }
0108 
0109 /** The difference of a Point and a Vector is a Point. The arguments must be defined
0110  *  in the same reference frame. The resulting point has the higher precision
0111  *  of the precisions of the two arguments.
0112  */
0113 template <typename T, typename U, class Frame>
0114 inline Point3DBase<typename PreciseFloatType<T, U>::Type, Frame> operator-(const Point3DBase<T, Frame>& p,
0115                                                                            const Vector3DBase<U, Frame>& v) {
0116   typedef Point3DBase<typename PreciseFloatType<T, U>::Type, Frame> RT;
0117   return RT(p.basicVector() - v.basicVector());
0118 }
0119 #endif  // GeometryVector_Point3DBase_h