aboutsummaryrefslogtreecommitdiff
path: root/src/engine/data
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-19 13:28:29 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:56 +0200
commit3dbf3b68c484704aafcda9fd05ae88a0337956ef (patch)
treeb7a2d45811c0ed5e336f87c23369f3929322b0cc /src/engine/data
parent55c93fe609888be73677317978959040cf35b2ff (diff)
feat: add inserting cells
Diffstat (limited to 'src/engine/data')
-rw-r--r--src/engine/data/bounds.cpp28
-rw-r--r--src/engine/data/bounds.hpp8
-rw-r--r--src/engine/data/vector2.cpp10
-rw-r--r--src/engine/data/vector2.hpp1
4 files changed, 35 insertions, 12 deletions
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;