From 1d3889e93f547df9f6c578b107552807c27fc6d4 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 4 May 2019 23:19:05 +0400 Subject: i commit --- point.h | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 point.h (limited to 'point.h') diff --git a/point.h b/point.h new file mode 100644 index 0000000..36cfda9 --- /dev/null +++ b/point.h @@ -0,0 +1,87 @@ +// +// Created by saintruler on 11.04.19. +// + +#ifndef OPENGLTEST_POINT_H +#define OPENGLTEST_POINT_H + +#include + +class point +{ +public: + point(double x, double y) + { + this->x = x; + this->y = y; + } + + friend point operator+(const point& left, const point& right) + { + return point(left.x + right.x, left.y + right.y); + } + + friend point operator+=(point& left, const point& right) + { + left.x += right.x; + left.y += right.y; + return left; + } + + friend point operator-(const point& left, const point& right) + { + return point(left.x - right.x, left.y - right.y); + } + + friend point operator-=(point& left, const double right) + { + left.x -= right; + left.y -= right; + return left; + } + + friend point operator/(const point& left, const double right) + { + return point(left.x / right, left.y / right); + } + + friend point operator/=(point& left, const double right) + { + left.x /= right; + left.y /= right; + return left; + } + + friend point operator*(const point& left, const double right) + { + return point(left.x * right, left.y * right); + } + + friend point operator*=(point& left, const double right) + { + left.x *= right; + left.y *= right; + return left; + } + + double length() + { + return sqrt(pow(x, 2) + pow(y, 2)); + } + + double length_sqared() + { + return pow(x, 2) + pow(y, 2); + } + + void normalize() + { + const double l = length(); + this->x /= l; + this->y /= l; + } + + double x, y; +}; + +#endif //OPENGLTEST_POINT_H -- cgit v1.2.3