summaryrefslogtreecommitdiffstats
path: root/source/Cuboid.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-29 20:45:42 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-29 20:45:42 +0100
commita633c45e8e714b91783b3625c1ec98c62302292d (patch)
treefbf60bef53bb2f7fa35de13eb7f3f5d7ba350ff1 /source/Cuboid.cpp
parentListenThread now reports the protocol used (IPv4 - IPv6) in its error messages (diff)
downloadcuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar
cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.gz
cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.bz2
cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.lz
cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.xz
cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.tar.zst
cuberite-a633c45e8e714b91783b3625c1ec98c62302292d.zip
Diffstat (limited to '')
-rw-r--r--source/Cuboid.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/source/Cuboid.cpp b/source/Cuboid.cpp
index e50ea1faf..54dd1f1a4 100644
--- a/source/Cuboid.cpp
+++ b/source/Cuboid.cpp
@@ -7,7 +7,24 @@
-void cCuboid::Sort()
+/// Returns true if the two specified intervals have a non-empty union
+static bool DoIntervalsIntersect(int a_Min1, int a_Max1, int a_Min2, int a_Max2)
+{
+ return (
+ ((a_Min1 >= a_Min2) && (a_Min1 <= a_Max2)) || // Start of first interval is within the second interval
+ ((a_Max1 >= a_Min2) && (a_Max1 <= a_Max2)) || // End of first interval is within the second interval
+ ((a_Min2 >= a_Min2) && (a_Min2 <= a_Max2)) // Start of second interval is within the first interval
+ );
+}
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cCuboid:
+
+void cCuboid::Sort(void)
{
if (p1.x > p2.x)
{
@@ -26,3 +43,32 @@ void cCuboid::Sort()
+
+bool cCuboid::DoesIntersect(const cCuboid & a_Other) const
+{
+ // 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)
+ );
+}
+
+
+
+
+
+void cCuboid::Move(int a_OfsX, int a_OfsY, int a_OfsZ)
+{
+ p1.x += a_OfsX;
+ p1.y += a_OfsY;
+ p1.z += a_OfsZ;
+ p2.x += a_OfsX;
+ p2.y += a_OfsY;
+ p2.z += a_OfsZ;
+}
+
+
+
+
+