diff options
Diffstat (limited to 'src/engine/bounds.cpp')
-rw-r--r-- | src/engine/bounds.cpp | 48 |
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()}); +} |