From 8889d3b73347a7cc094a0e233479e96f2bc25a49 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 19:54:27 +0100 Subject: Added cCuboid::Engulf(). --- src/Cuboid.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/Cuboid.cpp') diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index 782837b23..dc8df8500 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -197,3 +197,37 @@ bool cCuboid::IsSorted(void) const + +void cCuboid::Engulf(const Vector3i & a_Point) +{ + if (a_Point.x < p1.x) + { + p1.x = a_Point.x; + } + else if (a_Point.x > p2.x) + { + p2.x = a_Point.x; + } + + if (a_Point.y < p1.y) + { + p1.y = a_Point.y; + } + else if (a_Point.y > p2.y) + { + p2.y = a_Point.y; + } + + if (a_Point.z < p1.z) + { + p1.z = a_Point.z; + } + else if (a_Point.z > p2.z) + { + p2.z = a_Point.z; + } +} + + + + -- cgit v1.2.3 From dacb6cef1d6d2942f01d15186d8a12b30d39a385 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Mar 2014 22:02:08 +0100 Subject: Hardened cCuboid with asserts for its assumptions. --- src/Cuboid.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/Cuboid.cpp') diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index dc8df8500..2400c64f3 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -72,6 +72,9 @@ int cCuboid::GetVolume(void) 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 return ( 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 { + ASSERT(IsSorted()); + ASSERT(a_Outer.IsSorted()); + return ( (p1.x >= a_Outer.p1.x) && (p2.x <= a_Outer.p2.x) && -- cgit v1.2.3