diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-12-03 16:27:06 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-12-03 16:27:06 +0100 |
| commit | 7b7f6808a7b2db2ed21103767434c1445f7815c2 (patch) | |
| tree | 7b3553187d169757fedcdaf20f286761f29c2551 /labb7/src/Point.h | |
| parent | 0a8d737eccc6bfdb6ad7b9aaa1f6fc7c5b84f1eb (diff) | |
| download | tddd86-7b7f6808a7b2db2ed21103767434c1445f7815c2.tar.gz | |
add given files l7
Diffstat (limited to 'labb7/src/Point.h')
| -rw-r--r-- | labb7/src/Point.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/labb7/src/Point.h b/labb7/src/Point.h new file mode 100644 index 0000000..3b167a4 --- /dev/null +++ b/labb7/src/Point.h @@ -0,0 +1,57 @@ +/*
+ * TDDD86 Pattern Recognition
+ * This file contains the declaration of the Point class.
+ * See Point.cpp for implementation of each member.
+ * Your code should work properly with an unmodified version of this file.
+ */
+
+#ifndef POINT_H
+#define POINT_H
+
+#include <iostream>
+#include <QGraphicsScene>
+using namespace std;
+
+static const int COORD_MAX = 32767; // max value of x and y coordinates
+
+/*
+ * Each Point object represents an immutable single point
+ * with integer coordinates in the Euclidean plane.
+ */
+class Point {
+public:
+
+ Point() = delete;
+ Point(unsigned int _x, unsigned int _y) : x(_x), y(_y){}
+
+ /**
+ * Slope between this point and p
+ *
+ * If the points are the same, negative infinity is returned
+ * If the line between the points is horizontal positive zero is returned
+ * If the line between the points is vertical positive infinity is returned
+ */
+ double slopeTo(const Point& p) const;
+ /**
+ * Draw point to scene
+ */
+ void draw(QGraphicsScene* scene) const;
+ /**
+ * Draw line from this point to p to scene
+ */
+ void lineTo(QGraphicsScene* scene, const Point& p) const;
+
+ /**
+ * Is this point lexicographically smaller than p?
+ * Comparing x-ccordinates and breaking ties by y-coordinates
+ */
+ bool operator<(const Point&) const;
+ bool operator>(const Point&) const;
+
+ friend ostream& operator<<(ostream&, const Point&);
+
+private:
+ unsigned int x, y; // position
+};
+
+#endif // POINT_H
|
