1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Add VoxelArea::intersect()

This commit is contained in:
sfan5 2023-06-17 18:05:54 +02:00
parent 659828b142
commit 84fb663d6c
2 changed files with 41 additions and 0 deletions

View file

@ -183,6 +183,31 @@ public:
return {MinEdge-off, MaxEdge-off};
}
/*
Returns the intersection of this area and `a`.
*/
VoxelArea intersect(const VoxelArea &a) const
{
// This is an example of an operation that would be simpler with
// non-inclusive edges, but oh well.
VoxelArea ret;
if (a.MaxEdge.X < MinEdge.X || a.MinEdge.X > MaxEdge.X)
return VoxelArea();
if (a.MaxEdge.Y < MinEdge.Y || a.MinEdge.Y > MaxEdge.Y)
return VoxelArea();
if (a.MaxEdge.Z < MinEdge.Z || a.MinEdge.Z > MaxEdge.Z)
return VoxelArea();
ret.MinEdge.X = std::max(a.MinEdge.X, MinEdge.X);
ret.MaxEdge.X = std::min(a.MaxEdge.X, MaxEdge.X);
ret.MinEdge.Y = std::max(a.MinEdge.Y, MinEdge.Y);
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);
return ret;
}
/*
Returns 0-6 non-overlapping areas that can be added to
a to make up this area.