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.h"
24 #include "wx/gdicmn.h"
28 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
29 #elif defined( __WXMAC__ )
31 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
33 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
36 class wxDataInputStream
;
37 class wxDataOutputStream
;
39 // clipping from Cohen-Sutherland
50 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
52 class WXDLLEXPORT wxPoint2DDouble
56 wxPoint2DDouble( wxDouble x
, wxDouble y
) ;
57 wxPoint2DDouble( const wxPoint2DDouble
&pt
) ;
59 // two different conversions to integers, floor and rounding
60 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
61 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
63 wxDouble
GetVectorLength() ;
64 wxDouble
GetVectorAngle() ;
65 void SetVectorLength( wxDouble length
) ;
66 void SetVectorAngle( wxDouble degrees
) ;
67 void SetPolarCoordinates( wxDouble angle
, wxDouble length
) ;
68 // set the vector length to 1.0, preserving the angle
71 wxDouble
GetDistance( const wxPoint2DDouble
&pt
) ;
72 wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) ;
73 wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) ;
74 wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) ;
76 // the reflection of this point
77 wxPoint2DDouble
operator-() ;
79 wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
) ;
80 wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
) ;
81 wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
) ;
82 wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
) ;
83 wxPoint2DDouble
& operator*=(wxDouble n
) ;
84 wxPoint2DDouble
& operator*=(wxInt32 n
) ;
85 wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
) ;
86 wxPoint2DDouble
& operator/=(wxDouble n
) ;
87 wxPoint2DDouble
& operator/=(wxInt32 n
) ;
89 bool operator==(const wxPoint2DDouble
& pt
) const ;
90 bool operator!=(const wxPoint2DDouble
& pt
) const ;
96 wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
97 wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
98 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
99 wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
) ;
100 wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
) ;
101 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
) ;
102 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
103 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
104 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
) ;
105 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
107 inline wxPoint2DDouble::wxPoint2DDouble()
113 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
119 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
125 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
)
127 *x
= (wxInt32
) floor( m_x
) ;
128 *y
= (wxInt32
) floor( m_y
) ;
131 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
)
133 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
134 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
137 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
)
139 return sqrt( GetDistanceSquare( pt
) );
142 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
)
144 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
147 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
)
149 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
152 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
)
154 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
157 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
159 return wxPoint2DDouble( -m_x
, -m_y
);
162 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
169 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
176 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
183 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
190 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
197 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
199 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
202 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
204 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
207 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
209 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
212 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
214 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
218 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
220 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
223 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
225 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
228 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
230 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
233 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
235 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
238 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
240 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
243 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
245 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
248 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
250 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
253 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
255 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
258 // 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
259 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
260 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
262 class WXDLLEXPORT wxRect2DDouble
265 wxRect2DDouble() { m_x
= m_y
= m_width
= m_height
= 0 ; }
266 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
267 wxRect2DDouble(const wxPoint2DDouble
& topLeft
, const wxPoint2DDouble
& bottomRight
);
268 wxRect2DDouble(const wxPoint2DDouble
& pos
, const wxSize
& size
);
269 wxRect2DDouble(const wxRect2DDouble
& rect
);
271 // single attribute accessors
273 inline wxPoint2DDouble
GetPosition() { return wxPoint2DDouble(m_x
, m_y
); }
274 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
276 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
277 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
279 inline wxDouble
GetLeft() const { return m_x
; }
280 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
281 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
282 inline wxDouble
GetTop() const { return m_y
; }
283 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
284 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
285 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
286 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
) ;}
287 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
288 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
289 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
290 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
292 inline wxPoint2DDouble
GetLeftTop() const { return wxPoint2DDouble( m_x
, m_y
) ; }
293 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
; }
294 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
295 inline wxPoint2DDouble
GetLeftBottom() const { return wxPoint2DDouble( m_x
, m_y
+ m_height
) ; }
296 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
; }
297 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
298 inline wxPoint2DDouble
GetRightTop() const { return wxPoint2DDouble( m_x
+m_width
, m_y
) ; }
299 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
; }
300 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
301 inline wxPoint2DDouble
GetRightBottom() const { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
) ; }
302 inline void SetRightBottom( const wxPoint2DDouble
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
303 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
304 inline wxPoint2DDouble
GetCentre() const { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
305 inline void SetCentre( const wxPoint2DDouble
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
306 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) ; }
307 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
308 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
309 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
310 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
311 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
312 inline bool Contains( const wxPoint2DDouble
&pt
) const
313 { return GetOutcode( pt
) == wxInside
; }
314 inline bool Contains( const wxRect2DDouble
&rect
) const
315 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
316 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
317 inline bool IsEmpty() const
318 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
319 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
320 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
322 inline void Inset( wxDouble x
, wxDouble y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
323 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
324 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
325 inline void Offset( const wxPoint2DDouble
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
326 void ConstrainTo( const wxRect2DDouble
&rect
) ;
327 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
329 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
330 inline void Intersect( const wxRect2DDouble
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
331 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
) ; return result
; }
332 bool Intersects( const wxRect2DDouble
&rect
) const ;
334 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
335 void Union( const wxRect2DDouble
&otherRect
) { Union( *this , otherRect
, this ) ; }
336 void Union( const wxPoint2DDouble
&pt
) ;
337 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Union( *this , otherRect
, &result
) ; return result
; }
339 inline void Scale( wxDouble f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
340 inline void Scale( wxInt32 num
, wxInt32 denum
)
341 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;
342 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;}
344 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
345 bool operator == (const wxRect2DDouble
& rect
);
346 bool operator != (const wxRect2DDouble
& rect
);
354 class WXDLLEXPORT wxPoint2DInt
358 wxPoint2DInt( wxInt32 x
, wxInt32 y
) ;
359 wxPoint2DInt( const wxPoint2DInt
&pt
) ;
360 wxPoint2DInt( const wxPoint
&pt
) ;
362 // two different conversions to integers, floor and rounding
363 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
364 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
366 wxDouble
GetVectorLength() ;
367 wxDouble
GetVectorAngle() ;
368 void SetVectorLength( wxDouble length
) ;
369 void SetVectorAngle( wxDouble degrees
) ;
370 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
371 // set the vector length to 1.0, preserving the angle
374 wxDouble
GetDistance( const wxPoint2DInt
&pt
) const ;
375 wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
376 wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
377 wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
379 // the reflection of this point
380 wxPoint2DInt
operator-() ;
382 wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
) ;
383 wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
) ;
384 wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
) ;
385 wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
) ;
386 wxPoint2DInt
& operator*=(wxDouble n
) ;
387 wxPoint2DInt
& operator*=(wxInt32 n
) ;
388 wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
) ;
389 wxPoint2DInt
& operator/=(wxDouble n
) ;
390 wxPoint2DInt
& operator/=(wxInt32 n
) ;
391 operator wxPoint() const ;
392 bool operator==(const wxPoint2DInt
& pt
) const ;
393 bool operator!=(const wxPoint2DInt
& pt
) const ;
395 void WriteTo( wxDataOutputStream
&stream
) const ;
396 void ReadFrom( wxDataInputStream
&stream
) ;
402 wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
403 wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
404 wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
405 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
406 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
407 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
408 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
409 wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
410 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
411 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
413 inline wxPoint2DInt::wxPoint2DInt()
419 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
425 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
431 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
437 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
439 *x
= (wxInt32
) floor( m_x
) ;
440 *y
= (wxInt32
) floor( m_y
) ;
443 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
445 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
446 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
449 inline wxDouble
wxPoint2DInt::GetVectorLength()
451 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
454 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
456 wxDouble before
= GetVectorLength() ;
457 m_x
= (wxInt32
)(m_x
* length
/ before
) ;
458 m_y
= (wxInt32
)(m_y
* length
/ before
) ;
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
; }
740 #endif // wxUSE_GEOMETRY
742 #endif // _WX_GEOMETRY_H_