Added 'containsPoint' functions which take separate components instead of vectors.

This commit is contained in:
David Williams 2012-11-30 23:47:03 +01:00
parent 9c71c3fa30
commit ba827d446b
3 changed files with 55 additions and 24 deletions

View File

@ -546,8 +546,7 @@ namespace PolyVox
int32_t zPos = this->mZPosInVolume;
//FIXME - Can we speed this up?
//FIXME - replace with versions which don't build Vector3DInt32.
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos), 1))
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 1))
{
//We're well inside the region so all flags can be set.
m_uValidFlags = Current | PositiveX | NegativeX | PositiveY | NegativeY | PositiveZ | NegativeZ;
@ -556,13 +555,13 @@ namespace PolyVox
{
m_uValidFlags = 0;
//FIXME - replace with versions which don't build Vector3DInt32.
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos), 0)) m_uValidFlags |= Current;
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos+1, yPos, zPos), 0)) m_uValidFlags |= PositiveX;
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos-1, yPos, zPos), 0)) m_uValidFlags |= NegativeX;
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos+1, zPos), 0)) m_uValidFlags |= PositiveY;
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos-1, zPos), 0)) m_uValidFlags |= NegativeY;
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos+1), 0)) m_uValidFlags |= PositiveZ;
if(this->mVolume->getEnclosingRegion().containsPoint(Vector3DInt32(xPos, yPos, zPos-1), 0)) m_uValidFlags |= NegativeZ;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos, 0)) m_uValidFlags |= Current;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos+1, yPos, zPos, 0)) m_uValidFlags |= PositiveX;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos-1, yPos, zPos, 0)) m_uValidFlags |= NegativeX;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos+1, zPos, 0)) m_uValidFlags |= PositiveY;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos-1, zPos, 0)) m_uValidFlags |= NegativeY;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos+1, 0)) m_uValidFlags |= PositiveZ;
if(this->mVolume->getEnclosingRegion().containsPoint(xPos, yPos, zPos-1, 0)) m_uValidFlags |= NegativeZ;
}
}
}

View File

@ -128,9 +128,13 @@ namespace PolyVox
/// Sets the position of the upper corner.
void setUpperCorner(const Vector3DInt32& v3dUpperCorner);
/// Tests whether the given point is contained in this Region.
bool containsPoint(float fX, float fY, float fZ, float boundary = 0.0f) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(const Vector3DFloat& pos, float boundary = 0.0f) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary = 0) const;
/// Tests whether the given point is contained in this Region.
bool containsPoint(const Vector3DInt32& pos, uint8_t boundary = 0) const;
/// Tests whether the given position is contained in the 'x' range of this Region.
bool containsPointInX(float pos, float boundary = 0.0f) const;

View File

@ -163,34 +163,62 @@ namespace PolyVox
/// The boundary value can be used to ensure a position is only considered to be inside
/// the Region if it is that far in in all directions. Also, the test is inclusive such
/// that positions lying exactly on the edge of the Region are considered to be inside it.
/// \param pos The position to test.
/// \param fX The 'x' position of the point to test.
/// \param fY The 'y' position of the point to test.
/// \param fZ The 'z' position of the point to test.
/// \param boundary The desired boundary value.
////////////////////////////////////////////////////////////////////////////////
bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const
bool Region::containsPoint(float fX, float fY, float fZ, float boundary) const
{
return (pos.getX() <= m_iUpperX - boundary)
&& (pos.getY() <= m_iUpperY - boundary)
&& (pos.getZ() <= m_iUpperZ - boundary)
&& (pos.getX() >= m_iLowerX + boundary)
&& (pos.getY() >= m_iLowerY + boundary)
&& (pos.getZ() >= m_iLowerZ + boundary);
return (fX <= m_iUpperX - boundary)
&& (fY <= m_iUpperY - boundary)
&& (fZ <= m_iUpperZ - boundary)
&& (fX >= m_iLowerX + boundary)
&& (fY >= m_iLowerY + boundary)
&& (fZ >= m_iLowerZ + boundary);
}
////////////////////////////////////////////////////////////////////////////////
/// The boundary value can be used to ensure a position is only considered to be inside
/// the Region if it is that far in in all directions. Also, the test is inclusive such
/// that positions lying exactly on the edge of the Region are considered to be inside it.
/// \param pos The position to test.
/// \param pos The position of the point to test.
/// \param boundary The desired boundary value.
////////////////////////////////////////////////////////////////////////////////
bool Region::containsPoint(const Vector3DFloat& pos, float boundary) const
{
return containsPoint(pos.getX(), pos.getY(), pos.getZ(), boundary);
}
////////////////////////////////////////////////////////////////////////////////
/// The boundary value can be used to ensure a position is only considered to be inside
/// the Region if it is that far in in all directions. Also, the test is inclusive such
/// that positions lying exactly on the edge of the Region are considered to be inside it.
/// \param iX The 'x' position of the point to test.
/// \param iY The 'y' position of the point to test.
/// \param iZ The 'z' position of the point to test.
/// \param boundary The desired boundary value.
////////////////////////////////////////////////////////////////////////////////
bool Region::containsPoint(int32_t iX, int32_t iY, int32_t iZ, uint8_t boundary) const
{
return (iX <= m_iUpperX - boundary)
&& (iY <= m_iUpperY - boundary)
&& (iZ <= m_iUpperZ - boundary)
&& (iX >= m_iLowerX + boundary)
&& (iY >= m_iLowerY + boundary)
&& (iZ >= m_iLowerZ + boundary);
}
////////////////////////////////////////////////////////////////////////////////
/// The boundary value can be used to ensure a position is only considered to be inside
/// the Region if it is that far in in all directions. Also, the test is inclusive such
/// that positions lying exactly on the edge of the Region are considered to be inside it.
/// \param pos The position of the point to test.
/// \param boundary The desired boundary value.
////////////////////////////////////////////////////////////////////////////////
bool Region::containsPoint(const Vector3DInt32& pos, uint8_t boundary) const
{
return (pos.getX() <= m_iUpperX - boundary)
&& (pos.getY() <= m_iUpperY - boundary)
&& (pos.getZ() <= m_iUpperZ - boundary)
&& (pos.getX() >= m_iLowerX + boundary)
&& (pos.getY() >= m_iLowerY + boundary)
&& (pos.getZ() >= m_iLowerZ + boundary);
return containsPoint(pos.getX(), pos.getY(), pos.getZ(), boundary);
}
////////////////////////////////////////////////////////////////////////////////