From 5cceca7fbcda49fd803d8b31728a926a6b29e49c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 26 Feb 2014 20:22:34 +0100 Subject: Added more utility functions to cCuboid. GetVolume(), Expand(), ClampX(), ClampY(), ClampZ() --- src/Cuboid.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/Cuboid.h') diff --git a/src/Cuboid.h b/src/Cuboid.h index 44db7b98e..51ccf799b 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -29,7 +29,12 @@ public: int DifY(void) const { return p2.y - p1.y; } int DifZ(void) const { return p2.z - p1.z; } - /// Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. + /** Returns the volume of the cuboid, in blocks. + Note that the volume considers both coords inclusive. + Works on unsorted cuboids, too. */ + int GetVolume(void) const; + + /** Returns true if the cuboids have at least one voxel in common. Both coords are considered inclusive. */ bool DoesIntersect(const cCuboid & a_Other) const; bool IsInside(const Vector3i & v) const @@ -59,13 +64,27 @@ 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) */ 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 */ void Move(int a_OfsX, int a_OfsY, int a_OfsZ); + + /** Expands the cuboid by the specified amount in each direction. + Works on unsorted cuboids as well. + Note that this function doesn't check for underflows. */ + 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. */ + void ClampX(int a_MinX, int a_MaxX); + + /** Clamps both Y coords to the specified range. Works on unsorted cuboids, too. */ + void ClampY(int a_MinY, int a_MaxY); + + /** Clamps both Z coords to the specified range. Works on unsorted cuboids, too. */ + void ClampZ(int a_MinZ, int a_MaxZ); - /// Returns true if the coords are properly sorted (lesser in p1, greater in p2) + /** Returns true if the coords are properly sorted (lesser in p1, greater in p2) */ bool IsSorted(void) const; } ; // tolua_end -- cgit v1.2.3 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.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/Cuboid.h') diff --git a/src/Cuboid.h b/src/Cuboid.h index 51ccf799b..50a69b853 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -86,6 +86,9 @@ public: /** Returns true if the coords are properly sorted (lesser in p1, greater in p2) */ 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); } ; // tolua_end -- 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.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Cuboid.h') diff --git a/src/Cuboid.h b/src/Cuboid.h index 50a69b853..b95517f69 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -34,7 +34,8 @@ public: Works on unsorted cuboids, too. */ 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 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; /** 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. 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); /** Clamps both X coords to the specified range. Works on unsorted cuboids, too. */ -- cgit v1.2.3 From b4bf13aa4f004a7819e262679a295d8ca886557b Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 11 Mar 2014 16:01:17 +0200 Subject: Unified Vector classes --- src/Cuboid.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Cuboid.h') diff --git a/src/Cuboid.h b/src/Cuboid.h index b95517f69..b90a09e05 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -1,8 +1,7 @@ #pragma once -#include "Vector3i.h" -#include "Vector3d.h" +#include "Vector3.h" -- cgit v1.2.3 From 0442c41c872badfcc1a7a22c293161cc752623b8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sat, 15 Mar 2014 07:50:39 +0100 Subject: Added cCuboid:Assign(OtherCuboid) API function. --- src/Cuboid.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Cuboid.h') diff --git a/src/Cuboid.h b/src/Cuboid.h index b90a09e05..3239c54fc 100644 --- a/src/Cuboid.h +++ b/src/Cuboid.h @@ -21,6 +21,7 @@ public: 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) {} 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); void Sort(void); -- cgit v1.2.3