From 67126cbd1bab16e5860de6510b8af15fb9f7c9e7 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 6 Dec 2024 21:03:52 +0100 Subject: [PATCH] Fix meaning of VoxelArea::hasEmptyExtent() --- src/emerge_internal.h | 4 ++-- src/unittest/test_voxelarea.cpp | 2 +- src/voxel.h | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/emerge_internal.h b/src/emerge_internal.h index 6dd438603..6a71c7523 100644 --- a/src/emerge_internal.h +++ b/src/emerge_internal.h @@ -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(); } } diff --git a/src/unittest/test_voxelarea.cpp b/src/unittest/test_voxelarea.cpp index 4bdd9af5b..321420a52 100644 --- a/src/unittest/test_voxelarea.cpp +++ b/src/unittest/test_voxelarea.cpp @@ -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() diff --git a/src/voxel.h b/src/voxel.h index 2a0970aad..a5ffc7ce6 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -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); };