Removed dependency on boost::operators

This commit is contained in:
David Williams 2008-05-26 19:37:37 +00:00
parent 22fd38b255
commit 2745d52dc5
3 changed files with 96 additions and 85 deletions

View File

@ -25,21 +25,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <iostream>
#include "boost/cstdint.hpp"
#include <boost/operators.hpp>
namespace PolyVox
{
//template <boost::uint32_t Size, typename Type> class Matrix; //Forward declaration
///Represents a vector in space.
template <boost::uint32_t Size, typename Type>
class Vector
: boost::addable< Vector<Size,Type> // Vector + Vector
, boost::subtractable< Vector<Size,Type> // Vector - Vector
, boost::dividable2< Vector<Size,Type>, Type // Vector / Type
, boost::multipliable2< Vector<Size,Type>, Type // Vector * Type, Type * Vector
, boost::equality_comparable1< Vector<Size,Type> // Vector != Vector
> > > > >
{
public:
///Constructor.
@ -113,24 +104,38 @@ namespace PolyVox
};
//Non-member overloaded operators.
//!Multiplication operator.
//template <boost::uint32_t Size,typename Type>
//Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Matrix<Size,Type>& rhs) throw();
//!Multiplication operator.
//template <boost::uint32_t Size,typename Type>
//Vector<Size,Type> operator*(const Matrix<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Addition operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Subtraction operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw();
///Multiplication operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw();
///Division operator.
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw();
///Stream insertion operator.
template <boost::uint32_t Size, typename Type>
std::ostream& operator<<(std::ostream& os, const Vector<Size,Type>& vector) throw();
//Some handy typedefs
///A 3D Vector of floats.
typedef Vector<3,float> Vector3DFloat;
///A 3D Vector of doubles.
typedef Vector<3,double> Vector3DDouble;
///A 3D Vector of signed 8-bit values.
typedef Vector<3,boost::int8_t> Vector3DInt8;
///A 3D Vector of unsigned 8-bit values.
typedef Vector<3,boost::uint8_t> Vector3DUint8;
///A 3D Vector of signed 16-bit values.
typedef Vector<3,boost::int16_t> Vector3DInt16;
///A 3D Vector of unsigned 16-bit values.
typedef Vector<3,boost::uint16_t> Vector3DUint16;
///A 3D Vector of signed 32-bit values.
typedef Vector<3,boost::int32_t> Vector3DInt32;
///A 3D Vector of unsigned 32-bit values.
typedef Vector<3,boost::uint32_t> Vector3DUint32;

View File

@ -194,22 +194,7 @@ namespace PolyVox
return false;
}
return false;
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param rhs Vector to subtract
\return The resulting Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator-=(const Vector<Size, Type>& rhs) throw()
{
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] -= rhs.m_tElements[ct];
}
return *this;
}
}
/**
Addition operator adds corresponding elements of the two Vectors.
@ -226,6 +211,21 @@ namespace PolyVox
return *this;
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param rhs Vector to subtract
\return The resulting Vector.
*/
template <boost::uint32_t Size, typename Type>
inline Vector<Size, Type>& Vector<Size, Type>::operator-=(const Vector<Size, Type>& rhs) throw()
{
for(boost::uint32_t ct = 0; ct < Size; ++ct)
{
m_tElements[ct] -= rhs.m_tElements[ct];
}
return *this;
}
/**
Multiplication operator multiplies each element of the Vector by a number.
\param rhs the number the Vector is multiplied by.
@ -256,56 +256,6 @@ namespace PolyVox
return *this;
}
/**
Multiplies a Vector and a Matrix.
NOTE: Although the Vector class does not distinguish between row and column vectors, the Vector
must <i>conceptually</i> be in <i>row</i> form for this operation to make sense.
\param lhs The Vector to be multiplied
\param rhs The Matrix to multiply by.
\return The resulting Vector
*/
/*template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Matrix<Size,Type>& rhs) throw()
{
Type tZero = static_cast<Type>(0);
Vector<Size,Type> result(tZero,tZero,tZero);
for(boost::uint32_t colCt = 0; colCt < Size; ++colCt)
{
for(boost::uint32_t rowCt = 0; rowCt < Size; ++rowCt)
{
//result(colCt) += lhs(rowCt) * rhs(rowCt, colCt);
result.set(colCt, result(colCt) + (lhs(rowCt) * rhs(rowCt, colCt)));
}
}
return result;
}*/
/**
Multiplies a Matrix and a Vector.
NOTE: Although the Vector class does not distinguish between row and column vectors, the Vector
must <i>conceptually</i> be in <i>column</i> form for this operation to make sense.
\param lhs The Matrix to be multiplied
\param rhs The Vector to multiply by.
\return The resulting Vector
*/
/*template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Matrix<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Type tZero = static_cast<Type>(0);
Vector<Size,Type> result(tZero,tZero,tZero);
for(boost::uint32_t rowCt = 0; rowCt < Size; ++rowCt)
{
for(boost::uint32_t colCt = 0; colCt < Size; ++colCt)
{
//result(rowCt) += lhs(rowCt,colCt) * rhs(colCt);
result.set(rowCt, result(rowCt) + (lhs(rowCt,colCt) * rhs(colCt)));
}
}
return result;
}*/
/**
Enables the Vector to be used intuitively with output streams such as cout.
\param os The output stream to write to.
@ -525,4 +475,60 @@ namespace PolyVox
m_tElements[ct] /= static_cast<Type>(length);
}
}
/**
Addition operator adds corresponding elements of the two Vectors.
\param lhs Vector to add to.
\param rhs Vector to add.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator+(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result += rhs;
return result;
}
/**
Subtraction operator subtracts corresponding elements of one Vector from the other.
\param lhs Vector to subtract from.
\param rhs Vector to subtract.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator-(const Vector<Size,Type>& lhs, const Vector<Size,Type>& rhs) throw()
{
Vector<Size,Type> result = lhs;
result -= rhs;
return result;
}
/**
Multiplication operator multiplies each element of the Vector by a number.
\param lhs the Vector to multiply.
\param rhs the number the Vector is multiplied by.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator*(const Vector<Size,Type>& lhs, const Type& rhs) throw()
{
Vector<Size,Type> result = lhs;
result *= rhs;
return result;
}
/**
Division operator divides each element of the Vector by a number.
\param lhs the Vector to divide.
\param rhs the number the Vector is divided by.
\return The resulting Vector.
*/
template <boost::uint32_t Size,typename Type>
Vector<Size,Type> operator/(const Vector<Size,Type>& lhs, const Type& rhs) throw()
{
Vector<Size,Type> result = lhs;
result /= rhs;
return result;
}
}//namespace Thermite

View File

@ -383,7 +383,7 @@ namespace PolyVox
volIter.setPosition(static_cast<uint16_t>(posX),static_cast<uint16_t>(posY),static_cast<uint16_t>(posZ+1.0));
}
const Vector3DFloat gradCeil = computeSobelGradient(volIter);
result = ((gradFloor + gradCeil) * -1.0);
result = ((gradFloor + gradCeil) * -1.0f);
if(result.lengthSquared() < 0.0001)
{
//Operation failed - fall back on simple gradient estimation
@ -407,7 +407,7 @@ namespace PolyVox
volIter.setPosition(static_cast<uint16_t>(posX),static_cast<uint16_t>(posY),static_cast<uint16_t>(posZ+1.0));
}
const Vector3DFloat gradCeil = computeCentralDifferenceGradient(volIter);
result = ((gradFloor + gradCeil) * -1.0);
result = ((gradFloor + gradCeil) * -1.0f);
if(result.lengthSquared() < 0.0001)
{
//Operation failed - fall back on simple gradient estimation
@ -785,7 +785,7 @@ namespace PolyVox
volIter.setPosition(static_cast<uint16_t>(posX),static_cast<uint16_t>(posY),static_cast<uint16_t>(posZ+1.0));
}
const Vector3DFloat gradCeil = computeSobelGradient(volIter);
result = ((gradFloor + gradCeil) * -1.0);
result = ((gradFloor + gradCeil) * -1.0f);
if(result.lengthSquared() < 0.0001)
{
//Operation failed - fall back on simple gradient estimation
@ -809,7 +809,7 @@ namespace PolyVox
volIter.setPosition(static_cast<uint16_t>(posX),static_cast<uint16_t>(posY),static_cast<uint16_t>(posZ+1.0));
}
const Vector3DFloat gradCeil = computeSmoothCentralDifferenceGradient(volIter);
result = ((gradFloor + gradCeil) * -1.0);
result = ((gradFloor + gradCeil) * -1.0f);
if(result.lengthSquared() < 0.0001)
{
//Operation failed - fall back on simple gradient estimation