diff options
| author | Darksome <dev@darkso.me> | 2022-07-15 19:42:03 +0300 |
|---|---|---|
| committer | Darksome <dev@darkso.me> | 2022-07-15 19:42:03 +0300 |
| commit | 5388b54442614cb0d3d445f101e7cd86bf64c125 (patch) | |
| tree | 26057ff185e423e944e8b250ed7fe26654b69623 /src/helpers/Vector2D.cpp | |
| parent | cb8a6f881b11e9a269fd5f7aa64eafe2beda0b0d (diff) | |
| parent | 6306d4dae3fa221a6099e109c7faef60bac4fac5 (diff) | |
Merge upstream
Diffstat (limited to 'src/helpers/Vector2D.cpp')
| -rw-r--r-- | src/helpers/Vector2D.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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 <algorithm> 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 |
