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