math: avoid assert fail in std::clamp in closestPoint

This commit is contained in:
Vaxry 2024-07-04 15:49:06 +02:00
parent bbc76ba4e4
commit 1d20063da2

View file

@ -206,8 +206,14 @@ Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
Vector2D nv = vec; Vector2D nv = vec;
Vector2D maxPoint = {x + w - EPSILON, y + h - EPSILON}; Vector2D maxPoint = {x + w - EPSILON, y + h - EPSILON};
if (x < maxPoint.x)
nv.x = std::clamp(nv.x, x, maxPoint.x); nv.x = std::clamp(nv.x, x, maxPoint.x);
else
nv.x = x;
if (y < maxPoint.y)
nv.y = std::clamp(nv.y, y, maxPoint.y); nv.y = std::clamp(nv.y, y, maxPoint.y);
else
nv.y = y;
if (std::fabs(nv.x - x) < EPSILON) if (std::fabs(nv.x - x) < EPSILON)
nv.x = x; nv.x = x;