diff --git a/ostd/vecmath.hh b/ostd/vecmath.hh index fb7ed69..bc6c924 100644 --- a/ostd/vecmath.hh +++ b/ostd/vecmath.hh @@ -60,6 +60,19 @@ struct Vec2 { x /= o.x; y /= o.y; return *this; } + + Vec2 &neg() { + x = -x; y = -y; + return *this; + } + + bool is_zero() const { + return (x == 0) && (y == 0); + } + + T dot(const Vec2 &o) const { + return (x * o.x) + (y * o.y); + } }; template @@ -92,6 +105,11 @@ inline Vec2 operator/(const Vec2 &a, const Vec2 &b) { return Vec2(a).div(b); } +template +inline Vec2 operator-(const Vec2 &a) { + return Vec2(a).neg(); +} + using Vec2f = Vec2; using Vec2d = Vec2; using Vec2b = Vec2; @@ -148,6 +166,19 @@ struct Vec3 { x /= o.x; y /= o.y; z /= o.z; return *this; } + + Vec3 &neg() { + x = -x; y = -y; z = -z; + return *this; + } + + bool is_zero() const { + return (x == 0) && (y == 0) && (z == 0); + } + + T dot(const Vec3 &o) const { + return (x * o.x) + (y * o.y) + (z * o.z); + } }; template @@ -180,6 +211,11 @@ inline Vec3 operator/(const Vec3 &a, const Vec3 &b) { return Vec3(a).div(b); } +template +inline Vec3 operator-(const Vec3 &a) { + return Vec3(a).neg(); +} + using Vec3f = Vec3; using Vec3d = Vec3; using Vec3b = Vec3; @@ -236,6 +272,19 @@ struct Vec4 { x /= o.x; y /= o.y; z /= o.z; w /= o.w; return *this; } + + Vec4 &neg() { + x = -x; y = -y; z = -z; w = -w; + return *this; + } + + bool is_zero() const { + return (x == 0) && (y == 0) && (z == 0) && (w == 0); + } + + T dot(const Vec4 &o) const { + return (x * o.x) + (y * o.y) + (z * o.z) + (w * o.w); + } }; template @@ -268,6 +317,11 @@ inline Vec4 operator/(const Vec4 &a, const Vec4 &b) { return Vec4(a).div(b); } +template +inline Vec4 operator-(const Vec4 &a) { + return Vec4(a).neg(); +} + using Vec4f = Vec4; using Vec4d = Vec4; using Vec4b = Vec4;