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"
20 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
21 #elif defined( __WXMAC__ )
23 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
25 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
28 class wxDataInputStream
;
29 class wxDataOutputStream
;
31 // clipping from Cohen-Sutherland
42 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
44 class WXDLLEXPORT wxPoint2DDouble
48 wxPoint2DDouble( wxDouble x
, wxDouble y
) ;
49 wxPoint2DDouble( const wxPoint2DDouble
&pt
) ;
51 // two different conversions to integers, floor and rounding
52 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
53 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
55 wxDouble
GetVectorLength() ;
56 wxDouble
GetVectorAngle() ;
57 void SetVectorLength( wxDouble length
) ;
58 void SetVectorAngle( wxDouble degrees
) ;
59 void SetPolarCoordinates( wxDouble angle
, wxDouble length
) ;
60 // set the vector length to 1.0, preserving the angle
63 wxDouble
GetDistance( const wxPoint2DDouble
&pt
) ;
64 wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) ;
65 wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) ;
66 wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) ;
68 // the reflection of this point
69 wxPoint2DDouble
operator-() ;
71 wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
) ;
72 wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
) ;
73 wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
) ;
74 wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
) ;
75 wxPoint2DDouble
& operator*=(wxDouble n
) ;
76 wxPoint2DDouble
& operator*=(wxInt32 n
) ;
77 wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
) ;
78 wxPoint2DDouble
& operator/=(wxDouble n
) ;
79 wxPoint2DDouble
& operator/=(wxInt32 n
) ;
81 bool operator==(const wxPoint2DDouble
& pt
) const ;
82 bool operator!=(const wxPoint2DDouble
& pt
) const ;
88 wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
89 wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
90 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
91 wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
) ;
92 wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
) ;
93 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
) ;
94 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
95 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
96 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
) ;
97 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
99 inline wxPoint2DDouble::wxPoint2DDouble()
105 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
111 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
117 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
)
119 *x
= (wxInt32
) floor( m_x
) ;
120 *y
= (wxInt32
) floor( m_y
) ;
123 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
)
125 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
126 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
129 inline wxDouble
wxPoint2DDouble::GetVectorLength() ;
130 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
) ;
131 inline wxDouble
wxPoint2DDouble::GetVectorAngle() ;
132 inline void wxPoint2DDouble::SetVectorAngle( wxDouble degrees
) ;
133 inline void wxPoint2DDouble::SetPolarCoordinates( wxDouble angle
, wxDouble length
) ;
134 inline void wxPoint2DDouble::Normalize() ;
136 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
)
138 return sqrt( GetDistanceSquare( pt
) );
141 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
)
143 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
146 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
)
148 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
151 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
)
153 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
156 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
158 return wxPoint2DDouble( -m_x
, -m_y
);
161 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
168 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
175 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
182 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
189 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
196 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
198 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
201 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
203 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
206 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
208 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.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
) ;
217 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
219 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
222 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
224 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
227 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
229 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
232 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
234 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
237 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
239 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
242 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
244 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
247 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
249 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
252 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
254 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
257 // 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
258 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
259 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
261 class WXDLLEXPORT wxRect2DDouble
264 wxRect2DDouble() { m_x
= m_y
= m_width
= m_height
= 0 ; }
265 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
266 wxRect2DDouble(const wxPoint2DDouble
& topLeft
, const wxPoint2DDouble
& bottomRight
);
267 wxRect2DDouble(const wxPoint2DDouble
& pos
, const wxSize
& size
);
268 wxRect2DDouble(const wxRect2DDouble
& rect
);
270 // single attribute accessors
272 inline wxPoint2DDouble
GetPosition() { return wxPoint2DDouble(m_x
, m_y
); }
273 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
275 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
276 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
278 inline wxDouble
GetLeft() const { return m_x
; }
279 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
280 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
281 inline wxDouble
GetTop() const { return m_y
; }
282 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
283 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
284 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
285 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
) ;}
286 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
287 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
288 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
289 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
291 inline wxPoint2DDouble
GetLeftTop() const { return wxPoint2DDouble( m_x
, m_y
) ; }
292 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
; }
293 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
294 inline wxPoint2DDouble
GetLeftBottom() const { return wxPoint2DDouble( m_x
, m_y
+ m_height
) ; }
295 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
; }
296 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
297 inline wxPoint2DDouble
GetRightTop() const { return wxPoint2DDouble( m_x
+m_width
, m_y
) ; }
298 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
; }
299 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
300 inline wxPoint2DDouble
GetRightBottom() const { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
) ; }
301 inline void SetRightBottom( const wxPoint2DDouble
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
302 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
303 inline wxPoint2DDouble
GetCentre() const { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
304 inline void SetCentre( const wxPoint2DDouble
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
305 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) ; }
306 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
307 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
308 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
309 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
310 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
311 inline bool Contains( const wxPoint2DDouble
&pt
) const
312 { return GetOutcode( pt
) == wxInside
; }
313 inline bool Contains( const wxRect2DDouble
&rect
) const
314 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
315 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
316 inline bool IsEmpty() const
317 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
318 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
319 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
321 inline void Inset( wxDouble x
, wxDouble y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
322 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
323 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
324 inline void Offset( const wxPoint2DDouble
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
325 void ConstrainTo( const wxRect2DDouble
&rect
) ;
326 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
328 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
329 inline void Intersect( const wxRect2DDouble
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
330 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
) ; return result
; }
331 bool Intersects( const wxRect2DDouble
&rect
) const ;
333 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
334 void Union( const wxRect2DDouble
&otherRect
) { Union( *this , otherRect
, this ) ; }
335 void Union( const wxPoint2DDouble
&pt
) ;
336 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Union( *this , otherRect
, &result
) ; return result
; }
338 inline void Scale( wxDouble f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
339 inline void Scale( wxInt32 num
, wxInt32 denum
)
340 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;
341 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;}
343 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
344 bool operator == (const wxRect2DDouble
& rect
);
345 bool operator != (const wxRect2DDouble
& rect
);
353 class WXDLLEXPORT wxPoint2DInt
357 wxPoint2DInt( wxInt32 x
, wxInt32 y
) ;
358 wxPoint2DInt( const wxPoint2DInt
&pt
) ;
359 wxPoint2DInt( const wxPoint
&pt
) ;
361 // two different conversions to integers, floor and rounding
362 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
363 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
365 wxDouble
GetVectorLength() ;
366 wxDouble
GetVectorAngle() ;
367 void SetVectorLength( wxDouble length
) ;
368 void SetVectorAngle( wxDouble degrees
) ;
369 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
370 // set the vector length to 1.0, preserving the angle
373 wxDouble
GetDistance( const wxPoint2DInt
&pt
) const ;
374 wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
375 wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
376 wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
378 // the reflection of this point
379 wxPoint2DInt
operator-() ;
381 wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
) ;
382 wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
) ;
383 wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
) ;
384 wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
) ;
385 wxPoint2DInt
& operator*=(wxDouble n
) ;
386 wxPoint2DInt
& operator*=(wxInt32 n
) ;
387 wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
) ;
388 wxPoint2DInt
& operator/=(wxDouble n
) ;
389 wxPoint2DInt
& operator/=(wxInt32 n
) ;
390 operator wxPoint() const ;
391 bool operator==(const wxPoint2DInt
& pt
) const ;
392 bool operator!=(const wxPoint2DInt
& pt
) const ;
394 void WriteTo( wxDataOutputStream
&stream
) const ;
395 void ReadFrom( wxDataInputStream
&stream
) ;
401 wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
402 wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
403 wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
404 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
405 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
406 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
407 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
408 wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
409 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
410 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
412 inline wxPoint2DInt::wxPoint2DInt()
418 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
424 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
430 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
436 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
438 *x
= (wxInt32
) floor( m_x
) ;
439 *y
= (wxInt32
) floor( m_y
) ;
442 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
444 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
445 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
448 inline wxDouble
wxPoint2DInt::GetVectorLength()
450 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
453 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
455 wxDouble before
= GetVectorLength() ;
456 m_x
*= length
/ before
;
457 m_y
*= length
/ before
;
460 inline void wxPoint2DInt::SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
461 inline void wxPoint2DInt::Normalize()
463 SetVectorLength( 1 ) ;
466 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
468 return sqrt( GetDistanceSquare( pt
) );
471 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
473 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
476 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
478 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
481 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
483 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
486 inline wxPoint2DInt::operator wxPoint() const
488 return wxPoint( m_x
, m_y
);
491 inline wxPoint2DInt
wxPoint2DInt::operator-()
493 return wxPoint2DInt( -m_x
, -m_y
);
496 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
503 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
510 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
517 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
524 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
531 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
533 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
536 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
538 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
541 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
543 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.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
) ;
552 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
554 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
557 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
559 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
562 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
564 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
567 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
569 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
572 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
574 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
577 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
579 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
582 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
584 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
587 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
589 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
592 // 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
593 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
594 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
596 class WXDLLEXPORT wxRect2DInt
599 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0 ; }
600 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
601 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
602 wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
603 wxRect2DInt(const wxRect2DInt
& rect
);
605 // single attribute accessors
607 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
608 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
610 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
611 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
613 inline wxInt32
GetLeft() const { return m_x
; }
614 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
615 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
616 inline wxInt32
GetTop() const { return m_y
; }
617 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
618 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
619 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
620 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
) ;}
621 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
622 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
623 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
624 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
626 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
) ; }
627 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
; }
628 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
629 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
) ; }
630 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
; }
631 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
632 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
) ; }
633 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
; }
634 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
635 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
) ; }
636 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
637 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
638 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
639 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
640 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) ; }
641 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
642 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
643 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
644 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
645 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
646 inline bool Contains( const wxPoint2DInt
&pt
) const
647 { return GetOutcode( pt
) == wxInside
; }
648 inline bool Contains( const wxRect2DInt
&rect
) const
649 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
650 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
651 inline bool IsEmpty() const
652 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
653 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
654 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
656 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
657 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
658 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
659 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
660 void ConstrainTo( const wxRect2DInt
&rect
) ;
661 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
663 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
664 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
665 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
) ; return result
; }
666 bool Intersects( const wxRect2DInt
&rect
) const ;
668 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
669 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ) ; }
670 void Union( const wxPoint2DInt
&pt
) ;
671 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
) ; return result
; }
673 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
674 inline void Scale( wxInt32 num
, wxInt32 denum
)
675 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;
676 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;}
678 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
679 bool operator == (const wxRect2DInt
& rect
);
680 bool operator != (const wxRect2DInt
& rect
);
682 void WriteTo( wxDataOutputStream
&stream
) const ;
683 void ReadFrom( wxDataInputStream
&stream
) ;
691 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
695 m_width
= r
.m_width
;
696 m_height
= r
.m_height
;
699 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
701 m_x
= wxMin( a
.m_x
, b
.m_x
) ;
702 m_y
= wxMin( a
.m_y
, b
.m_y
) ;
703 m_width
= abs( a
.m_x
- b
.m_x
) ;
704 m_height
= abs( a
.m_y
- b
.m_y
) ;
710 virtual void Transform( wxPoint2DInt
* pt
)const = 0 ;
711 virtual void Transform( wxRect2DInt
* r
) const ;
712 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const ;
713 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
715 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
716 virtual void InverseTransform( wxRect2DInt
* r
) const ;
717 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
718 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
721 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
722 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; Transform( &a
) ; Transform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
724 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
725 { wxPoint2DInt res
= pt
; Transform( &res
) ; return res
; }
727 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
728 { wxRect2DInt res
= r
; Transform( &res
) ; return res
; }
730 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
731 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; InverseTransform( &a
) ; InverseTransform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
733 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
734 { wxPoint2DInt res
= pt
; InverseTransform( &res
) ; return res
; }
736 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
737 { wxRect2DInt res
= r
; InverseTransform( &res
) ; return res
; }