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