110 lines
3.2 KiB
C++
110 lines
3.2 KiB
C++
#include "Region.h"
|
|
|
|
namespace PolyVox
|
|
{
|
|
Region::Region()
|
|
:m_v3dLowerCorner(0,0,0)
|
|
,m_v3dUpperCorner(0,0,0)
|
|
{
|
|
}
|
|
|
|
Region::Region(const Vector3DInt16& v3dLowerCorner, const Vector3DInt16& v3dUpperCorner)
|
|
:m_v3dLowerCorner(v3dLowerCorner)
|
|
,m_v3dUpperCorner(v3dUpperCorner)
|
|
{
|
|
}
|
|
|
|
const Vector3DInt16& Region::getLowerCorner(void) const
|
|
{
|
|
return m_v3dLowerCorner;
|
|
}
|
|
|
|
const Vector3DInt16& Region::getUpperCorner(void) const
|
|
{
|
|
return m_v3dUpperCorner;
|
|
}
|
|
|
|
const Vector3DInt16& Region::getCentre(void) const
|
|
{
|
|
Vector3DInt32 v3dMidpoint = static_cast<Vector3DInt32>(m_v3dLowerCorner) + static_cast<Vector3DInt32>(m_v3dUpperCorner);
|
|
v3dMidpoint = v3dMidpoint / static_cast<int32_t>(2);
|
|
return m_v3dLowerCorner + static_cast<Vector3DInt16>(v3dMidpoint);
|
|
}
|
|
|
|
void Region::setLowerCorner(const Vector3DInt16& v3dLowerCorner)
|
|
{
|
|
m_v3dLowerCorner = v3dLowerCorner;
|
|
}
|
|
|
|
void Region::setUpperCorner(const Vector3DInt16& v3dUpperCorner)
|
|
{
|
|
m_v3dUpperCorner = v3dUpperCorner;
|
|
}
|
|
|
|
bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const
|
|
{
|
|
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
|
|
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
|
|
&& (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
|
|
&& (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
|
|
&& (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
|
|
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
|
|
}
|
|
|
|
bool Region::containsPoint(const Vector3DInt16& pos, uint8_t boundary) const
|
|
{
|
|
return (pos.getX() <= m_v3dUpperCorner.getX() - boundary)
|
|
&& (pos.getY() <= m_v3dUpperCorner.getY() - boundary)
|
|
&& (pos.getZ() <= m_v3dUpperCorner.getZ() - boundary)
|
|
&& (pos.getX() >= m_v3dLowerCorner.getX() + boundary)
|
|
&& (pos.getY() >= m_v3dLowerCorner.getY() + boundary)
|
|
&& (pos.getZ() >= m_v3dLowerCorner.getZ() + boundary);
|
|
}
|
|
|
|
void Region::cropTo(const Region& other)
|
|
{
|
|
m_v3dLowerCorner.setX((std::max)(m_v3dLowerCorner.getX(), other.m_v3dLowerCorner.getX()));
|
|
m_v3dLowerCorner.setY((std::max)(m_v3dLowerCorner.getY(), other.m_v3dLowerCorner.getY()));
|
|
m_v3dLowerCorner.setZ((std::max)(m_v3dLowerCorner.getZ(), other.m_v3dLowerCorner.getZ()));
|
|
m_v3dUpperCorner.setX((std::min)(m_v3dUpperCorner.getX(), other.m_v3dUpperCorner.getX()));
|
|
m_v3dUpperCorner.setY((std::min)(m_v3dUpperCorner.getY(), other.m_v3dUpperCorner.getY()));
|
|
m_v3dUpperCorner.setZ((std::min)(m_v3dUpperCorner.getZ(), other.m_v3dUpperCorner.getZ()));
|
|
}
|
|
|
|
int16_t Region::depth(void) const
|
|
{
|
|
return m_v3dUpperCorner.getZ() - m_v3dLowerCorner.getZ();
|
|
}
|
|
|
|
int16_t Region::height(void) const
|
|
{
|
|
return m_v3dUpperCorner.getY() - m_v3dLowerCorner.getY();
|
|
}
|
|
|
|
void Region::shift(const Vector3DInt16& amount)
|
|
{
|
|
m_v3dLowerCorner += amount;
|
|
m_v3dUpperCorner += amount;
|
|
}
|
|
|
|
void Region::shiftLowerCorner(const Vector3DInt16& amount)
|
|
{
|
|
m_v3dLowerCorner += amount;
|
|
}
|
|
|
|
void Region::shiftUpperCorner(const Vector3DInt16& amount)
|
|
{
|
|
m_v3dUpperCorner += amount;
|
|
}
|
|
|
|
Vector3DInt16 Region::dimensions(void)
|
|
{
|
|
return m_v3dUpperCorner - m_v3dLowerCorner;
|
|
}
|
|
|
|
int16_t Region::width(void) const
|
|
{
|
|
return m_v3dUpperCorner.getX() - m_v3dLowerCorner.getX();
|
|
}
|
|
}
|