mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-12-20 14:00:09 +01:00
region: introduce foreach and cleanup clangd warnings (#65)
* CRegion: introduce forEachRect makes us able to directly call a function on each rect instead of using getRects() allocating a vector every single time, especially when its used in hot paths like the renderer. * CRegion: cleanup CRegion of clangd warnings overload pixman() with const, remove const_cast, mark move as noexcept. ensure self assignment doesnt occur.
This commit is contained in:
parent
a8229739cf
commit
e21b18ff8f
2 changed files with 27 additions and 11 deletions
|
|
@ -21,17 +21,21 @@ namespace Hyprutils {
|
|||
CRegion(pixman_box32_t* box);
|
||||
|
||||
CRegion(const CRegion&);
|
||||
CRegion(CRegion&&);
|
||||
CRegion(CRegion&&) noexcept;
|
||||
|
||||
~CRegion();
|
||||
|
||||
CRegion& operator=(CRegion&& other) {
|
||||
CRegion& operator=(CRegion&& other) noexcept {
|
||||
if (this != &other)
|
||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
CRegion& operator=(CRegion& other) {
|
||||
CRegion& operator=(const CRegion& other) {
|
||||
if (this != &other)
|
||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -58,12 +62,24 @@ namespace Hyprutils {
|
|||
CRegion copy() const;
|
||||
|
||||
std::vector<pixman_box32_t> getRects() const;
|
||||
template <typename T>
|
||||
void forEachRect(T&& cb) const {
|
||||
int rectsNum = 0;
|
||||
const auto* rects = pixman_region32_rectangles(&m_rRegion, &rectsNum);
|
||||
for (int i = 0; i < rectsNum; ++i) {
|
||||
std::forward<T>(cb)(rects[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
pixman_region32_t* pixman() {
|
||||
return &m_rRegion;
|
||||
}
|
||||
|
||||
const pixman_region32_t* pixman() const {
|
||||
return &m_rRegion;
|
||||
}
|
||||
|
||||
private:
|
||||
pixman_region32_t m_rRegion;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ Hyprutils::Math::CRegion::CRegion(pixman_box32_t* box) {
|
|||
|
||||
Hyprutils::Math::CRegion::CRegion(const CRegion& other) {
|
||||
pixman_region32_init(&m_rRegion);
|
||||
pixman_region32_copy(&m_rRegion, const_cast<CRegion*>(&other)->pixman());
|
||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||
}
|
||||
|
||||
Hyprutils::Math::CRegion::CRegion(CRegion&& other) {
|
||||
Hyprutils::Math::CRegion::CRegion(CRegion&& other) noexcept {
|
||||
pixman_region32_init(&m_rRegion);
|
||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||
}
|
||||
|
|
@ -46,12 +46,12 @@ CRegion& Hyprutils::Math::CRegion::clear() {
|
|||
}
|
||||
|
||||
CRegion& Hyprutils::Math::CRegion::set(const CRegion& other) {
|
||||
pixman_region32_copy(&m_rRegion, const_cast<CRegion*>(&other)->pixman());
|
||||
pixman_region32_copy(&m_rRegion, other.pixman());
|
||||
return *this;
|
||||
}
|
||||
|
||||
CRegion& Hyprutils::Math::CRegion::add(const CRegion& other) {
|
||||
pixman_region32_union(&m_rRegion, &m_rRegion, const_cast<CRegion*>(&other)->pixman());
|
||||
pixman_region32_union(&m_rRegion, &m_rRegion, other.pixman());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -66,12 +66,12 @@ CRegion& Hyprutils::Math::CRegion::add(const CBox& other) {
|
|||
}
|
||||
|
||||
CRegion& Hyprutils::Math::CRegion::subtract(const CRegion& other) {
|
||||
pixman_region32_subtract(&m_rRegion, &m_rRegion, const_cast<CRegion*>(&other)->pixman());
|
||||
pixman_region32_subtract(&m_rRegion, &m_rRegion, other.pixman());
|
||||
return *this;
|
||||
}
|
||||
|
||||
CRegion& Hyprutils::Math::CRegion::intersect(const CRegion& other) {
|
||||
pixman_region32_intersect(&m_rRegion, &m_rRegion, const_cast<CRegion*>(&other)->pixman());
|
||||
pixman_region32_intersect(&m_rRegion, &m_rRegion, other.pixman());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue