internal: use an epsilon for scale calcs

This commit is contained in:
vaxerski 2023-04-09 18:26:11 +01:00
parent 9182de9ffc
commit 756fccfc53
4 changed files with 17 additions and 2 deletions

View file

@ -201,7 +201,7 @@ void CHyprpaper::ensurePoolBuffersPresent() {
auto it = std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [wt = &wt, &m](const std::unique_ptr<SPoolBuffer>& el) {
auto scale = std::round((m->pCurrentLayerSurface && m->pCurrentLayerSurface->pFractionalScaleInfo ? m->pCurrentLayerSurface->fScale : m->scale) * 120.0) / 120.0;
return el->target == wt->m_szPath && el->pixelSize == m->size * scale;
return el->target == wt->m_szPath && vectorDeltaLessThan(el->pixelSize, m->size * scale, 1);
});
if (it == m_vBuffers.end()) {
@ -394,7 +394,7 @@ void CHyprpaper::destroyBuffer(SPoolBuffer* pBuffer) {
SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWallpaperTarget) {
return std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [&](const std::unique_ptr<SPoolBuffer>& el) {
auto scale = std::round((pMonitor->pCurrentLayerSurface && pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? pMonitor->pCurrentLayerSurface->fScale : pMonitor->scale) * 120.0) / 120.0;
return el->target == pWallpaperTarget->m_szPath && el->pixelSize == pMonitor->size * scale;
return el->target == pWallpaperTarget->m_szPath && vectorDeltaLessThan(el->pixelSize, pMonitor->size * scale, 1);
})->get();
}

View file

@ -6,6 +6,7 @@
#include "helpers/Monitor.hpp"
#include "events/Events.hpp"
#include "helpers/PoolBuffer.hpp"
#include "helpers/MiscFunctions.hpp"
#include "ipc/Socket.hpp"
#include <mutex>

View file

@ -0,0 +1,9 @@
#include "MiscFunctions.hpp"
bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delta) {
return std::abs(a.x - b.x) < delta && std::abs(a.y - b.y) < delta;
}
bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& delta) {
return std::abs(a.x - b.x) < delta.x && std::abs(a.y - b.y) < delta.y;
}

View file

@ -0,0 +1,5 @@
#pragma once
#include "Vector2D.hpp"
bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delta);
bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& delta);