aboutsummaryrefslogtreecommitdiff
path: root/src/engine/bounds.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-15 20:27:51 +0100
committerHampusM <hampus@hampusmat.com>2022-02-15 20:27:51 +0100
commit5dae8f8d10d506abc3c75a1f66c1dfe620c84fc1 (patch)
tree2bfb6efef0535a35bab1da811a5f69cb5203dff9 /src/engine/bounds.cpp
parent9147551cd21d565f9503e3ebbcd2121e284d88d5 (diff)
refactor: improve project design
Diffstat (limited to 'src/engine/bounds.cpp')
-rw-r--r--src/engine/bounds.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/engine/bounds.cpp b/src/engine/bounds.cpp
new file mode 100644
index 0000000..782fd02
--- /dev/null
+++ b/src/engine/bounds.cpp
@@ -0,0 +1,48 @@
+#include "bounds.hpp"
+
+Bounds::Bounds(BoundsOpts opts) : _width(opts.width), _height(opts.height) {}
+
+unsigned int Bounds::width() const
+{
+ return _width;
+}
+
+void Bounds::width(unsigned int width)
+{
+ _width = width;
+}
+
+unsigned int Bounds::height() const
+{
+ return _height;
+}
+
+void Bounds::height(unsigned int height)
+{
+ _height = height;
+}
+
+void Bounds::verify_coords(const Vector2 &coords) const
+{
+ if (coords.x() >= _width)
+ {
+ throw "X coordinate cannot be higher than or equal to bounds width";
+ }
+
+ if (coords.y() >= _height)
+ {
+ throw "Y coordinate cannot be higher than or equal to bounds height";
+ }
+}
+
+Bounds Bounds::operator*(const Bounds &bounds) const
+{
+ return Bounds(
+ {.width = _width * bounds.width(), .height = _height * bounds.height()});
+}
+
+Bounds Bounds::operator+(const Bounds &bounds) const
+{
+ return Bounds(
+ {.width = _width + bounds.width(), .height = _height + bounds.height()});
+}