diff options
author | HampusM <hampus@hampusmat.com> | 2022-01-09 21:47:23 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-01-09 21:47:23 +0100 |
commit | 8ceb79db1d0687bba005cef4a77bb889bf7ec3c3 (patch) | |
tree | b7c13359f652506d60c8556ea386ae8d50bfc5bc /src/vector2.hpp | |
parent | 097aa95c1f0cb159e7d9d0a3edf9284c421ee298 (diff) |
refactor: rewrite to c++
Diffstat (limited to 'src/vector2.hpp')
-rw-r--r-- | src/vector2.hpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/vector2.hpp b/src/vector2.hpp new file mode 100644 index 0000000..ccfa75b --- /dev/null +++ b/src/vector2.hpp @@ -0,0 +1,62 @@ +#ifndef VECTOR2_HPP +#define VECTOR2_HPP + +#include <memory> + +/** + * A 2D Vector. + */ +class Vector2 +{ +public: + /** + * Creates a 2D vector. + * + * @param x A X coordinate + * @param y A Y coordinate + */ + Vector2(unsigned int x, unsigned int y); + + /** + * Returns the X coordinate. + */ + unsigned int x() const; + + /** + * Sets the X coordinate. + * + * @param x A new X coordinate + */ + void x(unsigned int x); + + /** + * Returns the Y coordinate. + */ + unsigned int y() const; + + /** + * Sets the Y coordinate. + * + * @param Y A new Y coordinate + */ + void y(unsigned int y); + + /** + * Creates a copy of the 2D vector. + * + * @returns A identical 2D vector. + */ + std::shared_ptr<Vector2> copy(); + + Vector2 operator+(const Vector2 vector2); + Vector2 operator-(const Vector2 vector2); + + Vector2 &operator+=(const Vector2 &vector2); + Vector2 &operator-=(const Vector2 &vector2); + +private: + unsigned int _x; + unsigned int _y; +}; + +#endif |