]> git.saurik.com Git - wxWidgets.git/blame - include/wx/geometry.h
ugh. Nesting the (per class) plugin sentries can require them to
[wxWidgets.git] / include / wx / geometry.h
CommitLineData
72e7876b 1/////////////////////////////////////////////////////////////////////////////
11e82c1b 2// Name: wx/geometry.h
72e7876b
SC
3// Purpose: Common Geometry Classes
4// Author: Stefan Csomor
5// Modified by:
6// Created: 08/05/99
f91de7da 7// RCS-ID:
11e82c1b 8// Copyright: (c) 1999 Stefan Csomor
c3a4297c 9// Licence: wxWindows licence
72e7876b
SC
10/////////////////////////////////////////////////////////////////////////////
11
c3a4297c
VZ
12#ifndef _WX_GEOMETRY_H_
13#define _WX_GEOMETRY_H_
72e7876b
SC
14
15#ifdef __GNUG__
6c7873e1 16 #pragma interface "geometry.cpp"
72e7876b
SC
17#endif
18
510fc784 19#include "wx/defs.h"
c3a4297c 20
5b781a67
SC
21#ifndef wxUSE_GEOMETRY
22 #define wxUSE_GEOMETRY 0
23#endif
24
c3a4297c
VZ
25#if wxUSE_GEOMETRY
26
510fc784
RR
27#include "wx/utils.h"
28#include "wx/gdicmn.h"
29#include <math.h>
30
72e7876b 31#ifdef __WXMSW__
c3a4297c 32 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
72e7876b 33#elif defined( __WXMAC__ )
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
11e82c1b
VZ
42class wxDataInputStream;
43class wxDataOutputStream;
72e7876b
SC
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
11e82c1b 54};
72e7876b 55
f91de7da 56// wxPoint2Ds represent a point or a vector in a 2d coordinate system
72e7876b
SC
57
58class WXDLLEXPORT wxPoint2DDouble
59{
60public :
11e82c1b
VZ
61 inline wxPoint2DDouble();
62 inline wxPoint2DDouble( wxDouble x , wxDouble y );
63 inline wxPoint2DDouble( const wxPoint2DDouble &pt );
64
65 // two different conversions to integers, floor and rounding
66 inline void GetFloor( wxInt32 *x , wxInt32 *y );
67 inline void GetRounded( wxInt32 *x , wxInt32 *y );
68
69 inline wxDouble GetVectorLength();
70 inline wxDouble GetVectorAngle();
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();
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 );
81
82 // the reflection of this point
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;
97
98 wxDouble m_x;
99 wxDouble m_y;
100};
c3a4297c 101
11e82c1b
VZ
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);
72e7876b 112
f91de7da
DW
113inline wxPoint2DDouble::wxPoint2DDouble()
114{
11e82c1b
VZ
115 m_x = 0.0;
116 m_y = 0.0;
72e7876b
SC
117}
118
f91de7da
DW
119inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y )
120{
11e82c1b
VZ
121 m_x = x;
122 m_y = y;
f91de7da 123}
72e7876b 124
f91de7da
DW
125inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt )
126{
11e82c1b
VZ
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{
11e82c1b
VZ
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{
11e82c1b
VZ
139 *x = (wxInt32) floor( m_x + 0.5 );
140 *y = (wxInt32) floor( m_y + 0.5);
f91de7da
DW
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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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 169{
11e82c1b 170 m_x = pt.m_x;
f91de7da 171 m_y = pt.m_y;
11e82c1b 172 return *this;
72e7876b
SC
173}
174
f91de7da 175inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt)
72e7876b 176{
11e82c1b 177 m_x = m_x + pt.m_x;
f91de7da 178 m_y = m_y + pt.m_y;
11e82c1b 179 return *this;
72e7876b
SC
180}
181
f91de7da
DW
182inline wxPoint2DDouble& wxPoint2DDouble::operator-=(const wxPoint2DDouble& pt)
183{
11e82c1b 184 m_x = m_x - pt.m_x;
f91de7da 185 m_y = m_y - pt.m_y;
11e82c1b 186 return *this;
72e7876b
SC
187}
188
f91de7da
DW
189inline wxPoint2DDouble& wxPoint2DDouble::operator*=(const wxPoint2DDouble& pt)
190{
11e82c1b 191 m_x = m_x * pt.m_x;
f91de7da 192 m_y = m_y * pt.m_y;
11e82c1b 193 return *this;
72e7876b
SC
194}
195
f91de7da
DW
196inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt)
197{
11e82c1b 198 m_x = m_x / pt.m_x;
da052901 199 m_y = m_y / pt.m_y;
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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()
11e82c1b 272 { m_x = m_y = m_width = m_height = 0; }
6c7873e1 273 wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h)
11e82c1b 274 { m_x = x; m_y = y; m_width = w; m_height = h; }
6c7873e1
RR
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 290 inline wxDouble GetLeft() const { return m_x; }
11e82c1b
VZ
291 inline void SetLeft( wxDouble n ) { m_width += m_x - n; m_x = n; }
292 inline void MoveLeftTo( wxDouble n ) { m_x = n; }
6c7873e1 293 inline wxDouble GetTop() const { return m_y; }
11e82c1b
VZ
294 inline void SetTop( wxDouble n ) { m_height += m_y - n; m_y = n; }
295 inline void MoveTopTo( wxDouble n ) { m_y = n; }
6c7873e1 296 inline wxDouble GetBottom() const { return m_y + m_height; }
11e82c1b
VZ
297 inline void SetBottom( wxDouble n ) { m_height += n - (m_y+m_height);}
298 inline void MoveBottomTo( wxDouble n ) { m_y = n - m_height; }
6c7873e1 299 inline wxDouble GetRight() const { return m_x + m_width; }
11e82c1b
VZ
300 inline void SetRight( wxDouble n ) { m_width += n - (m_x+m_width) ; }
301 inline void MoveRightTo( wxDouble n ) { m_x = n - m_width; }
6c7873e1
RR
302
303 inline wxPoint2DDouble GetLeftTop() const
11e82c1b 304 { return wxPoint2DDouble( m_x , m_y ); }
6c7873e1 305 inline void SetLeftTop( const wxPoint2DDouble &pt )
11e82c1b 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 )
11e82c1b 308 { m_x = pt.m_x; m_y = pt.m_y; }
6c7873e1 309 inline wxPoint2DDouble GetLeftBottom() const
11e82c1b 310 { return wxPoint2DDouble( m_x , m_y + m_height ); }
6c7873e1 311 inline void SetLeftBottom( const wxPoint2DDouble &pt )
11e82c1b 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 )
11e82c1b 314 { m_x = pt.m_x; m_y = pt.m_y - m_height; }
6c7873e1 315 inline wxPoint2DDouble GetRightTop() const
11e82c1b 316 { return wxPoint2DDouble( m_x+m_width , m_y ); }
6c7873e1 317 inline void SetRightTop( const wxPoint2DDouble &pt )
11e82c1b 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 )
11e82c1b 320 { m_x = pt.m_x - m_width; m_y = pt.m_y; }
6c7873e1 321 inline wxPoint2DDouble GetRightBottom() const
11e82c1b 322 { return wxPoint2DDouble( m_x+m_width , m_y + m_height ); }
6c7873e1 323 inline void SetRightBottom( const wxPoint2DDouble &pt )
11e82c1b 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 )
11e82c1b 326 { m_x = pt.m_x - m_width; m_y = pt.m_y - m_height; }
6c7873e1 327 inline wxPoint2DDouble GetCentre() const
11e82c1b 328 { return wxPoint2DDouble( m_x+m_width/2 , m_y+m_height/2 ); }
6c7873e1 329 inline void SetCentre( const wxPoint2DDouble &pt )
11e82c1b 330 { MoveCentreTo( pt ); } // since this is impossible without moving...
6c7873e1 331 inline void MoveCentreTo( const wxPoint2DDouble &pt )
11e82c1b 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 ) +
11e82c1b 337 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )); }
f91de7da 338 inline bool Contains( const wxPoint2DDouble &pt ) const
11e82c1b 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 ) ) &&
11e82c1b 342 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
f91de7da 343 inline bool IsEmpty() const
11e82c1b 344 { return ( m_width <= 0 || m_height <= 0 ); }
f91de7da 345 inline bool HaveEqualSize( const wxRect2DDouble &rect ) const
11e82c1b 346 { return ( rect.m_width == m_width && rect.m_height == m_height ); }
f91de7da 347
6c7873e1 348 inline void Inset( wxDouble x , wxDouble y )
11e82c1b 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 )
11e82c1b 351 { m_x += left; m_y += top; m_width -= left + right; m_height -= top + bottom;}
6c7873e1 352 inline void Offset( const wxPoint2DDouble &pt )
11e82c1b 353 { m_x += pt.m_x; m_y += pt.m_y; }
f91de7da 354
6c7873e1 355 void ConstrainTo( const wxRect2DDouble &rect );
f91de7da 356
6c7873e1 357 inline wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor )
11e82c1b 358 { return wxPoint2DDouble( m_x + m_width * widthfactor , m_y + m_height * heightfactor ); }
6c7873e1 359
11e82c1b 360 static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
6c7873e1 361 inline void Intersect( const wxRect2DDouble &otherRect )
11e82c1b 362 { Intersect( *this , otherRect , this ); }
6c7873e1 363 inline wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const
11e82c1b
VZ
364 { wxRect2DDouble result; Intersect( *this , otherRect , &result); return result; }
365 bool Intersects( const wxRect2DDouble &rect ) const;
6c7873e1 366
11e82c1b 367 static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
6c7873e1 368 void Union( const wxRect2DDouble &otherRect )
11e82c1b
VZ
369 { Union( *this , otherRect , this ); }
370 void Union( const wxPoint2DDouble &pt );
6c7873e1 371 inline wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const
11e82c1b 372 { wxRect2DDouble result; Union( *this , otherRect , &result); return result; }
6c7873e1
RR
373
374 inline void Scale( wxDouble f )
11e82c1b 375 { m_x *= f; m_y *= f; m_width *= f; m_height *= f;}
f91de7da 376 inline void Scale( wxInt32 num , wxInt32 denum )
11e82c1b
VZ
377 { m_x *= ((wxDouble)num)/((wxDouble)denum); m_y *= ((wxDouble)num)/((wxDouble)denum);
378 m_width *= ((wxDouble)num)/((wxDouble)denum); m_height *= ((wxDouble)num)/((wxDouble)denum);}
c3a4297c 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 386 wxDouble m_x;
11e82c1b 387 wxDouble m_y;
6c7873e1
RR
388 wxDouble m_width;
389 wxDouble m_height;
72e7876b
SC
390};
391
392class WXDLLEXPORT wxPoint2DInt
393{
394public :
297e4185
VZ
395 inline wxPoint2DInt();
396 inline wxPoint2DInt( wxInt32 x , wxInt32 y );
397 inline wxPoint2DInt( const wxPoint2DInt &pt );
398 inline wxPoint2DInt( const wxPoint &pt );
399
400 // noops for this class, just return the coords
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 );
409 // set the vector length to 1.0, preserving the angle
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;
416
417 // the reflection of this point
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;
432
433 void WriteTo( wxDataOutputStream &stream ) const;
434 void ReadFrom( wxDataInputStream &stream );
435
436 wxInt32 m_x;
437 wxInt32 m_y;
11e82c1b
VZ
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);
72e7876b 450
f91de7da
DW
451inline wxPoint2DInt::wxPoint2DInt()
452{
11e82c1b
VZ
453 m_x = 0;
454 m_y = 0;
72e7876b
SC
455}
456
f91de7da
DW
457inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
458{
11e82c1b
VZ
459 m_x = x;
460 m_y = y;
f91de7da 461}
72e7876b 462
f91de7da
DW
463inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
464{
11e82c1b
VZ
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{
11e82c1b
VZ
471 m_x = pt.x;
472 m_y = pt.y;
f91de7da
DW
473}
474
475inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y )
476{
297e4185
VZ
477 if ( x )
478 *x = m_x;
479 if ( y )
480 *y = m_y;
72e7876b
SC
481}
482
f91de7da
DW
483inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y )
484{
297e4185 485 GetFloor(x, y);
f91de7da
DW
486}
487
488inline wxDouble wxPoint2DInt::GetVectorLength()
72e7876b 489{
297e4185 490 // cast needed MIPSpro compiler under SGI
11e82c1b 491 return sqrt( (double)(m_x)*(m_x) + (m_y)*(m_y) );
72e7876b
SC
492}
493
f91de7da 494inline void wxPoint2DInt::SetVectorLength( wxDouble length )
72e7876b 495{
11e82c1b
VZ
496 wxDouble before = GetVectorLength();
497 m_x = (wxInt32)(m_x * length / before);
498 m_y = (wxInt32)(m_y * length / before);
72e7876b
SC
499}
500
f91de7da 501inline void wxPoint2DInt::Normalize()
72e7876b 502{
11e82c1b 503 SetVectorLength( 1 );
72e7876b
SC
504}
505
506inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const
f91de7da
DW
507{
508 return sqrt( GetDistanceSquare( pt ) );
72e7876b
SC
509}
510
511inline wxDouble wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt &pt ) const
f91de7da 512{
11e82c1b 513 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) );
f91de7da 514}
72e7876b
SC
515
516inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const
f91de7da 517{
11e82c1b 518 return ( m_x * vec.m_x + m_y * vec.m_y );
72e7876b
SC
519}
520
521inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const
f91de7da 522{
11e82c1b 523 return ( m_x * vec.m_y - vec.m_x * m_y );
f91de7da 524}
72e7876b
SC
525
526inline wxPoint2DInt::operator wxPoint() const
f91de7da 527{
c3a4297c 528 return wxPoint( m_x, m_y);
72e7876b
SC
529}
530
f91de7da
DW
531inline wxPoint2DInt wxPoint2DInt::operator-()
532{
c3a4297c 533 return wxPoint2DInt( -m_x, -m_y);
72e7876b
SC
534}
535
536inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt)
f91de7da 537{
11e82c1b 538 m_x = pt.m_x;
f91de7da 539 m_y = pt.m_y;
11e82c1b 540 return *this;
72e7876b
SC
541}
542
f91de7da 543inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt)
72e7876b 544{
11e82c1b 545 m_x = m_x + pt.m_x;
f91de7da 546 m_y = m_y + pt.m_y;
11e82c1b 547 return *this;
72e7876b
SC
548}
549
f91de7da
DW
550inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt)
551{
11e82c1b 552 m_x = m_x - pt.m_x;
f91de7da 553 m_y = m_y - pt.m_y;
11e82c1b 554 return *this;
72e7876b
SC
555}
556
f91de7da
DW
557inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
558{
11e82c1b 559 m_x = m_x + pt.m_x;
f91de7da 560 m_y = m_y + pt.m_y;
11e82c1b 561 return *this;
72e7876b
SC
562}
563
f91de7da
DW
564inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
565{
11e82c1b 566 m_x = m_x - pt.m_x;
c3a4297c 567 m_y = m_y - pt.m_y;
11e82c1b 568 return *this;
72e7876b
SC
569}
570
f91de7da
DW
571inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const
572{
573 return m_x == pt.m_x && m_y == pt.m_y;
72e7876b
SC
574}
575
f91de7da
DW
576inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const
577{
578 return m_x != pt.m_x || m_y != pt.m_y;
72e7876b
SC
579}
580
f91de7da 581inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
72e7876b 582{
11e82c1b 583 return wxPoint2DInt( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y );
72e7876b
SC
584}
585
f91de7da 586inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
72e7876b 587{
11e82c1b 588 return wxPoint2DInt( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y );
72e7876b
SC
589}
590
591
f91de7da 592inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
72e7876b 593{
11e82c1b 594 return wxPoint2DInt( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y );
72e7876b
SC
595}
596
f91de7da 597inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
72e7876b 598{
11e82c1b 599 return wxPoint2DInt( pt.m_x * n , pt.m_y * n );
72e7876b
SC
600}
601
f91de7da 602inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
72e7876b 603{
11e82c1b 604 return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) );
72e7876b
SC
605}
606
f91de7da 607inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n)
72e7876b 608{
11e82c1b 609 return wxPoint2DInt( pt.m_x * n , pt.m_y * n );
72e7876b
SC
610}
611
f91de7da 612inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n)
72e7876b 613{
11e82c1b 614 return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) );
72e7876b
SC
615}
616
f91de7da 617inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
72e7876b 618{
11e82c1b 619 return wxPoint2DInt( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y );
72e7876b
SC
620}
621
f91de7da 622inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n)
72e7876b 623{
11e82c1b 624 return wxPoint2DInt( pt.m_x / n , pt.m_y / n );
72e7876b
SC
625}
626
f91de7da 627inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n)
72e7876b 628{
11e82c1b 629 return wxPoint2DInt( (int) (pt.m_x / n) , (int) (pt.m_y / n) );
72e7876b
SC
630}
631
f91de7da 632// 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 633// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
f91de7da 634// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
72e7876b
SC
635
636class WXDLLEXPORT wxRect2DInt
637{
638public:
11e82c1b
VZ
639 wxRect2DInt() { m_x = m_y = m_width = m_height = 0; }
640 wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h) { m_x = x; m_y = y; m_width = w; m_height = h; }
c3a4297c 641 wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight);
f91de7da
DW
642 inline wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size);
643 inline wxRect2DInt(const wxRect2DInt& rect);
c3a4297c
VZ
644
645 // single attribute accessors
646
647 inline wxPoint2DInt GetPosition() { return wxPoint2DInt(m_x, m_y); }
648 inline wxSize GetSize() { return wxSize(m_width, m_height); }
649
650 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
651 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
652
653 inline wxInt32 GetLeft() const { return m_x; }
11e82c1b
VZ
654 inline void SetLeft( wxInt32 n ) { m_width += m_x - n; m_x = n; }
655 inline void MoveLeftTo( wxInt32 n ) { m_x = n; }
c3a4297c 656 inline wxInt32 GetTop() const { return m_y; }
11e82c1b
VZ
657 inline void SetTop( wxInt32 n ) { m_height += m_y - n; m_y = n; }
658 inline void MoveTopTo( wxInt32 n ) { m_y = n; }
c3a4297c 659 inline wxInt32 GetBottom() const { return m_y + m_height; }
11e82c1b
VZ
660 inline void SetBottom( wxInt32 n ) { m_height += n - (m_y+m_height);}
661 inline void MoveBottomTo( wxInt32 n ) { m_y = n - m_height; }
c3a4297c 662 inline wxInt32 GetRight() const { return m_x + m_width; }
11e82c1b
VZ
663 inline void SetRight( wxInt32 n ) { m_width += n - (m_x+m_width) ; }
664 inline void MoveRightTo( wxInt32 n ) { m_x = n - m_width; }
665
666 inline wxPoint2DInt GetLeftTop() const { return wxPoint2DInt( m_x , m_y ); }
667 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; }
668 inline void MoveLeftTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x; m_y = pt.m_y; }
669 inline wxPoint2DInt GetLeftBottom() const { return wxPoint2DInt( m_x , m_y + m_height ); }
670 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; }
671 inline void MoveLeftBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x; m_y = pt.m_y - m_height; }
672 inline wxPoint2DInt GetRightTop() const { return wxPoint2DInt( m_x+m_width , m_y ); }
673 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; }
674 inline void MoveRightTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width; m_y = pt.m_y; }
675 inline wxPoint2DInt GetRightBottom() const { return wxPoint2DInt( m_x+m_width , m_y + m_height ); }
676 inline void SetRightBottom( const wxPoint2DInt &pt ) { m_width += pt.m_x - ( m_x + m_width ); m_height += pt.m_y - (m_y+m_height);}
677 inline void MoveRightBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width; m_y = pt.m_y - m_height; }
678 inline wxPoint2DInt GetCentre() const { return wxPoint2DInt( m_x+m_width/2 , m_y+m_height/2 ); }
679 inline void SetCentre( const wxPoint2DInt &pt ) { MoveCentreTo( pt ); } // since this is impossible without moving...
680 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
681 inline wxOutCode GetOutcode( const wxPoint2DInt &pt ) const
682 { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
683 ( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) +
684 ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
11e82c1b 685 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )); }
f91de7da 686 inline bool Contains( const wxPoint2DInt &pt ) const
11e82c1b 687 { return GetOutcode( pt ) == wxInside; }
f91de7da
DW
688 inline bool Contains( const wxRect2DInt &rect ) const
689 { return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
11e82c1b 690 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
f91de7da 691 inline bool IsEmpty() const
11e82c1b 692 { return ( m_width <= 0 || m_height <= 0 ); }
f91de7da 693 inline bool HaveEqualSize( const wxRect2DInt &rect ) const
11e82c1b 694 { return ( rect.m_width == m_width && rect.m_height == m_height ); }
f91de7da 695
11e82c1b 696 inline void Inset( wxInt32 x , wxInt32 y ) { m_x += x; m_y += y; m_width -= 2 * x; m_height -= 2 * y; }
f91de7da 697 inline void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom )
11e82c1b
VZ
698 { m_x += left; m_y += top; m_width -= left + right; m_height -= top + bottom;}
699 inline void Offset( const wxPoint2DInt &pt ) { m_x += pt.m_x; m_y += pt.m_y; }
700 void ConstrainTo( const wxRect2DInt &rect );
701 inline wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ) { return wxPoint2DInt( m_x + m_width * widthfactor , m_y + m_height * heightfactor ); }
702
703 static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
704 inline void Intersect( const wxRect2DInt &otherRect ) { Intersect( *this , otherRect , this ); }
705 inline wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const { wxRect2DInt result; Intersect( *this , otherRect , &result); return result; }
706 bool Intersects( const wxRect2DInt &rect ) const;
707
708 static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
709 void Union( const wxRect2DInt &otherRect ) { Union( *this , otherRect , this ); }
710 void Union( const wxPoint2DInt &pt );
711 inline wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const { wxRect2DInt result; Union( *this , otherRect , &result); return result; }
712
713 inline void Scale( wxInt32 f ) { m_x *= f; m_y *= f; m_width *= f; m_height *= f;}
f91de7da 714 inline void Scale( wxInt32 num , wxInt32 denum )
11e82c1b
VZ
715 { m_x *= ((wxInt32)num)/((wxInt32)denum); m_y *= ((wxInt32)num)/((wxInt32)denum);
716 m_width *= ((wxInt32)num)/((wxInt32)denum); m_height *= ((wxInt32)num)/((wxInt32)denum);}
c3a4297c
VZ
717
718 wxRect2DInt& operator = (const wxRect2DInt& rect);
719 bool operator == (const wxRect2DInt& rect);
720 bool operator != (const wxRect2DInt& rect);
721
11e82c1b
VZ
722 void WriteTo( wxDataOutputStream &stream ) const;
723 void ReadFrom( wxDataInputStream &stream );
c3a4297c 724
11e82c1b
VZ
725 wxInt32 m_x;
726 wxInt32 m_y;
c3a4297c
VZ
727 wxInt32 m_width;
728 wxInt32 m_height;
72e7876b
SC
729};
730
f91de7da
DW
731inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r )
732{
11e82c1b
VZ
733 m_x = r.m_x;
734 m_y = r.m_y;
735 m_width = r.m_width;
736 m_height = r.m_height;
f91de7da
DW
737}
738
739inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b)
740{
11e82c1b
VZ
741 m_x = wxMin( a.m_x , b.m_x );
742 m_y = wxMin( a.m_y , b.m_y );
743 m_width = abs( a.m_x - b.m_x );
744 m_height = abs( a.m_y - b.m_y );
f91de7da 745}
72e7876b
SC
746
747class wxTransform2D
748{
749public :
11e82c1b
VZ
750 virtual void Transform( wxPoint2DInt* pt )const = 0;
751 virtual void Transform( wxRect2DInt* r ) const;
752 virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const;
753 virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ;
c3a4297c
VZ
754
755 virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
11e82c1b
VZ
756 virtual void InverseTransform( wxRect2DInt* r ) const ;
757 virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
758 virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
759};
72e7876b 760
f91de7da 761inline void wxTransform2D::Transform( wxRect2DInt* r ) const
11e82c1b 762 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); Transform( &a ); Transform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 763
f91de7da 764inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const
11e82c1b 765 { wxPoint2DInt res = pt; Transform( &res ); return res; }
72e7876b 766
f91de7da 767inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const
11e82c1b 768 { wxRect2DInt res = r; Transform( &res ); return res; }
72e7876b 769
f91de7da 770inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const
11e82c1b 771 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); InverseTransform( &a ); InverseTransform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 772
f91de7da 773inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const
11e82c1b 774 { wxPoint2DInt res = pt; InverseTransform( &res ); return res; }
72e7876b 775
f91de7da 776inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const
11e82c1b 777 { wxRect2DInt res = r; InverseTransform( &res ); return res; }
72e7876b 778
c3a4297c
VZ
779
780#endif // wxUSE_GEOMETRY
781
782#endif // _WX_GEOMETRY_H_