summaryrefslogtreecommitdiffstats
path: root/Line.cpp
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-09-16 22:59:04 +0200
committerneoraider <devnull@localhost>2007-09-16 22:59:04 +0200
commit96e9d04527dc17a2a4f8c2f7034c1c356ed5186e (patch)
tree20bc1fe6fd680005c47c49396aca5b6e237e1c7d /Line.cpp
parent5ea7f0464eb13581322215f0614eaae52393e02a (diff)
downloadzoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.tar
zoomedit-96e9d04527dc17a2a4f8c2f7034c1c356ed5186e.zip
zoomedit: C++ized Line & Rectangle
Diffstat (limited to 'Line.cpp')
-rw-r--r--Line.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/Line.cpp b/Line.cpp
index c755050..4bc0c3c 100644
--- a/Line.cpp
+++ b/Line.cpp
@@ -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;