]> git.saurik.com Git - wxWidgets.git/blame - include/wx/geometry.h
made wxADJUST_MINSIZE default
[wxWidgets.git] / include / wx / geometry.h
CommitLineData
72e7876b 1/////////////////////////////////////////////////////////////////////////////
11e82c1b 2// Name: wx/geometry.h
72e7876b
SC
3// Purpose: Common Geometry Classes
4// Author: Stefan Csomor
5// Modified by:
6// Created: 08/05/99
f91de7da 7// RCS-ID:
11e82c1b 8// Copyright: (c) 1999 Stefan Csomor
c3a4297c 9// Licence: wxWindows licence
72e7876b
SC
10/////////////////////////////////////////////////////////////////////////////
11
c3a4297c
VZ
12#ifndef _WX_GEOMETRY_H_
13#define _WX_GEOMETRY_H_
72e7876b 14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
6c7873e1 16 #pragma interface "geometry.cpp"
72e7876b
SC
17#endif
18
510fc784 19#include "wx/defs.h"
c3a4297c 20
5b781a67
SC
21#ifndef wxUSE_GEOMETRY
22 #define wxUSE_GEOMETRY 0
23#endif
24
c3a4297c
VZ
25#if wxUSE_GEOMETRY
26
510fc784
RR
27#include "wx/utils.h"
28#include "wx/gdicmn.h"
29#include <math.h>
30
72e7876b 31#ifdef __WXMSW__
c3a4297c 32 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
72e7876b 33#elif defined( __WXMAC__ )
d60f1012 34 #define wxMulDivInt32( a , b , c ) ( (wxInt32) ( ( (wxInt64)(a) * (wxInt64)(b) ) / (wxInt64)(c) ) )
72e7876b 35#else
c3a4297c 36 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
72e7876b
SC
37#endif
38
11e82c1b
VZ
39class wxDataInputStream;
40class wxDataOutputStream;
72e7876b
SC
41
42// clipping from Cohen-Sutherland
43
44enum wxOutCode
45{
c3a4297c
VZ
46 wxInside = 0x00 ,
47 wxOutLeft = 0x01 ,
48 wxOutRight = 0x02 ,
49 wxOutTop = 0x08 ,
f91de7da 50 wxOutBottom = 0x04
11e82c1b 51};
72e7876b 52
e2aa719c
SC
53class WXDLLEXPORT wxPoint2DInt
54{
55public :
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
2b5f62a0
VZ
62 inline void GetFloor( wxInt32 *x , wxInt32 *y ) const;
63 inline void GetRounded( wxInt32 *x , wxInt32 *y ) const;
e2aa719c 64
2b5f62a0
VZ
65 inline wxDouble GetVectorLength() const;
66 wxDouble GetVectorAngle() const;
e2aa719c
SC
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
e30285ab 94#if wxUSE_STREAMS
e2aa719c
SC
95 void WriteTo( wxDataOutputStream &stream ) const;
96 void ReadFrom( wxDataInputStream &stream );
e30285ab 97#endif // wxUSE_STREAMS
e2aa719c
SC
98
99 wxInt32 m_x;
100 wxInt32 m_y;
101};
102
295272bd
VZ
103inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
104inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
105inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
106inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
107inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
108inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
109inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
110inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
111inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
112inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
e2aa719c
SC
113
114inline wxPoint2DInt::wxPoint2DInt()
115{
116 m_x = 0;
117 m_y = 0;
118}
119
120inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
121{
122 m_x = x;
123 m_y = y;
124}
125
126inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
127{
128 m_x = pt.m_x;
129 m_y = pt.m_y;
130}
131
132inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt )
133{
134 m_x = pt.x;
135 m_y = pt.y;
136}
137
2b5f62a0 138inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y ) const
e2aa719c
SC
139{
140 if ( x )
141 *x = m_x;
142 if ( y )
143 *y = m_y;
144}
145
2b5f62a0 146inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y ) const
e2aa719c
SC
147{
148 GetFloor(x, y);
149}
150
2b5f62a0 151inline wxDouble wxPoint2DInt::GetVectorLength() const
e2aa719c
SC
152{
153 // cast needed MIPSpro compiler under SGI
154 return sqrt( (double)(m_x)*(m_x) + (m_y)*(m_y) );
155}
156
157inline 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
164inline void wxPoint2DInt::Normalize()
165{
166 SetVectorLength( 1 );
167}
168
169inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const
170{
171 return sqrt( GetDistanceSquare( pt ) );
172}
173
174inline 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
179inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const
180{
181 return ( m_x * vec.m_x + m_y * vec.m_y );
182}
183
184inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const
185{
186 return ( m_x * vec.m_y - vec.m_x * m_y );
187}
188
189inline wxPoint2DInt::operator wxPoint() const
190{
191 return wxPoint( m_x, m_y);
192}
193
194inline wxPoint2DInt wxPoint2DInt::operator-()
195{
196 return wxPoint2DInt( -m_x, -m_y);
197}
198
199inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt)
200{
201 m_x = pt.m_x;
202 m_y = pt.m_y;
203 return *this;
204}
205
206inline 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
213inline 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
220inline 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
227inline 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
234inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const
235{
236 return m_x == pt.m_x && m_y == pt.m_y;
237}
238
239inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const
240{
241 return m_x != pt.m_x || m_y != pt.m_y;
242}
243
244inline 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
249inline 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
255inline 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
260inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
261{
262 return wxPoint2DInt( pt.m_x * n , pt.m_y * n );
263}
264
265inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
266{
267 return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) );
268}
269
270inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n)
271{
272 return wxPoint2DInt( pt.m_x * n , pt.m_y * n );
273}
274
275inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n)
276{
277 return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) );
278}
279
280inline 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
285inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n)
286{
287 return wxPoint2DInt( pt.m_x / n , pt.m_y / n );
288}
289
290inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n)
291{
292 return wxPoint2DInt( (int) (pt.m_x / n) , (int) (pt.m_y / n) );
293}
294
f91de7da 295// wxPoint2Ds represent a point or a vector in a 2d coordinate system
72e7876b
SC
296
297class WXDLLEXPORT wxPoint2DDouble
298{
299public :
11e82c1b
VZ
300 inline wxPoint2DDouble();
301 inline wxPoint2DDouble( wxDouble x , wxDouble y );
302 inline wxPoint2DDouble( const wxPoint2DDouble &pt );
e2aa719c
SC
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 ; }
11e82c1b
VZ
307
308 // two different conversions to integers, floor and rounding
2b5f62a0
VZ
309 inline void GetFloor( wxInt32 *x , wxInt32 *y ) const;
310 inline void GetRounded( wxInt32 *x , wxInt32 *y ) const;
11e82c1b 311
e2aa719c
SC
312 inline wxDouble GetVectorLength() const;
313 wxDouble GetVectorAngle() const ;
11e82c1b
VZ
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
2b5f62a0
VZ
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;
11e82c1b
VZ
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};
c3a4297c 344
90350682
VZ
345inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
346inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
347inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
348inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt);
349inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt);
350inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n);
351inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n);
352inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
353inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n);
354inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n);
72e7876b 355
f91de7da
DW
356inline wxPoint2DDouble::wxPoint2DDouble()
357{
11e82c1b
VZ
358 m_x = 0.0;
359 m_y = 0.0;
72e7876b
SC
360}
361
f91de7da
DW
362inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y )
363{
11e82c1b
VZ
364 m_x = x;
365 m_y = y;
f91de7da 366}
72e7876b 367
f91de7da
DW
368inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt )
369{
11e82c1b
VZ
370 m_x = pt.m_x;
371 m_y = pt.m_y;
72e7876b
SC
372}
373
2b5f62a0 374inline void wxPoint2DDouble::GetFloor( wxInt32 *x , wxInt32 *y ) const
f91de7da 375{
11e82c1b
VZ
376 *x = (wxInt32) floor( m_x );
377 *y = (wxInt32) floor( m_y );
72e7876b
SC
378}
379
2b5f62a0 380inline void wxPoint2DDouble::GetRounded( wxInt32 *x , wxInt32 *y ) const
f91de7da 381{
11e82c1b
VZ
382 *x = (wxInt32) floor( m_x + 0.5 );
383 *y = (wxInt32) floor( m_y + 0.5);
f91de7da
DW
384}
385
e2aa719c
SC
386inline wxDouble wxPoint2DDouble::GetVectorLength() const
387{
388 return sqrt( (m_x)*(m_x) + (m_y)*(m_y) ) ;
389}
390
391inline 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
2b5f62a0 398inline wxDouble wxPoint2DDouble::GetDistance( const wxPoint2DDouble &pt ) const
f91de7da
DW
399{
400 return sqrt( GetDistanceSquare( pt ) );
72e7876b
SC
401}
402
2b5f62a0 403inline wxDouble wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble &pt ) const
f91de7da 404{
11e82c1b 405 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) );
f91de7da 406}
72e7876b 407
2b5f62a0 408inline wxDouble wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble &vec ) const
f91de7da 409{
11e82c1b 410 return ( m_x * vec.m_x + m_y * vec.m_y );
72e7876b
SC
411}
412
2b5f62a0 413inline wxDouble wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble &vec ) const
f91de7da 414{
11e82c1b 415 return ( m_x * vec.m_y - vec.m_x * m_y );
f91de7da 416}
72e7876b 417
f91de7da
DW
418inline wxPoint2DDouble wxPoint2DDouble::operator-()
419{
c3a4297c 420 return wxPoint2DDouble( -m_x, -m_y);
72e7876b
SC
421}
422
423inline wxPoint2DDouble& wxPoint2DDouble::operator=(const wxPoint2DDouble& pt)
f91de7da 424{
11e82c1b 425 m_x = pt.m_x;
f91de7da 426 m_y = pt.m_y;
11e82c1b 427 return *this;
72e7876b
SC
428}
429
f91de7da 430inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt)
72e7876b 431{
11e82c1b 432 m_x = m_x + pt.m_x;
f91de7da 433 m_y = m_y + pt.m_y;
11e82c1b 434 return *this;
72e7876b
SC
435}
436
f91de7da
DW
437inline wxPoint2DDouble& wxPoint2DDouble::operator-=(const wxPoint2DDouble& pt)
438{
11e82c1b 439 m_x = m_x - pt.m_x;
f91de7da 440 m_y = m_y - pt.m_y;
11e82c1b 441 return *this;
72e7876b
SC
442}
443
f91de7da
DW
444inline wxPoint2DDouble& wxPoint2DDouble::operator*=(const wxPoint2DDouble& pt)
445{
11e82c1b 446 m_x = m_x * pt.m_x;
f91de7da 447 m_y = m_y * pt.m_y;
11e82c1b 448 return *this;
72e7876b
SC
449}
450
f91de7da
DW
451inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt)
452{
11e82c1b 453 m_x = m_x / pt.m_x;
da052901 454 m_y = m_y / pt.m_y;
11e82c1b 455 return *this;
72e7876b
SC
456}
457
f91de7da
DW
458inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const
459{
460 return m_x == pt.m_x && m_y == pt.m_y;
72e7876b
SC
461}
462
f91de7da
DW
463inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const
464{
465 return m_x != pt.m_x || m_y != pt.m_y;
72e7876b
SC
466}
467
f91de7da 468inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 469{
11e82c1b 470 return wxPoint2DDouble( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y );
72e7876b
SC
471}
472
f91de7da 473inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 474{
11e82c1b 475 return wxPoint2DDouble( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y );
72e7876b
SC
476}
477
478
f91de7da 479inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 480{
11e82c1b 481 return wxPoint2DDouble( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y );
72e7876b
SC
482}
483
f91de7da 484inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt)
72e7876b 485{
11e82c1b 486 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
487}
488
f91de7da 489inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt)
72e7876b 490{
11e82c1b 491 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
492}
493
f91de7da 494inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n)
72e7876b 495{
11e82c1b 496 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
497}
498
f91de7da 499inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n)
72e7876b 500{
11e82c1b 501 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
502}
503
f91de7da 504inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 505{
11e82c1b 506 return wxPoint2DDouble( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y );
72e7876b
SC
507}
508
f91de7da 509inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n)
72e7876b 510{
11e82c1b 511 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n );
72e7876b
SC
512}
513
f91de7da 514inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n)
72e7876b 515{
11e82c1b 516 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n );
72e7876b
SC
517}
518
f91de7da 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
72e7876b 520// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
f91de7da 521// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
72e7876b
SC
522
523class WXDLLEXPORT wxRect2DDouble
524{
525public:
f91de7da 526 wxRect2DDouble()
11e82c1b 527 { m_x = m_y = m_width = m_height = 0; }
6c7873e1 528 wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h)
11e82c1b 529 { m_x = x; m_y = y; m_width = w; m_height = h; }
6c7873e1
RR
530/*
531 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
532 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
533 wxRect2DDouble(const wxRect2DDouble& rect);
534*/
c3a4297c
VZ
535 // single attribute accessors
536
f91de7da 537 inline wxPoint2DDouble GetPosition()
6c7873e1
RR
538 { return wxPoint2DDouble(m_x, m_y); }
539 inline wxSize GetSize()
7a5e6267 540 { return wxSize((int) m_width, (int) m_height); }
c3a4297c 541
6c7873e1 542 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
c3a4297c
VZ
543 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
544
6c7873e1 545 inline wxDouble GetLeft() const { return m_x; }
11e82c1b
VZ
546 inline void SetLeft( wxDouble n ) { m_width += m_x - n; m_x = n; }
547 inline void MoveLeftTo( wxDouble n ) { m_x = n; }
6c7873e1 548 inline wxDouble GetTop() const { return m_y; }
11e82c1b
VZ
549 inline void SetTop( wxDouble n ) { m_height += m_y - n; m_y = n; }
550 inline void MoveTopTo( wxDouble n ) { m_y = n; }
6c7873e1 551 inline wxDouble GetBottom() const { return m_y + m_height; }
11e82c1b
VZ
552 inline void SetBottom( wxDouble n ) { m_height += n - (m_y+m_height);}
553 inline void MoveBottomTo( wxDouble n ) { m_y = n - m_height; }
6c7873e1 554 inline wxDouble GetRight() const { return m_x + m_width; }
11e82c1b
VZ
555 inline void SetRight( wxDouble n ) { m_width += n - (m_x+m_width) ; }
556 inline void MoveRightTo( wxDouble n ) { m_x = n - m_width; }
6c7873e1
RR
557
558 inline wxPoint2DDouble GetLeftTop() const
11e82c1b 559 { return wxPoint2DDouble( m_x , m_y ); }
6c7873e1 560 inline void SetLeftTop( const wxPoint2DDouble &pt )
11e82c1b 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; }
6c7873e1 562 inline void MoveLeftTopTo( const wxPoint2DDouble &pt )
11e82c1b 563 { m_x = pt.m_x; m_y = pt.m_y; }
6c7873e1 564 inline wxPoint2DDouble GetLeftBottom() const
11e82c1b 565 { return wxPoint2DDouble( m_x , m_y + m_height ); }
6c7873e1 566 inline void SetLeftBottom( const wxPoint2DDouble &pt )
11e82c1b 567 { m_width += m_x - pt.m_x; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x; }
6c7873e1 568 inline void MoveLeftBottomTo( const wxPoint2DDouble &pt )
11e82c1b 569 { m_x = pt.m_x; m_y = pt.m_y - m_height; }
6c7873e1 570 inline wxPoint2DDouble GetRightTop() const
11e82c1b 571 { return wxPoint2DDouble( m_x+m_width , m_y ); }
6c7873e1 572 inline void SetRightTop( const wxPoint2DDouble &pt )
11e82c1b 573 { m_width += pt.m_x - ( m_x + m_width ); m_height += m_y - pt.m_y; m_y = pt.m_y; }
6c7873e1 574 inline void MoveRightTopTo( const wxPoint2DDouble &pt )
11e82c1b 575 { m_x = pt.m_x - m_width; m_y = pt.m_y; }
6c7873e1 576 inline wxPoint2DDouble GetRightBottom() const
11e82c1b 577 { return wxPoint2DDouble( m_x+m_width , m_y + m_height ); }
6c7873e1 578 inline void SetRightBottom( const wxPoint2DDouble &pt )
11e82c1b 579 { m_width += pt.m_x - ( m_x + m_width ); m_height += pt.m_y - (m_y+m_height);}
6c7873e1 580 inline void MoveRightBottomTo( const wxPoint2DDouble &pt )
11e82c1b 581 { m_x = pt.m_x - m_width; m_y = pt.m_y - m_height; }
6c7873e1 582 inline wxPoint2DDouble GetCentre() const
11e82c1b 583 { return wxPoint2DDouble( m_x+m_width/2 , m_y+m_height/2 ); }
6c7873e1 584 inline void SetCentre( const wxPoint2DDouble &pt )
11e82c1b 585 { MoveCentreTo( pt ); } // since this is impossible without moving...
6c7873e1 586 inline void MoveCentreTo( const wxPoint2DDouble &pt )
11e82c1b 587 { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2); }
0624ce56 588 inline wxOutCode GetOutCode( const wxPoint2DDouble &pt ) const
6c7873e1 589 { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
1b2a04da 590 ( ( pt.m_x > m_x + m_width ) ? wxOutRight : 0 ) +
c3a4297c 591 ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
1b2a04da 592 ( ( pt.m_y > m_y + m_height ) ? wxOutBottom : 0 )); }
0624ce56
SC
593 inline wxOutCode GetOutcode(const wxPoint2DDouble &pt) const
594 { return GetOutCode(pt) ; }
f91de7da 595 inline bool Contains( const wxPoint2DDouble &pt ) const
0624ce56 596 { return GetOutCode( pt ) == wxInside; }
f91de7da
DW
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 ) ) &&
11e82c1b 599 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
f91de7da 600 inline bool IsEmpty() const
11e82c1b 601 { return ( m_width <= 0 || m_height <= 0 ); }
f91de7da 602 inline bool HaveEqualSize( const wxRect2DDouble &rect ) const
11e82c1b 603 { return ( rect.m_width == m_width && rect.m_height == m_height ); }
f91de7da 604
6c7873e1 605 inline void Inset( wxDouble x , wxDouble y )
11e82c1b 606 { m_x += x; m_y += y; m_width -= 2 * x; m_height -= 2 * y; }
f91de7da 607 inline void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom )
11e82c1b 608 { m_x += left; m_y += top; m_width -= left + right; m_height -= top + bottom;}
6c7873e1 609 inline void Offset( const wxPoint2DDouble &pt )
11e82c1b 610 { m_x += pt.m_x; m_y += pt.m_y; }
f91de7da 611
6c7873e1 612 void ConstrainTo( const wxRect2DDouble &rect );
f91de7da 613
6c7873e1 614 inline wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor )
11e82c1b 615 { return wxPoint2DDouble( m_x + m_width * widthfactor , m_y + m_height * heightfactor ); }
6c7873e1 616
11e82c1b 617 static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
6c7873e1 618 inline void Intersect( const wxRect2DDouble &otherRect )
11e82c1b 619 { Intersect( *this , otherRect , this ); }
6c7873e1 620 inline wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const
11e82c1b
VZ
621 { wxRect2DDouble result; Intersect( *this , otherRect , &result); return result; }
622 bool Intersects( const wxRect2DDouble &rect ) const;
6c7873e1 623
11e82c1b 624 static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
6c7873e1 625 void Union( const wxRect2DDouble &otherRect )
11e82c1b
VZ
626 { Union( *this , otherRect , this ); }
627 void Union( const wxPoint2DDouble &pt );
6c7873e1 628 inline wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const
11e82c1b 629 { wxRect2DDouble result; Union( *this , otherRect , &result); return result; }
6c7873e1
RR
630
631 inline void Scale( wxDouble f )
11e82c1b 632 { m_x *= f; m_y *= f; m_width *= f; m_height *= f;}
f91de7da 633 inline void Scale( wxInt32 num , wxInt32 denum )
11e82c1b
VZ
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);}
c3a4297c 636
6c7873e1 637 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
7dc85fe2
VZ
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); }
c3a4297c 642
6c7873e1 643 wxDouble m_x;
11e82c1b 644 wxDouble m_y;
6c7873e1
RR
645 wxDouble m_width;
646 wxDouble m_height;
72e7876b
SC
647};
648
72e7876b 649
f91de7da 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
72e7876b 651// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
f91de7da 652// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
72e7876b
SC
653
654class WXDLLEXPORT wxRect2DInt
655{
656public:
11e82c1b 657 wxRect2DInt() { m_x = m_y = m_width = m_height = 0; }
e2aa719c 658 wxRect2DInt( const wxRect& r ) { m_x = r.x ; m_y = r.y ; m_width = r.width ; m_height = r.height ; }
11e82c1b 659 wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h) { m_x = x; m_y = y; m_width = w; m_height = h; }
c3a4297c 660 wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight);
f91de7da
DW
661 inline wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size);
662 inline wxRect2DInt(const wxRect2DInt& rect);
c3a4297c
VZ
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; }
11e82c1b
VZ
673 inline void SetLeft( wxInt32 n ) { m_width += m_x - n; m_x = n; }
674 inline void MoveLeftTo( wxInt32 n ) { m_x = n; }
c3a4297c 675 inline wxInt32 GetTop() const { return m_y; }
11e82c1b
VZ
676 inline void SetTop( wxInt32 n ) { m_height += m_y - n; m_y = n; }
677 inline void MoveTopTo( wxInt32 n ) { m_y = n; }
c3a4297c 678 inline wxInt32 GetBottom() const { return m_y + m_height; }
11e82c1b
VZ
679 inline void SetBottom( wxInt32 n ) { m_height += n - (m_y+m_height);}
680 inline void MoveBottomTo( wxInt32 n ) { m_y = n - m_height; }
c3a4297c 681 inline wxInt32 GetRight() const { return m_x + m_width; }
11e82c1b
VZ
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); }
0624ce56 700 inline wxOutCode GetOutCode( const wxPoint2DInt &pt ) const
c3a4297c
VZ
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 ) +
11e82c1b 704 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )); }
0624ce56
SC
705 inline wxOutCode GetOutcode( const wxPoint2DInt &pt ) const
706 { return GetOutCode( pt ) ; }
f91de7da 707 inline bool Contains( const wxPoint2DInt &pt ) const
0624ce56 708 { return GetOutCode( pt ) == wxInside; }
f91de7da
DW
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 ) ) &&
11e82c1b 711 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
f91de7da 712 inline bool IsEmpty() const
11e82c1b 713 { return ( m_width <= 0 || m_height <= 0 ); }
f91de7da 714 inline bool HaveEqualSize( const wxRect2DInt &rect ) const
11e82c1b 715 { return ( rect.m_width == m_width && rect.m_height == m_height ); }
f91de7da 716
11e82c1b 717 inline void Inset( wxInt32 x , wxInt32 y ) { m_x += x; m_y += y; m_width -= 2 * x; m_height -= 2 * y; }
f91de7da 718 inline void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom )
11e82c1b
VZ
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;}
f91de7da 735 inline void Scale( wxInt32 num , wxInt32 denum )
11e82c1b
VZ
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);}
c3a4297c
VZ
738
739 wxRect2DInt& operator = (const wxRect2DInt& rect);
cd501207
JS
740 bool operator == (const wxRect2DInt& rect) const;
741 bool operator != (const wxRect2DInt& rect) const;
c3a4297c 742
e30285ab 743#if wxUSE_STREAMS
cd501207
JS
744 void WriteTo( wxDataOutputStream &stream ) const;
745 void ReadFrom( wxDataInputStream &stream );
e30285ab 746#endif // wxUSE_STREAMS
c3a4297c 747
11e82c1b 748 wxInt32 m_x;
cd501207
JS
749 wxInt32 m_y;
750 wxInt32 m_width;
751 wxInt32 m_height;
72e7876b
SC
752};
753
f91de7da
DW
754inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r )
755{
11e82c1b
VZ
756 m_x = r.m_x;
757 m_y = r.m_y;
758 m_width = r.m_width;
759 m_height = r.m_height;
f91de7da
DW
760}
761
762inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b)
763{
11e82c1b
VZ
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 );
f91de7da 768}
72e7876b 769
c2fa4af4
SC
770inline 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
cd501207
JS
778inline 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
784inline bool wxRect2DInt::operator != (const wxRect2DInt& rect) const
785{
786 return !(*this == rect);
787}
788
72e7876b
SC
789class wxTransform2D
790{
791public :
11e82c1b
VZ
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 ;
c3a4297c
VZ
796
797 virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
11e82c1b
VZ
798 virtual void InverseTransform( wxRect2DInt* r ) const ;
799 virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
800 virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
801};
72e7876b 802
f91de7da 803inline void wxTransform2D::Transform( wxRect2DInt* r ) const
11e82c1b 804 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); Transform( &a ); Transform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 805
f91de7da 806inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const
11e82c1b 807 { wxPoint2DInt res = pt; Transform( &res ); return res; }
72e7876b 808
f91de7da 809inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const
11e82c1b 810 { wxRect2DInt res = r; Transform( &res ); return res; }
72e7876b 811
f91de7da 812inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const
11e82c1b 813 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); InverseTransform( &a ); InverseTransform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 814
f91de7da 815inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const
11e82c1b 816 { wxPoint2DInt res = pt; InverseTransform( &res ); return res; }
72e7876b 817
f91de7da 818inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const
11e82c1b 819 { wxRect2DInt res = r; InverseTransform( &res ); return res; }
72e7876b 820
c3a4297c
VZ
821
822#endif // wxUSE_GEOMETRY
823
824#endif // _WX_GEOMETRY_H_