diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-06 13:16:05 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:54 +0200 |
commit | 0e40bc7ce8c3b3be083002f88c3317d65f6570ad (patch) | |
tree | 2fcc470a0f1ce1d51ff26c53c8a9a890b3f31b3b /src/engine/graphics | |
parent | f4d812a5b9131e65bb55db7211dc68fc453792df (diff) |
refactor: make vector2 & bounds data classes
Diffstat (limited to 'src/engine/graphics')
-rw-r--r-- | src/engine/graphics/bounds.cpp | 65 | ||||
-rw-r--r-- | src/engine/graphics/bounds.hpp | 28 | ||||
-rw-r--r-- | src/engine/graphics/string_matrix.cpp | 6 | ||||
-rw-r--r-- | src/engine/graphics/string_matrix.hpp | 11 | ||||
-rw-r--r-- | src/engine/graphics/vector2.cpp | 39 | ||||
-rw-r--r-- | src/engine/graphics/vector2.hpp | 48 |
6 files changed, 9 insertions, 188 deletions
diff --git a/src/engine/graphics/bounds.cpp b/src/engine/graphics/bounds.cpp deleted file mode 100644 index 8cb83eb..0000000 --- a/src/engine/graphics/bounds.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include "bounds.hpp" - -Bounds::Bounds(const IBoundsOptions &options) - : _width(options.width), _height(options.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; -} - -CoordsValidation Bounds::validate_coords(const IVector2 &coords) const -{ - if (coords.x() >= _width) - { - return CoordsValidation::X_HIGH; - } - - if (coords.y() >= _height) - { - return CoordsValidation::Y_HIGH; - } - - return CoordsValidation::VALID; -} - -const IBounds &Bounds::operator*=(const IBounds &bounds) -{ - _width *= bounds.width(); - _height *= bounds.height(); - - return *this; -} - -const IBounds &Bounds::operator+=(const IBounds &bounds) -{ - _width += bounds.width(); - _height += bounds.height(); - - return *this; -} - -const IBounds &Bounds::operator-=(const IBounds &bounds) -{ - _width -= bounds.width(); - _height -= bounds.height(); - - return *this; -} diff --git a/src/engine/graphics/bounds.hpp b/src/engine/graphics/bounds.hpp deleted file mode 100644 index 3f4dd5b..0000000 --- a/src/engine/graphics/bounds.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "interfaces/bounds.hpp" -#include "interfaces/vector2.hpp" - -class Bounds : public IBounds -{ -public: - explicit Bounds(const IBoundsOptions &options); - - [[nodiscard]] unsigned int width() const override; - - void width(unsigned int width) override; - - [[nodiscard]] unsigned int height() const override; - - void height(unsigned int height) override; - - [[nodiscard]] CoordsValidation validate_coords(const IVector2 &coords) const override; - - const IBounds &operator*=(const IBounds &bounds) override; - const IBounds &operator+=(const IBounds &bounds) override; - const IBounds &operator-=(const IBounds &bounds) override; - -private: - unsigned int _width = 0U; - unsigned int _height = 0U; -}; diff --git a/src/engine/graphics/string_matrix.cpp b/src/engine/graphics/string_matrix.cpp index e259e96..aae2b9d 100644 --- a/src/engine/graphics/string_matrix.cpp +++ b/src/engine/graphics/string_matrix.cpp @@ -1,6 +1,6 @@ #include "string_matrix.hpp" -StringMatrix::StringMatrix(const IBounds &bounds) +StringMatrix::StringMatrix(const Bounds &bounds) : _rows(bounds.height()), _columns(bounds.width()) { _matrix.reserve(bounds.height()); @@ -20,12 +20,12 @@ void StringMatrix::fill(std::string_view element) } } -std::string_view StringMatrix::get(const IVector2 &pos) const +std::string_view StringMatrix::get(const Vector2 &pos) const { return _matrix[pos.y()][pos.x()]; } -void StringMatrix::set(const IVector2 &pos, std::string_view element) +void StringMatrix::set(const Vector2 &pos, std::string_view element) { _matrix[pos.y()][pos.x()] = element; } diff --git a/src/engine/graphics/string_matrix.hpp b/src/engine/graphics/string_matrix.hpp index 662ea7b..351053e 100644 --- a/src/engine/graphics/string_matrix.hpp +++ b/src/engine/graphics/string_matrix.hpp @@ -1,8 +1,9 @@ #pragma once -#include "interfaces/bounds.hpp" #include "interfaces/matrix.hpp" -#include "interfaces/vector2.hpp" + +#include "engine/data/bounds.hpp" +#include "engine/data/vector2.hpp" #include <string_view> #include <vector> @@ -18,7 +19,7 @@ public: * * @param bounds The bounds of the matrix */ - explicit StringMatrix(const IBounds &bounds); + explicit StringMatrix(const Bounds &bounds); /** * Fills the matrix with a element. @@ -32,7 +33,7 @@ public: * * @param pos The position of a element */ - [[nodiscard]] std::string_view get(const IVector2 &pos) const override; + [[nodiscard]] std::string_view get(const Vector2 &pos) const override; /** * Sets a element of the matrix. @@ -40,7 +41,7 @@ public: * @param pos The position of a element * @param element A new element */ - void set(const IVector2 &pos, std::string_view element) override; + void set(const Vector2 &pos, std::string_view element) override; /** * Returns the number of rows the matrix has. diff --git a/src/engine/graphics/vector2.cpp b/src/engine/graphics/vector2.cpp deleted file mode 100644 index dfdf4bd..0000000 --- a/src/engine/graphics/vector2.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "vector2.hpp" - -Vector2::Vector2(const IVector2Options &options) : _x(options.x), _y(options.y) {} - -unsigned int Vector2::x() const -{ - return _x; -} - -void Vector2::x(unsigned int x) -{ - _x = x; -} - -unsigned int Vector2::y() const -{ - return _y; -} - -void Vector2::y(unsigned int y) -{ - _y = y; -} - -const IVector2 &Vector2::operator+=(const IVector2 &vector2) -{ - _x += vector2.x(); - _y += vector2.y(); - - return *this; -} - -const IVector2 &Vector2::operator-=(const IVector2 &vector2) -{ - _x -= vector2.x(); - _y -= vector2.y(); - - return *this; -} diff --git a/src/engine/graphics/vector2.hpp b/src/engine/graphics/vector2.hpp deleted file mode 100644 index c8c6349..0000000 --- a/src/engine/graphics/vector2.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "interfaces/vector2.hpp" - -#include <memory> - -/** - * A 2D Vector. - */ -class Vector2 : public IVector2 -{ -public: - /** - * Creates a 2D vector. - */ - explicit Vector2(const IVector2Options &options); - - /** - * Returns the X coordinate. - */ - [[nodiscard]] unsigned int x() const override; - - /** - * Sets the X coordinate. - * - * @param x A new X coordinate - */ - void x(unsigned int x) override; - - /** - * Returns the Y coordinate. - */ - [[nodiscard]] unsigned int y() const override; - - /** - * Sets the Y coordinate. - * - * @param Y A new Y coordinate - */ - void y(unsigned int y) override; - - const IVector2 &operator+=(const IVector2 &vector2) override; - const IVector2 &operator-=(const IVector2 &vector2) override; - -private: - unsigned int _x; - unsigned int _y; -}; |