forked from pchalamet/Martinez
-
Notifications
You must be signed in to change notification settings - Fork 0
/
greiner.h
61 lines (55 loc) · 1.62 KB
/
greiner.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef GREINER_H
#define GREINER_H
#include <iostream>
#include <vector>
#include <limits>
#include "segment.h"
#include "polygon.h"
#include "point.h"
#include "martinez.h"
using namespace std;
struct Vertex {
double x, y;
Vertex *prev, *next;
Segment s; // Segment which first point is the vertex
bool intersect; // is the vertex an intersection point?
bool entry; // is the intersection point an entry point on the other polygon?
bool processed; // for step 3
Vertex *neighbor;
double alpha;
Vertex (double xp, double yp, Segment sp, bool i, double a = numeric_limits<double>::max());
Vertex () {}
};
ostream& operator<< (ostream& o, const Vertex& v);
class GreinerContour {
public:
GreinerContour (Contour& c);
~GreinerContour () { deleteIntersections (); }
Vertex *firstVertex () { return &v[0]; }
/** @brief Insert vertex (intersection) v before the vertex pointed by vp */
Vertex *insert (const Vertex& v, Vertex *vp);
void deleteIntersections ();
bool intersectBoundingbox (GreinerContour& gc) const;
private:
/** @brief It holds the original vertices of the polygon */
vector<Vertex> v;
/** @brief Number of intersection points */
int nint;
/** @ brief bounding box */
Point minbox;
Point maxbox;
};
ostream& operator<< (ostream& o, GreinerContour& gc);
class GreinerHormann {
public:
GreinerHormann (Polygon& p1, Polygon& p2);
~GreinerHormann ();
int boolop (Martinez::BoolOpType op, Polygon& result);
private:
vector<GreinerContour*> gp1;
vector<GreinerContour*> gp2;
Polygon& subject;
Polygon& clipping;
int boolop (Martinez::BoolOpType op, GreinerContour& gc1, GreinerContour& gc2, Polygon& result);
};
#endif