// // Created by cbihan on 5/13/20. // #ifndef COMSQUARE_VECTOR2_HPP #define COMSQUARE_VECTOR2_HPP #include #include namespace ComSquare { template class Vector2 { public: T x; T y; Vector2() : x(0), y(0) {} Vector2(T _x, T _y) : x(_x), y(_y) {} Vector2(sf::Vector2 v) : x(v.x), y(v.y) {} template Vector2 &operator+=(const Vector2 &vec) { this->x += vec.x; this->y += vec.y; return *this; } template Vector2 operator+(const Vector2 &vec) const { return Vector2(this->x + vec.x, this->y + vec.y); } template Vector2 &operator-=(const Vector2 &vec) { this->x -= vec.x; this->y -= vec.y; return *this; } template Vector2 &operator*=(T2 d) { this->x *= d; this->y *= d; return *this; } template Vector2 operator*(T2 d) const { return Vector2(this->x * d, this->y * d); } template T operator*(Vector2 &b) const { return this->x * b.x + this->y * b.y; } template Vector2 operator/=(Vector2 &b) { this->x /= b.x; this->y /= b.y; return this; } template Vector2 operator/(Vector2 &b) const { return Vector2(this->x / b.x, this->y / b.y); } template Vector2 operator/=(T2 b) { this->x /= b; this->y /= b; return this; } template Vector2 operator/(T2 b) const { return Vector2(this->x / b, this->y / b); } }; typedef Vector2 Vector2f; typedef Vector2 Vector2u; typedef Vector2 Vector2i; } template std::ostream &operator<<(std::ostream &s, const ComSquare::Vector2 &v) { s << v.x << " " << v.y; return s; } #endif //COMSQUARE_VECTOR2_HPP