mirror of
https://github.com/hyprwm/Hyprland.git
synced 2025-08-02 05:01:56 -07:00
input: minor constraint fixes
fixes the confined region, warping issues, etc. Closes #3158
This commit is contained in:
@@ -104,3 +104,34 @@ bool CRegion::containsPoint(const Vector2D& vec) {
|
||||
bool CRegion::empty() {
|
||||
return !pixman_region32_not_empty(&m_rRegion);
|
||||
}
|
||||
|
||||
Vector2D CRegion::closestPoint(const Vector2D& vec) {
|
||||
double bestDist = __FLT_MAX__;
|
||||
Vector2D leader = vec;
|
||||
|
||||
for (auto& box : getRects()) {
|
||||
double x = 0, y = 0;
|
||||
|
||||
if (vec.x >= box.x2)
|
||||
x = box.x2 - 1;
|
||||
else if (vec.x < box.x1)
|
||||
x = box.x1;
|
||||
else
|
||||
x = vec.x;
|
||||
|
||||
if (vec.y >= box.y2)
|
||||
y = box.y2 - 1;
|
||||
else if (vec.y < box.y1)
|
||||
y = box.y1;
|
||||
else
|
||||
y = vec.y;
|
||||
|
||||
double distance = sqrt(pow(x, 2) + pow(y, 2));
|
||||
if (distance < bestDist) {
|
||||
bestDist = distance;
|
||||
leader = {x, y};
|
||||
}
|
||||
}
|
||||
|
||||
return leader;
|
||||
}
|
Reference in New Issue
Block a user