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 /Line.cpp | |
parent | 5ea7f0464eb13581322215f0614eaae52393e02a (diff) | |
download | zoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.tar zoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.zip |
zoomedit: C++ized Line & Rectangle
Diffstat (limited to 'Line.cpp')
-rw-r--r-- | Line.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
@@ -2,11 +2,42 @@ #include <math.h> -int lineIntersection(const LINE *la, const LINE *lb, Vertex *v) { - double xa1 = la->v1.getX(), ya1 = la->v1.getY(); - double xa2 = la->v2.getX(), ya2 = la->v2.getY(); - double xb1 = lb->v1.getX(), yb1 = lb->v1.getY(); - double xb2 = lb->v2.getX(), yb2 = lb->v2.getY(); +bool Line::contains(const Vertex &v) const { + if(v1.getX() == v2.getX() && v1.getY() == v2.getY()) { + if(v1.getX() == v.getX() && v1.getY() == v.getY()) + return true; + else + return false; + } + + if(v1.getX() == v2.getX()) { + if(v1.getX() != v.getX()) + return false; + else if(v.getY() >= fmin(v1.getY(), v2.getY()) && v.getY() <= fmax(v1.getY(), v2.getY())) + return true; + else + return false; + } + + if(v1.getY() == v2.getY()) { + if(v1.getY() != v.getY()) + return false; + else if(v.getX() >= fmin(v1.getX(), v2.getX()) && v.getX() <= fmax(v1.getX(), v2.getX())) + return true; + else + return false; + } + if((v.getX()-v1.getX())/(v2.getX()-v1.getX()) - (v.getY()-v1.getY())/(v2.getY()-v1.getY()) == 0) + return true; + else + return false; +} + +int Line::intersects(const Line &l, Vertex *v) const { + double xa1 = v1.getX(), ya1 = v1.getY(); + double xa2 = v2.getX(), ya2 = v2.getY(); + double xb1 = l.v1.getX(), yb1 = l.v1.getY(); + double xb2 = l.v2.getX(), yb2 = l.v2.getY(); double temp; int switched = 0; Vertex v2; |