summaryrefslogtreecommitdiffstats
path: root/src/Cuboid.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cuboid.h')
-rw-r--r--src/Cuboid.h42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/Cuboid.h b/src/Cuboid.h
index 3ade5bc20..b39d3ad4a 100644
--- a/src/Cuboid.h
+++ b/src/Cuboid.h
@@ -13,16 +13,14 @@ public:
Vector3i p1, p2;
cCuboid(void) {}
- cCuboid(const cCuboid & a_Cuboid) : p1(a_Cuboid.p1), p2(a_Cuboid.p2) {}
cCuboid(const Vector3i & a_p1, const Vector3i & a_p2) : p1(a_p1), p2(a_p2) {}
cCuboid(int a_X1, int a_Y1, int a_Z1) : p1(a_X1, a_Y1, a_Z1), p2(a_X1, a_Y1, a_Z1) {}
- cCuboid(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) : p1(a_X1, a_Y1, a_Z1), p2(a_X2, a_Y2, a_Z2) {}
- // tolua_end
-
- cCuboid & operator =(cCuboid a_Other);
-
- // tolua_begin
+ // DEPRECATED, use cCuboid(Vector3i, Vector3i) instead
+ cCuboid(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) : p1(a_X1, a_Y1, a_Z1), p2(a_X2, a_Y2, a_Z2)
+ {
+ LOGWARNING("cCuboid(int, int, int, int, int, int) constructor is deprecated, use cCuboid(Vector3i, Vector3i) constructor instead.");
+ }
void Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2);
void Assign(const cCuboid & a_SrcCuboid);
@@ -40,9 +38,20 @@ public:
/** 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;
+ inline bool 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) &&
+ DoIntervalsIntersect(p1.y, p2.y, a_Other.p1.y, a_Other.p2.y) &&
+ DoIntervalsIntersect(p1.z, p2.z, a_Other.p1.z, a_Other.p2.z)
+ );
+ }
- bool IsInside(const Vector3i & v) const
+ bool IsInside(Vector3i v) const
{
return (
(v.x >= p1.x) && (v.x <= p2.x) &&
@@ -60,7 +69,7 @@ public:
);
}
- bool IsInside( const Vector3d & v) const
+ bool IsInside(Vector3d v) const
{
return (
(v.x >= p1.x) && (v.x <= p2.x) &&
@@ -94,7 +103,18 @@ public:
bool IsSorted(void) const;
/** If needed, expands the cuboid so that it contains the specified point. Assumes sorted. Doesn't contract. */
- void Engulf(const Vector3i & a_Point);
+ void Engulf(Vector3i a_Point);
+
+private:
+
+ /** Returns true if the two specified intervals have a non-empty union */
+ inline static bool DoIntervalsIntersect(int a_Min1, int a_Max1, int a_Min2, int a_Max2)
+ {
+ ASSERT(a_Min1 <= a_Max1);
+ ASSERT(a_Min2 <= a_Max2);
+ return ((a_Min1 <= a_Max2) && (a_Max1 >= a_Min2));
+ }
+
} ;
// tolua_end