Skip to content

Commit

Permalink
math: avoid assert fail in std::clamp in closestPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jul 4, 2024
1 parent bbc76ba commit 1d20063
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/math/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1d20063

Please sign in to comment.