Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:33

0001 #ifndef GeometryVector_Point2DBase_h
0002 #define GeometryVector_Point2DBase_h
0003 
0004 #include "DataFormats/GeometryVector/interface/PointTag.h"
0005 #include "DataFormats/GeometryVector/interface/PV2DBase.h"
0006 #include "DataFormats/GeometryVector/interface/Vector2DBase.h"
0007 
0008 template <class T, class FrameTag>
0009 class Point2DBase : public PV2DBase<T, PointTag, FrameTag> {
0010 public:
0011   typedef PV2DBase<T, PointTag, FrameTag> BaseClass;
0012   typedef Vector2DBase<T, FrameTag> VectorType;
0013   typedef Basic2DVector<T> BasicVectorType;
0014   typedef typename BaseClass::Polar Polar;
0015 
0016   /** default constructor uses default constructor of T to initialize the 
0017    *  components. For built-in floating-point types this means initialization 
0018    * to zero
0019    */
0020   Point2DBase() {}
0021 
0022   /** Construct from another point in the same reference frame, possiblly
0023    *  with different precision
0024    */
0025   template <class U>
0026   Point2DBase(const Point2DBase<U, FrameTag>& p) : BaseClass(p.basicVector()) {}
0027 
0028   /// construct from cartesian coordinates
0029   Point2DBase(const T& x, const T& y) : BaseClass(x, y) {}
0030 
0031   /// construct from polar coordinates
0032   explicit Point2DBase(const Polar& set) : BaseClass(set) {}
0033 
0034   /** Explicit constructor from BasicVectorType, bypasses consistency checks
0035    *  for point/vector and for coordinate frame. To be used as carefully as
0036    *  e.g. const_cast.
0037    */
0038   template <class U>
0039   explicit Point2DBase(const Basic2DVector<U>& v) : BaseClass(v) {}
0040 
0041   /** A Point can be shifted by a Vector of possibly different precision,
0042    *  defined in the same coordinate frame
0043    */
0044   template <class U>
0045   Point2DBase& operator+=(const Vector2DBase<U, FrameTag>& v) {
0046     this->basicVector() += v.basicVector();
0047     return *this;
0048   }
0049 
0050   template <class U>
0051   Point2DBase& operator-=(const Vector2DBase<U, FrameTag>& v) {
0052     this->basicVector() -= v.basicVector();
0053     return *this;
0054   }
0055 };
0056 
0057 /** The sum of a Point and a Vector is a Point. The arguments must be defined
0058  *  in the same reference frame. The resulting point has the higher precision
0059  *  of the precisions of the two arguments.
0060  */
0061 template <typename T, typename U, class Frame>
0062 inline Point2DBase<typename PreciseFloatType<T, U>::Type, Frame> operator+(const Point2DBase<T, Frame>& p,
0063                                                                            const Vector2DBase<U, Frame>& v) {
0064   typedef Point2DBase<typename PreciseFloatType<T, U>::Type, Frame> RT;
0065   return RT(p.basicVector() + v.basicVector());
0066 }
0067 
0068 /** Same as operator+(Point,Vector) (see above)
0069  */
0070 template <typename T, typename U, class Frame>
0071 inline Point2DBase<typename PreciseFloatType<T, U>::Type, Frame> operator+(const Vector2DBase<T, Frame>& p,
0072                                                                            const Point2DBase<U, Frame>& v) {
0073   typedef Point2DBase<typename PreciseFloatType<T, U>::Type, Frame> RT;
0074   return RT(p.basicVector() + v.basicVector());
0075 }
0076 
0077 /** The difference of two points is a vector. The arguments must be defined
0078  *  in the same reference frame. The resulting vector has the higher precision
0079  *  of the precisions of the two arguments.
0080  */
0081 template <typename T, typename U, class Frame>
0082 inline Vector2DBase<typename PreciseFloatType<T, U>::Type, Frame> operator-(const Point2DBase<T, Frame>& p1,
0083                                                                             const Point2DBase<U, Frame>& p2) {
0084   typedef Vector2DBase<typename PreciseFloatType<T, U>::Type, Frame> RT;
0085   return RT(p1.basicVector() - p2.basicVector());
0086 }
0087 
0088 #endif  // GeometryVector_Point2DBase_h