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