X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;fp=src%2Freal.h;h=2be3fdd44bd0e7ca45865c8fd3980595a52564a6;hp=406cb8e730cb018abbd686c6bd77c3b79b3d7f3e;hb=b04b227b04626afb2a8bf665dbcbf035bfa1cef8;hpb=3172dd5af487e0f8a6e5cd5439dea594b9cbd7c9 diff --git a/src/real.h b/src/real.h index 406cb8e..2be3fdd 100644 --- a/src/real.h +++ b/src/real.h @@ -82,7 +82,31 @@ namespace IPDF return r; } + struct Vec2 + { + Real x; + Real y; + Vec2() : x(0), y(0) {} + Vec2(Real _x, Real _y) : x(_x), y(_y) {} + bool operator==(const Vec2& other) const { return (x == other.x) && (y == other.y); } + bool operator!=(const Vec2& other) const { return !(*this == other); } + + Vec2& operator=(const Vec2& other) { x = other.x; y = other.y; return *this; } + Vec2& operator+=(const Vec2& other) { x += other.x; y += other.y; return *this; } + Vec2& operator-=(const Vec2& other) { x -= other.x; y -= other.y; return *this; } + Vec2& operator*=(const Real& lambda) { x *= lambda; y *= lambda; return *this; } + Vec2& operator/=(const Real& lambda) { x /= lambda; y /= lambda; return *this; } + + Vec2 operator+(const Vec2& other) const { return Vec2(x + other.x, y + other.y); } + Vec2 operator-(const Vec2& other) const { return Vec2(x - other.x, y - other.y); } + Vec2 operator*(const Real& lambda) const { return Vec2(x * lambda, y * lambda); } + Vec2 operator/(const Real& lambda) const { return Vec2(x / lambda, y / lambda); } + + const Real SquareLength() const { return (x*x + y*y); } + + }; + }