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
160
161
162
163
164
165
|
#ifndef ESIZE_H
#define ESIZE_H
#define MIN(a,b) (a < b ? a : b)
#define MAX(a,b) (a > b ? a : b)
class eSize
{
public:
eSize();
eSize( int w, int h );
bool isNull() const;
bool isEmpty() const;
bool isValid() const;
int width() const;
int height() const;
void setWidth( int w );
void setHeight( int h );
void transpose();
eSize expandedTo( const eSize & ) const;
eSize boundedTo( const eSize & ) const;
int &rwidth();
int &rheight();
eSize &operator+=( const eSize & );
eSize &operator-=( const eSize & );
eSize &operator*=( int c );
eSize &operator*=( double c );
eSize &operator/=( int c );
eSize &operator/=( double c );
friend inline bool operator==( const eSize &, const eSize & );
friend inline bool operator!=( const eSize &, const eSize & );
friend inline eSize operator+( const eSize &, const eSize & );
friend inline eSize operator-( const eSize &, const eSize & );
friend inline eSize operator*( const eSize &, int );
friend inline eSize operator*( int, const eSize & );
friend inline eSize operator*( const eSize &, double );
friend inline eSize operator*( double, const eSize & );
friend inline eSize operator/( const eSize &, int );
friend inline eSize operator/( const eSize &, double );
private:
int wd;
int ht;
};
/*****************************************************************************
eSize inline functions
*****************************************************************************/
inline eSize::eSize()
{ wd = ht = -1; }
inline eSize::eSize( int w, int h )
{ wd=w; ht=h; }
inline bool eSize::isNull() const
{ return wd==0 && ht==0; }
inline bool eSize::isEmpty() const
{ return wd<1 || ht<1; }
inline bool eSize::isValid() const
{ return wd>=0 && ht>=0; }
inline int eSize::width() const
{ return wd; }
inline int eSize::height() const
{ return ht; }
inline void eSize::setWidth( int w )
{ wd=w; }
inline void eSize::setHeight( int h )
{ ht=h; }
inline int &eSize::rwidth()
{ return wd; }
inline int &eSize::rheight()
{ return ht; }
inline eSize &eSize::operator+=( const eSize &s )
{ wd+=s.wd; ht+=s.ht; return *this; }
inline eSize &eSize::operator-=( const eSize &s )
{ wd-=s.wd; ht-=s.ht; return *this; }
inline eSize &eSize::operator*=( int c )
{ wd*=c; ht*=c; return *this; }
inline eSize &eSize::operator*=( double c )
{ wd=(int)(wd*c); ht=(int)(ht*c); return *this; }
inline bool operator==( const eSize &s1, const eSize &s2 )
{ return s1.wd == s2.wd && s1.ht == s2.ht; }
inline bool operator!=( const eSize &s1, const eSize &s2 )
{ return s1.wd != s2.wd || s1.ht != s2.ht; }
inline eSize operator+( const eSize & s1, const eSize & s2 )
{ return eSize(s1.wd+s2.wd, s1.ht+s2.ht); }
inline eSize operator-( const eSize &s1, const eSize &s2 )
{ return eSize(s1.wd-s2.wd, s1.ht-s2.ht); }
inline eSize operator*( const eSize &s, int c )
{ return eSize(s.wd*c, s.ht*c); }
inline eSize operator*( int c, const eSize &s )
{ return eSize(s.wd*c, s.ht*c); }
inline eSize operator*( const eSize &s, double c )
{ return eSize((int)(s.wd*c), (int)(s.ht*c)); }
inline eSize operator*( double c, const eSize &s )
{ return eSize((int)(s.wd*c), (int)(s.ht*c)); }
inline eSize &eSize::operator/=( int c )
{
wd/=c; ht/=c;
return *this;
}
inline eSize &eSize::operator/=( double c )
{
wd=(int)(wd/c); ht=(int)(ht/c);
return *this;
}
inline eSize operator/( const eSize &s, int c )
{
return eSize(s.wd/c, s.ht/c);
}
inline eSize operator/( const eSize &s, double c )
{
return eSize((int)(s.wd/c), (int)(s.ht/c));
}
inline eSize eSize::expandedTo( const eSize & otherSize ) const
{
return eSize( MAX(wd,otherSize.wd), MAX(ht,otherSize.ht) );
}
inline eSize eSize::boundedTo( const eSize & otherSize ) const
{
return eSize( MIN(wd,otherSize.wd), MIN(ht,otherSize.ht) );
}
inline void eSize::transpose()
{
int tmp = wd;
wd = ht;
ht = tmp;
}
#endif // ESIZE_H
|