Skip to content

Commit

Permalink
math: adjust right and bottom box edges (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
drendog authored Jul 2, 2024
1 parent 7e1b661 commit bbc76ba
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/math/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,21 @@ Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
if (containsPoint(vec))
return vec;

Vector2D nv = vec;
nv.x = std::clamp(nv.x, x, x + w);
nv.y = std::clamp(nv.y, y, y + h);
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 (std::fabs(nv.x - x) < EPSILON)
nv.x = x;
else if (std::fabs(nv.x - (x + w)) < EPSILON)
nv.x = x + w;
else if (std::fabs(nv.x - (maxPoint.x)) < EPSILON)
nv.x = maxPoint.x;

if (std::fabs(nv.y - y) < EPSILON)
nv.y = y;
else if (std::fabs(nv.y - (y + h)) < EPSILON)
nv.y = y + h;
else if (std::fabs(nv.y - (maxPoint.y)) < EPSILON)
nv.y = maxPoint.y;

return nv;
}
Expand Down

0 comments on commit bbc76ba

Please sign in to comment.