mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-23 01:46:00 +01:00
added Vector2D::clamp
This commit is contained in:
parent
9d6999345e
commit
e81de82706
2 changed files with 10 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
#include "Vector2D.hpp"
|
#include "Vector2D.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
Vector2D::Vector2D(double xx, double yy) {
|
Vector2D::Vector2D(double xx, double yy) {
|
||||||
x = xx;
|
x = xx;
|
||||||
|
@ -21,3 +22,10 @@ double Vector2D::normalize() {
|
||||||
Vector2D Vector2D::floor() {
|
Vector2D Vector2D::floor() {
|
||||||
return Vector2D((int)x, (int)y);
|
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)
|
||||||
|
);
|
||||||
|
}
|
|
@ -35,5 +35,7 @@ class Vector2D {
|
||||||
return a.x != x || a.y != y;
|
return a.x != x || a.y != y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2D clamp(const Vector2D& min, const Vector2D& max = Vector2D());
|
||||||
|
|
||||||
Vector2D floor();
|
Vector2D floor();
|
||||||
};
|
};
|
Loading…
Reference in a new issue