]> git.saurik.com Git - wxWidgets.git/blame - include/wx/geometry.h
added GetApplicationScript for non Carbon builds
[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
SC
14
15#ifdef __GNUG__
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
62 inline void GetFloor( wxInt32 *x , wxInt32 *y );
63 inline void GetRounded( wxInt32 *x , wxInt32 *y );
64
65 inline wxDouble GetVectorLength();
66 wxDouble GetVectorAngle();
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
94 void WriteTo( wxDataOutputStream &stream ) const;
95 void ReadFrom( wxDataInputStream &stream );
96
97 wxInt32 m_x;
98 wxInt32 m_y;
99};
100
295272bd
VZ
101inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
102inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
103inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
104inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
105inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
106inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
107inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
108inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
109inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
110inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
e2aa719c
SC
111
112inline wxPoint2DInt::wxPoint2DInt()
113{
114 m_x = 0;
115 m_y = 0;
116}
117
118inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
119{
120 m_x = x;
121 m_y = y;
122}
123
124inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
125{
126 m_x = pt.m_x;
127 m_y = pt.m_y;
128}
129
130inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt )
131{
132 m_x = pt.x;
133 m_y = pt.y;
134}
135
136inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y )
137{
138 if ( x )
139 *x = m_x;
140 if ( y )
141 *y = m_y;
142}
143
144inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y )
145{
146 GetFloor(x, y);
147}
148
149inline wxDouble wxPoint2DInt::GetVectorLength()
150{
151 // cast needed MIPSpro compiler under SGI
152 return sqrt( (double)(m_x)*(m_x) + (m_y)*(m_y) );
153}
154
155inline void wxPoint2DInt::SetVectorLength( wxDouble length )
156{
157 wxDouble before = GetVectorLength();
158 m_x = (wxInt32)(m_x * length / before);
159 m_y = (wxInt32)(m_y * length / before);
160}
161
162inline void wxPoint2DInt::Normalize()
163{
164 SetVectorLength( 1 );
165}
166
167inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const
168{
169 return sqrt( GetDistanceSquare( pt ) );
170}
171
172inline wxDouble wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt &pt ) const
173{
174 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) );
175}
176
177inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const
178{
179 return ( m_x * vec.m_x + m_y * vec.m_y );
180}
181
182inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const
183{
184 return ( m_x * vec.m_y - vec.m_x * m_y );
185}
186
187inline wxPoint2DInt::operator wxPoint() const
188{
189 return wxPoint( m_x, m_y);
190}
191
192inline wxPoint2DInt wxPoint2DInt::operator-()
193{
194 return wxPoint2DInt( -m_x, -m_y);
195}
196
197inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt)
198{
199 m_x = pt.m_x;
200 m_y = pt.m_y;
201 return *this;
202}
203
204inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt)
205{
206 m_x = m_x + pt.m_x;
207 m_y = m_y + pt.m_y;
208 return *this;
209}
210
211inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt)
212{
213 m_x = m_x - pt.m_x;
214 m_y = m_y - pt.m_y;
215 return *this;
216}
217
218inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
219{
220 m_x = m_x + pt.m_x;
221 m_y = m_y + pt.m_y;
222 return *this;
223}
224
225inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
226{
227 m_x = m_x - pt.m_x;
228 m_y = m_y - pt.m_y;
229 return *this;
230}
231
232inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const
233{
234 return m_x == pt.m_x && m_y == pt.m_y;
235}
236
237inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const
238{
239 return m_x != pt.m_x || m_y != pt.m_y;
240}
241
242inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
243{
244 return wxPoint2DInt( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y );
245}
246
247inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
248{
249 return wxPoint2DInt( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y );
250}
251
252
253inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
254{
255 return wxPoint2DInt( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y );
256}
257
258inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
259{
260 return wxPoint2DInt( pt.m_x * n , pt.m_y * n );
261}
262
263inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
264{
265 return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) );
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
278inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
279{
280 return wxPoint2DInt( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y );
281}
282
283inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n)
284{
285 return wxPoint2DInt( pt.m_x / n , pt.m_y / n );
286}
287
288inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n)
289{
290 return wxPoint2DInt( (int) (pt.m_x / n) , (int) (pt.m_y / n) );
291}
292
f91de7da 293// wxPoint2Ds represent a point or a vector in a 2d coordinate system
72e7876b
SC
294
295class WXDLLEXPORT wxPoint2DDouble
296{
297public :
11e82c1b
VZ
298 inline wxPoint2DDouble();
299 inline wxPoint2DDouble( wxDouble x , wxDouble y );
300 inline wxPoint2DDouble( const wxPoint2DDouble &pt );
e2aa719c
SC
301 wxPoint2DDouble( const wxPoint2DInt &pt )
302 { m_x = (wxDouble) pt.m_x ; m_y = (wxDouble) pt.m_y ; }
303 wxPoint2DDouble( const wxPoint &pt )
304 { m_x = (wxDouble) pt.x ; m_y = (wxDouble) pt.y ; }
11e82c1b
VZ
305
306 // two different conversions to integers, floor and rounding
307 inline void GetFloor( wxInt32 *x , wxInt32 *y );
308 inline void GetRounded( wxInt32 *x , wxInt32 *y );
309
e2aa719c
SC
310 inline wxDouble GetVectorLength() const;
311 wxDouble GetVectorAngle() const ;
11e82c1b
VZ
312 void SetVectorLength( wxDouble length );
313 void SetVectorAngle( wxDouble degrees );
314 void SetPolarCoordinates( wxDouble angle , wxDouble length );
315 // set the vector length to 1.0, preserving the angle
316 void Normalize();
317
318 inline wxDouble GetDistance( const wxPoint2DDouble &pt );
319 inline wxDouble GetDistanceSquare( const wxPoint2DDouble &pt );
320 inline wxDouble GetDotProduct( const wxPoint2DDouble &vec );
321 inline wxDouble GetCrossProduct( const wxPoint2DDouble &vec );
322
323 // the reflection of this point
324 inline wxPoint2DDouble operator-();
325
326 inline wxPoint2DDouble& operator=(const wxPoint2DDouble& pt);
327 inline wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt);
328 inline wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt);
329 inline wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt);
330 inline wxPoint2DDouble& operator*=(wxDouble n);
331 inline wxPoint2DDouble& operator*=(wxInt32 n);
332 inline wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt);
333 inline wxPoint2DDouble& operator/=(wxDouble n);
334 inline wxPoint2DDouble& operator/=(wxInt32 n);
335
336 inline bool operator==(const wxPoint2DDouble& pt) const;
337 inline bool operator!=(const wxPoint2DDouble& pt) const;
338
339 wxDouble m_x;
340 wxDouble m_y;
341};
c3a4297c 342
90350682
VZ
343inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
344inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
345inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
346inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt);
347inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt);
348inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n);
349inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n);
350inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
351inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n);
352inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n);
72e7876b 353
f91de7da
DW
354inline wxPoint2DDouble::wxPoint2DDouble()
355{
11e82c1b
VZ
356 m_x = 0.0;
357 m_y = 0.0;
72e7876b
SC
358}
359
f91de7da
DW
360inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y )
361{
11e82c1b
VZ
362 m_x = x;
363 m_y = y;
f91de7da 364}
72e7876b 365
f91de7da
DW
366inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt )
367{
11e82c1b
VZ
368 m_x = pt.m_x;
369 m_y = pt.m_y;
72e7876b
SC
370}
371
f91de7da
DW
372inline void wxPoint2DDouble::GetFloor( wxInt32 *x , wxInt32 *y )
373{
11e82c1b
VZ
374 *x = (wxInt32) floor( m_x );
375 *y = (wxInt32) floor( m_y );
72e7876b
SC
376}
377
f91de7da
DW
378inline void wxPoint2DDouble::GetRounded( wxInt32 *x , wxInt32 *y )
379{
11e82c1b
VZ
380 *x = (wxInt32) floor( m_x + 0.5 );
381 *y = (wxInt32) floor( m_y + 0.5);
f91de7da
DW
382}
383
e2aa719c
SC
384inline wxDouble wxPoint2DDouble::GetVectorLength() const
385{
386 return sqrt( (m_x)*(m_x) + (m_y)*(m_y) ) ;
387}
388
389inline void wxPoint2DDouble::SetVectorLength( wxDouble length )
390{
391 wxDouble before = GetVectorLength() ;
392 m_x = (m_x * length / before) ;
393 m_y = (m_y * length / before) ;
394}
395
f91de7da
DW
396inline wxDouble wxPoint2DDouble::GetDistance( const wxPoint2DDouble &pt )
397{
398 return sqrt( GetDistanceSquare( pt ) );
72e7876b
SC
399}
400
f91de7da
DW
401inline wxDouble wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble &pt )
402{
11e82c1b 403 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) );
f91de7da 404}
72e7876b 405
f91de7da
DW
406inline wxDouble wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble &vec )
407{
11e82c1b 408 return ( m_x * vec.m_x + m_y * vec.m_y );
72e7876b
SC
409}
410
f91de7da
DW
411inline wxDouble wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble &vec )
412{
11e82c1b 413 return ( m_x * vec.m_y - vec.m_x * m_y );
f91de7da 414}
72e7876b 415
f91de7da
DW
416inline wxPoint2DDouble wxPoint2DDouble::operator-()
417{
c3a4297c 418 return wxPoint2DDouble( -m_x, -m_y);
72e7876b
SC
419}
420
421inline wxPoint2DDouble& wxPoint2DDouble::operator=(const wxPoint2DDouble& pt)
f91de7da 422{
11e82c1b 423 m_x = pt.m_x;
f91de7da 424 m_y = pt.m_y;
11e82c1b 425 return *this;
72e7876b
SC
426}
427
f91de7da 428inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt)
72e7876b 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;
f91de7da 445 m_y = m_y * pt.m_y;
11e82c1b 446 return *this;
72e7876b
SC
447}
448
f91de7da
DW
449inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt)
450{
11e82c1b 451 m_x = m_x / pt.m_x;
da052901 452 m_y = m_y / pt.m_y;
11e82c1b 453 return *this;
72e7876b
SC
454}
455
f91de7da
DW
456inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const
457{
458 return m_x == pt.m_x && m_y == pt.m_y;
72e7876b
SC
459}
460
f91de7da
DW
461inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const
462{
463 return m_x != pt.m_x || m_y != pt.m_y;
72e7876b
SC
464}
465
f91de7da 466inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 467{
11e82c1b 468 return wxPoint2DDouble( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y );
72e7876b
SC
469}
470
f91de7da 471inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 472{
11e82c1b 473 return wxPoint2DDouble( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y );
72e7876b
SC
474}
475
476
f91de7da 477inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 478{
11e82c1b 479 return wxPoint2DDouble( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y );
72e7876b
SC
480}
481
f91de7da 482inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt)
72e7876b 483{
11e82c1b 484 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
485}
486
f91de7da 487inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt)
72e7876b 488{
11e82c1b 489 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
490}
491
f91de7da 492inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n)
72e7876b 493{
11e82c1b 494 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
495}
496
f91de7da 497inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n)
72e7876b 498{
11e82c1b 499 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
500}
501
f91de7da 502inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 503{
11e82c1b 504 return wxPoint2DDouble( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y );
72e7876b
SC
505}
506
f91de7da 507inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n)
72e7876b 508{
11e82c1b 509 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n );
72e7876b
SC
510}
511
f91de7da 512inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n)
72e7876b 513{
11e82c1b 514 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n );
72e7876b
SC
515}
516
f91de7da 517// 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 518// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
f91de7da 519// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
72e7876b
SC
520
521class WXDLLEXPORT wxRect2DDouble
522{
523public:
f91de7da 524 wxRect2DDouble()
11e82c1b 525 { m_x = m_y = m_width = m_height = 0; }
6c7873e1 526 wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h)
11e82c1b 527 { m_x = x; m_y = y; m_width = w; m_height = h; }
6c7873e1
RR
528/*
529 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
530 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
531 wxRect2DDouble(const wxRect2DDouble& rect);
532*/
c3a4297c
VZ
533 // single attribute accessors
534
f91de7da 535 inline wxPoint2DDouble GetPosition()
6c7873e1
RR
536 { return wxPoint2DDouble(m_x, m_y); }
537 inline wxSize GetSize()
7a5e6267 538 { return wxSize((int) m_width, (int) m_height); }
c3a4297c 539
6c7873e1 540 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
c3a4297c
VZ
541 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
542
6c7873e1 543 inline wxDouble GetLeft() const { return m_x; }
11e82c1b
VZ
544 inline void SetLeft( wxDouble n ) { m_width += m_x - n; m_x = n; }
545 inline void MoveLeftTo( wxDouble n ) { m_x = n; }
6c7873e1 546 inline wxDouble GetTop() const { return m_y; }
11e82c1b
VZ
547 inline void SetTop( wxDouble n ) { m_height += m_y - n; m_y = n; }
548 inline void MoveTopTo( wxDouble n ) { m_y = n; }
6c7873e1 549 inline wxDouble GetBottom() const { return m_y + m_height; }
11e82c1b
VZ
550 inline void SetBottom( wxDouble n ) { m_height += n - (m_y+m_height);}
551 inline void MoveBottomTo( wxDouble n ) { m_y = n - m_height; }
6c7873e1 552 inline wxDouble GetRight() const { return m_x + m_width; }
11e82c1b
VZ
553 inline void SetRight( wxDouble n ) { m_width += n - (m_x+m_width) ; }
554 inline void MoveRightTo( wxDouble n ) { m_x = n - m_width; }
6c7873e1
RR
555
556 inline wxPoint2DDouble GetLeftTop() const
11e82c1b 557 { return wxPoint2DDouble( m_x , m_y ); }
6c7873e1 558 inline void SetLeftTop( const wxPoint2DDouble &pt )
11e82c1b 559 { 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 560 inline void MoveLeftTopTo( const wxPoint2DDouble &pt )
11e82c1b 561 { m_x = pt.m_x; m_y = pt.m_y; }
6c7873e1 562 inline wxPoint2DDouble GetLeftBottom() const
11e82c1b 563 { return wxPoint2DDouble( m_x , m_y + m_height ); }
6c7873e1 564 inline void SetLeftBottom( const wxPoint2DDouble &pt )
11e82c1b 565 { m_width += m_x - pt.m_x; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x; }
6c7873e1 566 inline void MoveLeftBottomTo( const wxPoint2DDouble &pt )
11e82c1b 567 { m_x = pt.m_x; m_y = pt.m_y - m_height; }
6c7873e1 568 inline wxPoint2DDouble GetRightTop() const
11e82c1b 569 { return wxPoint2DDouble( m_x+m_width , m_y ); }
6c7873e1 570 inline void SetRightTop( const wxPoint2DDouble &pt )
11e82c1b 571 { m_width += pt.m_x - ( m_x + m_width ); m_height += m_y - pt.m_y; m_y = pt.m_y; }
6c7873e1 572 inline void MoveRightTopTo( const wxPoint2DDouble &pt )
11e82c1b 573 { m_x = pt.m_x - m_width; m_y = pt.m_y; }
6c7873e1 574 inline wxPoint2DDouble GetRightBottom() const
11e82c1b 575 { return wxPoint2DDouble( m_x+m_width , m_y + m_height ); }
6c7873e1 576 inline void SetRightBottom( const wxPoint2DDouble &pt )
11e82c1b 577 { m_width += pt.m_x - ( m_x + m_width ); m_height += pt.m_y - (m_y+m_height);}
6c7873e1 578 inline void MoveRightBottomTo( const wxPoint2DDouble &pt )
11e82c1b 579 { m_x = pt.m_x - m_width; m_y = pt.m_y - m_height; }
6c7873e1 580 inline wxPoint2DDouble GetCentre() const
11e82c1b 581 { return wxPoint2DDouble( m_x+m_width/2 , m_y+m_height/2 ); }
6c7873e1 582 inline void SetCentre( const wxPoint2DDouble &pt )
11e82c1b 583 { MoveCentreTo( pt ); } // since this is impossible without moving...
6c7873e1 584 inline void MoveCentreTo( const wxPoint2DDouble &pt )
11e82c1b 585 { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2); }
6c7873e1
RR
586 inline wxOutCode GetOutcode( const wxPoint2DDouble &pt ) const
587 { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
c3a4297c
VZ
588 ( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) +
589 ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
11e82c1b 590 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )); }
f91de7da 591 inline bool Contains( const wxPoint2DDouble &pt ) const
11e82c1b 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
RR
633/*
634 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
635 bool operator == (const wxRect2DDouble& rect);
636 bool operator != (const wxRect2DDouble& rect);
637*/
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); }
c3a4297c
VZ
696 inline wxOutCode GetOutcode( const wxPoint2DInt &pt ) const
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 )); }
f91de7da 701 inline bool Contains( const wxPoint2DInt &pt ) const
11e82c1b 702 { return GetOutcode( pt ) == wxInside; }
f91de7da
DW
703 inline bool Contains( const wxRect2DInt &rect ) const
704 { return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
11e82c1b 705 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
f91de7da 706 inline bool IsEmpty() const
11e82c1b 707 { return ( m_width <= 0 || m_height <= 0 ); }
f91de7da 708 inline bool HaveEqualSize( const wxRect2DInt &rect ) const
11e82c1b 709 { return ( rect.m_width == m_width && rect.m_height == m_height ); }
f91de7da 710
11e82c1b 711 inline void Inset( wxInt32 x , wxInt32 y ) { m_x += x; m_y += y; m_width -= 2 * x; m_height -= 2 * y; }
f91de7da 712 inline void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom )
11e82c1b
VZ
713 { m_x += left; m_y += top; m_width -= left + right; m_height -= top + bottom;}
714 inline void Offset( const wxPoint2DInt &pt ) { m_x += pt.m_x; m_y += pt.m_y; }
715 void ConstrainTo( const wxRect2DInt &rect );
716 inline wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ) { return wxPoint2DInt( m_x + m_width * widthfactor , m_y + m_height * heightfactor ); }
717
718 static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
719 inline void Intersect( const wxRect2DInt &otherRect ) { Intersect( *this , otherRect , this ); }
720 inline wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const { wxRect2DInt result; Intersect( *this , otherRect , &result); return result; }
721 bool Intersects( const wxRect2DInt &rect ) const;
722
723 static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
724 void Union( const wxRect2DInt &otherRect ) { Union( *this , otherRect , this ); }
725 void Union( const wxPoint2DInt &pt );
726 inline wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const { wxRect2DInt result; Union( *this , otherRect , &result); return result; }
727
728 inline void Scale( wxInt32 f ) { m_x *= f; m_y *= f; m_width *= f; m_height *= f;}
f91de7da 729 inline void Scale( wxInt32 num , wxInt32 denum )
11e82c1b
VZ
730 { m_x *= ((wxInt32)num)/((wxInt32)denum); m_y *= ((wxInt32)num)/((wxInt32)denum);
731 m_width *= ((wxInt32)num)/((wxInt32)denum); m_height *= ((wxInt32)num)/((wxInt32)denum);}
c3a4297c
VZ
732
733 wxRect2DInt& operator = (const wxRect2DInt& rect);
734 bool operator == (const wxRect2DInt& rect);
735 bool operator != (const wxRect2DInt& rect);
736
11e82c1b
VZ
737 void WriteTo( wxDataOutputStream &stream ) const;
738 void ReadFrom( wxDataInputStream &stream );
c3a4297c 739
11e82c1b
VZ
740 wxInt32 m_x;
741 wxInt32 m_y;
c3a4297c
VZ
742 wxInt32 m_width;
743 wxInt32 m_height;
72e7876b
SC
744};
745
f91de7da
DW
746inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r )
747{
11e82c1b
VZ
748 m_x = r.m_x;
749 m_y = r.m_y;
750 m_width = r.m_width;
751 m_height = r.m_height;
f91de7da
DW
752}
753
754inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b)
755{
11e82c1b
VZ
756 m_x = wxMin( a.m_x , b.m_x );
757 m_y = wxMin( a.m_y , b.m_y );
758 m_width = abs( a.m_x - b.m_x );
759 m_height = abs( a.m_y - b.m_y );
f91de7da 760}
72e7876b
SC
761
762class wxTransform2D
763{
764public :
11e82c1b
VZ
765 virtual void Transform( wxPoint2DInt* pt )const = 0;
766 virtual void Transform( wxRect2DInt* r ) const;
767 virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const;
768 virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ;
c3a4297c
VZ
769
770 virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
11e82c1b
VZ
771 virtual void InverseTransform( wxRect2DInt* r ) const ;
772 virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
773 virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
774};
72e7876b 775
f91de7da 776inline void wxTransform2D::Transform( wxRect2DInt* r ) const
11e82c1b 777 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); Transform( &a ); Transform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 778
f91de7da 779inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const
11e82c1b 780 { wxPoint2DInt res = pt; Transform( &res ); return res; }
72e7876b 781
f91de7da 782inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const
11e82c1b 783 { wxRect2DInt res = r; Transform( &res ); return res; }
72e7876b 784
f91de7da 785inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const
11e82c1b 786 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); InverseTransform( &a ); InverseTransform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 787
f91de7da 788inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const
11e82c1b 789 { wxPoint2DInt res = pt; InverseTransform( &res ); return res; }
72e7876b 790
f91de7da 791inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const
11e82c1b 792 { wxRect2DInt res = r; InverseTransform( &res ); return res; }
72e7876b 793
c3a4297c
VZ
794
795#endif // wxUSE_GEOMETRY
796
797#endif // _WX_GEOMETRY_H_