1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common Geometry Classes
4 // Author: Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GEOMETRY_H_
13 #define _WX_GEOMETRY_H_
16 #pragma interface "geometry.cpp"
21 #ifndef wxUSE_GEOMETRY
22 #define wxUSE_GEOMETRY 0
28 #include "wx/gdicmn.h"
32 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
33 #elif defined( __WXMAC__ )
35 #include <CarbonCore/Math64.h>
39 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
41 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
44 class wxDataInputStream
;
45 class wxDataOutputStream
;
47 // clipping from Cohen-Sutherland
58 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
60 class WXDLLEXPORT wxPoint2DDouble
64 wxPoint2DDouble( wxDouble x
, wxDouble y
) ;
65 wxPoint2DDouble( const wxPoint2DDouble
&pt
) ;
67 // two different conversions to integers, floor and rounding
68 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
69 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
71 wxDouble
GetVectorLength() ;
72 wxDouble
GetVectorAngle() ;
73 void SetVectorLength( wxDouble length
) ;
74 void SetVectorAngle( wxDouble degrees
) ;
75 void SetPolarCoordinates( wxDouble angle
, wxDouble length
) ;
76 // set the vector length to 1.0, preserving the angle
79 wxDouble
GetDistance( const wxPoint2DDouble
&pt
) ;
80 wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) ;
81 wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) ;
82 wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) ;
84 // the reflection of this point
85 wxPoint2DDouble
operator-() ;
87 wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
) ;
88 wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
) ;
89 wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
) ;
90 wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
) ;
91 wxPoint2DDouble
& operator*=(wxDouble n
) ;
92 wxPoint2DDouble
& operator*=(wxInt32 n
) ;
93 wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
) ;
94 wxPoint2DDouble
& operator/=(wxDouble n
) ;
95 wxPoint2DDouble
& operator/=(wxInt32 n
) ;
97 bool operator==(const wxPoint2DDouble
& pt
) const ;
98 bool operator!=(const wxPoint2DDouble
& pt
) const ;
104 wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
105 wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
106 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
107 wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
) ;
108 wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
) ;
109 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
) ;
110 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
111 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
112 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
) ;
113 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
115 inline wxPoint2DDouble::wxPoint2DDouble()
121 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
127 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
133 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
)
135 *x
= (wxInt32
) floor( m_x
) ;
136 *y
= (wxInt32
) floor( m_y
) ;
139 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
)
141 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
142 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
145 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
)
147 return sqrt( GetDistanceSquare( pt
) );
150 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
)
152 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
155 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
)
157 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
160 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
)
162 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
165 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
167 return wxPoint2DDouble( -m_x
, -m_y
);
170 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
177 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
184 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
191 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
198 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
205 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
207 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
210 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
212 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
215 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
217 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
220 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
222 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
226 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
228 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
231 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
233 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
236 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
238 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
241 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
243 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
246 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
248 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
251 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
253 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
256 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
258 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
261 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
263 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
266 // 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
267 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
268 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
270 class WXDLLEXPORT wxRect2DDouble
274 { m_x
= m_y
= m_width
= m_height
= 0 ; }
275 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
276 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
278 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
279 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
280 wxRect2DDouble(const wxRect2DDouble& rect);
282 // single attribute accessors
284 inline wxPoint2DDouble
GetPosition()
285 { return wxPoint2DDouble(m_x
, m_y
); }
286 inline wxSize
GetSize()
287 { return wxSize((int) m_width
, (int) m_height
); }
289 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
290 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
292 inline wxDouble
GetLeft() const { return m_x
; }
293 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
294 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
295 inline wxDouble
GetTop() const { return m_y
; }
296 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
297 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
298 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
299 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
) ;}
300 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
301 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
302 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
303 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
305 inline wxPoint2DDouble
GetLeftTop() const
306 { return wxPoint2DDouble( m_x
, m_y
) ; }
307 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
308 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
309 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
310 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
311 inline wxPoint2DDouble
GetLeftBottom() const
312 { return wxPoint2DDouble( m_x
, m_y
+ m_height
) ; }
313 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
314 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
315 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
316 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
317 inline wxPoint2DDouble
GetRightTop() const
318 { return wxPoint2DDouble( m_x
+m_width
, m_y
) ; }
319 inline void SetRightTop( const wxPoint2DDouble
&pt
)
320 { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
321 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
322 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
323 inline wxPoint2DDouble
GetRightBottom() const
324 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
) ; }
325 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
326 { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
327 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
328 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
329 inline wxPoint2DDouble
GetCentre() const
330 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
331 inline void SetCentre( const wxPoint2DDouble
&pt
)
332 { MoveCentreTo( pt
) ; } // since this is impossible without moving...
333 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
334 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2) ; }
335 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
336 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
337 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
338 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
339 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
340 inline bool Contains( const wxPoint2DDouble
&pt
) const
341 { return GetOutcode( pt
) == wxInside
; }
342 inline bool Contains( const wxRect2DDouble
&rect
) const
343 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
344 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
345 inline bool IsEmpty() const
346 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
347 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
348 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
350 inline void Inset( wxDouble x
, wxDouble y
)
351 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
352 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
353 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
354 inline void Offset( const wxPoint2DDouble
&pt
)
355 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
357 void ConstrainTo( const wxRect2DDouble
&rect
);
359 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
360 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
362 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
363 inline void Intersect( const wxRect2DDouble
&otherRect
)
364 { Intersect( *this , otherRect
, this ) ; }
365 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
366 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
) ; return result
; }
367 bool Intersects( const wxRect2DDouble
&rect
) const ;
369 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
370 void Union( const wxRect2DDouble
&otherRect
)
371 { Union( *this , otherRect
, this ) ; }
372 void Union( const wxPoint2DDouble
&pt
) ;
373 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
374 { wxRect2DDouble result
; Union( *this , otherRect
, &result
) ; return result
; }
376 inline void Scale( wxDouble f
)
377 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
378 inline void Scale( wxInt32 num
, wxInt32 denum
)
379 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;
380 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;}
383 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
384 bool operator == (const wxRect2DDouble& rect);
385 bool operator != (const wxRect2DDouble& rect);
394 class WXDLLEXPORT wxPoint2DInt
398 wxPoint2DInt( wxInt32 x
, wxInt32 y
) ;
399 wxPoint2DInt( const wxPoint2DInt
&pt
) ;
400 wxPoint2DInt( const wxPoint
&pt
) ;
402 // two different conversions to integers, floor and rounding
403 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
404 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
406 wxDouble
GetVectorLength() ;
407 wxDouble
GetVectorAngle() ;
408 void SetVectorLength( wxDouble length
) ;
409 void SetVectorAngle( wxDouble degrees
) ;
410 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
411 // set the vector length to 1.0, preserving the angle
414 wxDouble
GetDistance( const wxPoint2DInt
&pt
) const ;
415 wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
416 wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
417 wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
419 // the reflection of this point
420 wxPoint2DInt
operator-() ;
422 wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
) ;
423 wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
) ;
424 wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
) ;
425 wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
) ;
426 wxPoint2DInt
& operator*=(wxDouble n
) ;
427 wxPoint2DInt
& operator*=(wxInt32 n
) ;
428 wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
) ;
429 wxPoint2DInt
& operator/=(wxDouble n
) ;
430 wxPoint2DInt
& operator/=(wxInt32 n
) ;
431 operator wxPoint() const ;
432 bool operator==(const wxPoint2DInt
& pt
) const ;
433 bool operator!=(const wxPoint2DInt
& pt
) const ;
435 void WriteTo( wxDataOutputStream
&stream
) const ;
436 void ReadFrom( wxDataInputStream
&stream
) ;
442 wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
443 wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
444 wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
445 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
446 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
447 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
448 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
449 wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
450 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
451 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
453 inline wxPoint2DInt::wxPoint2DInt()
459 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
465 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
471 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
477 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
479 *x
= (wxInt32
) floor( m_x
) ;
480 *y
= (wxInt32
) floor( m_y
) ;
483 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
485 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
486 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
489 inline wxDouble
wxPoint2DInt::GetVectorLength()
491 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
494 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
496 wxDouble before
= GetVectorLength() ;
497 m_x
= (wxInt32
)(m_x
* length
/ before
) ;
498 m_y
= (wxInt32
)(m_y
* length
/ before
) ;
501 inline void wxPoint2DInt::Normalize()
503 SetVectorLength( 1 ) ;
506 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
508 return sqrt( GetDistanceSquare( pt
) );
511 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
513 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
516 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
518 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
521 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
523 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
526 inline wxPoint2DInt::operator wxPoint() const
528 return wxPoint( m_x
, m_y
);
531 inline wxPoint2DInt
wxPoint2DInt::operator-()
533 return wxPoint2DInt( -m_x
, -m_y
);
536 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
543 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
550 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
557 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
564 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
571 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
573 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
576 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
578 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
581 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
583 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
586 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
588 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
592 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
594 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
597 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
599 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
602 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
604 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) ) ;
607 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
609 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
612 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
614 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) ) ;
617 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
619 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
622 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
624 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
627 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
629 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) ) ;
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
633 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
634 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
636 class WXDLLEXPORT wxRect2DInt
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
; }
641 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
642 wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
643 wxRect2DInt(const wxRect2DInt
& rect
);
645 // single attribute accessors
647 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
648 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
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
653 inline wxInt32
GetLeft() const { return m_x
; }
654 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
655 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
656 inline wxInt32
GetTop() const { return m_y
; }
657 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
658 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
659 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
660 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
) ;}
661 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
662 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
663 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
664 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
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) ; }
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 ) +
685 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
686 inline bool Contains( const wxPoint2DInt
&pt
) const
687 { return GetOutcode( pt
) == wxInside
; }
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
) ) &&
690 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
691 inline bool IsEmpty() const
692 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
693 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
694 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
696 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
697 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
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
) ; }
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 ;
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
; }
713 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
714 inline void Scale( wxInt32 num
, wxInt32 denum
)
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
) ;}
718 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
719 bool operator == (const wxRect2DInt
& rect
);
720 bool operator != (const wxRect2DInt
& rect
);
722 void WriteTo( wxDataOutputStream
&stream
) const ;
723 void ReadFrom( wxDataInputStream
&stream
) ;
731 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
735 m_width
= r
.m_width
;
736 m_height
= r
.m_height
;
739 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
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
) ;
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 ;
755 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
756 virtual void InverseTransform( wxRect2DInt
* r
) const ;
757 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
758 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
761 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
762 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; Transform( &a
) ; Transform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
764 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
765 { wxPoint2DInt res
= pt
; Transform( &res
) ; return res
; }
767 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
768 { wxRect2DInt res
= r
; Transform( &res
) ; return res
; }
770 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
771 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; InverseTransform( &a
) ; InverseTransform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
773 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
774 { wxPoint2DInt res
= pt
; InverseTransform( &res
) ; return res
; }
776 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
777 { wxRect2DInt res
= r
; InverseTransform( &res
) ; return res
; }
780 #endif // wxUSE_GEOMETRY
782 #endif // _WX_GEOMETRY_H_