summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-08-09 14:53:57 +0200
committerMattes D <github@xoft.cz>2019-08-10 12:25:06 +0200
commitd0b095ad512959bf15be0f81a972898f5b89099d (patch)
treec8ed92dc28a048e134d3f13b4c215d42dca7b956
parentRemoved coord-based API from cCuboid. (#4362) (diff)
downloadcuberite-d0b095ad512959bf15be0f81a972898f5b89099d.tar
cuberite-d0b095ad512959bf15be0f81a972898f5b89099d.tar.gz
cuberite-d0b095ad512959bf15be0f81a972898f5b89099d.tar.bz2
cuberite-d0b095ad512959bf15be0f81a972898f5b89099d.tar.lz
cuberite-d0b095ad512959bf15be0f81a972898f5b89099d.tar.xz
cuberite-d0b095ad512959bf15be0f81a972898f5b89099d.tar.zst
cuberite-d0b095ad512959bf15be0f81a972898f5b89099d.zip
-rw-r--r--Server/Plugins/APIDump/Classes/Geometry.lua22
-rw-r--r--src/Cuboid.cpp51
-rw-r--r--src/Cuboid.h8
3 files changed, 75 insertions, 6 deletions
diff --git a/Server/Plugins/APIDump/Classes/Geometry.lua b/Server/Plugins/APIDump/Classes/Geometry.lua
index e086d23fa..def786685 100644
--- a/Server/Plugins/APIDump/Classes/Geometry.lua
+++ b/Server/Plugins/APIDump/Classes/Geometry.lua
@@ -581,6 +581,28 @@ return
Notes = "Assigns all the coords to the specified values. Sort-state is ignored.",
},
},
+ Clamp =
+ {
+ Params =
+ {
+ {
+ Name = "Limits",
+ Type = "cCuboid",
+ },
+ },
+ Notes = "Clamps this cuboid, so that it doesn't reach outside of Limits in any direction. Assumes both cuboids are sorted.",
+ },
+ ClampSize =
+ {
+ Params =
+ {
+ {
+ Name = "MaxSize",
+ Type = "Vector3i",
+ },
+ },
+ Notes = "Clamps this cuboid's p2 so that the cuboid's size doesn't exceed the specified max size. Assumes the cuboid is sorted.",
+ },
ClampX =
{
Params =
diff --git a/src/Cuboid.cpp b/src/Cuboid.cpp
index 93749491e..a311edc63 100644
--- a/src/Cuboid.cpp
+++ b/src/Cuboid.cpp
@@ -121,10 +121,49 @@ void cCuboid::Expand(int a_SubMinX, int a_AddMaxX, int a_SubMinY, int a_AddMaxY,
+void cCuboid::Clamp(const cCuboid & a_Limits)
+{
+ ASSERT(IsSorted());
+ ASSERT(a_Limits.IsSorted());
+
+ p1.x = ::Clamp(p1.x, a_Limits.p1.x, a_Limits.p2.x);
+ p1.y = ::Clamp(p1.y, a_Limits.p1.y, a_Limits.p2.y);
+ p1.z = ::Clamp(p1.z, a_Limits.p1.z, a_Limits.p2.z);
+ p2.x = ::Clamp(p2.x, a_Limits.p1.x, a_Limits.p2.x);
+ p2.y = ::Clamp(p2.y, a_Limits.p1.y, a_Limits.p2.y);
+ p2.z = ::Clamp(p2.z, a_Limits.p1.z, a_Limits.p2.z);
+}
+
+
+
+
+
+void cCuboid::ClampSize(Vector3i a_MaxSize)
+{
+ ASSERT(IsSorted());
+
+ if (p2.x - p1.x > a_MaxSize.x)
+ {
+ p2.x = p1.x + a_MaxSize.x;
+ }
+ if (p2.y - p1.y > a_MaxSize.y)
+ {
+ p2.y = p1.y + a_MaxSize.y;
+ }
+ if (p2.z - p1.z > a_MaxSize.z)
+ {
+ p2.z = p1.z + a_MaxSize.z;
+ }
+}
+
+
+
+
+
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);
+ p1.x = ::Clamp(p1.x, a_MinX, a_MaxX);
+ p2.x = ::Clamp(p2.x, a_MinX, a_MaxX);
}
@@ -133,8 +172,8 @@ void cCuboid::ClampX(int a_MinX, int 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);
+ p1.y = ::Clamp(p1.y, a_MinY, a_MaxY);
+ p2.y = ::Clamp(p2.y, a_MinY, a_MaxY);
}
@@ -143,8 +182,8 @@ void cCuboid::ClampY(int a_MinY, int 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);
+ p1.z = ::Clamp(p1.z, a_MinZ, a_MaxZ);
+ p2.z = ::Clamp(p2.z, a_MinZ, a_MaxZ);
}
diff --git a/src/Cuboid.h b/src/Cuboid.h
index 864bea7a2..ed36a2298 100644
--- a/src/Cuboid.h
+++ b/src/Cuboid.h
@@ -94,6 +94,14 @@ public:
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 this cuboid, so that it doesn't reach outside of a_Limits in any direction.
+ Assumes both this and a_Limits are sorted. */
+ void Clamp(const cCuboid & a_Limits);
+
+ /** Clamps this cuboid's p2 so that the cuboid's size doesn't exceed the specified max size.
+ Assumes this cuboid is sorted. */
+ void ClampSize(Vector3i a_MaxSize);
+
/** Clamps both X coords to the specified range. Works on unsorted cuboids, too. */
void ClampX(int a_MinX, int a_MaxX);