#pragma once #include #include namespace Swan { template class Vector2 { public: constexpr Vector2(T x = 0, T y = 0): x_(x), y_(y) {} Vector2 &set(T x, T y) { x_ = x; y_ = y; return *this; } operator sf::Vector2() const { return sf::Vector2(x_, y_); } operator std::pair() const { return std::pair(x_, y_); } operator Vector2() const { return Vector2(x_, y_); } bool operator==(const Vector2 &vec) const { return x_ == vec.x_ && y_ == vec.y_; } bool operator!=(const Vector2 &vec) const { return !(*this == vec); } Vector2 operator-() const { return Vector2(-x_, -y_); } Vector2 operator+(const Vector2 &vec) const { return Vector2(x_ + vec.x_, y_ + vec.y_); } Vector2 &operator+=(const Vector2 &vec) { x_ += vec.x_; y_ += vec.y_; return *this; } Vector2 operator-(const Vector2 &vec) const { return Vector2(x_ - vec.x_, y_ - vec.y_); } Vector2 &operator-=(const Vector2 &vec) { x_ -= vec.x_; y_ -= vec.y_; return *this; } Vector2 operator*(const Vector2 &vec) const { return Vector2(x_ * vec.x_, y_ * vec.y_); } Vector2 &operator*=(const Vector2 &vec) { x_ *= vec.x_; y_ *= vec.y_; return *this; } Vector2 operator*(T num) const { return Vector2(x_ * num, y_ * num); } Vector2 operator*=(T num) { x_ *= num; y_ *= num; return *this; } Vector2 operator/(const Vector2 &vec) const { return Vector2(x_ / vec.x_, y_ / vec.y_); } Vector2 &operator/=(const Vector2 &vec) { x_ /= vec.x_; y_ /= vec.y_; return *this; } Vector2 operator/(T num) const { return Vector2(x_ / num, y_ / num); } Vector2 operator/=(T num) { x_ /= num; y_ /= num; return *this; } T x_; T y_; static const Vector2 ZERO; }; template const Vector2 Vector2::ZERO = Vector2(0, 0); using Vec2 = Vector2; using Vec2i = Vector2; }