import of enigma2
[enigma2.git] / lib / gdi / epoint.h
1 #ifndef EPOINT_H
2 #define EPOINT_H
3
4 #include <iostream>
5
6 #ifndef ABS
7 #define ABS(x) ( x>0 ? x : -x )
8 #endif
9
10 class ePoint
11 {
12 public:
13         ePoint();
14         ePoint( int xpos, int ypos );
15
16         bool   isNull() const;
17
18         int        x()          const;
19         int        y()          const;
20         void   setX( int x );
21         void   setY( int y );
22
23         int manhattanLength() const;
24
25         int &rx();
26         int &ry();
27
28         ePoint &operator+=( const ePoint &p );
29         ePoint &operator-=( const ePoint &p );
30         ePoint &operator*=( int c );
31         ePoint &operator*=( double c );
32         ePoint &operator/=( int c );
33         ePoint &operator/=( double c );
34
35         friend inline bool       operator==( const ePoint &, const ePoint & );
36         friend inline bool       operator!=( const ePoint &, const ePoint & );
37         friend inline ePoint operator+( const ePoint &, const ePoint & );
38         friend inline ePoint operator-( const ePoint &, const ePoint & );
39         friend inline ePoint operator*( const ePoint &, int );
40         friend inline ePoint operator*( int, const ePoint & );
41         friend inline ePoint operator*( const ePoint &, double );
42         friend inline ePoint operator*( double, const ePoint & );
43         friend inline ePoint operator-( const ePoint & );
44         friend inline ePoint operator/( const ePoint &, int );
45         friend inline ePoint operator/( const ePoint &, double );
46 private:
47         int xp;
48         int yp;
49 };
50
51
52 inline int ePoint::manhattanLength() const
53 {
54         return ABS(x())+ABS(y());
55 }
56
57
58 /*****************************************************************************
59   ePoint stream functions
60  *****************************************************************************/
61 namespace std
62 {
63         inline ostream &operator<<( ostream & s, const ePoint & p )
64         {
65                 s << p.x() << p.y();
66                 return s;
67         }
68
69         inline istream &operator>>( istream & s, ePoint & p )
70         {
71                 s >> p.rx() >> p.ry();
72           return s;
73         }
74 }
75
76
77 /*****************************************************************************
78   ePoint inline functions
79  *****************************************************************************/
80
81 inline ePoint::ePoint()
82 { xp=0; yp=0; }
83
84 inline ePoint::ePoint( int xpos, int ypos )
85 { xp=(int)xpos; yp=(int)ypos; }
86
87 inline bool ePoint::isNull() const
88 { return xp == 0 && yp == 0; }
89
90 inline int ePoint::x() const
91 { return xp; }
92
93 inline int ePoint::y() const
94 { return yp; }
95
96 inline void ePoint::setX( int x )
97 { xp = (int)x; }
98
99 inline void ePoint::setY( int y )
100 { yp = (int)y; }
101
102 inline int &ePoint::rx()
103 { return xp; }
104
105 inline int &ePoint::ry()
106 { return yp; }
107
108 inline ePoint &ePoint::operator+=( const ePoint &p )
109 { xp+=p.xp; yp+=p.yp; return *this; }
110
111 inline ePoint &ePoint::operator-=( const ePoint &p )
112 { xp-=p.xp; yp-=p.yp; return *this; }
113
114 inline ePoint &ePoint::operator*=( int c )
115 { xp*=(int)c; yp*=(int)c; return *this; }
116
117 inline ePoint &ePoint::operator*=( double c )
118 { xp=(int)(xp*c); yp=(int)(yp*c); return *this; }
119
120 inline bool operator==( const ePoint &p1, const ePoint &p2 )
121 { return p1.xp == p2.xp && p1.yp == p2.yp; }
122
123 inline bool operator!=( const ePoint &p1, const ePoint &p2 )
124 { return p1.xp != p2.xp || p1.yp != p2.yp; }
125
126 inline ePoint operator+( const ePoint &p1, const ePoint &p2 )
127 { return ePoint(p1.xp+p2.xp, p1.yp+p2.yp); }
128
129 inline ePoint operator-( const ePoint &p1, const ePoint &p2 )
130 { return ePoint(p1.xp-p2.xp, p1.yp-p2.yp); }
131
132 inline ePoint operator*( const ePoint &p, int c )
133 { return ePoint(p.xp*c, p.yp*c); }
134
135 inline ePoint operator*( int c, const ePoint &p )
136 { return ePoint(p.xp*c, p.yp*c); }
137
138 inline ePoint operator*( const ePoint &p, double c )
139 { return ePoint((int)(p.xp*c), (int)(p.yp*c)); }
140
141 inline ePoint operator*( double c, const ePoint &p )
142 { return ePoint((int)(p.xp*c), (int)(p.yp*c)); }
143
144 inline ePoint operator-( const ePoint &p )
145 { return ePoint(-p.xp, -p.yp); }
146
147 inline ePoint &ePoint::operator/=( int c )
148 {
149         xp/=(int)c;
150         yp/=(int)c;
151         return *this;
152 }
153
154 inline ePoint &ePoint::operator/=( double c )
155 {
156         xp=(int)(xp/c);
157         yp=(int)(yp/c);
158         return *this;
159 }
160
161 inline ePoint operator/( const ePoint &p, int c )
162 {
163         return ePoint(p.xp/c, p.yp/c);
164 }
165
166 inline ePoint operator/( const ePoint &p, double c )
167 {
168         return ePoint((int)(p.xp/c), (int)(p.yp/c));
169 }
170
171
172 #endif // EPOINT_H