Fix meaning of VoxelArea::hasEmptyExtent()

This commit is contained in:
sfan5 2024-12-06 21:03:52 +01:00
parent 8957739cdf
commit 67126cbd1b
3 changed files with 6 additions and 8 deletions

@ -93,7 +93,7 @@ public:
MapEditEventAreaIgnorer(VoxelArea *ignorevariable, const VoxelArea &a):
m_ignorevariable(ignorevariable)
{
if (m_ignorevariable->getVolume() == 0)
if (m_ignorevariable->hasEmptyExtent())
*m_ignorevariable = a;
else
m_ignorevariable = nullptr;
@ -102,7 +102,7 @@ public:
~MapEditEventAreaIgnorer()
{
if (m_ignorevariable) {
assert(m_ignorevariable->getVolume() != 0);
assert(!m_ignorevariable->hasEmptyExtent());
*m_ignorevariable = VoxelArea();
}
}

@ -118,7 +118,7 @@ void TestVoxelArea::test_extent()
UASSERT(VoxelArea().hasEmptyExtent());
UASSERT(VoxelArea({2,3,4}, {1,2,3}).hasEmptyExtent());
UASSERT(VoxelArea({2,3,4}, {2,2,3}).hasEmptyExtent() == false);
UASSERT(VoxelArea({2,3,4}, {2,2,3}).hasEmptyExtent());
}
void TestVoxelArea::test_volume()

@ -114,11 +114,9 @@ public:
return m_cache_extent;
}
/// @note `getVolume() == 0` and `getEmptyExtent()` are not equivalent.
bool hasEmptyExtent() const
{
// FIXME: shouldn't this actually be a component-wise check?
return m_cache_extent == v3s32(0,0,0);
return !m_cache_extent.X || !m_cache_extent.Y || !m_cache_extent.Z;
}
s32 getVolume() const
@ -207,7 +205,7 @@ public:
if(a.hasEmptyExtent())
{
VoxelArea b = *this;
if (b.getVolume() != 0)
if (!b.hasEmptyExtent())
result.push_back(b);
return;
}
@ -216,7 +214,7 @@ public:
const auto &take = [&result] (v3s16 min, v3s16 max) {
VoxelArea b(min, max);
if (b.getVolume() != 0)
if (!b.hasEmptyExtent())
result.push_back(b);
};