Skip to content

Commit

Permalink
[+] added normal2 to renderlib.h
Browse files Browse the repository at this point in the history
[!] 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
joesfer committed Mar 4, 2012
1 parent 7d55ffb commit 402eaf6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/math/algebra/normal/normal2.h
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions include/math/algebra/normal/normal2.inl
Expand Up @@ -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 >
Expand All @@ -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;
}
25 changes: 13 additions & 12 deletions include/math/algebra/normal/normal3.inl
Expand Up @@ -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 >
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions include/renderlib.h
Expand Up @@ -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>
Expand Down

0 comments on commit 402eaf6

Please sign in to comment.