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