diff options
author | neoraider <devnull@localhost> | 2007-09-16 22:59:04 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-09-16 22:59:04 +0200 |
commit | 96e9d04527dc17a2a4f8c2f7034c1c356ed5186e (patch) | |
tree | 20bc1fe6fd680005c47c49396aca5b6e237e1c7d /Polygon.cpp | |
parent | 5ea7f0464eb13581322215f0614eaae52393e02a (diff) | |
download | zoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.tar zoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.zip |
zoomedit: C++ized Line & Rectangle
Diffstat (limited to 'Polygon.cpp')
-rw-r--r-- | Polygon.cpp | 24 |
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; } |