Corrected ByteItem position lookup bug

This commit is contained in:
Nav
2023-05-07 03:30:21 +01:00
parent 68059e9dfd
commit e6d290f866

View File

@@ -2,7 +2,6 @@
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include "src/Logger/Logger.hpp"
namespace Bloom::Widgets namespace Bloom::Widgets
{ {
@@ -22,8 +21,13 @@ namespace Bloom::Widgets
const auto gridPointCount = this->byteItemGrid.size(); const auto gridPointCount = this->byteItemGrid.size();
const auto startGridPointIndex = static_cast<decltype(this->byteItemGrid)::size_type>( const auto startGridPointIndex = static_cast<decltype(this->byteItemGrid)::size_type>(
std::floor( std::max(
static_cast<float>(yStart) / static_cast<float>(HexViewerItemIndex::GRID_SIZE) static_cast<int>(
std::floor(
static_cast<float>(yStart) / static_cast<float>(HexViewerItemIndex::GRID_SIZE) - 1
)
),
0
) )
); );
@@ -35,7 +39,7 @@ namespace Bloom::Widgets
static_cast<decltype(this->byteItemGrid)::size_type>( static_cast<decltype(this->byteItemGrid)::size_type>(
std::ceil( std::ceil(
static_cast<float>(yEnd) / static_cast<float>(HexViewerItemIndex::GRID_SIZE) static_cast<float>(yEnd) / static_cast<float>(HexViewerItemIndex::GRID_SIZE)
) ) + 1
), ),
gridPointCount - 1 gridPointCount - 1
)); ));
@@ -52,9 +56,14 @@ namespace Bloom::Widgets
const auto gridPointCount = this->byteItemGrid.size(); const auto gridPointCount = this->byteItemGrid.size();
const auto startGridPointIndex = static_cast<decltype(this->byteItemGrid)::size_type>( const auto startGridPointIndex = static_cast<decltype(this->byteItemGrid)::size_type>(
std::floor( std::max(
static_cast<float>(std::max(position.y(), static_cast<qreal>(0))) static_cast<int>(
/ static_cast<float>(HexViewerItemIndex::GRID_SIZE) std::floor(
static_cast<float>(std::max(position.y(), static_cast<qreal>(0)))
/ static_cast<float>(HexViewerItemIndex::GRID_SIZE) - 1
)
),
0
) )
); );