From 1d20063da23c499506587919affcdc9d42bdbdc6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 4 Jul 2024 15:49:06 +0200 Subject: [PATCH] math: avoid assert fail in std::clamp in closestPoint --- src/math/Box.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/math/Box.cpp b/src/math/Box.cpp index e987e9e..e587f75 100644 --- a/src/math/Box.cpp +++ b/src/math/Box.cpp @@ -206,8 +206,14 @@ Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const { Vector2D nv = vec; Vector2D maxPoint = {x + w - EPSILON, y + h - EPSILON}; - nv.x = std::clamp(nv.x, x, maxPoint.x); - nv.y = std::clamp(nv.y, y, maxPoint.y); + if (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); + else + nv.y = y; if (std::fabs(nv.x - x) < EPSILON) nv.x = x;