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