diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Vector2.cpp | 33 | ||||
-rw-r--r-- | src/crepe/api/Vector2.h | 7 | ||||
-rw-r--r-- | src/crepe/api/Vector2.hpp | 44 |
3 files changed, 49 insertions, 35 deletions
diff --git a/src/crepe/api/Vector2.cpp b/src/crepe/api/Vector2.cpp deleted file mode 100644 index 30b968e..0000000 --- a/src/crepe/api/Vector2.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "Vector2.h" - -using namespace crepe; - -Vector2 Vector2::operator-(const Vector2 & other) const { return {x - other.x, y - other.y}; } - -Vector2 Vector2::operator+(const Vector2 & other) const { return {x + other.x, y + other.y}; } - -Vector2 Vector2::operator*(double scalar) const { return {x * scalar, y * scalar}; } - -Vector2 & Vector2::operator*=(const Vector2 & other) { - x *= other.x; - y *= other.y; - return *this; -} - -Vector2 & Vector2::operator+=(const Vector2 & other) { - x += other.x; - y += other.y; - return *this; -} - -Vector2 & Vector2::operator+=(double other) { - x += other; - y += other; - return *this; -} - -Vector2 Vector2::operator-() const { return {-x, -y}; } - -bool Vector2::operator==(const Vector2 & other) const { return x == other.x && y == other.y; } - -bool Vector2::operator!=(const Vector2 & other) const { return !(*this == other); } diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h index 2fb6136..0e41936 100644 --- a/src/crepe/api/Vector2.h +++ b/src/crepe/api/Vector2.h @@ -3,11 +3,12 @@ namespace crepe { //! 2D vector +template <class T> struct Vector2 { //! X component of the vector - double x = 0; + T x = 0; //! Y component of the vector - double y = 0; + T y = 0; //! Subtracts another vector from this vector and returns the result. Vector2 operator-(const Vector2 & other) const; @@ -38,3 +39,5 @@ struct Vector2 { }; } // namespace crepe + +#include "Vector2.hpp" 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 |