Cleaned up float vs double types in Vec*d and Vec2f classes

This commit is contained in:
Robert Osfield 2004-06-09 13:06:12 +00:00
parent 81082648c3
commit 893eaaa3f4
4 changed files with 28 additions and 28 deletions

View File

@ -20,11 +20,11 @@
namespace osg {
/** General purpose float pair, uses include representation of
/** General purpose double pair, uses include representation of
texture coordinates.
No support yet added for float * Vec2d - is it necessary?
No support yet added for double * Vec2d - is it necessary?
Need to define a non-member non-friend operator* etc.
BTW: Vec2d * float is okay
BTW: Vec2d * double is okay
*/
class Vec2d
@ -72,7 +72,7 @@ class Vec2d
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
/// dot product
inline float operator * (const Vec2d& rhs) const
inline value_type operator * (const Vec2d& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1];
}
@ -141,13 +141,13 @@ class Vec2d
}
/// Length of the vector = sqrt( vec . vec )
inline float length() const
inline value_type length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] );
}
/// Length squared of the vector = vec . vec
inline float length2( void ) const
inline value_type length2( void ) const
{
return _v[0]*_v[0] + _v[1]*_v[1];
}

View File

@ -35,7 +35,7 @@ class Vec2f
value_type _v[2];
Vec2f() {_v[0]=0.0; _v[1]=0.0;}
Vec2f(float x,float y) { _v[0]=x; _v[1]=y; }
Vec2f(value_type x,value_type y) { _v[0]=x; _v[1]=y; }
inline bool operator == (const Vec2f& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; }
@ -49,37 +49,37 @@ class Vec2f
else return (_v[1]<v._v[1]);
}
inline float* ptr() { return _v; }
inline const float* ptr() const { return _v; }
inline value_type * ptr() { return _v; }
inline const value_type * ptr() const { return _v; }
inline void set( float x, float y ) { _v[0]=x; _v[1]=y; }
inline void set( value_type x, value_type y ) { _v[0]=x; _v[1]=y; }
inline float& operator [] (int i) { return _v[i]; }
inline float operator [] (int i) const { return _v[i]; }
inline value_type & operator [] (int i) { return _v[i]; }
inline value_type operator [] (int i) const { return _v[i]; }
inline float& x() { return _v[0]; }
inline float& y() { return _v[1]; }
inline value_type & x() { return _v[0]; }
inline value_type & y() { return _v[1]; }
inline float x() const { return _v[0]; }
inline float y() const { return _v[1]; }
inline value_type x() const { return _v[0]; }
inline value_type y() const { return _v[1]; }
inline bool valid() const { return !isNaN(); }
inline bool isNaN() const { return osg::isNaN(_v[0]) || osg::isNaN(_v[1]); }
/// dot product
inline float operator * (const Vec2f& rhs) const
inline value_type operator * (const Vec2f& rhs) const
{
return _v[0]*rhs._v[0]+_v[1]*rhs._v[1];
}
/// multiply by scalar
inline const Vec2f operator * (float rhs) const
inline const Vec2f operator * (value_type rhs) const
{
return Vec2f(_v[0]*rhs, _v[1]*rhs);
}
/// unary multiply by scalar
inline Vec2f& operator *= (float rhs)
inline Vec2f& operator *= (value_type rhs)
{
_v[0]*=rhs;
_v[1]*=rhs;
@ -87,13 +87,13 @@ class Vec2f
}
/// divide by scalar
inline const Vec2f operator / (float rhs) const
inline const Vec2f operator / (value_type rhs) const
{
return Vec2f(_v[0]/rhs, _v[1]/rhs);
}
/// unary divide by scalar
inline Vec2f& operator /= (float rhs)
inline Vec2f& operator /= (value_type rhs)
{
_v[0]/=rhs;
_v[1]/=rhs;
@ -136,25 +136,25 @@ class Vec2f
}
/// Length of the vector = sqrt( vec . vec )
inline float length() const
inline value_type length() const
{
return sqrtf( _v[0]*_v[0] + _v[1]*_v[1] );
}
/// Length squared of the vector = vec . vec
inline float length2( void ) const
inline value_type length2( void ) const
{
return _v[0]*_v[0] + _v[1]*_v[1];
}
/** normalize the vector so that it has length unity
returns the previous length of the vector*/
inline float normalize()
inline value_type normalize()
{
float norm = Vec2f::length();
value_type norm = Vec2f::length();
if (norm>0.0)
{
float inv = 1.0f/norm;
value_type inv = 1.0f/norm;
_v[0] *= inv;
_v[1] *= inv;
}

View File

@ -38,7 +38,7 @@ class Vec3d
inline Vec3d(const Vec3f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; _v[2]=vec._v[2];}
inline operator Vec3f() const { return Vec3f(_v[0],_v[1],_v[2]);}
inline operator Vec3f() const { return Vec3f((float)_v[0],(float)_v[1],(float)_v[2]);}
Vec3d(value_type x,value_type y,value_type z) { _v[0]=x; _v[1]=y; _v[2]=z; }

View File

@ -55,7 +55,7 @@ class Vec4d
inline Vec4d(const Vec4f& vec) { _v[0]=vec._v[0]; _v[1]=vec._v[1]; _v[2]=vec._v[2]; _v[3]=vec._v[3];}
inline operator Vec4f() const { return Vec4f(_v[0],_v[1],_v[2],_v[3]);}
inline operator Vec4f() const { return Vec4f((float)_v[0],(float)_v[1],(float)_v[2],(float)_v[3]);}
inline bool operator == (const Vec4d& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; }