1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common Geometry Classes
4 // Author: Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GEOMETRY__
13 #define _WX_GEOMETRY__
16 #pragma interface "geometry.h"
21 #include "wx/gdicmn.h"
25 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
26 #elif defined( __WXMAC__ )
28 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
30 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
33 class wxDataInputStream
;
34 class wxDataOutputStream
;
36 // clipping from Cohen-Sutherland
47 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
49 class WXDLLEXPORT wxPoint2DDouble
53 wxPoint2DDouble( wxDouble x
, wxDouble y
) ;
54 wxPoint2DDouble( const wxPoint2DDouble
&pt
) ;
56 // two different conversions to integers, floor and rounding
57 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
58 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
60 wxDouble
GetVectorLength() ;
61 wxDouble
GetVectorAngle() ;
62 void SetVectorLength( wxDouble length
) ;
63 void SetVectorAngle( wxDouble degrees
) ;
64 void SetPolarCoordinates( wxDouble angle
, wxDouble length
) ;
65 // set the vector length to 1.0, preserving the angle
68 wxDouble
GetDistance( const wxPoint2DDouble
&pt
) ;
69 wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) ;
70 wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) ;
71 wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) ;
73 // the reflection of this point
74 wxPoint2DDouble
operator-() ;
76 wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
) ;
77 wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
) ;
78 wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
) ;
79 wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
) ;
80 wxPoint2DDouble
& operator*=(wxDouble n
) ;
81 wxPoint2DDouble
& operator*=(wxInt32 n
) ;
82 wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
) ;
83 wxPoint2DDouble
& operator/=(wxDouble n
) ;
84 wxPoint2DDouble
& operator/=(wxInt32 n
) ;
86 bool operator==(const wxPoint2DDouble
& pt
) const ;
87 bool operator!=(const wxPoint2DDouble
& pt
) const ;
93 wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
94 wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
95 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
96 wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
) ;
97 wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
) ;
98 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
) ;
99 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
100 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
101 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
) ;
102 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
104 inline wxPoint2DDouble::wxPoint2DDouble()
110 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
116 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
122 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
)
124 *x
= (wxInt32
) floor( m_x
) ;
125 *y
= (wxInt32
) floor( m_y
) ;
128 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
)
130 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
131 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
134 inline wxDouble
wxPoint2DDouble::GetVectorLength() ;
135 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
) ;
136 inline wxDouble
wxPoint2DDouble::GetVectorAngle() ;
137 inline void wxPoint2DDouble::SetVectorAngle( wxDouble degrees
) ;
138 inline void wxPoint2DDouble::SetPolarCoordinates( wxDouble angle
, wxDouble length
) ;
139 inline void wxPoint2DDouble::Normalize() ;
141 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
)
143 return sqrt( GetDistanceSquare( pt
) );
146 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
)
148 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
151 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
)
153 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
156 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
)
158 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
161 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
163 return wxPoint2DDouble( -m_x
, -m_y
);
166 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
173 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
180 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
187 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
194 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
201 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
203 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
206 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
208 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
211 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
213 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
216 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
218 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
222 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
224 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
227 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
229 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
232 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
234 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
237 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
239 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
242 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
244 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
247 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
249 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
252 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
254 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
257 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
259 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
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
263 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
264 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
266 class WXDLLEXPORT wxRect2DDouble
269 wxRect2DDouble() { m_x
= m_y
= m_width
= m_height
= 0 ; }
270 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
271 wxRect2DDouble(const wxPoint2DDouble
& topLeft
, const wxPoint2DDouble
& bottomRight
);
272 wxRect2DDouble(const wxPoint2DDouble
& pos
, const wxSize
& size
);
273 wxRect2DDouble(const wxRect2DDouble
& rect
);
275 // single attribute accessors
277 inline wxPoint2DDouble
GetPosition() { return wxPoint2DDouble(m_x
, m_y
); }
278 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
280 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
281 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
283 inline wxDouble
GetLeft() const { return m_x
; }
284 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
285 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
286 inline wxDouble
GetTop() const { return m_y
; }
287 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
288 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
289 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
290 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
) ;}
291 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
292 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
293 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
294 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
296 inline wxPoint2DDouble
GetLeftTop() const { return wxPoint2DDouble( m_x
, m_y
) ; }
297 inline void SetLeftTop( const wxPoint2DDouble
&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
; }
298 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
299 inline wxPoint2DDouble
GetLeftBottom() const { return wxPoint2DDouble( m_x
, m_y
+ m_height
) ; }
300 inline void SetLeftBottom( const wxPoint2DDouble
&pt
) { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
301 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
302 inline wxPoint2DDouble
GetRightTop() const { return wxPoint2DDouble( m_x
+m_width
, m_y
) ; }
303 inline void SetRightTop( const wxPoint2DDouble
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
304 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
305 inline wxPoint2DDouble
GetRightBottom() const { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
) ; }
306 inline void SetRightBottom( const wxPoint2DDouble
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
307 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
308 inline wxPoint2DDouble
GetCentre() const { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
309 inline void SetCentre( const wxPoint2DDouble
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
310 inline void MoveCentreTo( const wxPoint2DDouble
&pt
) { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2) ; }
311 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
312 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
313 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
314 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
315 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
316 inline bool Contains( const wxPoint2DDouble
&pt
) const
317 { return GetOutcode( pt
) == wxInside
; }
318 inline bool Contains( const wxRect2DDouble
&rect
) const
319 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
320 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
321 inline bool IsEmpty() const
322 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
323 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
324 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
326 inline void Inset( wxDouble x
, wxDouble y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
327 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
328 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
329 inline void Offset( const wxPoint2DDouble
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
330 void ConstrainTo( const wxRect2DDouble
&rect
) ;
331 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
333 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
334 inline void Intersect( const wxRect2DDouble
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
335 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
) ; return result
; }
336 bool Intersects( const wxRect2DDouble
&rect
) const ;
338 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
339 void Union( const wxRect2DDouble
&otherRect
) { Union( *this , otherRect
, this ) ; }
340 void Union( const wxPoint2DDouble
&pt
) ;
341 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Union( *this , otherRect
, &result
) ; return result
; }
343 inline void Scale( wxDouble f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
344 inline void Scale( wxInt32 num
, wxInt32 denum
)
345 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;
346 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;}
348 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
349 bool operator == (const wxRect2DDouble
& rect
);
350 bool operator != (const wxRect2DDouble
& rect
);
358 class WXDLLEXPORT wxPoint2DInt
362 wxPoint2DInt( wxInt32 x
, wxInt32 y
) ;
363 wxPoint2DInt( const wxPoint2DInt
&pt
) ;
364 wxPoint2DInt( const wxPoint
&pt
) ;
366 // two different conversions to integers, floor and rounding
367 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
368 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
370 wxDouble
GetVectorLength() ;
371 wxDouble
GetVectorAngle() ;
372 void SetVectorLength( wxDouble length
) ;
373 void SetVectorAngle( wxDouble degrees
) ;
374 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
375 // set the vector length to 1.0, preserving the angle
378 wxDouble
GetDistance( const wxPoint2DInt
&pt
) const ;
379 wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
380 wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
381 wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
383 // the reflection of this point
384 wxPoint2DInt
operator-() ;
386 wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
) ;
387 wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
) ;
388 wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
) ;
389 wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
) ;
390 wxPoint2DInt
& operator*=(wxDouble n
) ;
391 wxPoint2DInt
& operator*=(wxInt32 n
) ;
392 wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
) ;
393 wxPoint2DInt
& operator/=(wxDouble n
) ;
394 wxPoint2DInt
& operator/=(wxInt32 n
) ;
395 operator wxPoint() const ;
396 bool operator==(const wxPoint2DInt
& pt
) const ;
397 bool operator!=(const wxPoint2DInt
& pt
) const ;
399 void WriteTo( wxDataOutputStream
&stream
) const ;
400 void ReadFrom( wxDataInputStream
&stream
) ;
406 wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
407 wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
408 wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
409 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
410 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
411 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
412 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
413 wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
414 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
415 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
417 inline wxPoint2DInt::wxPoint2DInt()
423 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
429 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
435 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
441 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
443 *x
= (wxInt32
) floor( m_x
) ;
444 *y
= (wxInt32
) floor( m_y
) ;
447 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
449 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
450 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
453 inline wxDouble
wxPoint2DInt::GetVectorLength()
455 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
458 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
460 wxDouble before
= GetVectorLength() ;
461 m_x
= (wxInt32
)(m_x
* length
/ before
) ;
462 m_y
= (wxInt32
)(m_y
* length
/ before
) ;
465 inline void wxPoint2DInt::SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
466 inline void wxPoint2DInt::Normalize()
468 SetVectorLength( 1 ) ;
471 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
473 return sqrt( GetDistanceSquare( pt
) );
476 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
478 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
481 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
483 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
486 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
488 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
491 inline wxPoint2DInt::operator wxPoint() const
493 return wxPoint( m_x
, m_y
);
496 inline wxPoint2DInt
wxPoint2DInt::operator-()
498 return wxPoint2DInt( -m_x
, -m_y
);
501 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
508 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
515 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
522 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
529 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
536 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
538 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
541 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
543 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
546 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
548 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
551 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
553 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
557 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
559 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
562 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
564 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
567 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
569 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
572 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
574 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
577 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
579 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
582 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
584 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
587 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
589 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
592 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
594 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
597 // 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
598 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
599 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
601 class WXDLLEXPORT wxRect2DInt
604 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0 ; }
605 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
606 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
607 wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
608 wxRect2DInt(const wxRect2DInt
& rect
);
610 // single attribute accessors
612 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
613 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
615 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
616 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
618 inline wxInt32
GetLeft() const { return m_x
; }
619 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
620 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
621 inline wxInt32
GetTop() const { return m_y
; }
622 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
623 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
624 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
625 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
) ;}
626 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
627 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
628 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
629 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
631 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
) ; }
632 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
; }
633 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
634 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
) ; }
635 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
; }
636 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
637 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
) ; }
638 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
; }
639 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
640 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
) ; }
641 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
642 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
643 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
644 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
645 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) ; }
646 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
647 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
648 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
649 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
650 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
651 inline bool Contains( const wxPoint2DInt
&pt
) const
652 { return GetOutcode( pt
) == wxInside
; }
653 inline bool Contains( const wxRect2DInt
&rect
) const
654 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
655 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
656 inline bool IsEmpty() const
657 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
658 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
659 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
661 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
662 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
663 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
664 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
665 void ConstrainTo( const wxRect2DInt
&rect
) ;
666 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
668 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
669 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
670 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
) ; return result
; }
671 bool Intersects( const wxRect2DInt
&rect
) const ;
673 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
674 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ) ; }
675 void Union( const wxPoint2DInt
&pt
) ;
676 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
) ; return result
; }
678 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
679 inline void Scale( wxInt32 num
, wxInt32 denum
)
680 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;
681 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;}
683 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
684 bool operator == (const wxRect2DInt
& rect
);
685 bool operator != (const wxRect2DInt
& rect
);
687 void WriteTo( wxDataOutputStream
&stream
) const ;
688 void ReadFrom( wxDataInputStream
&stream
) ;
696 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
700 m_width
= r
.m_width
;
701 m_height
= r
.m_height
;
704 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
706 m_x
= wxMin( a
.m_x
, b
.m_x
) ;
707 m_y
= wxMin( a
.m_y
, b
.m_y
) ;
708 m_width
= abs( a
.m_x
- b
.m_x
) ;
709 m_height
= abs( a
.m_y
- b
.m_y
) ;
715 virtual void Transform( wxPoint2DInt
* pt
)const = 0 ;
716 virtual void Transform( wxRect2DInt
* r
) const ;
717 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const ;
718 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
720 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
721 virtual void InverseTransform( wxRect2DInt
* r
) const ;
722 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
723 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
726 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
727 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; Transform( &a
) ; Transform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
729 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
730 { wxPoint2DInt res
= pt
; Transform( &res
) ; return res
; }
732 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
733 { wxRect2DInt res
= r
; Transform( &res
) ; return res
; }
735 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
736 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; InverseTransform( &a
) ; InverseTransform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
738 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
739 { wxPoint2DInt res
= pt
; InverseTransform( &res
) ; return res
; }
741 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
742 { wxRect2DInt res
= r
; InverseTransform( &res
) ; return res
; }