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