aboutsummaryrefslogtreecommitdiff
path: root/src/engine/data/bounds.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-06 13:16:05 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:54 +0200
commit0e40bc7ce8c3b3be083002f88c3317d65f6570ad (patch)
tree2fcc470a0f1ce1d51ff26c53c8a9a890b3f31b3b /src/engine/data/bounds.cpp
parentf4d812a5b9131e65bb55db7211dc68fc453792df (diff)
refactor: make vector2 & bounds data classes
Diffstat (limited to 'src/engine/data/bounds.cpp')
-rw-r--r--src/engine/data/bounds.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/engine/data/bounds.cpp b/src/engine/data/bounds.cpp
new file mode 100644
index 0000000..cd08a02
--- /dev/null
+++ b/src/engine/data/bounds.cpp
@@ -0,0 +1,65 @@
+#include "bounds.hpp"
+
+Bounds::Bounds(const BoundsOptions &options)
+ : _width(options.width), _height(options.height)
+{
+}
+
+uint32_t Bounds::width() const noexcept
+{
+ return _width;
+}
+
+void Bounds::width(uint32_t width) noexcept
+{
+ _width = width;
+}
+
+uint32_t Bounds::height() const noexcept
+{
+ return _height;
+}
+
+void Bounds::height(uint32_t height) noexcept
+{
+ _height = height;
+}
+
+CoordsValidation Bounds::validate_coords(const Vector2 &coords) const noexcept
+{
+ if (coords.x() >= _width)
+ {
+ return CoordsValidation::X_HIGH;
+ }
+
+ if (coords.y() >= _height)
+ {
+ return CoordsValidation::Y_HIGH;
+ }
+
+ return CoordsValidation::VALID;
+}
+
+const Bounds &Bounds::operator*=(const Bounds &bounds) noexcept
+{
+ _width *= bounds.width();
+ _height *= bounds.height();
+
+ return *this;
+}
+
+const Bounds &Bounds::operator+=(const Bounds &bounds) noexcept
+{
+ _width += bounds.width();
+ _height += bounds.height();
+
+ return *this;
+}
+
+const Bounds &Bounds::operator-=(const Bounds &bounds) noexcept
+{
+ _width -= bounds.width();
+ _height -= bounds.height();
+
+ return *this;
+}