summaryrefslogtreecommitdiff
path: root/libraries/point
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-05-05 22:53:12 +0400
committerAndrew <saintruler@gmail.com>2019-05-05 22:53:12 +0400
commit3a94328b3cff255ac64a208ac98919cc3e530aa0 (patch)
tree377ab395a13e95b5c12a442645c2eaa4b2a644f8 /libraries/point
parent15ccb946f43283bfc91d80ddf012d9ae2a0333ed (diff)
Made changes to CMakeLists.txt so CUDA version of program builds when CUDA is installed.
Replaced C-style approach to generating texture to OOP-style with Canvas.h
Diffstat (limited to 'libraries/point')
-rw-r--r--libraries/point/Point.cpp75
-rw-r--r--libraries/point/Point.h30
2 files changed, 105 insertions, 0 deletions
diff --git a/libraries/point/Point.cpp b/libraries/point/Point.cpp
new file mode 100644
index 0000000..4ca4a8c
--- /dev/null
+++ b/libraries/point/Point.cpp
@@ -0,0 +1,75 @@
+//
+// Created by saintruler on 05.05.19.
+//
+#include "Point.h"
+
+Point::Point(double x, double y)
+{
+ this->x = x;
+ this->y = y;
+}
+
+Point operator+(const Point& left, const Point& right)
+{
+ return Point(left.x + right.x, left.y + right.y);
+}
+
+Point operator+=(Point& left, const Point& right)
+{
+ left.x += right.x;
+ left.y += right.y;
+ return left;
+}
+
+Point operator-(const Point& left, const Point& right)
+{
+ return Point(left.x - right.x, left.y - right.y);
+}
+
+Point operator-=(Point& left, const double right)
+{
+ left.x -= right;
+ left.y -= right;
+ return left;
+}
+
+Point operator/(const Point& left, const double right)
+{
+ return Point(left.x / right, left.y / right);
+}
+
+Point operator/=(Point& left, const double right)
+{
+ left.x /= right;
+ left.y /= right;
+ return left;
+}
+
+Point operator*(const Point& left, const double right)
+{
+ return Point(left.x * right, left.y * right);
+}
+
+Point operator*=(Point& left, const double right)
+{
+ left.x *= right;
+ left.y *= right;
+ return left;
+}
+
+double Point::length()
+{
+ return sqrt(pow(x, 2) + pow(y, 2));
+}
+
+double Point::length_squared()
+{
+ return pow(x, 2) + pow(y, 2);
+}
+
+void Point::normalize()
+{
+ const double l = length();
+ this->x /= l;
+ this->y /= l;
+}
diff --git a/libraries/point/Point.h b/libraries/point/Point.h
new file mode 100644
index 0000000..8163f8f
--- /dev/null
+++ b/libraries/point/Point.h
@@ -0,0 +1,30 @@
+//
+// Created by saintruler on 11.04.19.
+//
+
+#ifndef OPENGLTEST_POINT_H
+#define OPENGLTEST_POINT_H
+
+#include <cmath>
+
+class Point
+{
+public:
+ Point(double x, double y);
+
+ friend Point operator+(const Point& left, const Point& right);
+ friend Point operator+=(Point& left, const Point& right);
+ friend Point operator-(const Point& left, const Point& right);
+ friend Point operator-=(Point& left, double right);
+ friend Point operator/(const Point& left, double right);
+ friend Point operator/=(Point& left, double right);
+ friend Point operator*(const Point& left, double right);
+ friend Point operator*=(Point& left, double right);
+
+ double length();
+ double length_squared();
+ void normalize();
+ double x, y;
+};
+
+#endif //OPENGLTEST_POINT_H