2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Cuboid.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-03-29 15:45:42 -04:00
|
|
|
// cCuboid:
|
|
|
|
|
2019-08-08 21:13:15 -04:00
|
|
|
void cCuboid::Assign(Vector3i a_Point1, Vector3i a_Point2)
|
2013-03-31 12:22:35 -04:00
|
|
|
{
|
2019-08-08 21:13:15 -04:00
|
|
|
p1 = a_Point1;
|
|
|
|
p2 = a_Point2;
|
2013-03-31 12:22:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-29 15:45:42 -04:00
|
|
|
void cCuboid::Sort(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-03-29 12:45:00 -04:00
|
|
|
if (p1.x > p2.x)
|
|
|
|
{
|
|
|
|
std::swap(p1.x, p2.x);
|
|
|
|
}
|
|
|
|
if (p1.y > p2.y)
|
|
|
|
{
|
|
|
|
std::swap(p1.y, p2.y);
|
|
|
|
}
|
|
|
|
if (p1.z > p2.z)
|
|
|
|
{
|
|
|
|
std::swap(p1.z, p2.z);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-29 15:45:42 -04:00
|
|
|
|
2014-02-26 14:22:34 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-31 14:22:55 -04:00
|
|
|
bool cCuboid::IsCompletelyInside(const cCuboid & a_Outer) const
|
|
|
|
{
|
2014-03-09 17:02:08 -04:00
|
|
|
ASSERT(IsSorted());
|
|
|
|
ASSERT(a_Outer.IsSorted());
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-03-31 14:22:55 -04:00
|
|
|
return (
|
|
|
|
(p1.x >= a_Outer.p1.x) &&
|
|
|
|
(p2.x <= a_Outer.p2.x) &&
|
|
|
|
(p1.y >= a_Outer.p1.y) &&
|
|
|
|
(p2.y <= a_Outer.p2.y) &&
|
|
|
|
(p1.z >= a_Outer.p1.z) &&
|
|
|
|
(p2.z <= a_Outer.p2.z)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-08 21:13:15 -04:00
|
|
|
void cCuboid::Move(Vector3i a_Offset)
|
2013-03-29 15:45:42 -04:00
|
|
|
{
|
2019-08-08 21:13:15 -04:00
|
|
|
p1.Move(a_Offset);
|
|
|
|
p2.Move(a_Offset);
|
2013-03-29 15:45:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-26 14:22:34 -05:00
|
|
|
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;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-26 14:22:34 -05:00
|
|
|
if (p1.y < p2.y)
|
|
|
|
{
|
|
|
|
p1.y -= a_SubMinY;
|
|
|
|
p2.y += a_AddMaxY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p2.y -= a_SubMinY;
|
|
|
|
p1.y += a_AddMaxY;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-26 14:22:34 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-03-29 16:50:32 -04:00
|
|
|
bool cCuboid::IsSorted(void) const
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(p1.x <= p2.x) &&
|
|
|
|
(p1.y <= p2.y) &&
|
|
|
|
(p1.z <= p2.z)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-09 14:54:27 -04:00
|
|
|
|
2017-08-17 09:48:38 -04:00
|
|
|
void cCuboid::Engulf(Vector3i a_Point)
|
2014-03-09 14:54:27 -04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|