diff options
author | daniel0916 <theschokolps@gmail.com> | 2014-04-07 20:12:17 +0200 |
---|---|---|
committer | daniel0916 <theschokolps@gmail.com> | 2014-04-07 20:12:17 +0200 |
commit | 2e9754ac1cf0537c12ab7974cf55c451c0724540 (patch) | |
tree | 713c5b8c8f22f77893b30b9c8cefca4a7c491483 /src/Cuboid.cpp | |
parent | Fixed merge conflict (diff) | |
parent | Fixed some more minor issues with the redstone simulator. (diff) | |
download | cuberite-2e9754ac1cf0537c12ab7974cf55c451c0724540.tar cuberite-2e9754ac1cf0537c12ab7974cf55c451c0724540.tar.gz cuberite-2e9754ac1cf0537c12ab7974cf55c451c0724540.tar.bz2 cuberite-2e9754ac1cf0537c12ab7974cf55c451c0724540.tar.lz cuberite-2e9754ac1cf0537c12ab7974cf55c451c0724540.tar.xz cuberite-2e9754ac1cf0537c12ab7974cf55c451c0724540.tar.zst cuberite-2e9754ac1cf0537c12ab7974cf55c451c0724540.zip |
Diffstat (limited to 'src/Cuboid.cpp')
-rw-r--r-- | src/Cuboid.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp index ea6f7c453..3e5240248 100644 --- a/src/Cuboid.cpp +++ b/src/Cuboid.cpp @@ -38,6 +38,20 @@ void cCuboid::Assign(int a_X1, int a_Y1, int a_Z1, int a_X2, int a_Y2, int a_Z2) +void cCuboid::Assign(const cCuboid & a_SrcCuboid) +{ + p1.x = a_SrcCuboid.p1.x; + p1.y = a_SrcCuboid.p1.y; + p1.z = a_SrcCuboid.p1.z; + p2.x = a_SrcCuboid.p2.x; + p2.y = a_SrcCuboid.p2.y; + p2.z = a_SrcCuboid.p2.z; +} + + + + + void cCuboid::Sort(void) { if (p1.x > p2.x) @@ -58,8 +72,23 @@ void cCuboid::Sort(void) +int cCuboid::GetVolume(void) const +{ + int DifX = abs(p2.x - p1.x) + 1; + int DifY = abs(p2.y - p1.y) + 1; + int DifZ = abs(p2.z - p1.z) + 1; + return DifX * DifY * DifZ; +} + + + + + 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) && @@ -74,6 +103,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) && @@ -103,6 +135,76 @@ void cCuboid::Move(int a_OfsX, int a_OfsY, int a_OfsZ) +void cCuboid::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY, int a_SubMinZ, int a_AddMaxZ) +{ + if (p1.x < p2.x) + { + p1.x -= a_SubMinX; + p2.x += a_AddMaxX; + } + else + { + p2.x -= a_SubMinX; + p1.x += a_AddMaxX; + } + + if (p1.y < p2.y) + { + p1.y -= a_SubMinY; + p2.y += a_AddMaxY; + } + else + { + p2.y -= a_SubMinY; + p1.y += a_AddMaxY; + } + + if (p1.z < p2.z) + { + p1.z -= a_SubMinZ; + p2.z += a_AddMaxZ; + } + else + { + p2.z -= a_SubMinZ; + p1.z += a_AddMaxZ; + } +} + + + + + +void cCuboid::ClampX(int a_MinX, int a_MaxX) +{ + p1.x = Clamp(p1.x, a_MinX, a_MaxX); + p2.x = Clamp(p2.x, a_MinX, a_MaxX); +} + + + + + +void cCuboid::ClampY(int a_MinY, int a_MaxY) +{ + p1.y = Clamp(p1.y, a_MinY, a_MaxY); + p2.y = Clamp(p2.y, a_MinY, a_MaxY); +} + + + + + +void cCuboid::ClampZ(int a_MinZ, int a_MaxZ) +{ + p1.z = Clamp(p1.z, a_MinZ, a_MaxZ); + p2.z = Clamp(p2.z, a_MinZ, a_MaxZ); +} + + + + + bool cCuboid::IsSorted(void) const { return ( @@ -115,3 +217,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; + } +} + + + + |