diff options
author | max-001 <maxsmits21@kpnmail.nl> | 2024-11-21 17:04:37 +0100 |
---|---|---|
committer | max-001 <maxsmits21@kpnmail.nl> | 2024-11-21 17:04:37 +0100 |
commit | adbd81d3937a1363af312202c7e4b5ec0bf3458d (patch) | |
tree | a45ebed952a0d4720f93192cf5f638f6e2f2961d /src/crepe/api/Vector2.hpp | |
parent | 115d6f50152dc018073345800ca90b85846ebaa9 (diff) |
Made Vector2 templated
Diffstat (limited to 'src/crepe/api/Vector2.hpp')
-rw-r--r-- | src/crepe/api/Vector2.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/crepe/api/Vector2.hpp b/src/crepe/api/Vector2.hpp new file mode 100644 index 0000000..e0ac3d4 --- /dev/null +++ b/src/crepe/api/Vector2.hpp @@ -0,0 +1,44 @@ +#include "Vector2.h" + +namespace crepe { + +template <class T> +Vector2<T> Vector2<T>::operator-(const Vector2<T> & other) const { return {x - other.x, y - other.y}; } + +template <class T> +Vector2<T> Vector2<T>::operator+(const Vector2<T> & other) const { return {x + other.x, y + other.y}; } + +template <class T> +Vector2<T> Vector2<T>::operator*(double scalar) const { return {x * scalar, y * scalar}; } + +template <class T> +Vector2<T> & Vector2<T>::operator*=(const Vector2<T> & other) { + x *= other.x; + y *= other.y; + return *this; +} + +template <class T> +Vector2<T> & Vector2<T>::operator+=(const Vector2<T> & other) { + x += other.x; + y += other.y; + return *this; +} + +template <class T> +Vector2<T> & Vector2<T>::operator+=(double other) { + x += other; + y += other; + return *this; +} + +template <class T> +Vector2<T> Vector2<T>::operator-() const { return {-x, -y}; } + +template <class T> +bool Vector2<T>::operator==(const Vector2<T> & other) const { return x == other.x && y == other.y; } + +template <class T> +bool Vector2<T>::operator!=(const Vector2<T> & other) const { return !(*this == other); } + +} // namespace crepe |