Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:31:27

0001 #ifndef FourPointPlaneBounds_H
0002 #define FourPointPlaneBounds_H
0003 
0004 #include "DataFormats/GeometrySurface/interface/Bounds.h"
0005 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0006 #include "DataFormats/GeometryVector/interface/Vector2DBase.h"
0007 
0008 typedef Vector2DBase<float, LocalTag> Local2DVector;
0009 
0010 class FourPointPlaneBounds : public Bounds {
0011 public:
0012   typedef LocalPoint::ScalarType Scalar;
0013 
0014   /** The corners are ASSUMED to come in cyclic order
0015  */
0016   FourPointPlaneBounds(const LocalPoint& a, const LocalPoint& b, const LocalPoint& c, const LocalPoint& d);
0017   ~FourPointPlaneBounds() override {}
0018 
0019   float length() const override;
0020   float width() const override;
0021   float thickness() const override;
0022 
0023   // basic bounds function
0024   bool inside(const Local3DPoint& lp) const override;
0025 
0026   bool inside(const Local3DPoint& lp, const LocalError& e, float scale) const override { return inside(lp); }
0027 
0028   Bounds* clone() const override { return new FourPointPlaneBounds(*this); }
0029 
0030 private:
0031   Local2DPoint corners_[4];
0032 
0033   const Local2DPoint& corner(int i) const { return corners_[i % 4]; }
0034   double checkSide(int i, const Local2DPoint& lp) const;
0035 
0036   double checkSide(int i, Scalar x, Scalar y) const {
0037     const Local2DPoint& cor(corner(i));
0038     Local2DVector v(corner(i + 1) - cor);
0039     // Local2DVector normal( -v.y(), v.x());  //  90 deg rotated
0040     return -v.y() * (x - cor.x()) + v.x() * (y - cor.y());  // == normal.dot(LP(x,y)-cor))
0041   }
0042 };
0043 
0044 #endif