#pragma once #include #include "Vector2.h" namespace crepe { template Vector2 Vector2::operator-(const Vector2 & other) const { return {x - other.x, y - other.y}; } template Vector2 Vector2::operator-(T scalar) const { return {x - scalar, y - scalar}; } template Vector2 Vector2::operator+(const Vector2 & other) const { return {x + other.x, y + other.y}; } template Vector2 Vector2::operator+(T scalar) const { return {x + scalar, y + scalar}; } template Vector2 Vector2::operator*(const Vector2 & other) const { return {x * other.x, y * other.y}; } template Vector2 Vector2::operator*(T scalar) const { return {x * scalar, y * scalar}; } template Vector2 Vector2::operator/(const Vector2 & other) const { return {x / other.x, y / other.y}; } template Vector2 Vector2::operator/(T scalar) const { return {x / scalar, y / scalar}; } template Vector2 & Vector2::operator+=(const Vector2 & other) { x += other.x; y += other.y; return *this; } template Vector2 & Vector2::operator+=(T other) { x += other; y += other; return *this; } template Vector2 & Vector2::operator-=(const Vector2 & other) { x -= other.x; y -= other.y; return *this; } template Vector2 & Vector2::operator-=(T other) { x -= other; y -= other; return *this; } template Vector2 & Vector2::operator*=(const Vector2 & other) { x *= other.x; y *= other.y; return *this; } template Vector2 & Vector2::operator*=(T other) { x *= other; y *= other; return *this; } template Vector2 & Vector2::operator/=(const Vector2 & other) { x /= other.x; y /= other.y; return *this; } template Vector2 & Vector2::operator/=(T other) { x /= other; y /= other; return *this; } template Vector2 Vector2::operator-() const { return {-x, -y}; } template bool Vector2::operator==(const Vector2 & other) const { return x == other.x && y == other.y; } template bool Vector2::operator!=(const Vector2 & other) const { return !(*this == other); } template void Vector2::truncate(T max) { if (length() > max) { normalize(); *this *= max; } } template void Vector2::normalize() { T len = length(); if (len > 0) { *this /= len; } } template T Vector2::length() const { return std::sqrt(x * x + y * y); } template T Vector2::length_squared() const { return x * x + y * y; } template T Vector2::dot(const Vector2 & other) const { return x * other.x + y * other.y; } template T Vector2::distance(const Vector2 & other) const { return (*this - other).length(); } template T Vector2::distance_squared(const Vector2 & other) const { return (*this - other).length_squared(); } template Vector2 Vector2::perpendicular() const { return {-y, x}; } } // namespace crepe