Skip to content

Commit

Permalink
Add VoxelArea::hasEmptyExtent
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorycu authored and Zeno- committed Jan 13, 2015
1 parent c0066a7 commit 5d08ada
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/voxel.cpp
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
15 changes: 12 additions & 3 deletions src/voxel.h
Expand Up @@ -82,7 +82,7 @@ class VoxelArea

void addArea(const VoxelArea &a)
{
if(getExtent() == v3s16(0,0,0))
if (hasEmptyExtent())
{
*this = a;
return;
Expand All @@ -96,7 +96,7 @@ class VoxelArea
}
void addPoint(const v3s16 &p)
{
if(getExtent() == v3s16(0,0,0))
if(hasEmptyExtent())
{
MinEdge = p;
MaxEdge = p;
Expand Down Expand Up @@ -137,6 +137,15 @@ class VoxelArea
{
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();
Expand All @@ -146,7 +155,7 @@ class VoxelArea
{
// 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(
Expand Down

0 comments on commit 5d08ada

Please sign in to comment.