From a026546bb40683a877fd39ae1f4298dc4abc6b12 Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 29 Nov 2012 18:16:32 +0100 Subject: [PATCH] Making some functions in Vector use the new 'OperationType'. --- .../PolyVoxCore/include/PolyVoxCore/Vector.h | 8 +++---- .../include/PolyVoxCore/Vector.inl | 22 +++++++++---------- tests/testvector.cpp | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.h b/library/PolyVoxCore/include/PolyVoxCore/Vector.h index 9f4b51de..fc689dc5 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.h @@ -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& vector) const; + float angleTo(const Vector& vector) const; ///Find the cross product between this vector and the vector passed as a parameter. Vector cross(const Vector& vector) const; ///Find the dot product between this vector and the vector passed as a parameter. - StorageType dot(const Vector& rhs) const; + OperationType dot(const Vector& rhs) const; ///Normalise the vector. void normalise(void); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index 504c4fbb..c93a0b9b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -573,23 +573,23 @@ namespace PolyVox \return Length of the Vector. */ template - inline double Vector::length(void) const + inline float Vector::length(void) const { - return sqrt(lengthSquared()); + return sqrt(static_cast(lengthSquared())); } /** \return Squared length of the Vector. */ template - inline double Vector::lengthSquared(void) const + inline OperationType Vector::lengthSquared(void) const { - double result = 0.0f; + OperationType tLengthSquared = static_cast(0); for(uint32_t ct = 0; ct < Size; ++ct) { - result += m_tElements[ct] * m_tElements[ct]; + tLengthSquared += static_cast(m_tElements[ct]) * static_cast(m_tElements[ct]); } - return result; + return tLengthSquared; } /** @@ -602,9 +602,9 @@ namespace PolyVox \return The angle between them in radians. */ template - inline double Vector::angleTo(const Vector& vector) const + inline float Vector::angleTo(const Vector& vector) const { - return acos(dot(vector) / (vector.length() * this->length())); + return acos(static_cast(dot(vector)) / (vector.length() * this->length())); } /** @@ -636,12 +636,12 @@ namespace PolyVox \see cross() */ template - inline StorageType Vector::dot(const Vector& rhs) const + inline OperationType Vector::dot(const Vector& rhs) const { - StorageType dotProduct = static_cast(0); + OperationType dotProduct = static_cast(0); for(uint32_t ct = 0; ct < Size; ++ct) { - dotProduct += m_tElements[ct] * rhs.m_tElements[ct]; + dotProduct += static_cast(m_tElements[ct]) * static_cast(rhs.m_tElements[ct]); } return dotProduct; } diff --git a/tests/testvector.cpp b/tests/testvector.cpp index 0239bd0f..78d24383 100644 --- a/tests/testvector.cpp +++ b/tests/testvector.cpp @@ -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()