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