From 7b7f6808a7b2db2ed21103767434c1445f7815c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 3 Dec 2020 16:27:06 +0100 Subject: add given files l7 --- labb7/src/Point.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 labb7/src/Point.h (limited to 'labb7/src/Point.h') 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 +#include +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 -- cgit v1.2.1