Permalink
Browse files

[+] added normal2 to renderlib.h

[!] fixed caps on Normal2::normalize
[!] added length == 0 test on Normal3 constructor, instead of simply relying on an assert
[!] Normal3::dot is const now
  • Loading branch information...
1 parent 7d55ffb commit 402eaf656d7faaa125ea18d84d833697c6689333 @joesfer committed Mar 4, 2012
@@ -33,7 +33,7 @@ namespace Math {
inline Normal2<T> operator -() const;
- inline Normal2<T>& Normalize();
+ inline T normalize();
inline static Normal2<T> normalize(const Normal2<T>& n);
inline bool equals( const Normal2<T>& p, T epsilon ) const;
@@ -80,13 +80,13 @@ inline Normal2<T> Normal2<T>::operator -() const {
}
template< typename T >
-inline Normal2<T>& Normal2<T>::normalize() {
+inline T Normal2<T>::normalize() {
T length = sqrt( x * x + y * y);
assert(length != 0);
T invLength = 1.0 / length;
x *= invLength;
y *= invLength;
- return *this;
+ return length;
}
template< typename T >
@@ -112,11 +112,11 @@ inline bool Normal2<float>::equals( const Normal2<float>& p, float epsilon ) con
}
template<>
-inline Normal2<float>& Normal2<float>::normalize() {
+inline float Normal2<float>::normalize() {
float length = sqrtf( x * x + y * y );
assert(length != 0);
float invLength = 1.0f / length;
x *= invLength;
y *= invLength;
- return *this;
+ return length;
}
@@ -4,23 +4,24 @@ inline Normal3<T>::Normal3( const T X, const T Y, const T Z) {
// build Normal3<T> making vector <x,y,z> unitary
T length = sqrt(X*X + Y*Y + Z*Z);
- assert(length > 0);
-
- x = X / length;
- y = Y / length;
- z = Z / length;
+ if ( length > 0 ) {
+ x = X / length;
+ y = Y / length;
+ z = Z / length;
+ }
}
template< typename T >
inline Normal3<T>::Normal3( const Vector3<T>& v) {
// build Normal3<T> making vector <x,y,z> unitary
- T length = v.Length();
+ T length = v.length();
- assert(length > 0);
- x = v.x / length;
- y = v.y / length;
- z = v.z / length;
+ if ( length > 0 ) {
+ x = v.x / length;
+ y = v.y / length;
+ z = v.z / length;
+ }
}
template< typename T >
@@ -94,12 +95,12 @@ inline Normal3<T> Normal3<T>::normalize(const Normal3<T>& n) {
}
template< typename T >
-inline T Normal3<T>::dot(const Normal3<T>& n, const Vector3<T>& v) const {
+inline T Normal3<T>::dot(const Normal3<T>& n, const Vector3<T>& v) {
return n.x*v.x + n.y*v.y + n.z*v.z;
}
template< typename T >
-inline T Normal3<T>::dot(const Normal3<T>& n1, const Normal3<T>& n2) const {
+inline T Normal3<T>::dot(const Normal3<T>& n1, const Normal3<T>& n2) {
return x*v.x + y*v.y + z*v.z;
}
View
@@ -33,6 +33,8 @@
#include <math/algebra/point/point3.h>
#include <math/algebra/vector/vector2.h>
#include <math/algebra/vector/vector3.h>
+#include <math/algebra/normal/normal2.h>
+#include <math/algebra/normal/normal3.h>
#include <math/algebra/quaternion/quaternion.h>
#include <math/sampling/random.h>

0 comments on commit 402eaf6

Please sign in to comment.