summaryrefslogtreecommitdiffstats
path: root/Polygon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Polygon.cpp')
-rw-r--r--Polygon.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/Polygon.cpp b/Polygon.cpp
index 05d06ca..9340135 100644
--- a/Polygon.cpp
+++ b/Polygon.cpp
@@ -38,11 +38,11 @@ int Polygon::quadrant(const Vertex &v) const {
}
bool Polygon::contains(const Vertex &v) const {
+ const Line d1(-1, -1, 1, 1);
+ const Line d2(-1, 1, 1, -1);
int d = 0;
int q, ql, q2;
- LINE d1 = {Vertex(-1, -1), Vertex(1, 1)};
- LINE d2 = {Vertex(-1, 1), Vertex(1, -1)};
- LINE l;
+ Line l;
Vertex v2;
@@ -73,11 +73,11 @@ bool Polygon::contains(const Vertex &v) const {
d--;
break;
default:
- l.v1 = ((it == begin()) ? back() : *(it-1)) - v;
- l.v2 = v2;
+ l.setVertex1(((it == begin()) ? back() : *(it-1)) - v);
+ l.setVertex2(v2);
if(q == 1 || q == 3) {
- if(!(lineIntersection(&l, &d2, &v2) & INTERSECTION_LINE)) return false;
+ if(!(l.intersects(d2, &v2) & INTERSECTION_LINE)) return false;
q2 = quadrant(v2);
if(q2 == 0) return true;
@@ -86,7 +86,7 @@ bool Polygon::contains(const Vertex &v) const {
else d += 2;
}
else {
- if(!(lineIntersection(&l, &d1, &v2) & INTERSECTION_LINE)) return false;
+ if(!(l.intersects(d1, &v2) & INTERSECTION_LINE)) return false;
q2 = quadrant(v2);
if(q2 == 0) return true;
@@ -100,17 +100,17 @@ bool Polygon::contains(const Vertex &v) const {
return (d != 0);
}
-bool Polygon::intersects(const LINE *l) const {
- LINE line;
+bool Polygon::intersects(const Line &l) const {
+ Line line;
for(Polygon::const_iterator it = begin(); it != end(); it++) {
Polygon::const_iterator it2 = it+1;
if(it2 == end()) it2 = begin();
- line.v1 = *it;
- line.v2 = *it2;
+ line.setVertex1(*it);
+ line.setVertex2(*it2);
- if(lineIntersection(l, &line, NULL) == INTERSECTION_SEGMENT_SEGMENT)
+ if(l.intersects(line, NULL) == INTERSECTION_SEGMENT_SEGMENT)
return true;
}