]> git.saurik.com Git - wxWidgets.git/blame - include/wx/geometry.h
no (real) changes
[wxWidgets.git] / include / wx / geometry.h
CommitLineData
72e7876b 1/////////////////////////////////////////////////////////////////////////////
11e82c1b 2// Name: wx/geometry.h
72e7876b
SC
3// Purpose: Common Geometry Classes
4// Author: Stefan Csomor
5// Modified by:
6// Created: 08/05/99
f91de7da 7// RCS-ID:
11e82c1b 8// Copyright: (c) 1999 Stefan Csomor
c3a4297c 9// Licence: wxWindows licence
72e7876b
SC
10/////////////////////////////////////////////////////////////////////////////
11
c3a4297c
VZ
12#ifndef _WX_GEOMETRY_H_
13#define _WX_GEOMETRY_H_
72e7876b
SC
14
15#ifdef __GNUG__
6c7873e1 16 #pragma interface "geometry.cpp"
72e7876b
SC
17#endif
18
510fc784 19#include "wx/defs.h"
c3a4297c 20
5b781a67
SC
21#ifndef wxUSE_GEOMETRY
22 #define wxUSE_GEOMETRY 0
23#endif
24
c3a4297c
VZ
25#if wxUSE_GEOMETRY
26
510fc784
RR
27#include "wx/utils.h"
28#include "wx/gdicmn.h"
29#include <math.h>
30
72e7876b 31#ifdef __WXMSW__
c3a4297c 32 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
72e7876b 33#elif defined( __WXMAC__ )
799ea011 34 #include "Math64.h"
c3a4297c 35 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
72e7876b 36#else
c3a4297c 37 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
72e7876b
SC
38#endif
39
11e82c1b
VZ
40class wxDataInputStream;
41class wxDataOutputStream;
72e7876b
SC
42
43// clipping from Cohen-Sutherland
44
45enum wxOutCode
46{
c3a4297c
VZ
47 wxInside = 0x00 ,
48 wxOutLeft = 0x01 ,
49 wxOutRight = 0x02 ,
50 wxOutTop = 0x08 ,
f91de7da 51 wxOutBottom = 0x04
11e82c1b 52};
72e7876b 53
f91de7da 54// wxPoint2Ds represent a point or a vector in a 2d coordinate system
72e7876b
SC
55
56class WXDLLEXPORT wxPoint2DDouble
57{
58public :
11e82c1b
VZ
59 inline wxPoint2DDouble();
60 inline wxPoint2DDouble( wxDouble x , wxDouble y );
61 inline wxPoint2DDouble( const wxPoint2DDouble &pt );
62
63 // two different conversions to integers, floor and rounding
64 inline void GetFloor( wxInt32 *x , wxInt32 *y );
65 inline void GetRounded( wxInt32 *x , wxInt32 *y );
66
67 inline wxDouble GetVectorLength();
68 inline wxDouble GetVectorAngle();
69 void SetVectorLength( wxDouble length );
70 void SetVectorAngle( wxDouble degrees );
71 void SetPolarCoordinates( wxDouble angle , wxDouble length );
72 // set the vector length to 1.0, preserving the angle
73 void Normalize();
74
75 inline wxDouble GetDistance( const wxPoint2DDouble &pt );
76 inline wxDouble GetDistanceSquare( const wxPoint2DDouble &pt );
77 inline wxDouble GetDotProduct( const wxPoint2DDouble &vec );
78 inline wxDouble GetCrossProduct( const wxPoint2DDouble &vec );
79
80 // the reflection of this point
81 inline wxPoint2DDouble operator-();
82
83 inline wxPoint2DDouble& operator=(const wxPoint2DDouble& pt);
84 inline wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt);
85 inline wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt);
86 inline wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt);
87 inline wxPoint2DDouble& operator*=(wxDouble n);
88 inline wxPoint2DDouble& operator*=(wxInt32 n);
89 inline wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt);
90 inline wxPoint2DDouble& operator/=(wxDouble n);
91 inline wxPoint2DDouble& operator/=(wxInt32 n);
92
93 inline bool operator==(const wxPoint2DDouble& pt) const;
94 inline bool operator!=(const wxPoint2DDouble& pt) const;
95
96 wxDouble m_x;
97 wxDouble m_y;
98};
c3a4297c 99
11e82c1b
VZ
100wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
101wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
102wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
103wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt);
104wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt);
105wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n);
106wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n);
107wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
108wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n);
109wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n);
72e7876b 110
f91de7da
DW
111inline wxPoint2DDouble::wxPoint2DDouble()
112{
11e82c1b
VZ
113 m_x = 0.0;
114 m_y = 0.0;
72e7876b
SC
115}
116
f91de7da
DW
117inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y )
118{
11e82c1b
VZ
119 m_x = x;
120 m_y = y;
f91de7da 121}
72e7876b 122
f91de7da
DW
123inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt )
124{
11e82c1b
VZ
125 m_x = pt.m_x;
126 m_y = pt.m_y;
72e7876b
SC
127}
128
f91de7da
DW
129inline void wxPoint2DDouble::GetFloor( wxInt32 *x , wxInt32 *y )
130{
11e82c1b
VZ
131 *x = (wxInt32) floor( m_x );
132 *y = (wxInt32) floor( m_y );
72e7876b
SC
133}
134
f91de7da
DW
135inline void wxPoint2DDouble::GetRounded( wxInt32 *x , wxInt32 *y )
136{
11e82c1b
VZ
137 *x = (wxInt32) floor( m_x + 0.5 );
138 *y = (wxInt32) floor( m_y + 0.5);
f91de7da
DW
139}
140
141inline wxDouble wxPoint2DDouble::GetDistance( const wxPoint2DDouble &pt )
142{
143 return sqrt( GetDistanceSquare( pt ) );
72e7876b
SC
144}
145
f91de7da
DW
146inline wxDouble wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble &pt )
147{
11e82c1b 148 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) );
f91de7da 149}
72e7876b 150
f91de7da
DW
151inline wxDouble wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble &vec )
152{
11e82c1b 153 return ( m_x * vec.m_x + m_y * vec.m_y );
72e7876b
SC
154}
155
f91de7da
DW
156inline wxDouble wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble &vec )
157{
11e82c1b 158 return ( m_x * vec.m_y - vec.m_x * m_y );
f91de7da 159}
72e7876b 160
f91de7da
DW
161inline wxPoint2DDouble wxPoint2DDouble::operator-()
162{
c3a4297c 163 return wxPoint2DDouble( -m_x, -m_y);
72e7876b
SC
164}
165
166inline wxPoint2DDouble& wxPoint2DDouble::operator=(const wxPoint2DDouble& pt)
f91de7da 167{
11e82c1b 168 m_x = pt.m_x;
f91de7da 169 m_y = pt.m_y;
11e82c1b 170 return *this;
72e7876b
SC
171}
172
f91de7da 173inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt)
72e7876b 174{
11e82c1b 175 m_x = m_x + pt.m_x;
f91de7da 176 m_y = m_y + pt.m_y;
11e82c1b 177 return *this;
72e7876b
SC
178}
179
f91de7da
DW
180inline wxPoint2DDouble& wxPoint2DDouble::operator-=(const wxPoint2DDouble& pt)
181{
11e82c1b 182 m_x = m_x - pt.m_x;
f91de7da 183 m_y = m_y - pt.m_y;
11e82c1b 184 return *this;
72e7876b
SC
185}
186
f91de7da
DW
187inline wxPoint2DDouble& wxPoint2DDouble::operator*=(const wxPoint2DDouble& pt)
188{
11e82c1b 189 m_x = m_x * pt.m_x;
f91de7da 190 m_y = m_y * pt.m_y;
11e82c1b 191 return *this;
72e7876b
SC
192}
193
f91de7da
DW
194inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt)
195{
11e82c1b 196 m_x = m_x / pt.m_x;
da052901 197 m_y = m_y / pt.m_y;
11e82c1b 198 return *this;
72e7876b
SC
199}
200
f91de7da
DW
201inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const
202{
203 return m_x == pt.m_x && m_y == pt.m_y;
72e7876b
SC
204}
205
f91de7da
DW
206inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const
207{
208 return m_x != pt.m_x || m_y != pt.m_y;
72e7876b
SC
209}
210
f91de7da 211inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 212{
11e82c1b 213 return wxPoint2DDouble( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y );
72e7876b
SC
214}
215
f91de7da 216inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 217{
11e82c1b 218 return wxPoint2DDouble( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y );
72e7876b
SC
219}
220
221
f91de7da 222inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 223{
11e82c1b 224 return wxPoint2DDouble( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y );
72e7876b
SC
225}
226
f91de7da 227inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt)
72e7876b 228{
11e82c1b 229 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
230}
231
f91de7da 232inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt)
72e7876b 233{
11e82c1b 234 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
235}
236
f91de7da 237inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n)
72e7876b 238{
11e82c1b 239 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
240}
241
f91de7da 242inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n)
72e7876b 243{
11e82c1b 244 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n );
72e7876b
SC
245}
246
f91de7da 247inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
72e7876b 248{
11e82c1b 249 return wxPoint2DDouble( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y );
72e7876b
SC
250}
251
f91de7da 252inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n)
72e7876b 253{
11e82c1b 254 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n );
72e7876b
SC
255}
256
f91de7da 257inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n)
72e7876b 258{
11e82c1b 259 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n );
72e7876b
SC
260}
261
f91de7da 262// 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 263// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
f91de7da 264// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
72e7876b
SC
265
266class WXDLLEXPORT wxRect2DDouble
267{
268public:
f91de7da 269 wxRect2DDouble()
11e82c1b 270 { m_x = m_y = m_width = m_height = 0; }
6c7873e1 271 wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h)
11e82c1b 272 { m_x = x; m_y = y; m_width = w; m_height = h; }
6c7873e1
RR
273/*
274 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
275 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
276 wxRect2DDouble(const wxRect2DDouble& rect);
277*/
c3a4297c
VZ
278 // single attribute accessors
279
f91de7da 280 inline wxPoint2DDouble GetPosition()
6c7873e1
RR
281 { return wxPoint2DDouble(m_x, m_y); }
282 inline wxSize GetSize()
7a5e6267 283 { return wxSize((int) m_width, (int) m_height); }
c3a4297c 284
6c7873e1 285 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
c3a4297c
VZ
286 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
287
6c7873e1 288 inline wxDouble GetLeft() const { return m_x; }
11e82c1b
VZ
289 inline void SetLeft( wxDouble n ) { m_width += m_x - n; m_x = n; }
290 inline void MoveLeftTo( wxDouble n ) { m_x = n; }
6c7873e1 291 inline wxDouble GetTop() const { return m_y; }
11e82c1b
VZ
292 inline void SetTop( wxDouble n ) { m_height += m_y - n; m_y = n; }
293 inline void MoveTopTo( wxDouble n ) { m_y = n; }
6c7873e1 294 inline wxDouble GetBottom() const { return m_y + m_height; }
11e82c1b
VZ
295 inline void SetBottom( wxDouble n ) { m_height += n - (m_y+m_height);}
296 inline void MoveBottomTo( wxDouble n ) { m_y = n - m_height; }
6c7873e1 297 inline wxDouble GetRight() const { return m_x + m_width; }
11e82c1b
VZ
298 inline void SetRight( wxDouble n ) { m_width += n - (m_x+m_width) ; }
299 inline void MoveRightTo( wxDouble n ) { m_x = n - m_width; }
6c7873e1
RR
300
301 inline wxPoint2DDouble GetLeftTop() const
11e82c1b 302 { return wxPoint2DDouble( m_x , m_y ); }
6c7873e1 303 inline void SetLeftTop( const wxPoint2DDouble &pt )
11e82c1b 304 { 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 305 inline void MoveLeftTopTo( const wxPoint2DDouble &pt )
11e82c1b 306 { m_x = pt.m_x; m_y = pt.m_y; }
6c7873e1 307 inline wxPoint2DDouble GetLeftBottom() const
11e82c1b 308 { return wxPoint2DDouble( m_x , m_y + m_height ); }
6c7873e1 309 inline void SetLeftBottom( const wxPoint2DDouble &pt )
11e82c1b 310 { m_width += m_x - pt.m_x; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x; }
6c7873e1 311 inline void MoveLeftBottomTo( const wxPoint2DDouble &pt )
11e82c1b 312 { m_x = pt.m_x; m_y = pt.m_y - m_height; }
6c7873e1 313 inline wxPoint2DDouble GetRightTop() const
11e82c1b 314 { return wxPoint2DDouble( m_x+m_width , m_y ); }
6c7873e1 315 inline void SetRightTop( const wxPoint2DDouble &pt )
11e82c1b 316 { m_width += pt.m_x - ( m_x + m_width ); m_height += m_y - pt.m_y; m_y = pt.m_y; }
6c7873e1 317 inline void MoveRightTopTo( const wxPoint2DDouble &pt )
11e82c1b 318 { m_x = pt.m_x - m_width; m_y = pt.m_y; }
6c7873e1 319 inline wxPoint2DDouble GetRightBottom() const
11e82c1b 320 { return wxPoint2DDouble( m_x+m_width , m_y + m_height ); }
6c7873e1 321 inline void SetRightBottom( const wxPoint2DDouble &pt )
11e82c1b 322 { m_width += pt.m_x - ( m_x + m_width ); m_height += pt.m_y - (m_y+m_height);}
6c7873e1 323 inline void MoveRightBottomTo( const wxPoint2DDouble &pt )
11e82c1b 324 { m_x = pt.m_x - m_width; m_y = pt.m_y - m_height; }
6c7873e1 325 inline wxPoint2DDouble GetCentre() const
11e82c1b 326 { return wxPoint2DDouble( m_x+m_width/2 , m_y+m_height/2 ); }
6c7873e1 327 inline void SetCentre( const wxPoint2DDouble &pt )
11e82c1b 328 { MoveCentreTo( pt ); } // since this is impossible without moving...
6c7873e1 329 inline void MoveCentreTo( const wxPoint2DDouble &pt )
11e82c1b 330 { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2); }
6c7873e1
RR
331 inline wxOutCode GetOutcode( const wxPoint2DDouble &pt ) const
332 { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
c3a4297c
VZ
333 ( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) +
334 ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
11e82c1b 335 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )); }
f91de7da 336 inline bool Contains( const wxPoint2DDouble &pt ) const
11e82c1b 337 { return GetOutcode( pt ) == wxInside; }
f91de7da
DW
338 inline bool Contains( const wxRect2DDouble &rect ) const
339 { return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
11e82c1b 340 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
f91de7da 341 inline bool IsEmpty() const
11e82c1b 342 { return ( m_width <= 0 || m_height <= 0 ); }
f91de7da 343 inline bool HaveEqualSize( const wxRect2DDouble &rect ) const
11e82c1b 344 { return ( rect.m_width == m_width && rect.m_height == m_height ); }
f91de7da 345
6c7873e1 346 inline void Inset( wxDouble x , wxDouble y )
11e82c1b 347 { m_x += x; m_y += y; m_width -= 2 * x; m_height -= 2 * y; }
f91de7da 348 inline void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom )
11e82c1b 349 { m_x += left; m_y += top; m_width -= left + right; m_height -= top + bottom;}
6c7873e1 350 inline void Offset( const wxPoint2DDouble &pt )
11e82c1b 351 { m_x += pt.m_x; m_y += pt.m_y; }
f91de7da 352
6c7873e1 353 void ConstrainTo( const wxRect2DDouble &rect );
f91de7da 354
6c7873e1 355 inline wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor )
11e82c1b 356 { return wxPoint2DDouble( m_x + m_width * widthfactor , m_y + m_height * heightfactor ); }
6c7873e1 357
11e82c1b 358 static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
6c7873e1 359 inline void Intersect( const wxRect2DDouble &otherRect )
11e82c1b 360 { Intersect( *this , otherRect , this ); }
6c7873e1 361 inline wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const
11e82c1b
VZ
362 { wxRect2DDouble result; Intersect( *this , otherRect , &result); return result; }
363 bool Intersects( const wxRect2DDouble &rect ) const;
6c7873e1 364
11e82c1b 365 static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
6c7873e1 366 void Union( const wxRect2DDouble &otherRect )
11e82c1b
VZ
367 { Union( *this , otherRect , this ); }
368 void Union( const wxPoint2DDouble &pt );
6c7873e1 369 inline wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const
11e82c1b 370 { wxRect2DDouble result; Union( *this , otherRect , &result); return result; }
6c7873e1
RR
371
372 inline void Scale( wxDouble f )
11e82c1b 373 { m_x *= f; m_y *= f; m_width *= f; m_height *= f;}
f91de7da 374 inline void Scale( wxInt32 num , wxInt32 denum )
11e82c1b
VZ
375 { m_x *= ((wxDouble)num)/((wxDouble)denum); m_y *= ((wxDouble)num)/((wxDouble)denum);
376 m_width *= ((wxDouble)num)/((wxDouble)denum); m_height *= ((wxDouble)num)/((wxDouble)denum);}
c3a4297c 377
6c7873e1
RR
378/*
379 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
380 bool operator == (const wxRect2DDouble& rect);
381 bool operator != (const wxRect2DDouble& rect);
382*/
c3a4297c 383
6c7873e1 384 wxDouble m_x;
11e82c1b 385 wxDouble m_y;
6c7873e1
RR
386 wxDouble m_width;
387 wxDouble m_height;
72e7876b
SC
388};
389
390class WXDLLEXPORT wxPoint2DInt
391{
392public :
297e4185
VZ
393 inline wxPoint2DInt();
394 inline wxPoint2DInt( wxInt32 x , wxInt32 y );
395 inline wxPoint2DInt( const wxPoint2DInt &pt );
396 inline wxPoint2DInt( const wxPoint &pt );
397
398 // noops for this class, just return the coords
399 inline void GetFloor( wxInt32 *x , wxInt32 *y );
400 inline void GetRounded( wxInt32 *x , wxInt32 *y );
401
402 inline wxDouble GetVectorLength();
403 wxDouble GetVectorAngle();
404 inline void SetVectorLength( wxDouble length );
405 void SetVectorAngle( wxDouble degrees );
406 void SetPolarCoordinates( wxInt32 angle , wxInt32 length );
407 // set the vector length to 1.0, preserving the angle
408 inline void Normalize();
409
410 inline wxDouble GetDistance( const wxPoint2DInt &pt ) const;
411 inline wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const;
412 inline wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const;
413 inline wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const;
414
415 // the reflection of this point
416 inline wxPoint2DInt operator-();
417
418 inline wxPoint2DInt& operator=(const wxPoint2DInt& pt);
419 inline wxPoint2DInt& operator+=(const wxPoint2DInt& pt);
420 inline wxPoint2DInt& operator-=(const wxPoint2DInt& pt);
421 inline wxPoint2DInt& operator*=(const wxPoint2DInt& pt);
422 inline wxPoint2DInt& operator*=(wxDouble n);
423 inline wxPoint2DInt& operator*=(wxInt32 n);
424 inline wxPoint2DInt& operator/=(const wxPoint2DInt& pt);
425 inline wxPoint2DInt& operator/=(wxDouble n);
426 inline wxPoint2DInt& operator/=(wxInt32 n);
427 inline operator wxPoint() const;
428 inline bool operator==(const wxPoint2DInt& pt) const;
429 inline bool operator!=(const wxPoint2DInt& pt) const;
430
431 void WriteTo( wxDataOutputStream &stream ) const;
432 void ReadFrom( wxDataInputStream &stream );
433
434 wxInt32 m_x;
435 wxInt32 m_y;
11e82c1b
VZ
436};
437
438wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
439wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
440wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
441wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
442wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
443wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
444wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
445wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
446wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
447wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
72e7876b 448
f91de7da
DW
449inline wxPoint2DInt::wxPoint2DInt()
450{
11e82c1b
VZ
451 m_x = 0;
452 m_y = 0;
72e7876b
SC
453}
454
f91de7da
DW
455inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
456{
11e82c1b
VZ
457 m_x = x;
458 m_y = y;
f91de7da 459}
72e7876b 460
f91de7da
DW
461inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
462{
11e82c1b
VZ
463 m_x = pt.m_x;
464 m_y = pt.m_y;
72e7876b
SC
465}
466
f91de7da
DW
467inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt )
468{
11e82c1b
VZ
469 m_x = pt.x;
470 m_y = pt.y;
f91de7da
DW
471}
472
473inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y )
474{
297e4185
VZ
475 if ( x )
476 *x = m_x;
477 if ( y )
478 *y = m_y;
72e7876b
SC
479}
480
f91de7da
DW
481inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y )
482{
297e4185 483 GetFloor(x, y);
f91de7da
DW
484}
485
486inline wxDouble wxPoint2DInt::GetVectorLength()
72e7876b 487{
297e4185 488 // cast needed MIPSpro compiler under SGI
11e82c1b 489 return sqrt( (double)(m_x)*(m_x) + (m_y)*(m_y) );
72e7876b
SC
490}
491
f91de7da 492inline void wxPoint2DInt::SetVectorLength( wxDouble length )
72e7876b 493{
11e82c1b
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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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 535{
11e82c1b 536 m_x = pt.m_x;
f91de7da 537 m_y = pt.m_y;
11e82c1b 538 return *this;
72e7876b
SC
539}
540
f91de7da 541inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt)
72e7876b 542{
11e82c1b 543 m_x = m_x + pt.m_x;
f91de7da 544 m_y = m_y + pt.m_y;
11e82c1b 545 return *this;
72e7876b
SC
546}
547
f91de7da
DW
548inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt)
549{
11e82c1b 550 m_x = m_x - pt.m_x;
f91de7da 551 m_y = m_y - pt.m_y;
11e82c1b 552 return *this;
72e7876b
SC
553}
554
f91de7da
DW
555inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
556{
11e82c1b 557 m_x = m_x + pt.m_x;
f91de7da 558 m_y = m_y + pt.m_y;
11e82c1b 559 return *this;
72e7876b
SC
560}
561
f91de7da
DW
562inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
563{
11e82c1b 564 m_x = m_x - pt.m_x;
c3a4297c 565 m_y = m_y - pt.m_y;
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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{
11e82c1b 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:
11e82c1b
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; }
c3a4297c 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; }
11e82c1b
VZ
652 inline void SetLeft( wxInt32 n ) { m_width += m_x - n; m_x = n; }
653 inline void MoveLeftTo( wxInt32 n ) { m_x = n; }
c3a4297c 654 inline wxInt32 GetTop() const { return m_y; }
11e82c1b
VZ
655 inline void SetTop( wxInt32 n ) { m_height += m_y - n; m_y = n; }
656 inline void MoveTopTo( wxInt32 n ) { m_y = n; }
c3a4297c 657 inline wxInt32 GetBottom() const { return m_y + m_height; }
11e82c1b
VZ
658 inline void SetBottom( wxInt32 n ) { m_height += n - (m_y+m_height);}
659 inline void MoveBottomTo( wxInt32 n ) { m_y = n - m_height; }
c3a4297c 660 inline wxInt32 GetRight() const { return m_x + m_width; }
11e82c1b
VZ
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 ); }
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; }
667 inline wxPoint2DInt GetLeftBottom() const { return wxPoint2DInt( m_x , m_y + m_height ); }
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; }
670 inline wxPoint2DInt GetRightTop() const { return wxPoint2DInt( m_x+m_width , m_y ); }
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; }
673 inline wxPoint2DInt GetRightBottom() const { return wxPoint2DInt( m_x+m_width , m_y + m_height ); }
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; }
676 inline wxPoint2DInt GetCentre() const { return wxPoint2DInt( m_x+m_width/2 , m_y+m_height/2 ); }
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 ) +
11e82c1b 683 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )); }
f91de7da 684 inline bool Contains( const wxPoint2DInt &pt ) const
11e82c1b 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 ) ) &&
11e82c1b 688 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ); }
f91de7da 689 inline bool IsEmpty() const
11e82c1b 690 { return ( m_width <= 0 || m_height <= 0 ); }
f91de7da 691 inline bool HaveEqualSize( const wxRect2DInt &rect ) const
11e82c1b 692 { return ( rect.m_width == m_width && rect.m_height == m_height ); }
f91de7da 693
11e82c1b 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 )
11e82c1b
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
711 inline void Scale( wxInt32 f ) { m_x *= f; m_y *= f; m_width *= f; m_height *= f;}
f91de7da 712 inline void Scale( wxInt32 num , wxInt32 denum )
11e82c1b
VZ
713 { m_x *= ((wxInt32)num)/((wxInt32)denum); m_y *= ((wxInt32)num)/((wxInt32)denum);
714 m_width *= ((wxInt32)num)/((wxInt32)denum); m_height *= ((wxInt32)num)/((wxInt32)denum);}
c3a4297c
VZ
715
716 wxRect2DInt& operator = (const wxRect2DInt& rect);
717 bool operator == (const wxRect2DInt& rect);
718 bool operator != (const wxRect2DInt& rect);
719
11e82c1b
VZ
720 void WriteTo( wxDataOutputStream &stream ) const;
721 void ReadFrom( wxDataInputStream &stream );
c3a4297c 722
11e82c1b
VZ
723 wxInt32 m_x;
724 wxInt32 m_y;
c3a4297c
VZ
725 wxInt32 m_width;
726 wxInt32 m_height;
72e7876b
SC
727};
728
f91de7da
DW
729inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r )
730{
11e82c1b
VZ
731 m_x = r.m_x;
732 m_y = r.m_y;
733 m_width = r.m_width;
734 m_height = r.m_height;
f91de7da
DW
735}
736
737inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b)
738{
11e82c1b
VZ
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 );
f91de7da 743}
72e7876b
SC
744
745class wxTransform2D
746{
747public :
11e82c1b
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 ;
c3a4297c
VZ
752
753 virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
11e82c1b
VZ
754 virtual void InverseTransform( wxRect2DInt* r ) const ;
755 virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
756 virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
757};
72e7876b 758
f91de7da 759inline void wxTransform2D::Transform( wxRect2DInt* r ) const
11e82c1b 760 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); Transform( &a ); Transform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 761
f91de7da 762inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const
11e82c1b 763 { wxPoint2DInt res = pt; Transform( &res ); return res; }
72e7876b 764
f91de7da 765inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const
11e82c1b 766 { wxRect2DInt res = r; Transform( &res ); return res; }
72e7876b 767
f91de7da 768inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const
11e82c1b 769 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom(); InverseTransform( &a ); InverseTransform( &b ); *r = wxRect2DInt( a , b ); }
72e7876b 770
f91de7da 771inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const
11e82c1b 772 { wxPoint2DInt res = pt; InverseTransform( &res ); return res; }
72e7876b 773
f91de7da 774inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const
11e82c1b 775 { wxRect2DInt res = r; InverseTransform( &res ); return res; }
72e7876b 776
c3a4297c
VZ
777
778#endif // wxUSE_GEOMETRY
779
780#endif // _WX_GEOMETRY_H_