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