LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 <vector>
19 #include <utility>
20 #include <math.h>
21 #include <stdlib.h>
22 #include <iostream>
23 #include <fstream>
24 #include <ctime>
25 
26 //a polygon is a vector of std::pairs with first = x coordinate
27 //and second = y coordinate of that vertex
28 //access vertices with Point function. Points are:
29 //0 = first ordered vertex
30 //n-1 = last ordered vertex (n=size of polygon)
31 //n = first vertex again
32 //>n = invalid...return error message
33 
34 //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
35 // BEGIN POLYGON CLASS //
36 //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
37 class Polygon2D{
38 
39 private:
40  std::vector< std::pair<float,float> > vertices;
41 
42  public:
43 
44  Polygon2D() { }
45  Polygon2D(const std::vector< std::pair<float,float> > &points) { vertices = points; }
46  Polygon2D(const Polygon2D &poly1, const Polygon2D &poly2);
47  unsigned int Size() const { return vertices.size(); }
48  const std::pair<float,float>& Point(unsigned int p) const;
49  std::pair<float,float> Project(const std::pair<float,float>&,float) const;
50  float Area() const;
51  float Perimeter() const;
52  bool Overlap(float slope, const Polygon2D &poly2, const std::pair<float,float> &origin) const;
53  bool PolyOverlap(const Polygon2D &poly2) const;
54  bool PolyOverlapSegments(const Polygon2D &poly2) const;
55  bool PointInside(const std::pair<float,float> &point) const;
56  bool Contained(const Polygon2D &poly2) const;
57  void UntanglePolygon();
58 }; // end of doxygen group
60 
61 #endif
float Area() const
Definition: Polygon2D.cxx:96
std::pair< float, float > Project(const std::pair< float, float > &, float) const
Definition: Polygon2D.cxx:153
bool Contained(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:271
const std::pair< float, float > & Point(unsigned int p) const
Definition: Polygon2D.cxx:135
Polygon2D()
Definition: Polygon2D.h:44
unsigned int Size() const
Create Intersection Polygon.
Definition: Polygon2D.h:47
float Perimeter() const
Definition: Polygon2D.cxx:113
std::vector< std::pair< float, float > > vertices
Definition: Polygon2D.h:40
Polygon2D(const std::vector< std::pair< float, float > > &points)
Definition: Polygon2D.h:45
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
bool PolyOverlapSegments(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:227
bool Overlap(float slope, const Polygon2D &poly2, const std::pair< float, float > &origin) const
Definition: Polygon2D.cxx:180
bool PointInside(const std::pair< float, float > &point) const
Definition: Polygon2D.cxx:249
bool PolyOverlap(const Polygon2D &poly2) const
Definition: Polygon2D.cxx:199
void UntanglePolygon()
check if poly2 is inside poly1
Definition: Polygon2D.cxx:286
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:230