Tidying up Vector class
This commit is contained in:
parent
d0ffdee870
commit
ebeebee126
@ -22,10 +22,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#ifndef __PolyVox_Vector_H__
|
#ifndef __PolyVox_Vector_H__
|
||||||
#define __PolyVox_Vector_H__
|
#define __PolyVox_Vector_H__
|
||||||
|
|
||||||
#include <iostream>
|
#pragma region Headers
|
||||||
|
|
||||||
#include "boost/cstdint.hpp"
|
#include "boost/cstdint.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
namespace PolyVox
|
namespace PolyVox
|
||||||
{
|
{
|
||||||
///Represents a vector in space.
|
///Represents a vector in space.
|
||||||
|
@ -47,6 +47,7 @@ namespace PolyVox
|
|||||||
Vector2DInt4 test(1,2); //Declares a 2 dimensional Vector of type int4.
|
Vector2DInt4 test(1,2); //Declares a 2 dimensional Vector of type int4.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#pragma region Constructors/Destructors
|
||||||
//-------------------------- Constructors, etc ---------------------------------
|
//-------------------------- Constructors, etc ---------------------------------
|
||||||
/**
|
/**
|
||||||
Creates a Vector object and initialises it with given values.
|
Creates a Vector object and initialises it with given values.
|
||||||
@ -136,9 +137,9 @@ namespace PolyVox
|
|||||||
Vector<Size, Type>::~Vector(void) throw()
|
Vector<Size, Type>::~Vector(void) throw()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
//------------------------------- Overloaded Operators -------------------------
|
#pragma region Operators
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Assignment operator copies each element of first Vector to the second.
|
Assignment operator copies each element of first Vector to the second.
|
||||||
\param rhs Vector to assign to.
|
\param rhs Vector to assign to.
|
||||||
@ -211,6 +212,20 @@ namespace PolyVox
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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.
|
Subtraction operator subtracts corresponding elements of one Vector from the other.
|
||||||
\param rhs Vector to subtract
|
\param rhs Vector to subtract
|
||||||
@ -227,6 +242,20 @@ namespace PolyVox
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
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.
|
Multiplication operator multiplies each element of the Vector by a number.
|
||||||
\param rhs the number the Vector is multiplied by.
|
\param rhs the number the Vector is multiplied by.
|
||||||
\return The resulting Vector.
|
\return The resulting Vector.
|
||||||
@ -241,6 +270,20 @@ namespace PolyVox
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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.
|
Division operator divides each element of the Vector by a number.
|
||||||
\param rhs the number the Vector is divided by.
|
\param rhs the number the Vector is divided by.
|
||||||
@ -256,6 +299,20 @@ namespace PolyVox
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Enables the Vector to be used intuitively with output streams such as cout.
|
Enables the Vector to be used intuitively with output streams such as cout.
|
||||||
\param os The output stream to write to.
|
\param os The output stream to write to.
|
||||||
@ -277,9 +334,9 @@ namespace PolyVox
|
|||||||
os << ")";
|
os << ")";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
//----------------------------------- Getters ----------------------------------
|
#pragma region Getters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the element at the given position.
|
Returns the element at the given position.
|
||||||
\param index The index of the element to return.
|
\param index The index of the element to return.
|
||||||
@ -326,9 +383,9 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
return m_tElements[3];
|
return m_tElements[3];
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
//----------------------------------- Setters ----------------------------------
|
#pragma region Setters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\param index The index of the element to set.
|
\param index The index of the element to set.
|
||||||
\param tValue The new value for the element.
|
\param tValue The new value for the element.
|
||||||
@ -374,9 +431,9 @@ namespace PolyVox
|
|||||||
{
|
{
|
||||||
m_tElements[3] = tW;
|
m_tElements[3] = tW;
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
//-------------------------------- Other Functions -----------------------------
|
#pragma region Others
|
||||||
|
|
||||||
/**
|
/**
|
||||||
NOTE: This function does not make much sense on integer Vectors.
|
NOTE: This function does not make much sense on integer Vectors.
|
||||||
\return Length of the Vector.
|
\return Length of the Vector.
|
||||||
@ -475,60 +532,5 @@ namespace PolyVox
|
|||||||
m_tElements[ct] /= static_cast<Type>(length);
|
m_tElements[ct] /= static_cast<Type>(length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#pragma endregion
|
||||||
/**
|
|
||||||
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
|
}//namespace Thermite
|
||||||
|
Loading…
x
Reference in New Issue
Block a user