math/region: add expand

This commit is contained in:
Vaxry 2024-07-05 20:17:19 +02:00
parent 259ecfa098
commit a8c3a13570
2 changed files with 14 additions and 0 deletions

View file

@ -49,6 +49,7 @@ namespace Hyprutils {
CRegion& invert(const CBox& box); CRegion& invert(const CBox& box);
CRegion& scale(float scale); CRegion& scale(float scale);
CRegion& scale(const Vector2D& scale); CRegion& scale(const Vector2D& scale);
CRegion& expand(double units);
CRegion& rationalize(); CRegion& rationalize();
CBox getExtents(); CBox getExtents();
bool containsPoint(const Vector2D& vec) const; bool containsPoint(const Vector2D& vec) const;

View file

@ -112,6 +112,19 @@ CRegion& Hyprutils::Math::CRegion::transform(const eTransform t, double w, doubl
return *this; return *this;
} }
CRegion& Hyprutils::Math::CRegion::expand(double units) {
auto rects = getRects();
clear();
for (auto& r : rects) {
CBox b{(double)r.x1 - units, (double)r.y1 - units, (double)r.x2 - r.x1 + units * 2, (double)r.y2 - r.y1 + units * 2};
add(b);
}
return *this;
}
CRegion& Hyprutils::Math::CRegion::rationalize() { CRegion& Hyprutils::Math::CRegion::rationalize() {
intersect(CBox{-MAX_REGION_SIDE, -MAX_REGION_SIDE, MAX_REGION_SIDE * 2, MAX_REGION_SIDE * 2}); intersect(CBox{-MAX_REGION_SIDE, -MAX_REGION_SIDE, MAX_REGION_SIDE * 2, MAX_REGION_SIDE * 2});
return *this; return *this;