LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
Polygon2D.h
Go to the documentation of this file.
1 
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  Polygon2D() {}
39  Polygon2D(const std::vector<std::pair<float, float>>& points) { vertices = points; }
40  Polygon2D(const Polygon2D& poly1, const Polygon2D& poly2);
41  unsigned int Size() const { return vertices.size(); }
42  const std::pair<float, float>& Point(unsigned int p) const;
43  std::pair<float, float> Project(const std::pair<float, float>&, float) const;
44  float Area() const;
45  float Perimeter() const;
46  bool Overlap(float slope, const Polygon2D& poly2, const std::pair<float, float>& origin) const;
47  bool PolyOverlap(const Polygon2D& poly2) const;
48  bool PolyOverlapSegments(const Polygon2D& poly2) const;
49  bool PointInside(const std::pair<float, float>& point) const;
50  bool Contained(const Polygon2D& poly2) const;
51  void UntanglePolygon();
52 }; // end of doxygen group
54 
55 #endif
float Area() const
Definition: Polygon2D.cxx:118
std::pair< float, float > Project(const std::pair< float, float > &, float) const
Definition: Polygon2D.cxx:175
bool Contained(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:296
const std::pair< float, float > & Point(unsigned int p) const
Definition: Polygon2D.cxx:158
Polygon2D()
Definition: Polygon2D.h:38
unsigned int Size() const
Create Intersection Polygon.
Definition: Polygon2D.h:41
std::vector< std::pair< float, float > > vertices
Definition: Polygon2D.h:35
float Perimeter() const
Definition: Polygon2D.cxx:136
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
bool PolyOverlapSegments(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:247
bool Overlap(float slope, const Polygon2D &poly2, const std::pair< float, float > &origin) const
Definition: Polygon2D.cxx:199
Polygon2D(const std::vector< std::pair< float, float >> &points)
Definition: Polygon2D.h:39
bool PointInside(const std::pair< float, float > &point) const
Definition: Polygon2D.cxx:271
bool PolyOverlap(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:221
void UntanglePolygon()
check if poly2 is inside poly1
Definition: Polygon2D.cxx:309
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:229