X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FVector.h;h=50ae8c8de067b184e7d49888c7c31c457fd724ef;hb=HEAD;hp=c355091c114e21fd789997ddef53dd4130e67725;hpb=4a51a83bdff30d1e25a5867cfb19936adc0034b1;p=orbi.git diff --git a/src/graphics/Vector.h b/src/graphics/Vector.h index c355091..50ae8c8 100644 --- a/src/graphics/Vector.h +++ b/src/graphics/Vector.h @@ -163,6 +163,22 @@ template constexpr Vector abs(Vector v) { return Vector(std::abs(v.x), std::abs(v.y)); } +template +inline Vector round(Vector v) { + return Vector(std::round(v.x), std::round(v.y)); +} +template<> +inline Vector round(Vector v) { + return Vector(std::roundf(v.x), std::roundf(v.y)); +} +template +constexpr Vector min(Vector lhs, Vector rhs) { + return Vector(std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y)); +} +template +constexpr Vector max(Vector lhs, Vector rhs) { + return Vector(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y)); +} template @@ -182,6 +198,15 @@ constexpr Vector Norm(Vector v) { return v / Length(v); } +template +constexpr Vector MirrorX(Vector v) { + return Vector(v.x, -v.y); +} +template +constexpr Vector MirrorY(Vector v) { + return Vector(-v.x, v.y); +} + template constexpr Vector Rotate90(Vector v) { return Vector(-v.y, v.x); @@ -194,6 +219,7 @@ template constexpr Vector Rotate270(Vector v) { return Vector(v.y, -v.x); } +// angle given in radians template inline Vector Rotate(Vector v, Float by) { Float sine(std::sin(by));