From 5dae8f8d10d506abc3c75a1f66c1dfe620c84fc1 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 15 Feb 2022 20:27:51 +0100 Subject: refactor: improve project design --- src/engine/vector2.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/engine/vector2.cpp') 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 + +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::copy() { - return std::shared_ptr(new Vector2(*this)); + return std::make_shared(*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) -- cgit v1.2.3-18-g5258