Hardened cCuboid with asserts for its assumptions.
This commit is contained in:
parent
81bf846e64
commit
dacb6cef1d
@ -72,6 +72,9 @@ int cCuboid::GetVolume(void) const
|
|||||||
|
|
||||||
bool cCuboid::DoesIntersect(const cCuboid & a_Other) const
|
bool cCuboid::DoesIntersect(const cCuboid & a_Other) const
|
||||||
{
|
{
|
||||||
|
ASSERT(IsSorted());
|
||||||
|
ASSERT(a_Other.IsSorted());
|
||||||
|
|
||||||
// In order for cuboids to intersect, each of their coord intervals need to intersect
|
// In order for cuboids to intersect, each of their coord intervals need to intersect
|
||||||
return (
|
return (
|
||||||
DoIntervalsIntersect(p1.x, p2.x, a_Other.p1.x, a_Other.p2.x) &&
|
DoIntervalsIntersect(p1.x, p2.x, a_Other.p1.x, a_Other.p2.x) &&
|
||||||
@ -86,6 +89,9 @@ bool cCuboid::DoesIntersect(const cCuboid & a_Other) const
|
|||||||
|
|
||||||
bool cCuboid::IsCompletelyInside(const cCuboid & a_Outer) const
|
bool cCuboid::IsCompletelyInside(const cCuboid & a_Outer) const
|
||||||
{
|
{
|
||||||
|
ASSERT(IsSorted());
|
||||||
|
ASSERT(a_Outer.IsSorted());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(p1.x >= a_Outer.p1.x) &&
|
(p1.x >= a_Outer.p1.x) &&
|
||||||
(p2.x <= a_Outer.p2.x) &&
|
(p2.x <= a_Outer.p2.x) &&
|
||||||
|
@ -34,7 +34,8 @@ public:
|
|||||||
Works on unsorted cuboids, too. */
|
Works on unsorted cuboids, too. */
|
||||||
int GetVolume(void) const;
|
int GetVolume(void) const;
|
||||||
|
|
||||||
/** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. */
|
/** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive.
|
||||||
|
Assumes both cuboids are sorted. */
|
||||||
bool DoesIntersect(const cCuboid & a_Other) const;
|
bool DoesIntersect(const cCuboid & a_Other) const;
|
||||||
|
|
||||||
bool IsInside(const Vector3i & v) const
|
bool IsInside(const Vector3i & v) const
|
||||||
@ -64,7 +65,8 @@ public:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords) */
|
/** Returns true if this cuboid is completely inside the specifie cuboid (in all 6 coords).
|
||||||
|
Assumes both cuboids are sorted. */
|
||||||
bool IsCompletelyInside(const cCuboid & a_Outer) const;
|
bool IsCompletelyInside(const cCuboid & a_Outer) const;
|
||||||
|
|
||||||
/** Moves the cuboid by the specified offsets in each direction */
|
/** Moves the cuboid by the specified offsets in each direction */
|
||||||
@ -72,7 +74,7 @@ public:
|
|||||||
|
|
||||||
/** Expands the cuboid by the specified amount in each direction.
|
/** Expands the cuboid by the specified amount in each direction.
|
||||||
Works on unsorted cuboids as well.
|
Works on unsorted cuboids as well.
|
||||||
Note that this function doesn't check for underflows. */
|
Note that this function doesn't check for underflows when using negative amounts. */
|
||||||
void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
|
void Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ);
|
||||||
|
|
||||||
/** Clamps both X coords to the specified range. Works on unsorted cuboids, too. */
|
/** Clamps both X coords to the specified range. Works on unsorted cuboids, too. */
|
||||||
|
Loading…
Reference in New Issue
Block a user