Playing around with some additional math functions and testing. I know I'm probably not doing the testing entirely correctly, or at least my naming of the tests sucks. Would love feedback, though of course I'll be doing research on it. With the addition of cmpf, Vector is clearly intended to be used with a floating point type, float, double, or long double. I may or may not change this. In my commercial ready version the class would support virtually any type, even a custom number class (fixed point).

This commit is contained in:
Brian 2014-02-20 23:03:12 -07:00
parent ce04edb8cb
commit bf29fa91e7
5 changed files with 47 additions and 21 deletions

View file

@ -10,26 +10,27 @@
#ifndef __MATHDEFS_H__
#define __MATHDEFS_H__
# include <limits>
# include <math.h>
typedef float Scalar;
// May not need this, so may be removed.
struct CoordinateSystem
template< typename T >
inline int cmpf( T lhs, T rhs )
{
struct Types
{
enum Enum
{
RightHandedZUp, // x-right, y-forward, z-up
RightHandedYUp, // x-right, y-up, z-backwards
LeftHandedZUp, // x-left y-forward, z-up
LeftHandedYUp // x-right, y-up, z-backwards
};
};
// set this to whichever you like
static const Types::Enum Type = Types::RightHandedZUp;
return abs( lhs - rhs ) < std::numeric_limits< T >::epsilon( ) ? 0 : (lhs < rhs ? -1 : 1 );
}
// If I want to provide helpers for up/down/left/right/forward/backwards vectors, then you'll need to know the coordinate system type^
};
template< typename T >
inline T min( T lhs, T rhs )
{
return lhs < rhs ? lhs : rhs;
}
template< typename T >
inline T max( T lhs, T rhs )
{
return lhs > rhs ? lhs : rhs;
}
#endif