diff options
author | HampusM <hampus@hampusmat.com> | 2022-02-15 20:27:51 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-02-15 20:27:51 +0100 |
commit | 5dae8f8d10d506abc3c75a1f66c1dfe620c84fc1 (patch) | |
tree | 2bfb6efef0535a35bab1da811a5f69cb5203dff9 /src/engine/vector2.cpp | |
parent | 9147551cd21d565f9503e3ebbcd2121e284d88d5 (diff) |
refactor: improve project design
Diffstat (limited to 'src/engine/vector2.cpp')
-rw-r--r-- | src/engine/vector2.cpp | 23 |
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) |