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/bounds.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/engine/bounds.cpp (limited to 'src/engine/bounds.cpp') 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()}); +} -- cgit v1.2.3-18-g5258