From a8c3a135701a7b64db0a88ec353a392f402d2a87 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 5 Jul 2024 20:17:19 +0200 Subject: [PATCH] math/region: add expand --- include/hyprutils/math/Region.hpp | 1 + src/math/Region.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/hyprutils/math/Region.hpp b/include/hyprutils/math/Region.hpp index 856489b..f7589f2 100644 --- a/include/hyprutils/math/Region.hpp +++ b/include/hyprutils/math/Region.hpp @@ -49,6 +49,7 @@ namespace Hyprutils { CRegion& invert(const CBox& box); CRegion& scale(float scale); CRegion& scale(const Vector2D& scale); + CRegion& expand(double units); CRegion& rationalize(); CBox getExtents(); bool containsPoint(const Vector2D& vec) const; diff --git a/src/math/Region.cpp b/src/math/Region.cpp index 81eda8b..e69ddb8 100644 --- a/src/math/Region.cpp +++ b/src/math/Region.cpp @@ -112,6 +112,19 @@ CRegion& Hyprutils::Math::CRegion::transform(const eTransform t, double w, doubl 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() { intersect(CBox{-MAX_REGION_SIDE, -MAX_REGION_SIDE, MAX_REGION_SIDE * 2, MAX_REGION_SIDE * 2}); return *this;