Skip to content

Commit

Permalink
VoxelArea: Fix missing cacheExtent calls in helpers (#15657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour authored Jan 11, 2025
1 parent 37899f7 commit 436b391
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/unittest/test_voxelarea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ void TestVoxelArea::test_addarea()
void TestVoxelArea::test_pad()
{
VoxelArea v1(v3s16(-1447, -9547, -875), v3s16(-147, 8854, 669));
auto old_extent = v1.getExtent();
v1.pad(v3s16(100, 200, 300));

UASSERT(v1.MinEdge == v3s16(-1547, -9747, -1175));
UASSERT(v1.MaxEdge == v3s16(-47, 9054, 969));
UASSERT(v1.getExtent() > old_extent);
}

void TestVoxelArea::test_extent()
Expand Down Expand Up @@ -165,6 +167,12 @@ void TestVoxelArea::test_contains_point()
UASSERTEQ(bool, v1.contains(v3s16(-100, 100, 10000)), false);
UASSERTEQ(bool, v1.contains(v3s16(-100, 100, -10000)), false);
UASSERTEQ(bool, v1.contains(v3s16(10000, 100, 10)), false);

VoxelArea v2;
UASSERTEQ(bool, v2.contains(v3s16(-200, 10, 10)), false);
UASSERTEQ(bool, v2.contains(v3s16(0, 0, 0)), false);
UASSERTEQ(bool, v2.contains(v3s16(1, 1, 1)), false);
UASSERTEQ(bool, v2.contains(v3s16(-1, -1, -1)), false);
}

void TestVoxelArea::test_contains_i()
Expand All @@ -180,6 +188,12 @@ void TestVoxelArea::test_contains_i()
UASSERTEQ(bool, v2.contains(10), true);
UASSERTEQ(bool, v2.contains(0), true);
UASSERTEQ(bool, v2.contains(-1), false);

VoxelArea v3;
UASSERTEQ(bool, v3.contains(0), false);
UASSERTEQ(bool, v3.contains(-1), false);
UASSERTEQ(bool, v3.contains(1), false);
UASSERTEQ(bool, v3.contains(2), false);
}

void TestVoxelArea::test_equal()
Expand Down Expand Up @@ -244,6 +258,7 @@ void TestVoxelArea::test_intersect()
VoxelArea v3({11, 11, 11}, {11, 11, 11});
VoxelArea v4({-11, -2, -10}, {10, 2, 11});
UASSERT(v2.intersect(v1) == v2);
UASSERT(!v2.intersect(v1).hasEmptyExtent());
UASSERT(v1.intersect(v2) == v2.intersect(v1));
UASSERT(v1.intersect(v3).hasEmptyExtent());
UASSERT(v3.intersect(v1) == v1.intersect(v3));
Expand Down
2 changes: 2 additions & 0 deletions src/voxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class VoxelArea
{
MinEdge -= d;
MaxEdge += d;
cacheExtent();
}

/*
Expand Down Expand Up @@ -188,6 +189,7 @@ class VoxelArea
ret.MaxEdge.Y = std::min(a.MaxEdge.Y, MaxEdge.Y);
ret.MinEdge.Z = std::max(a.MinEdge.Z, MinEdge.Z);
ret.MaxEdge.Z = std::min(a.MaxEdge.Z, MaxEdge.Z);
ret.cacheExtent();

return ret;
}
Expand Down

0 comments on commit 436b391

Please sign in to comment.