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