Making some functions in Vector use the new 'OperationType'.
This commit is contained in:
parent
b10b995a84
commit
a026546bb4
@ -131,15 +131,15 @@ namespace PolyVox
|
||||
void setW(StorageType tW);
|
||||
|
||||
///Get the length of the vector.
|
||||
double length(void) const;
|
||||
float length(void) const;
|
||||
///Get the squared length of the vector.
|
||||
double lengthSquared(void) const;
|
||||
OperationType lengthSquared(void) const;
|
||||
///Find the angle between this vector and that which is passed as a parameter.
|
||||
double angleTo(const Vector<Size,StorageType,OperationType>& vector) const;
|
||||
float angleTo(const Vector<Size,StorageType,OperationType>& vector) const;
|
||||
///Find the cross product between this vector and the vector passed as a parameter.
|
||||
Vector<Size,StorageType,OperationType> cross(const Vector<Size,StorageType,OperationType>& vector) const;
|
||||
///Find the dot product between this vector and the vector passed as a parameter.
|
||||
StorageType dot(const Vector<Size,StorageType,OperationType>& rhs) const;
|
||||
OperationType dot(const Vector<Size,StorageType,OperationType>& rhs) const;
|
||||
///Normalise the vector.
|
||||
void normalise(void);
|
||||
|
||||
|
@ -573,23 +573,23 @@ namespace PolyVox
|
||||
\return Length of the Vector.
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline double Vector<Size, StorageType, OperationType>::length(void) const
|
||||
inline float Vector<Size, StorageType, OperationType>::length(void) const
|
||||
{
|
||||
return sqrt(lengthSquared());
|
||||
return sqrt(static_cast<float>(lengthSquared()));
|
||||
}
|
||||
|
||||
/**
|
||||
\return Squared length of the Vector.
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline double Vector<Size, StorageType, OperationType>::lengthSquared(void) const
|
||||
inline OperationType Vector<Size, StorageType, OperationType>::lengthSquared(void) const
|
||||
{
|
||||
double result = 0.0f;
|
||||
OperationType tLengthSquared = static_cast<OperationType>(0);
|
||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
result += m_tElements[ct] * m_tElements[ct];
|
||||
tLengthSquared += static_cast<OperationType>(m_tElements[ct]) * static_cast<OperationType>(m_tElements[ct]);
|
||||
}
|
||||
return result;
|
||||
return tLengthSquared;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -602,9 +602,9 @@ namespace PolyVox
|
||||
\return The angle between them in radians.
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline double Vector<Size, StorageType, OperationType>::angleTo(const Vector<Size, StorageType, OperationType>& vector) const
|
||||
inline float Vector<Size, StorageType, OperationType>::angleTo(const Vector<Size, StorageType, OperationType>& vector) const
|
||||
{
|
||||
return acos(dot(vector) / (vector.length() * this->length()));
|
||||
return acos(static_cast<float>(dot(vector)) / (vector.length() * this->length()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -636,12 +636,12 @@ namespace PolyVox
|
||||
\see cross()
|
||||
*/
|
||||
template <uint32_t Size, typename StorageType, typename OperationType>
|
||||
inline StorageType Vector<Size, StorageType, OperationType>::dot(const Vector<Size, StorageType, OperationType>& rhs) const
|
||||
inline OperationType Vector<Size, StorageType, OperationType>::dot(const Vector<Size, StorageType, OperationType>& rhs) const
|
||||
{
|
||||
StorageType dotProduct = static_cast<StorageType>(0);
|
||||
OperationType dotProduct = static_cast<OperationType>(0);
|
||||
for(uint32_t ct = 0; ct < Size; ++ct)
|
||||
{
|
||||
dotProduct += m_tElements[ct] * rhs.m_tElements[ct];
|
||||
dotProduct += static_cast<OperationType>(m_tElements[ct]) * static_cast<OperationType>(rhs.m_tElements[ct]);
|
||||
}
|
||||
return dotProduct;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ using namespace PolyVox;
|
||||
void TestVector::testLength()
|
||||
{
|
||||
Vector3DInt8 vec(3, 4, 5);
|
||||
QCOMPARE(vec.lengthSquared(), double(3*3+4*4+5*5));
|
||||
QCOMPARE(vec.lengthSquared(), int32_t(3*3+4*4+5*5)); // QCOMPARE is strict on types. For an int8 vector, the OperationType is int32_t.
|
||||
}
|
||||
|
||||
void TestVector::testDotProduct()
|
||||
@ -40,7 +40,7 @@ void TestVector::testDotProduct()
|
||||
Vector3DInt8 vecxy(3, 4, 0);
|
||||
Vector3DInt8 vecz(0, 0, 1);
|
||||
|
||||
QCOMPARE(vecxy.dot(vecz), int8_t(0)); //QCOMPARE is very strict on the types matching
|
||||
QCOMPARE(vecxy.dot(vecz), int32_t(0)); // QCOMPARE is strict on types. For an int8 vector, the OperationType is int32_t .
|
||||
}
|
||||
|
||||
void TestVector::testEquality()
|
||||
|
Loading…
x
Reference in New Issue
Block a user