Polygon2D.h
Go to the documentation of this file.
1 /**
2  * \file Polygon2D.h
3  *
4  * \ingroup ClusterRecoUtil
5  *
6  * \brief 2D polygon object
7  *
8  * @author kazuhiro & david caratelli
9  */
10 
11 /** \addtogroup ClusterRecoUtil
12 
13  @{*/
14 
15 #ifndef RECOTOOL_POLYGON2D_H
16 #define RECOTOOL_POLYGON2D_H
17 
18 #include <utility>
19 #include <vector>
20 
21 //a polygon is a vector of std::pairs with first = x coordinate
22 //and second = y coordinate of that vertex
23 //access vertices with Point function. Points are:
24 //0 = first ordered vertex
25 //n-1 = last ordered vertex (n=size of polygon)
26 //n = first vertex again
27 //>n = invalid...return error message
28 
29 //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
30 // BEGIN POLYGON CLASS //
31 //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
32 class Polygon2D{
33 
34 private:
35  std::vector< std::pair<float,float> > vertices;
36 
37  public:
38 
39  Polygon2D() { }
40  Polygon2D(const std::vector< std::pair<float,float> > &points) { vertices = points; }
41  Polygon2D(const Polygon2D &poly1, const Polygon2D &poly2); /// Create Intersection Polygon
42  unsigned int Size() const { return vertices.size(); }
43  const std::pair<float,float>& Point(unsigned int p) const;
44  std::pair<float,float> Project(const std::pair<float,float>&,float) const;
45  float Area() const;
46  float Perimeter() const;
47  bool Overlap(float slope, const Polygon2D &poly2, const std::pair<float,float> &origin) const;
48  bool PolyOverlap(const Polygon2D &poly2) const;
49  bool PolyOverlapSegments(const Polygon2D &poly2) const;
50  bool PointInside(const std::pair<float,float> &point) const;
51  bool Contained(const Polygon2D &poly2) const; /// check if poly2 is inside poly1
52  void UntanglePolygon();
53 };
54 /** @} */ // end of doxygen group
55 
56 #endif
float Area() const
Definition: Polygon2D.cxx:99
std::pair< float, float > Project(const std::pair< float, float > &, float) const
Definition: Polygon2D.cxx:156
bool Contained(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:274
struct vector vector
const std::pair< float, float > & Point(unsigned int p) const
Definition: Polygon2D.cxx:138
Polygon2D()
Definition: Polygon2D.h:39
unsigned int Size() const
Create Intersection Polygon.
Definition: Polygon2D.h:42
float Perimeter() const
Definition: Polygon2D.cxx:116
std::vector< std::pair< float, float > > vertices
Definition: Polygon2D.h:35
Polygon2D(const std::vector< std::pair< float, float > > &points)
Definition: Polygon2D.h:40
bool PolyOverlapSegments(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:230
bool Overlap(float slope, const Polygon2D &poly2, const std::pair< float, float > &origin) const
Definition: Polygon2D.cxx:183
p
Definition: test.py:223
bool PointInside(const std::pair< float, float > &point) const
Definition: Polygon2D.cxx:252
bool PolyOverlap(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:202
void UntanglePolygon()
check if poly2 is inside poly1
Definition: Polygon2D.cxx:289
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227