From 3dbf3b68c484704aafcda9fd05ae88a0337956ef Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 19 Mar 2022 13:28:29 +0100 Subject: feat: add inserting cells --- src/engine/data/bounds.cpp | 28 +++++++++++++++++++--------- src/engine/data/bounds.hpp | 8 +++++--- src/engine/data/vector2.cpp | 10 ++++++++++ src/engine/data/vector2.hpp | 1 + 4 files changed, 35 insertions(+), 12 deletions(-) (limited to 'src/engine/data') diff --git a/src/engine/data/bounds.cpp b/src/engine/data/bounds.cpp index fdf8c6b..1a8c4d0 100644 --- a/src/engine/data/bounds.cpp +++ b/src/engine/data/bounds.cpp @@ -50,26 +50,36 @@ CoordsValidation Bounds::validate_coords(const Vector2 &coords) const noexcept return CoordsValidation::VALID; } -const Bounds &Bounds::operator*=(const Bounds &bounds) noexcept +const Bounds &Bounds::operator*=(const Bounds &rhs) noexcept { - _width *= bounds._width; - _height *= bounds._height; + _width *= rhs._width; + _height *= rhs._height; return *this; } -const Bounds &Bounds::operator+=(const Bounds &bounds) noexcept +const Bounds &Bounds::operator+=(const Bounds &rhs) noexcept { - _width += bounds._width; - _height += bounds._height; + _width += rhs._width; + _height += rhs._height; return *this; } -const Bounds &Bounds::operator-=(const Bounds &bounds) noexcept +const Bounds &Bounds::operator-=(const Bounds &rhs) noexcept { - _width -= bounds._width; - _height -= bounds._height; + _width -= rhs._width; + _height -= rhs._height; return *this; } + +Bounds Bounds::operator-(const Bounds &rhs) const noexcept +{ + auto new_bounds = Bounds(*this); + + new_bounds._width -= rhs._width; + new_bounds._height -= rhs._height; + + return new_bounds; +} diff --git a/src/engine/data/bounds.hpp b/src/engine/data/bounds.hpp index 4a29158..ccea2c3 100644 --- a/src/engine/data/bounds.hpp +++ b/src/engine/data/bounds.hpp @@ -36,9 +36,11 @@ public: [[nodiscard]] CoordsValidation validate_coords(const Vector2 &coords) const noexcept; - const Bounds &operator*=(const Bounds &bounds) noexcept; - const Bounds &operator+=(const Bounds &bounds) noexcept; - const Bounds &operator-=(const Bounds &bounds) noexcept; + const Bounds &operator*=(const Bounds &rhs) noexcept; + const Bounds &operator+=(const Bounds &rhs) noexcept; + const Bounds &operator-=(const Bounds &rhs) noexcept; + + Bounds operator-(const Bounds &rhs) const noexcept; private: Value _width = 0U; diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp index dba745f..ba155b5 100644 --- a/src/engine/data/vector2.cpp +++ b/src/engine/data/vector2.cpp @@ -54,6 +54,16 @@ Vector2 Vector2::operator+(const Vector2 &vector2) const noexcept return new_vector2; } +Vector2 Vector2::operator-(const Vector2 &vector2) const noexcept +{ + auto new_vector2 = Vector2(*this); + + new_vector2._x -= vector2._x; + new_vector2._y -= vector2._y; + + return new_vector2; +} + Vector2 Vector2::operator*(const Vector2 &vector2) const noexcept { auto new_vector2 = Vector2(*this); diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp index 868394a..60cecf3 100644 --- a/src/engine/data/vector2.hpp +++ b/src/engine/data/vector2.hpp @@ -37,6 +37,7 @@ public: const Vector2 &operator-=(const Vector2 &vector2) noexcept; Vector2 operator+(const Vector2 &vector2) const noexcept; + Vector2 operator-(const Vector2 &vector2) const noexcept; Vector2 operator*(const Vector2 &vector2) const noexcept; bool operator==(const Vector2 &vector2) const noexcept; -- cgit v1.2.3-18-g5258