diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp index acaace13..a96411e6 100644 --- a/src/helpers/Vector2D.cpp +++ b/src/helpers/Vector2D.cpp @@ -1,4 +1,5 @@ #include "Vector2D.hpp" +#include Vector2D::Vector2D(double xx, double yy) { x = xx; @@ -20,4 +21,11 @@ double Vector2D::normalize() { Vector2D Vector2D::floor() { return Vector2D((int)x, (int)y); +} + +Vector2D Vector2D::clamp(const Vector2D& min, const Vector2D& max) { + return Vector2D( + std::clamp(this->x, min.x, max.x == 0 ? INFINITY : max.x), + std::clamp(this->y, min.y, max.y == 0 ? INFINITY : max.y) + ); } \ No newline at end of file diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 7288a088..7ca52a68 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -35,5 +35,7 @@ class Vector2D { return a.x != x || a.y != y; } + Vector2D clamp(const Vector2D& min, const Vector2D& max = Vector2D()); + Vector2D floor(); }; \ No newline at end of file