diff --git a/src/coord.cpp b/src/coord.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c04f2ccde5c5f78bbcfb34ed7cd54facee7c9ac5 --- /dev/null +++ b/src/coord.cpp @@ -0,0 +1,26 @@ +#include "include/coord.h" +#include <string> + +Coord::Coord(int x, int y) + : x(x) + , y(y) + {} + +int& Coord::operator[](int dimension) { + switch (dimension) { + case 0: + return this->x; + case 1: + return this->y; + } + throw "bad dimension " + std::to_string(dimension); + return this->x; +} + +Coord Coord::operator+(const Coord& other) { + return Coord(this->x + other.x, this->y + other.y); +} + +Coord Coord::operator-(const Coord& other) { + return Coord(this->x - other.x, this->y - other.y); +} diff --git a/src/include/coord.h b/src/include/coord.h index 77f141aa9aab566a3a86b61df06d2996b1222fbb..29d6bf8b9ab8500a80738420ba94418b1f12cbf3 100644 --- a/src/include/coord.h +++ b/src/include/coord.h @@ -4,9 +4,10 @@ class Coord { public: + Coord(int, int); int& operator[](int); - Coord operator+(Coord); - Coord operator-(Coord); + Coord operator+(const Coord&); + Coord operator-(const Coord&); private: int x;