summaryrefslogtreecommitdiffstats
path: root/Polygon.h
blob: 33ba873f593efcd023416a90df36ef34227b4892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef POLYGON_H_
#define POLYGON_H_

#include "Vertex.h"
#include "Line.h"
#include "Triangle.h"
#include <vector>
#include <list>

class Polygon : public std::vector<Vertex> {
  private:
    struct Intersection {
      size_t va1, va2, vb1, vb2;
      Vertex v;
    };
    
    typedef Triangle::Direction Direction;
    
    int quadrant(const Vertex &v) const;
    
    float signedArea() const;
    
    bool isConcave(const Triangle::Direction &dir, const Vertex &v1, const Vertex &v2, const Vertex &v3) const;
    
    bool intersections(std::vector<Intersection> *intersections = NULL) const;
    
    void doTriangulate(std::vector<Triangle> &triangles) const;
  public:
    float area() const;
    float perimeter() const;
    
    bool contains(const Vertex &v) const;
    bool intersects(const Line &l) const;
    
    Triangle::Direction getDirection() const;
    
    bool isSimple() const;
    bool simplify(std::list<Polygon> &polygons) const;
    
    void triangulate(std::vector<Triangle> &triangles) const;
};

#endif /*POLYGON_H_*/