summaryrefslogtreecommitdiffstats
path: root/Line.h
diff options
context:
space:
mode:
Diffstat (limited to 'Line.h')
-rw-r--r--Line.h34
1 files changed, 29 insertions, 5 deletions
diff --git a/Line.h b/Line.h
index 0fad7f3..18f714c 100644
--- a/Line.h
+++ b/Line.h
@@ -2,6 +2,7 @@
#define LINE_H_
#include "Vertex.h"
+#include <math.h>
#define INTERSECTION_ERROR -1
@@ -13,11 +14,34 @@
#define INTERSECTION_SEGMENT_LINE 6
#define INTERSECTION_SEGMENT_SEGMENT 7
-typedef struct _LINE {
- Vertex v1, v2;
-} LINE;
+class Line {
+ private:
+ Vertex v1, v2;
+ public:
+ Line() {}
+ Line(const Vertex& v1, const Vertex& v2) {
+ this->v1 = v1; this->v2 = v2;
+ }
+ Line(double x1, double y1, double x2, double y2) {
+ v1.setLocation(x1, y1);
+ v2.setLocation(x2, y2);
+ }
+
+ Vertex &getVertex1() {return v1;}
+ const Vertex &getVertex1() const {return v1;}
+ void setVertex1(const Vertex &v) {v1 = v;}
+
+ Vertex &getVertex2() {return v2;}
+ const Vertex &getVertex2() const {return v2;}
+ void setVertex2(const Vertex &v) {v2 = v;}
+
+ double lengthSq() const {return v1.distanceSq(v2);}
+ double length() const {return sqrt(lengthSq());}
+
+ bool contains(const Vertex &v) const;
+
+ int intersects(const Line &l, Vertex *v) const;
+};
-int lineIntersection(const LINE *la, const LINE *lb, Vertex *v);
-
#endif /*LINE_H_*/