]>
Commit | Line | Data |
---|---|---|
72e7876b SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: geometry.h | |
3 | // Purpose: Common Geometry Classes | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 08/05/99 | |
f91de7da | 7 | // RCS-ID: |
72e7876b | 8 | // Copyright: (c) |
c3a4297c | 9 | // Licence: wxWindows licence |
72e7876b SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
c3a4297c VZ |
12 | #ifndef _WX_GEOMETRY_H_ |
13 | #define _WX_GEOMETRY_H_ | |
72e7876b SC |
14 | |
15 | #ifdef __GNUG__ | |
6c7873e1 | 16 | #pragma interface "geometry.cpp" |
72e7876b SC |
17 | #endif |
18 | ||
510fc784 | 19 | #include "wx/defs.h" |
c3a4297c | 20 | |
5b781a67 SC |
21 | #ifndef wxUSE_GEOMETRY |
22 | #define wxUSE_GEOMETRY 0 | |
23 | #endif | |
24 | ||
c3a4297c VZ |
25 | #if wxUSE_GEOMETRY |
26 | ||
510fc784 RR |
27 | #include "wx/utils.h" |
28 | #include "wx/gdicmn.h" | |
29 | #include <math.h> | |
30 | ||
72e7876b | 31 | #ifdef __WXMSW__ |
c3a4297c | 32 | #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c ) |
72e7876b | 33 | #elif defined( __WXMAC__ ) |
03e11df5 | 34 | #ifdef __WXMAC_X__ |
5fde6fcc | 35 | #include <CoreServices/CoreServices.h> |
03e11df5 | 36 | #else |
c3a4297c | 37 | #include "Math64.h" |
03e11df5 | 38 | #endif |
c3a4297c | 39 | #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) ) |
72e7876b | 40 | #else |
c3a4297c | 41 | #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c)))) |
72e7876b SC |
42 | #endif |
43 | ||
44 | class wxDataInputStream ; | |
45 | class wxDataOutputStream ; | |
46 | ||
47 | // clipping from Cohen-Sutherland | |
48 | ||
49 | enum wxOutCode | |
50 | { | |
c3a4297c VZ |
51 | wxInside = 0x00 , |
52 | wxOutLeft = 0x01 , | |
53 | wxOutRight = 0x02 , | |
54 | wxOutTop = 0x08 , | |
f91de7da | 55 | wxOutBottom = 0x04 |
72e7876b SC |
56 | } ; |
57 | ||
f91de7da | 58 | // wxPoint2Ds represent a point or a vector in a 2d coordinate system |
72e7876b SC |
59 | |
60 | class WXDLLEXPORT wxPoint2DDouble | |
61 | { | |
62 | public : | |
f91de7da DW |
63 | inline wxPoint2DDouble(); |
64 | inline wxPoint2DDouble( wxDouble x , wxDouble y ) ; | |
65 | inline wxPoint2DDouble( const wxPoint2DDouble &pt ) ; | |
66 | ||
c3a4297c | 67 | // two different conversions to integers, floor and rounding |
f91de7da DW |
68 | inline void GetFloor( wxInt32 *x , wxInt32 *y ) ; |
69 | inline void GetRounded( wxInt32 *x , wxInt32 *y ) ; | |
c3a4297c | 70 | |
f91de7da DW |
71 | inline wxDouble GetVectorLength() ; |
72 | inline wxDouble GetVectorAngle() ; | |
c3a4297c VZ |
73 | void SetVectorLength( wxDouble length ) ; |
74 | void SetVectorAngle( wxDouble degrees ) ; | |
75 | void SetPolarCoordinates( wxDouble angle , wxDouble length ) ; | |
76 | // set the vector length to 1.0, preserving the angle | |
77 | void Normalize() ; | |
f91de7da DW |
78 | |
79 | inline wxDouble GetDistance( const wxPoint2DDouble &pt ) ; | |
80 | inline wxDouble GetDistanceSquare( const wxPoint2DDouble &pt ) ; | |
81 | inline wxDouble GetDotProduct( const wxPoint2DDouble &vec ) ; | |
82 | inline wxDouble GetCrossProduct( const wxPoint2DDouble &vec ) ; | |
c3a4297c VZ |
83 | |
84 | // the reflection of this point | |
f91de7da DW |
85 | inline wxPoint2DDouble operator-() ; |
86 | ||
87 | inline wxPoint2DDouble& operator=(const wxPoint2DDouble& pt) ; | |
88 | inline wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt) ; | |
89 | inline wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt) ; | |
90 | inline wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt) ; | |
91 | inline wxPoint2DDouble& operator*=(wxDouble n) ; | |
92 | inline wxPoint2DDouble& operator*=(wxInt32 n) ; | |
93 | inline wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt) ; | |
94 | inline wxPoint2DDouble& operator/=(wxDouble n) ; | |
95 | inline wxPoint2DDouble& operator/=(wxInt32 n) ; | |
96 | ||
97 | inline bool operator==(const wxPoint2DDouble& pt) const ; | |
98 | inline bool operator!=(const wxPoint2DDouble& pt) const ; | |
c3a4297c VZ |
99 | |
100 | wxDouble m_x ; | |
101 | wxDouble m_y ; | |
72e7876b SC |
102 | } ; |
103 | ||
104 | wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ; | |
105 | wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ; | |
106 | wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ; | |
107 | wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt) ; | |
108 | wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt) ; | |
109 | wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n) ; | |
110 | wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n) ; | |
111 | wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ; | |
112 | wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n) ; | |
113 | wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n) ; | |
114 | ||
f91de7da DW |
115 | inline wxPoint2DDouble::wxPoint2DDouble() |
116 | { | |
117 | m_x = 0.0 ; | |
118 | m_y = 0.0 ; | |
72e7876b SC |
119 | } |
120 | ||
f91de7da DW |
121 | inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y ) |
122 | { | |
123 | m_x = x ; | |
124 | m_y = y ; | |
125 | } | |
72e7876b | 126 | |
f91de7da DW |
127 | inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt ) |
128 | { | |
129 | m_x = pt.m_x ; | |
130 | m_y = pt.m_y ; | |
72e7876b SC |
131 | } |
132 | ||
f91de7da DW |
133 | inline void wxPoint2DDouble::GetFloor( wxInt32 *x , wxInt32 *y ) |
134 | { | |
135 | *x = (wxInt32) floor( m_x ) ; | |
136 | *y = (wxInt32) floor( m_y ) ; | |
72e7876b SC |
137 | } |
138 | ||
f91de7da DW |
139 | inline void wxPoint2DDouble::GetRounded( wxInt32 *x , wxInt32 *y ) |
140 | { | |
141 | *x = (wxInt32) floor( m_x + 0.5 ) ; | |
142 | *y = (wxInt32) floor( m_y + 0.5) ; | |
143 | } | |
144 | ||
145 | inline wxDouble wxPoint2DDouble::GetDistance( const wxPoint2DDouble &pt ) | |
146 | { | |
147 | return sqrt( GetDistanceSquare( pt ) ); | |
72e7876b SC |
148 | } |
149 | ||
f91de7da DW |
150 | inline wxDouble wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble &pt ) |
151 | { | |
c3a4297c | 152 | return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ; |
f91de7da | 153 | } |
72e7876b | 154 | |
f91de7da DW |
155 | inline wxDouble wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble &vec ) |
156 | { | |
c3a4297c | 157 | return ( m_x * vec.m_x + m_y * vec.m_y ) ; |
72e7876b SC |
158 | } |
159 | ||
f91de7da DW |
160 | inline wxDouble wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble &vec ) |
161 | { | |
c3a4297c | 162 | return ( m_x * vec.m_y - vec.m_x * m_y ) ; |
f91de7da | 163 | } |
72e7876b | 164 | |
f91de7da DW |
165 | inline wxPoint2DDouble wxPoint2DDouble::operator-() |
166 | { | |
c3a4297c | 167 | return wxPoint2DDouble( -m_x, -m_y); |
72e7876b SC |
168 | } |
169 | ||
170 | inline wxPoint2DDouble& wxPoint2DDouble::operator=(const wxPoint2DDouble& pt) | |
f91de7da DW |
171 | { |
172 | m_x = pt.m_x ; | |
173 | m_y = pt.m_y; | |
c3a4297c | 174 | return *this ; |
72e7876b SC |
175 | } |
176 | ||
f91de7da | 177 | inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt) |
72e7876b | 178 | { |
f91de7da DW |
179 | m_x = m_x + pt.m_x ; |
180 | m_y = m_y + pt.m_y; | |
c3a4297c | 181 | return *this ; |
72e7876b SC |
182 | } |
183 | ||
f91de7da DW |
184 | inline wxPoint2DDouble& wxPoint2DDouble::operator-=(const wxPoint2DDouble& pt) |
185 | { | |
186 | m_x = m_x - pt.m_x ; | |
187 | m_y = m_y - pt.m_y; | |
c3a4297c | 188 | return *this ; |
72e7876b SC |
189 | } |
190 | ||
f91de7da DW |
191 | inline wxPoint2DDouble& wxPoint2DDouble::operator*=(const wxPoint2DDouble& pt) |
192 | { | |
193 | m_x = m_x * pt.m_x ; | |
194 | m_y = m_y * pt.m_y; | |
c3a4297c | 195 | return *this ; |
72e7876b SC |
196 | } |
197 | ||
f91de7da DW |
198 | inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt) |
199 | { | |
200 | m_x = m_x / pt.m_x ; | |
da052901 | 201 | m_y = m_y / pt.m_y; |
c3a4297c | 202 | return *this ; |
72e7876b SC |
203 | } |
204 | ||
f91de7da DW |
205 | inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const |
206 | { | |
207 | return m_x == pt.m_x && m_y == pt.m_y; | |
72e7876b SC |
208 | } |
209 | ||
f91de7da DW |
210 | inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const |
211 | { | |
212 | return m_x != pt.m_x || m_y != pt.m_y; | |
72e7876b SC |
213 | } |
214 | ||
f91de7da | 215 | inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) |
72e7876b | 216 | { |
c3a4297c | 217 | return wxPoint2DDouble( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ; |
72e7876b SC |
218 | } |
219 | ||
f91de7da | 220 | inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) |
72e7876b | 221 | { |
c3a4297c | 222 | return wxPoint2DDouble( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ; |
72e7876b SC |
223 | } |
224 | ||
225 | ||
f91de7da | 226 | inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) |
72e7876b | 227 | { |
c3a4297c | 228 | return wxPoint2DDouble( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ; |
72e7876b SC |
229 | } |
230 | ||
f91de7da | 231 | inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt) |
72e7876b | 232 | { |
c3a4297c | 233 | return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ; |
72e7876b SC |
234 | } |
235 | ||
f91de7da | 236 | inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt) |
72e7876b | 237 | { |
c3a4297c | 238 | return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ; |
72e7876b SC |
239 | } |
240 | ||
f91de7da | 241 | inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n) |
72e7876b | 242 | { |
c3a4297c | 243 | return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ; |
72e7876b SC |
244 | } |
245 | ||
f91de7da | 246 | inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n) |
72e7876b | 247 | { |
c3a4297c | 248 | return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ; |
72e7876b SC |
249 | } |
250 | ||
f91de7da | 251 | inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) |
72e7876b | 252 | { |
c3a4297c | 253 | return wxPoint2DDouble( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ; |
72e7876b SC |
254 | } |
255 | ||
f91de7da | 256 | inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n) |
72e7876b | 257 | { |
c3a4297c | 258 | return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ; |
72e7876b SC |
259 | } |
260 | ||
f91de7da | 261 | inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n) |
72e7876b | 262 | { |
c3a4297c | 263 | return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ; |
72e7876b SC |
264 | } |
265 | ||
f91de7da | 266 | // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the |
72e7876b | 267 | // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if |
f91de7da | 268 | // left <= x < right and top <= m_y < bottom , thus it is a half open interval. |
72e7876b SC |
269 | |
270 | class WXDLLEXPORT wxRect2DDouble | |
271 | { | |
272 | public: | |
f91de7da | 273 | wxRect2DDouble() |
6c7873e1 RR |
274 | { m_x = m_y = m_width = m_height = 0 ; } |
275 | wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h) | |
276 | { m_x = x ; m_y = y ; m_width = w ; m_height = h ; } | |
277 | /* | |
278 | wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight); | |
279 | wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size); | |
280 | wxRect2DDouble(const wxRect2DDouble& rect); | |
281 | */ | |
c3a4297c VZ |
282 | // single attribute accessors |
283 | ||
f91de7da | 284 | inline wxPoint2DDouble GetPosition() |
6c7873e1 RR |
285 | { return wxPoint2DDouble(m_x, m_y); } |
286 | inline wxSize GetSize() | |
7a5e6267 | 287 | { return wxSize((int) m_width, (int) m_height); } |
c3a4297c | 288 | |
6c7873e1 | 289 | // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their |
c3a4297c VZ |
290 | // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately |
291 | ||
6c7873e1 RR |
292 | inline wxDouble GetLeft() const { return m_x; } |
293 | inline void SetLeft( wxDouble n ) { m_width += m_x - n ; m_x = n ; } | |
294 | inline void MoveLeftTo( wxDouble n ) { m_x = n ; } | |
295 | inline wxDouble GetTop() const { return m_y; } | |
296 | inline void SetTop( wxDouble n ) { m_height += m_y - n ; m_y = n ; } | |
297 | inline void MoveTopTo( wxDouble n ) { m_y = n ; } | |
298 | inline wxDouble GetBottom() const { return m_y + m_height; } | |
299 | inline void SetBottom( wxDouble n ) { m_height += n - (m_y+m_height) ;} | |
300 | inline void MoveBottomTo( wxDouble n ) { m_y = n - m_height ; } | |
301 | inline wxDouble GetRight() const { return m_x + m_width; } | |
302 | inline void SetRight( wxDouble n ) { m_width += n - (m_x+m_width) ; } | |
303 | inline void MoveRightTo( wxDouble n ) { m_x = n - m_width ; } | |
304 | ||
305 | inline wxPoint2DDouble GetLeftTop() const | |
306 | { return wxPoint2DDouble( m_x , m_y ) ; } | |
307 | inline void SetLeftTop( const wxPoint2DDouble &pt ) | |
f91de7da | 308 | { m_width += m_x - pt.m_x ; m_height += m_y - pt.m_y ; m_x = pt.m_x ; m_y = pt.m_y ; } |
6c7873e1 | 309 | inline void MoveLeftTopTo( const wxPoint2DDouble &pt ) |
f91de7da | 310 | { m_x = pt.m_x ; m_y = pt.m_y ; } |
6c7873e1 RR |
311 | inline wxPoint2DDouble GetLeftBottom() const |
312 | { return wxPoint2DDouble( m_x , m_y + m_height ) ; } | |
313 | inline void SetLeftBottom( const wxPoint2DDouble &pt ) | |
f91de7da | 314 | { m_width += m_x - pt.m_x ; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x ; } |
6c7873e1 | 315 | inline void MoveLeftBottomTo( const wxPoint2DDouble &pt ) |
f91de7da | 316 | { m_x = pt.m_x ; m_y = pt.m_y - m_height; } |
6c7873e1 RR |
317 | inline wxPoint2DDouble GetRightTop() const |
318 | { return wxPoint2DDouble( m_x+m_width , m_y ) ; } | |
319 | inline void SetRightTop( const wxPoint2DDouble &pt ) | |
f91de7da | 320 | { m_width += pt.m_x - ( m_x + m_width ) ; m_height += m_y - pt.m_y ; m_y = pt.m_y ; } |
6c7873e1 | 321 | inline void MoveRightTopTo( const wxPoint2DDouble &pt ) |
f91de7da | 322 | { m_x = pt.m_x - m_width ; m_y = pt.m_y ; } |
6c7873e1 RR |
323 | inline wxPoint2DDouble GetRightBottom() const |
324 | { return wxPoint2DDouble( m_x+m_width , m_y + m_height ) ; } | |
325 | inline void SetRightBottom( const wxPoint2DDouble &pt ) | |
f91de7da | 326 | { m_width += pt.m_x - ( m_x + m_width ) ; m_height += pt.m_y - (m_y+m_height) ;} |
6c7873e1 | 327 | inline void MoveRightBottomTo( const wxPoint2DDouble &pt ) |
f91de7da | 328 | { m_x = pt.m_x - m_width ; m_y = pt.m_y - m_height; } |
6c7873e1 RR |
329 | inline wxPoint2DDouble GetCentre() const |
330 | { return wxPoint2DDouble( m_x+m_width/2 , m_y+m_height/2 ) ; } | |
331 | inline void SetCentre( const wxPoint2DDouble &pt ) | |
f91de7da | 332 | { MoveCentreTo( pt ) ; } // since this is impossible without moving... |
6c7873e1 | 333 | inline void MoveCentreTo( const wxPoint2DDouble &pt ) |
f91de7da | 334 | { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2) ; } |
6c7873e1 RR |
335 | inline wxOutCode GetOutcode( const wxPoint2DDouble &pt ) const |
336 | { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) + | |
c3a4297c VZ |
337 | ( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) + |
338 | ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) + | |
339 | ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )) ; } | |
f91de7da | 340 | inline bool Contains( const wxPoint2DDouble &pt ) const |
6c7873e1 | 341 | { return GetOutcode( pt ) == wxInside ; } |
f91de7da DW |
342 | inline bool Contains( const wxRect2DDouble &rect ) const |
343 | { return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) && | |
c3a4297c | 344 | ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ) ; } |
f91de7da | 345 | inline bool IsEmpty() const |
6c7873e1 | 346 | { return ( m_width <= 0 || m_height <= 0 ) ; } |
f91de7da | 347 | inline bool HaveEqualSize( const wxRect2DDouble &rect ) const |
6c7873e1 | 348 | { return ( rect.m_width == m_width && rect.m_height == m_height ) ; } |
f91de7da | 349 | |
6c7873e1 RR |
350 | inline void Inset( wxDouble x , wxDouble y ) |
351 | { m_x += x ; m_y += y ; m_width -= 2 * x ; m_height -= 2 * y ; } | |
f91de7da | 352 | inline void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom ) |
6c7873e1 RR |
353 | { m_x += left ; m_y += top ; m_width -= left + right ; m_height -= top + bottom ;} |
354 | inline void Offset( const wxPoint2DDouble &pt ) | |
355 | { m_x += pt.m_x ; m_y += pt.m_y ; } | |
f91de7da | 356 | |
6c7873e1 | 357 | void ConstrainTo( const wxRect2DDouble &rect ); |
f91de7da | 358 | |
6c7873e1 RR |
359 | inline wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ) |
360 | { return wxPoint2DDouble( m_x + m_width * widthfactor , m_y + m_height * heightfactor ) ; } | |
361 | ||
362 | static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ) ; | |
363 | inline void Intersect( const wxRect2DDouble &otherRect ) | |
364 | { Intersect( *this , otherRect , this ) ; } | |
365 | inline wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const | |
366 | { wxRect2DDouble result ; Intersect( *this , otherRect , &result) ; return result ; } | |
367 | bool Intersects( const wxRect2DDouble &rect ) const ; | |
368 | ||
369 | static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ) ; | |
370 | void Union( const wxRect2DDouble &otherRect ) | |
371 | { Union( *this , otherRect , this ) ; } | |
372 | void Union( const wxPoint2DDouble &pt ) ; | |
373 | inline wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const | |
374 | { wxRect2DDouble result ; Union( *this , otherRect , &result) ; return result ; } | |
375 | ||
376 | inline void Scale( wxDouble f ) | |
f91de7da DW |
377 | { m_x *= f ; m_y *= f ; m_width *= f ; m_height *= f ;} |
378 | inline void Scale( wxInt32 num , wxInt32 denum ) | |
379 | { m_x *= ((wxDouble)num)/((wxDouble)denum) ; m_y *= ((wxDouble)num)/((wxDouble)denum) ; | |
c3a4297c VZ |
380 | m_width *= ((wxDouble)num)/((wxDouble)denum) ; m_height *= ((wxDouble)num)/((wxDouble)denum) ;} |
381 | ||
6c7873e1 RR |
382 | /* |
383 | wxRect2DDouble& operator = (const wxRect2DDouble& rect); | |
384 | bool operator == (const wxRect2DDouble& rect); | |
385 | bool operator != (const wxRect2DDouble& rect); | |
386 | */ | |
c3a4297c | 387 | |
6c7873e1 RR |
388 | wxDouble m_x; |
389 | wxDouble m_y ; | |
390 | wxDouble m_width; | |
391 | wxDouble m_height; | |
72e7876b SC |
392 | }; |
393 | ||
394 | class WXDLLEXPORT wxPoint2DInt | |
395 | { | |
396 | public : | |
f91de7da DW |
397 | inline wxPoint2DInt(); |
398 | inline wxPoint2DInt( wxInt32 x , wxInt32 y ) ; | |
399 | inline wxPoint2DInt( const wxPoint2DInt &pt ) ; | |
400 | inline wxPoint2DInt( const wxPoint &pt ) ; | |
c3a4297c | 401 | |
f91de7da DW |
402 | // two different conversions to integers, floor and rounding |
403 | inline void GetFloor( wxInt32 *x , wxInt32 *y ) ; | |
404 | inline void GetRounded( wxInt32 *x , wxInt32 *y ) ; | |
405 | ||
406 | inline wxDouble GetVectorLength() ; | |
407 | wxDouble GetVectorAngle() ; | |
408 | inline void SetVectorLength( wxDouble length ) ; | |
409 | void SetVectorAngle( wxDouble degrees ) ; | |
410 | void SetPolarCoordinates( wxInt32 angle , wxInt32 length ) ; | |
c3a4297c | 411 | // set the vector length to 1.0, preserving the angle |
f91de7da DW |
412 | inline void Normalize() ; |
413 | ||
414 | inline wxDouble GetDistance( const wxPoint2DInt &pt ) const ; | |
415 | inline wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const; | |
416 | inline wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const; | |
417 | inline wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const; | |
c3a4297c VZ |
418 | |
419 | // the reflection of this point | |
f91de7da DW |
420 | inline wxPoint2DInt operator-() ; |
421 | ||
422 | inline wxPoint2DInt& operator=(const wxPoint2DInt& pt) ; | |
423 | inline wxPoint2DInt& operator+=(const wxPoint2DInt& pt) ; | |
424 | inline wxPoint2DInt& operator-=(const wxPoint2DInt& pt) ; | |
425 | inline wxPoint2DInt& operator*=(const wxPoint2DInt& pt) ; | |
426 | inline wxPoint2DInt& operator*=(wxDouble n) ; | |
427 | inline wxPoint2DInt& operator*=(wxInt32 n) ; | |
428 | inline wxPoint2DInt& operator/=(const wxPoint2DInt& pt) ; | |
429 | inline wxPoint2DInt& operator/=(wxDouble n) ; | |
430 | inline wxPoint2DInt& operator/=(wxInt32 n) ; | |
431 | inline operator wxPoint() const ; | |
432 | inline bool operator==(const wxPoint2DInt& pt) const ; | |
433 | inline bool operator!=(const wxPoint2DInt& pt) const ; | |
c3a4297c VZ |
434 | |
435 | void WriteTo( wxDataOutputStream &stream ) const ; | |
436 | void ReadFrom( wxDataInputStream &stream ) ; | |
437 | ||
438 | wxInt32 m_x ; | |
439 | wxInt32 m_y ; | |
72e7876b SC |
440 | } ; |
441 | ||
442 | wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ; | |
443 | wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ; | |
444 | wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ; | |
445 | wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt) ; | |
446 | wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt) ; | |
447 | wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n) ; | |
448 | wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n) ; | |
449 | wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ; | |
450 | wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n) ; | |
451 | wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n) ; | |
452 | ||
f91de7da DW |
453 | inline wxPoint2DInt::wxPoint2DInt() |
454 | { | |
455 | m_x = 0 ; | |
456 | m_y = 0 ; | |
72e7876b SC |
457 | } |
458 | ||
f91de7da DW |
459 | inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y ) |
460 | { | |
461 | m_x = x ; | |
462 | m_y = y ; | |
463 | } | |
72e7876b | 464 | |
f91de7da DW |
465 | inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt ) |
466 | { | |
467 | m_x = pt.m_x ; | |
468 | m_y = pt.m_y ; | |
72e7876b SC |
469 | } |
470 | ||
f91de7da DW |
471 | inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt ) |
472 | { | |
473 | m_x = pt.x ; | |
474 | m_y = pt.y ; | |
475 | } | |
476 | ||
477 | inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y ) | |
478 | { | |
479 | *x = (wxInt32) floor( m_x ) ; | |
480 | *y = (wxInt32) floor( m_y ) ; | |
72e7876b SC |
481 | } |
482 | ||
f91de7da DW |
483 | inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y ) |
484 | { | |
485 | *x = (wxInt32) floor( m_x + 0.5 ) ; | |
486 | *y = (wxInt32) floor( m_y + 0.5) ; | |
487 | } | |
488 | ||
489 | inline wxDouble wxPoint2DInt::GetVectorLength() | |
72e7876b | 490 | { |
c3a4297c | 491 | return sqrt( (m_x)*(m_x) + (m_y)*(m_y) ) ; |
72e7876b SC |
492 | } |
493 | ||
f91de7da | 494 | inline void wxPoint2DInt::SetVectorLength( wxDouble length ) |
72e7876b | 495 | { |
c3a4297c VZ |
496 | wxDouble before = GetVectorLength() ; |
497 | m_x = (wxInt32)(m_x * length / before) ; | |
498 | m_y = (wxInt32)(m_y * length / before) ; | |
72e7876b SC |
499 | } |
500 | ||
f91de7da | 501 | inline void wxPoint2DInt::Normalize() |
72e7876b | 502 | { |
c3a4297c | 503 | SetVectorLength( 1 ) ; |
72e7876b SC |
504 | } |
505 | ||
506 | inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const | |
f91de7da DW |
507 | { |
508 | return sqrt( GetDistanceSquare( pt ) ); | |
72e7876b SC |
509 | } |
510 | ||
511 | inline wxDouble wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt &pt ) const | |
f91de7da | 512 | { |
c3a4297c | 513 | return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ; |
f91de7da | 514 | } |
72e7876b SC |
515 | |
516 | inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const | |
f91de7da | 517 | { |
c3a4297c | 518 | return ( m_x * vec.m_x + m_y * vec.m_y ) ; |
72e7876b SC |
519 | } |
520 | ||
521 | inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const | |
f91de7da | 522 | { |
c3a4297c | 523 | return ( m_x * vec.m_y - vec.m_x * m_y ) ; |
f91de7da | 524 | } |
72e7876b SC |
525 | |
526 | inline wxPoint2DInt::operator wxPoint() const | |
f91de7da | 527 | { |
c3a4297c | 528 | return wxPoint( m_x, m_y); |
72e7876b SC |
529 | } |
530 | ||
f91de7da DW |
531 | inline wxPoint2DInt wxPoint2DInt::operator-() |
532 | { | |
c3a4297c | 533 | return wxPoint2DInt( -m_x, -m_y); |
72e7876b SC |
534 | } |
535 | ||
536 | inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt) | |
f91de7da DW |
537 | { |
538 | m_x = pt.m_x ; | |
539 | m_y = pt.m_y; | |
c3a4297c | 540 | return *this ; |
72e7876b SC |
541 | } |
542 | ||
f91de7da | 543 | inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt) |
72e7876b | 544 | { |
f91de7da DW |
545 | m_x = m_x + pt.m_x ; |
546 | m_y = m_y + pt.m_y; | |
c3a4297c | 547 | return *this ; |
72e7876b SC |
548 | } |
549 | ||
f91de7da DW |
550 | inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt) |
551 | { | |
552 | m_x = m_x - pt.m_x ; | |
553 | m_y = m_y - pt.m_y; | |
c3a4297c | 554 | return *this ; |
72e7876b SC |
555 | } |
556 | ||
f91de7da DW |
557 | inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt) |
558 | { | |
559 | m_x = m_x + pt.m_x ; | |
560 | m_y = m_y + pt.m_y; | |
c3a4297c | 561 | return *this ; |
72e7876b SC |
562 | } |
563 | ||
f91de7da DW |
564 | inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt) |
565 | { | |
566 | m_x = m_x - pt.m_x ; | |
c3a4297c VZ |
567 | m_y = m_y - pt.m_y; |
568 | return *this ; | |
72e7876b SC |
569 | } |
570 | ||
f91de7da DW |
571 | inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const |
572 | { | |
573 | return m_x == pt.m_x && m_y == pt.m_y; | |
72e7876b SC |
574 | } |
575 | ||
f91de7da DW |
576 | inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const |
577 | { | |
578 | return m_x != pt.m_x || m_y != pt.m_y; | |
72e7876b SC |
579 | } |
580 | ||
f91de7da | 581 | inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) |
72e7876b | 582 | { |
c3a4297c | 583 | return wxPoint2DInt( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ; |
72e7876b SC |
584 | } |
585 | ||
f91de7da | 586 | inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) |
72e7876b | 587 | { |
c3a4297c | 588 | return wxPoint2DInt( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ; |
72e7876b SC |
589 | } |
590 | ||
591 | ||
f91de7da | 592 | inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) |
72e7876b | 593 | { |
c3a4297c | 594 | return wxPoint2DInt( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ; |
72e7876b SC |
595 | } |
596 | ||
f91de7da | 597 | inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt) |
72e7876b | 598 | { |
c3a4297c | 599 | return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ; |
72e7876b SC |
600 | } |
601 | ||
f91de7da | 602 | inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt) |
72e7876b | 603 | { |
7a5e6267 | 604 | return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) ) ; |
72e7876b SC |
605 | } |
606 | ||
f91de7da | 607 | inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n) |
72e7876b | 608 | { |
c3a4297c | 609 | return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ; |
72e7876b SC |
610 | } |
611 | ||
f91de7da | 612 | inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n) |
72e7876b | 613 | { |
7a5e6267 | 614 | return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) ) ; |
72e7876b SC |
615 | } |
616 | ||
f91de7da | 617 | inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) |
72e7876b | 618 | { |
c3a4297c | 619 | return wxPoint2DInt( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ; |
72e7876b SC |
620 | } |
621 | ||
f91de7da | 622 | inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n) |
72e7876b | 623 | { |
c3a4297c | 624 | return wxPoint2DInt( pt.m_x / n , pt.m_y / n ) ; |
72e7876b SC |
625 | } |
626 | ||
f91de7da | 627 | inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n) |
72e7876b | 628 | { |
7a5e6267 | 629 | return wxPoint2DInt( (int) (pt.m_x / n) , (int) (pt.m_y / n) ) ; |
72e7876b SC |
630 | } |
631 | ||
f91de7da | 632 | // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the |
72e7876b | 633 | // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if |
f91de7da | 634 | // left <= x < right and top <= m_y < bottom , thus it is a half open interval. |
72e7876b SC |
635 | |
636 | class WXDLLEXPORT wxRect2DInt | |
637 | { | |
638 | public: | |
c3a4297c VZ |
639 | wxRect2DInt() { m_x = m_y = m_width = m_height = 0 ; } |
640 | wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h) { m_x = x ; m_y = y ; m_width = w ; m_height = h ; } | |
641 | wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight); | |
f91de7da DW |
642 | inline wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size); |
643 | inline wxRect2DInt(const wxRect2DInt& rect); | |
c3a4297c VZ |
644 | |
645 | // single attribute accessors | |
646 | ||
647 | inline wxPoint2DInt GetPosition() { return wxPoint2DInt(m_x, m_y); } | |
648 | inline wxSize GetSize() { return wxSize(m_width, m_height); } | |
649 | ||
650 | // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their | |
651 | // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately | |
652 | ||
653 | inline wxInt32 GetLeft() const { return m_x; } | |
654 | inline void SetLeft( wxInt32 n ) { m_width += m_x - n ; m_x = n ; } | |
655 | inline void MoveLeftTo( wxInt32 n ) { m_x = n ; } | |
656 | inline wxInt32 GetTop() const { return m_y; } | |
657 | inline void SetTop( wxInt32 n ) { m_height += m_y - n ; m_y = n ; } | |
658 | inline void MoveTopTo( wxInt32 n ) { m_y = n ; } | |
659 | inline wxInt32 GetBottom() const { return m_y + m_height; } | |
660 | inline void SetBottom( wxInt32 n ) { m_height += n - (m_y+m_height) ;} | |
661 | inline void MoveBottomTo( wxInt32 n ) { m_y = n - m_height ; } | |
662 | inline wxInt32 GetRight() const { return m_x + m_width; } | |
663 | inline void SetRight( wxInt32 n ) { m_width += n - (m_x+m_width) ; } | |
664 | inline void MoveRightTo( wxInt32 n ) { m_x = n - m_width ; } | |
665 | ||
666 | inline wxPoint2DInt GetLeftTop() const { return wxPoint2DInt( m_x , m_y ) ; } | |
f91de7da DW |
667 | inline void SetLeftTop( const wxPoint2DInt &pt ) { m_width += m_x - pt.m_x ; m_height += m_y - pt.m_y ; m_x = pt.m_x ; m_y = pt.m_y ; } |
668 | inline void MoveLeftTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x ; m_y = pt.m_y ; } | |
c3a4297c | 669 | inline wxPoint2DInt GetLeftBottom() const { return wxPoint2DInt( m_x , m_y + m_height ) ; } |
f91de7da DW |
670 | inline void SetLeftBottom( const wxPoint2DInt &pt ) { m_width += m_x - pt.m_x ; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x ; } |
671 | inline void MoveLeftBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x ; m_y = pt.m_y - m_height; } | |
c3a4297c | 672 | inline wxPoint2DInt GetRightTop() const { return wxPoint2DInt( m_x+m_width , m_y ) ; } |
f91de7da DW |
673 | inline void SetRightTop( const wxPoint2DInt &pt ) { m_width += pt.m_x - ( m_x + m_width ) ; m_height += m_y - pt.m_y ; m_y = pt.m_y ; } |
674 | inline void MoveRightTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y ; } | |
c3a4297c | 675 | inline wxPoint2DInt GetRightBottom() const { return wxPoint2DInt( m_x+m_width , m_y + m_height ) ; } |
f91de7da DW |
676 | inline void SetRightBottom( const wxPoint2DInt &pt ) { m_width += pt.m_x - ( m_x + m_width ) ; m_height += pt.m_y - (m_y+m_height) ;} |
677 | inline void MoveRightBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y - m_height; } | |
c3a4297c | 678 | inline wxPoint2DInt GetCentre() const { return wxPoint2DInt( m_x+m_width/2 , m_y+m_height/2 ) ; } |
f91de7da DW |
679 | inline void SetCentre( const wxPoint2DInt &pt ) { MoveCentreTo( pt ) ; } // since this is impossible without moving... |
680 | inline void MoveCentreTo( const wxPoint2DInt &pt ) { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2) ; } | |
c3a4297c VZ |
681 | inline wxOutCode GetOutcode( const wxPoint2DInt &pt ) const |
682 | { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) + | |
683 | ( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) + | |
684 | ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) + | |
685 | ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )) ; } | |
f91de7da | 686 | inline bool Contains( const wxPoint2DInt &pt ) const |
c3a4297c | 687 | { return GetOutcode( pt ) == wxInside ; } |
f91de7da DW |
688 | inline bool Contains( const wxRect2DInt &rect ) const |
689 | { return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) && | |
c3a4297c | 690 | ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ) ; } |
f91de7da | 691 | inline bool IsEmpty() const |
c3a4297c | 692 | { return ( m_width <= 0 || m_height <= 0 ) ; } |
f91de7da | 693 | inline bool HaveEqualSize( const wxRect2DInt &rect ) const |
c3a4297c | 694 | { return ( rect.m_width == m_width && rect.m_height == m_height ) ; } |
f91de7da | 695 | |
c3a4297c | 696 | inline void Inset( wxInt32 x , wxInt32 y ) { m_x += x ; m_y += y ; m_width -= 2 * x ; m_height -= 2 * y ; } |
f91de7da | 697 | inline void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom ) |
c3a4297c VZ |
698 | { m_x += left ; m_y += top ; m_width -= left + right ; m_height -= top + bottom ;} |
699 | inline void Offset( const wxPoint2DInt &pt ) { m_x += pt.m_x ; m_y += pt.m_y ; } | |
700 | void ConstrainTo( const wxRect2DInt &rect ) ; | |
701 | inline wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ) { return wxPoint2DInt( m_x + m_width * widthfactor , m_y + m_height * heightfactor ) ; } | |
702 | ||
703 | static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ) ; | |
704 | inline void Intersect( const wxRect2DInt &otherRect ) { Intersect( *this , otherRect , this ) ; } | |
705 | inline wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const { wxRect2DInt result ; Intersect( *this , otherRect , &result) ; return result ; } | |
706 | bool Intersects( const wxRect2DInt &rect ) const ; | |
707 | ||
708 | static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ) ; | |
709 | void Union( const wxRect2DInt &otherRect ) { Union( *this , otherRect , this ) ; } | |
710 | void Union( const wxPoint2DInt &pt ) ; | |
711 | inline wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const { wxRect2DInt result ; Union( *this , otherRect , &result) ; return result ; } | |
712 | ||
f91de7da DW |
713 | inline void Scale( wxInt32 f ) { m_x *= f ; m_y *= f ; m_width *= f ; m_height *= f ;} |
714 | inline void Scale( wxInt32 num , wxInt32 denum ) | |
715 | { m_x *= ((wxInt32)num)/((wxInt32)denum) ; m_y *= ((wxInt32)num)/((wxInt32)denum) ; | |
c3a4297c VZ |
716 | m_width *= ((wxInt32)num)/((wxInt32)denum) ; m_height *= ((wxInt32)num)/((wxInt32)denum) ;} |
717 | ||
718 | wxRect2DInt& operator = (const wxRect2DInt& rect); | |
719 | bool operator == (const wxRect2DInt& rect); | |
720 | bool operator != (const wxRect2DInt& rect); | |
721 | ||
722 | void WriteTo( wxDataOutputStream &stream ) const ; | |
723 | void ReadFrom( wxDataInputStream &stream ) ; | |
724 | ||
725 | wxInt32 m_x ; | |
726 | wxInt32 m_y ; | |
727 | wxInt32 m_width; | |
728 | wxInt32 m_height; | |
72e7876b SC |
729 | }; |
730 | ||
f91de7da DW |
731 | inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r ) |
732 | { | |
733 | m_x = r.m_x ; | |
734 | m_y = r.m_y ; | |
735 | m_width = r.m_width ; | |
736 | m_height = r.m_height ; | |
737 | } | |
738 | ||
739 | inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b) | |
740 | { | |
741 | m_x = wxMin( a.m_x , b.m_x ) ; | |
742 | m_y = wxMin( a.m_y , b.m_y ) ; | |
743 | m_width = abs( a.m_x - b.m_x ) ; | |
744 | m_height = abs( a.m_y - b.m_y ) ; | |
745 | } | |
72e7876b SC |
746 | |
747 | class wxTransform2D | |
748 | { | |
749 | public : | |
c3a4297c VZ |
750 | virtual void Transform( wxPoint2DInt* pt )const = 0 ; |
751 | virtual void Transform( wxRect2DInt* r ) const ; | |
752 | virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const ; | |
753 | virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ; | |
754 | ||
755 | virtual void InverseTransform( wxPoint2DInt* pt ) const = 0; | |
756 | virtual void InverseTransform( wxRect2DInt* r ) const ; | |
757 | virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ; | |
758 | virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ; | |
72e7876b SC |
759 | } ; |
760 | ||
f91de7da | 761 | inline void wxTransform2D::Transform( wxRect2DInt* r ) const |
72e7876b SC |
762 | { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; Transform( &a ) ; Transform( &b ) ; *r = wxRect2DInt( a , b ) ; } |
763 | ||
f91de7da | 764 | inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const |
72e7876b SC |
765 | { wxPoint2DInt res = pt ; Transform( &res ) ; return res ; } |
766 | ||
f91de7da | 767 | inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const |
72e7876b SC |
768 | { wxRect2DInt res = r ; Transform( &res ) ; return res ; } |
769 | ||
f91de7da | 770 | inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const |
72e7876b SC |
771 | { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; InverseTransform( &a ) ; InverseTransform( &b ) ; *r = wxRect2DInt( a , b ) ; } |
772 | ||
f91de7da | 773 | inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const |
72e7876b SC |
774 | { wxPoint2DInt res = pt ; InverseTransform( &res ) ; return res ; } |
775 | ||
f91de7da | 776 | inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const |
72e7876b SC |
777 | { wxRect2DInt res = r ; InverseTransform( &res ) ; return res ; } |
778 | ||
c3a4297c VZ |
779 | |
780 | #endif // wxUSE_GEOMETRY | |
781 | ||
782 | #endif // _WX_GEOMETRY_H_ |