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