NLPACS::CVector2s Class Reference

#include <vector_2s.h>


Detailed Description

Author:
Benjamin Legros

Nevrax France

Date:
2001

Definition at line 46 of file vector_2s.h.

Public Member Functions

void pack (const NLMISC::CVector2f &v)
void pack (const NLMISC::CVector &v)
NLMISC::CVector2f unpack () const
NLMISC::CVector unpack3f (float hintz=0.0f) const
Object.
 CVector2s (const NLMISC::CVector &v)
 CVector2s (const CVector2s &v)
 Copy Constructor.

 CVector2s (sint16 _x, sint16 _y)
 Constructor .

 CVector2s ()
 Constructor which do nothing.

Misc.
bool isNull () const
void maxof (const CVector2s &a, const CVector2s &b)
 Set all vector x/y/z as maximum of a/b x/y/z (respectively).

void minof (const CVector2s &a, const CVector2s &b)
 Set all vector x/y/z as minimum of a/b x/y/z (respectively).

bool operator!= (const CVector2s &v) const
bool operator== (const CVector2s &v) const
void serial (NLMISC::IStream &f)
 serial.

void set (sint16 _x, sint16 _y)
Advanced Maths.
float norm () const
 Return the norm of the vector.

void normalize ()
 Normalize the vector.

CVector2s normed () const
 Return the vector normalized.

float operator * (const CVector2s &v) const
 Dot product.

float sqrnorm () const
 Return the square of the norm of the vector.

Base Maths.
CVector2s operator * (float f) const
CVector2soperator *= (float f)
CVector2s operator+ (const CVector2s &v) const
CVector2soperator+= (const CVector2s &v)
CVector2s operator- () const
CVector2s operator- (const CVector2s &v) const
CVector2soperator-= (const CVector2s &v)
CVector2s operator/ (float f) const
CVector2soperator/= (float f)

Data Fields

sint16 x
sint16 y

Static Private Member Functions

bool checkCastSint16 (float f)
bool checkCastSint16 (sint64 s)
sint16 pack (float f)
sint16 safeCastSint16 (float f)
sint16 safeCastSint16 (sint64 s)
float unpack (sint16 s)


Constructor & Destructor Documentation

NLPACS::CVector2s::CVector2s  )  [inline]
 

Constructor which do nothing.

Definition at line 105 of file vector_2s.h.

Referenced by operator *(), operator+(), operator-(), and operator/().

00105 {}

NLPACS::CVector2s::CVector2s sint16  _x,
sint16  _y
[inline]
 

Constructor .

Definition at line 107 of file vector_2s.h.

References sint16, x, and y.

00107 : x(_x), y(_y) {}

NLPACS::CVector2s::CVector2s const CVector2s v  )  [inline]
 

Copy Constructor.

Definition at line 109 of file vector_2s.h.

References v, x, and y.

00109 : x(v.x), y(v.y) {}

NLPACS::CVector2s::CVector2s const NLMISC::CVector v  )  [inline]
 

Definition at line 110 of file vector_2s.h.

References pack(), and v.

00110 { pack(v); }


Member Function Documentation

bool NLPACS::CVector2s::checkCastSint16 float  f  )  [inline, static, private]
 

Definition at line 79 of file vector_2s.h.

References s, and sint64.

00080         {
00081                 sint64  s = (sint64)f;
00082                 return (s<=32767 && s>=-32768);
00083         }

bool NLPACS::CVector2s::checkCastSint16 sint64  s  )  [inline, static, private]
 

Definition at line 73 of file vector_2s.h.

References s, and sint64.

00074         {
00075                 return (s<=32767 && s>=-32768);
00076         }

bool NLPACS::CVector2s::isNull  )  const [inline]
 

Definition at line 157 of file vector_2s.h.

References x, and y.

00157 {return x==0.0f && y==0.0f;}

void NLPACS::CVector2s::maxof const CVector2s a,
const CVector2s b
[inline]
 

Set all vector x/y/z as maximum of a/b x/y/z (respectively).

Definition at line 165 of file vector_2s.h.

References x, x, y, and y.

Referenced by NLPACS::COrderedChain::pack(), and NLPACS::COrderedChain::serial().

00166         {
00167                 x= std::max(a.x, b.x);
00168                 y= std::max(a.y, b.y);
00169         }

void NLPACS::CVector2s::minof const CVector2s a,
const CVector2s b
[inline]
 

Set all vector x/y/z as minimum of a/b x/y/z (respectively).

Definition at line 159 of file vector_2s.h.

References min, x, x, y, and y.

Referenced by NLPACS::COrderedChain::computeMinMax(), and NLPACS::COrderedChain::pack().

00160         {
00161                 x= std::min(a.x, b.x);
00162                 y= std::min(a.y, b.y);
00163         }

float NLPACS::CVector2s::norm  )  const [inline]
 

Return the norm of the vector.

Definition at line 133 of file vector_2s.h.

References sqrnorm().

Referenced by normalize().

00133 {return (float)sqrt(sqrnorm());}

void NLPACS::CVector2s::normalize  )  [inline]
 

Normalize the vector.

Definition at line 137 of file vector_2s.h.

References norm().

00138         {
00139                 float   f= norm();
00140                 if(f>0)
00141                         *this/=f;
00142         }

CVector2s NLPACS::CVector2s::normed  )  const [inline]
 

Return the vector normalized.

Definition at line 144 of file vector_2s.h.

References v.

00145         {
00146                 CVector2s       v= *this;
00147                 v.normalize();
00148                 return v;
00149         }

float NLPACS::CVector2s::operator * const CVector2s v  )  const [inline]
 

Dot product.

Definition at line 131 of file vector_2s.h.

References v, NLPACS::Vector2sAccuracy, x, and y.

00131 {return ((float)x*(float)v.x + (float)y*(float)v.y)/(Vector2sAccuracy*Vector2sAccuracy);}

CVector2s NLPACS::CVector2s::operator * float  f  )  const [inline]
 

Definition at line 124 of file vector_2s.h.

References CVector2s(), safeCastSint16(), x, and y.

00124 {return CVector2s(safeCastSint16(x*f), safeCastSint16(y*f));}

CVector2s& NLPACS::CVector2s::operator *= float  f  )  [inline]
 

Definition at line 122 of file vector_2s.h.

References safeCastSint16(), x, and y.

00122 { x = safeCastSint16(f*x); y = safeCastSint16(f*y); return *this; }

bool NLPACS::CVector2s::operator!= const CVector2s v  )  const [inline]
 

Definition at line 156 of file vector_2s.h.

References v.

00156 {return !(*this==v);}

CVector2s NLPACS::CVector2s::operator+ const CVector2s v  )  const [inline]
 

Definition at line 118 of file vector_2s.h.

References CVector2s(), safeCastSint16(), sint64, v, x, and y.

00118 {return CVector2s(safeCastSint16((sint64)v.x+(sint64)x), safeCastSint16((sint64)v.y+(sint64)y));}

CVector2s& NLPACS::CVector2s::operator+= const CVector2s v  )  [inline]
 

Definition at line 116 of file vector_2s.h.

References safeCastSint16(), sint64, v, x, and y.

00116 {x=safeCastSint16((sint64)v.x+(sint64)x); y=safeCastSint16((sint64)v.y+(sint64)y); return *this;}

CVector2s NLPACS::CVector2s::operator-  )  const [inline]
 

Definition at line 120 of file vector_2s.h.

References CVector2s(), safeCastSint16(), sint64, x, and y.

CVector2s NLPACS::CVector2s::operator- const CVector2s v  )  const [inline]
 

Definition at line 119 of file vector_2s.h.

References CVector2s(), safeCastSint16(), sint64, v, x, and y.

00119 {return CVector2s(safeCastSint16((sint64)v.x-(sint64)x), safeCastSint16((sint64)v.y-(sint64)y));}

CVector2s& NLPACS::CVector2s::operator-= const CVector2s v  )  [inline]
 

Definition at line 117 of file vector_2s.h.

References safeCastSint16(), sint64, v, x, and y.

00117 {x=safeCastSint16((sint64)v.x-(sint64)x); y=safeCastSint16((sint64)v.y-(sint64)y); return *this;}

CVector2s NLPACS::CVector2s::operator/ float  f  )  const [inline]
 

Definition at line 125 of file vector_2s.h.

References CVector2s(), safeCastSint16(), x, and y.

00125 {return CVector2s(safeCastSint16(x/f), safeCastSint16(y/f));}

CVector2s& NLPACS::CVector2s::operator/= float  f  )  [inline]
 

Definition at line 123 of file vector_2s.h.

References safeCastSint16(), x, and y.

00123 { x = safeCastSint16(f/x); y = safeCastSint16(f/y); return *this; }

bool NLPACS::CVector2s::operator== const CVector2s v  )  const [inline]
 

Definition at line 155 of file vector_2s.h.

References v, x, and y.

00155 {return x==v.x && y==v.y;}

void NLPACS::CVector2s::pack const NLMISC::CVector2f v  )  [inline]
 

Definition at line 175 of file vector_2s.h.

References pack(), v, x, and y.

00175 { x = pack(v.x); y = pack(v.y); }

void NLPACS::CVector2s::pack const NLMISC::CVector v  )  [inline]
 

Definition at line 174 of file vector_2s.h.

References pack(), v, x, and y.

00174 { x = pack(v.x); y = pack(v.y); }

sint16 NLPACS::CVector2s::pack float  f  )  [inline, static, private]
 

Definition at line 87 of file vector_2s.h.

References safeCastSint16(), sint16, and NLPACS::Vector2sAccuracy.

Referenced by CVector2s(), pack(), and NLPACS::COrderedChain::translate().

00088         {
00089                 return safeCastSint16(f*Vector2sAccuracy);
00090         }

sint16 NLPACS::CVector2s::safeCastSint16 float  f  )  [inline, static, private]
 

Definition at line 60 of file vector_2s.h.

References nlerror, s, sint16, and sint64.

00061         {
00062 #ifdef NL_DEBUG
00063                 sint64  s = (sint64)f;
00064                 if (s>32767 || s<-32768)
00065                         nlerror("in CVector2s::safeCastSint16(float): value doesn't fit sint16 (value=%f)", f);
00066                 return (sint16)s;
00067 #else
00068                 return (sint16)f;
00069 #endif
00070         }

sint16 NLPACS::CVector2s::safeCastSint16 sint64  s  )  [inline, static, private]
 

Definition at line 50 of file vector_2s.h.

References NL_I64, nlerror, s, sint16, and sint64.

Referenced by operator *(), operator *=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), and pack().

00051         {
00052 #ifdef NL_DEBUG
00053                 if (s>32767 || s<-32768)
00054                         nlerror("in CVector2s::safeCastSint16(sint64): value doesn't fit sint16 (value=%" NL_I64 "d)", s);
00055 #endif
00056                 return (sint16)s;
00057         }

void NLPACS::CVector2s::serial NLMISC::IStream f  )  [inline]
 

serial.

Definition at line 171 of file vector_2s.h.

References NLMISC::IStream::serial(), x, and y.

00171 {f.serial(x,y);}

void NLPACS::CVector2s::set sint16  _x,
sint16  _y
[inline]
 

Definition at line 154 of file vector_2s.h.

References sint16, x, and y.

00154 {x= _x; y=_y;}

float NLPACS::CVector2s::sqrnorm  )  const [inline]
 

Return the square of the norm of the vector.

Definition at line 135 of file vector_2s.h.

References NLPACS::Vector2sAccuracy, x, and y.

Referenced by norm().

00135 {return ((float)x*(float)x + (float)y*(float)y)/(Vector2sAccuracy*Vector2sAccuracy);}

NLMISC::CVector2f NLPACS::CVector2s::unpack  )  const [inline]
 

Definition at line 176 of file vector_2s.h.

References x, and y.

Referenced by unpack3f().

00176 { return NLMISC::CVector2f(unpack(x), unpack(y)); }

float NLPACS::CVector2s::unpack sint16  s  )  [inline, static, private]
 

Definition at line 93 of file vector_2s.h.

References s, sint16, and NLPACS::Vector2sAccuracy.

00094         {
00095                 return (float)s/Vector2sAccuracy;
00096         }

NLMISC::CVector NLPACS::CVector2s::unpack3f float  hintz = 0.0f  )  const [inline]
 

Definition at line 177 of file vector_2s.h.

References unpack(), x, and y.

Referenced by NLPACS::CLocalRetriever::retrieveAccuratePosition().

00177 { return NLMISC::CVector(unpack(x), unpack(y), hintz); }


Field Documentation

sint16 NLPACS::CVector2s::x
 

Definition at line 99 of file vector_2s.h.

Referenced by maxof(), minof(), NLPACS::CLocalRetriever::retrieveAccuratePosition(), and NLPACS::CLocalRetriever::retrievePosition().

sint16 NLPACS::CVector2s::y
 

Definition at line 99 of file vector_2s.h.

Referenced by maxof(), minof(), NLPACS::CLocalRetriever::retrieveAccuratePosition(), and NLPACS::CLocalRetriever::retrievePosition().


The documentation for this class was generated from the following file:
Generated on Tue Mar 16 14:24:53 2004 for NeL by doxygen 1.3.6