aboutsummaryrefslogtreecommitdiff
path: root/src/engine/vector2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/vector2.cpp')
-rw-r--r--src/engine/vector2.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/engine/vector2.cpp b/src/engine/vector2.cpp
index effc8b5..d091ea5 100644
--- a/src/engine/vector2.cpp
+++ b/src/engine/vector2.cpp
@@ -1,10 +1,8 @@
#include "vector2.hpp"
-Vector2::Vector2(unsigned int x, unsigned int y)
-{
- _x = x;
- _y = y;
-}
+#include <memory>
+
+Vector2::Vector2(Vector2Opts opts) : _x(opts.x), _y(opts.y) {}
unsigned int Vector2::x() const
{
@@ -28,17 +26,22 @@ void Vector2::y(unsigned int y)
std::shared_ptr<Vector2> Vector2::copy()
{
- return std::shared_ptr<Vector2>(new Vector2(*this));
+ return std::make_shared<Vector2>(*this);
+}
+
+Vector2 Vector2::operator*(const Vector2 &vector2) const
+{
+ return Vector2({.x = _x * vector2.x(), .y = _y * vector2.y()});
}
-Vector2 Vector2::operator+(const Vector2 vector2)
+Vector2 Vector2::operator+(const Vector2 &vector2) const
{
- return Vector2(_x + vector2.x(), _y + vector2.y());
+ return Vector2({.x = _x + vector2.x(), .y = _y + vector2.y()});
}
-Vector2 Vector2::operator-(const Vector2 vector2)
+Vector2 Vector2::operator-(const Vector2 &vector2) const
{
- return Vector2(_x - vector2.x(), _y - vector2.y());
+ return Vector2({.x = _x - vector2.x(), .y = _y - vector2.y()});
}
Vector2 &Vector2::operator+=(const Vector2 &vector2)