From 5d08ada2241569501fa22bfc5e5cde0ee7dfd0c7 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 13 Jan 2015 23:23:31 +1000 Subject: Add VoxelArea::hasEmptyExtent --- src/voxel.cpp | 4 ++-- src/voxel.h | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/voxel.cpp b/src/voxel.cpp index 1299a5296..02da42459 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -139,7 +139,7 @@ void VoxelManipulator::print(std::ostream &o, INodeDefManager *ndef, void VoxelManipulator::addArea(const VoxelArea &area) { // Cancel if requested area has zero volume - if(area.getExtent() == v3s16(0,0,0)) + if (area.hasEmptyExtent()) return; // Cancel if m_area already contains the requested area @@ -151,7 +151,7 @@ void VoxelManipulator::addArea(const VoxelArea &area) // Calculate new area VoxelArea new_area; // New area is the requested area if m_area has zero volume - if(m_area.getExtent() == v3s16(0,0,0)) + if(m_area.hasEmptyExtent()) { new_area = area; } diff --git a/src/voxel.h b/src/voxel.h index 53b6edbc7..52274ac19 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -82,7 +82,7 @@ public: void addArea(const VoxelArea &a) { - if(getExtent() == v3s16(0,0,0)) + if (hasEmptyExtent()) { *this = a; return; @@ -96,7 +96,7 @@ public: } void addPoint(const v3s16 &p) { - if(getExtent() == v3s16(0,0,0)) + if(hasEmptyExtent()) { MinEdge = p; MaxEdge = p; @@ -137,6 +137,15 @@ public: { return MaxEdge - MinEdge + v3s16(1,1,1); } + + /* Because MaxEdge and MinEdge are included in the voxel area an empty extent + * is not represented by (0, 0, 0), but instead (-1, -1, -1) + */ + bool hasEmptyExtent() const + { + return MaxEdge - MinEdge == v3s16(-1, -1, -1); + } + s32 getVolume() const { v3s16 e = getExtent(); @@ -146,7 +155,7 @@ public: { // No area contains an empty area // NOTE: Algorithms depend on this, so do not change. - if(a.getExtent() == v3s16(0,0,0)) + if(a.hasEmptyExtent()) return false; return( -- cgit v1.2.3