#pragma once #include #include // 2D Vectors template class Vec2D{ public: Vec2D() {}; Vec2D(T x, T y) : x(x), y(y) {} T x = 0; T y = 0; T dist(Vec2D* v) { return sqrt(pow((v->x - x), 2) + pow((v->y - y), 2));}; T length() { return (T)sqrt(pow(x, 2) + pow(y, 2));}; T angle(Vec2D &v){ T angle = atan2(v.y, v.x) - atan2(y,x); if(angle > M_PI) angle -= M_PI_2; if(angle < -M_PI) angle += M_PI_2; return angle; //return acos(dot(v)); }; T angleDeg(Vec2D &v){ return angle(v) * 180 / M_PI; }; T dot(Vec2D &v){ return (x*v.x) + (y*v.y); }; Vec2D norm() { return *this / length();}; Vec2D& operator=(const Vec2D& vec){ if (this == &vec){ return *this; } x = vec.x; y = vec.y; return *this; }; Vec2D& operator+=(const Vec2D& vec){ this->x += vec.x; this->y += vec.y; return *this; }; Vec2D& operator-=(const Vec2D& vec){ this->x -= vec.x; this->y -= vec.y; return *this; }; Vec2D& operator*=(const Vec2D& vec){ this->x *= vec.x; this->y *= vec.y; return *this; }; Vec2D& operator/=(const Vec2D& vec){ this->x /= vec.x; this->y /= vec.y; return *this; }; Vec2D& operator*=(T scalar){ this->x *= scalar; this->y *= scalar; return *this; }; Vec2D& operator/=(T scalar){ this->x /= scalar; this->y /= scalar; return *this; }; }; template Vec2D operator+(const Vec2D& left, const Vec2D& right){ return Vec2D(left.x + right.x, left.y + right.y); }; template Vec2D operator-(const Vec2D& left, const Vec2D& right){ return Vec2D(left.x - right.x, left.y - right.y); }; template Vec2D operator*(const Vec2D& left, const Vec2D& right){ return Vec2D(left.x * right.x, left.y * right.y); }; template Vec2D operator/(const Vec2D& left, const Vec2D& right){ return Vec2D(left.x / right.x, left.y / right.y); }; template Vec2D operator/(const Vec2D& left, T scalar){ return Vec2D(left.x / scalar, left.y / scalar); }; template Vec2D operator*(const Vec2D& left, T scalar){ return Vec2D(left.x * scalar, left.y * scalar); }; /*template */ /*bool contains(T X, T Y) {*/ /* for (unsigned int i=0;i