summaryrefslogtreecommitdiffstats
path: root/Line.cpp
diff options
context:
space:
mode:
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;