diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2003-10-17 15:36:42 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2003-10-17 15:36:42 +0000 |
| commit | d63d2c3c6cbbd574dda4f8b00ebe6c661735edd5 (patch) | |
| tree | 84d0cacfd0b6c1241c236c7860f7cbd7f26901bb /lib/gdi/epoint.h | |
| download | enigma2-d63d2c3c6cbbd574dda4f8b00ebe6c661735edd5.tar.gz enigma2-d63d2c3c6cbbd574dda4f8b00ebe6c661735edd5.zip | |
import of enigma2
Diffstat (limited to 'lib/gdi/epoint.h')
| -rw-r--r-- | lib/gdi/epoint.h | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/lib/gdi/epoint.h b/lib/gdi/epoint.h new file mode 100644 index 00000000..fc5f9836 --- /dev/null +++ b/lib/gdi/epoint.h @@ -0,0 +1,172 @@ +#ifndef EPOINT_H +#define EPOINT_H + +#include <iostream> + +#ifndef ABS +#define ABS(x) ( x>0 ? x : -x ) +#endif + +class ePoint +{ +public: + ePoint(); + ePoint( int xpos, int ypos ); + + bool isNull() const; + + int x() const; + int y() const; + void setX( int x ); + void setY( int y ); + + int manhattanLength() const; + + int &rx(); + int &ry(); + + ePoint &operator+=( const ePoint &p ); + ePoint &operator-=( const ePoint &p ); + ePoint &operator*=( int c ); + ePoint &operator*=( double c ); + ePoint &operator/=( int c ); + ePoint &operator/=( double c ); + + friend inline bool operator==( const ePoint &, const ePoint & ); + friend inline bool operator!=( const ePoint &, const ePoint & ); + friend inline ePoint operator+( const ePoint &, const ePoint & ); + friend inline ePoint operator-( const ePoint &, const ePoint & ); + friend inline ePoint operator*( const ePoint &, int ); + friend inline ePoint operator*( int, const ePoint & ); + friend inline ePoint operator*( const ePoint &, double ); + friend inline ePoint operator*( double, const ePoint & ); + friend inline ePoint operator-( const ePoint & ); + friend inline ePoint operator/( const ePoint &, int ); + friend inline ePoint operator/( const ePoint &, double ); +private: + int xp; + int yp; +}; + + +inline int ePoint::manhattanLength() const +{ + return ABS(x())+ABS(y()); +} + + +/***************************************************************************** + ePoint stream functions + *****************************************************************************/ +namespace std +{ + inline ostream &operator<<( ostream & s, const ePoint & p ) + { + s << p.x() << p.y(); + return s; + } + + inline istream &operator>>( istream & s, ePoint & p ) + { + s >> p.rx() >> p.ry(); + return s; + } +} + + +/***************************************************************************** + ePoint inline functions + *****************************************************************************/ + +inline ePoint::ePoint() +{ xp=0; yp=0; } + +inline ePoint::ePoint( int xpos, int ypos ) +{ xp=(int)xpos; yp=(int)ypos; } + +inline bool ePoint::isNull() const +{ return xp == 0 && yp == 0; } + +inline int ePoint::x() const +{ return xp; } + +inline int ePoint::y() const +{ return yp; } + +inline void ePoint::setX( int x ) +{ xp = (int)x; } + +inline void ePoint::setY( int y ) +{ yp = (int)y; } + +inline int &ePoint::rx() +{ return xp; } + +inline int &ePoint::ry() +{ return yp; } + +inline ePoint &ePoint::operator+=( const ePoint &p ) +{ xp+=p.xp; yp+=p.yp; return *this; } + +inline ePoint &ePoint::operator-=( const ePoint &p ) +{ xp-=p.xp; yp-=p.yp; return *this; } + +inline ePoint &ePoint::operator*=( int c ) +{ xp*=(int)c; yp*=(int)c; return *this; } + +inline ePoint &ePoint::operator*=( double c ) +{ xp=(int)(xp*c); yp=(int)(yp*c); return *this; } + +inline bool operator==( const ePoint &p1, const ePoint &p2 ) +{ return p1.xp == p2.xp && p1.yp == p2.yp; } + +inline bool operator!=( const ePoint &p1, const ePoint &p2 ) +{ return p1.xp != p2.xp || p1.yp != p2.yp; } + +inline ePoint operator+( const ePoint &p1, const ePoint &p2 ) +{ return ePoint(p1.xp+p2.xp, p1.yp+p2.yp); } + +inline ePoint operator-( const ePoint &p1, const ePoint &p2 ) +{ return ePoint(p1.xp-p2.xp, p1.yp-p2.yp); } + +inline ePoint operator*( const ePoint &p, int c ) +{ return ePoint(p.xp*c, p.yp*c); } + +inline ePoint operator*( int c, const ePoint &p ) +{ return ePoint(p.xp*c, p.yp*c); } + +inline ePoint operator*( const ePoint &p, double c ) +{ return ePoint((int)(p.xp*c), (int)(p.yp*c)); } + +inline ePoint operator*( double c, const ePoint &p ) +{ return ePoint((int)(p.xp*c), (int)(p.yp*c)); } + +inline ePoint operator-( const ePoint &p ) +{ return ePoint(-p.xp, -p.yp); } + +inline ePoint &ePoint::operator/=( int c ) +{ + xp/=(int)c; + yp/=(int)c; + return *this; +} + +inline ePoint &ePoint::operator/=( double c ) +{ + xp=(int)(xp/c); + yp=(int)(yp/c); + return *this; +} + +inline ePoint operator/( const ePoint &p, int c ) +{ + return ePoint(p.xp/c, p.yp/c); +} + +inline ePoint operator/( const ePoint &p, double c ) +{ + return ePoint((int)(p.xp/c), (int)(p.yp/c)); +} + + +#endif // EPOINT_H |
