From 1e0a52b03fe655d7073ef20703dbb2e7646f74d3 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 23 Oct 2024 19:16:19 +0200 Subject: add XY struct for 2d points and offsets --- XY.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 XY.cpp (limited to 'XY.cpp') diff --git a/XY.cpp b/XY.cpp new file mode 100644 index 0000000..ad1262b --- /dev/null +++ b/XY.cpp @@ -0,0 +1,35 @@ +#include "XY.h" + +XY XY::operator - () const { + return XY { + .x = -x, + .y = -y, + }; +} + +XY XY::operator + (const XY & rhs) const { + return XY { + .x = x + rhs.x, + .y = y + rhs.y, + }; +} + +XY XY::operator - (const XY & rhs) const { + return XY { + .x = x - rhs.x, + .y = y - rhs.y, + }; +} + +XY& XY::operator += (const XY & rhs) { + this->x += rhs.x; + this->y += rhs.y; + return *this; +} + +XY& XY::operator -= (const XY & rhs) { + this->x -= rhs.x; + this->y -= rhs.y; + return *this; +} + -- cgit v1.2.3