aboutsummaryrefslogtreecommitdiff
path: root/lib/gdi/epoint.h
blob: d7cdf399876dbda8bceb3ffcc67d20ef33ed7271 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef EPOINT_H
#define EPOINT_H

#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 eSize & );
	friend inline ePoint operator-( const ePoint &, const ePoint & );
	friend inline ePoint operator-( const ePoint &, const eSize & );
	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 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 &p1, const eSize &p2 )
{ return ePoint(p1.xp+p2.width(), p1.yp+p2.height()); }

inline ePoint operator-( const ePoint &p1, const eSize &p2 )
{ return ePoint(p1.xp-p2.width(), p1.yp-p2.height()); }

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