mirror of
https://github.com/hyprwm/hyprutils.git
synced 2024-12-22 16:39:48 +01:00
math: adjust right and bottom box edges (#6)
This commit is contained in:
parent
7e1b6610a2
commit
bbc76ba4e4
1 changed files with 9 additions and 7 deletions
|
@ -204,18 +204,20 @@ Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
|
||||||
return vec;
|
return vec;
|
||||||
|
|
||||||
Vector2D nv = vec;
|
Vector2D nv = vec;
|
||||||
nv.x = std::clamp(nv.x, x, x + w);
|
Vector2D maxPoint = {x + w - EPSILON, y + h - EPSILON};
|
||||||
nv.y = std::clamp(nv.y, y, y + h);
|
|
||||||
|
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)
|
if (std::fabs(nv.x - x) < EPSILON)
|
||||||
nv.x = x;
|
nv.x = x;
|
||||||
else if (std::fabs(nv.x - (x + w)) < EPSILON)
|
else if (std::fabs(nv.x - (maxPoint.x)) < EPSILON)
|
||||||
nv.x = x + w;
|
nv.x = maxPoint.x;
|
||||||
|
|
||||||
if (std::fabs(nv.y - y) < EPSILON)
|
if (std::fabs(nv.y - y) < EPSILON)
|
||||||
nv.y = y;
|
nv.y = y;
|
||||||
else if (std::fabs(nv.y - (y + h)) < EPSILON)
|
else if (std::fabs(nv.y - (maxPoint.y)) < EPSILON)
|
||||||
nv.y = y + h;
|
nv.y = maxPoint.y;
|
||||||
|
|
||||||
return nv;
|
return nv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue