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"
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
266 { m_x
= m_y
= m_width
= m_height
= 0 ; }
267 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
268 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
270 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
271 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
272 wxRect2DDouble(const wxRect2DDouble& rect);
274 // single attribute accessors
276 inline wxPoint2DDouble
GetPosition()
277 { return wxPoint2DDouble(m_x
, m_y
); }
278 inline wxSize
GetSize()
279 { return wxSize(m_width
, m_height
); }
281 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
282 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
284 inline wxDouble
GetLeft() const { return m_x
; }
285 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
286 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
287 inline wxDouble
GetTop() const { return m_y
; }
288 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
289 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
290 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
291 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
) ;}
292 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
293 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
294 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
295 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
297 inline wxPoint2DDouble
GetLeftTop() const
298 { return wxPoint2DDouble( m_x
, m_y
) ; }
299 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
300 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
301 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
302 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
303 inline wxPoint2DDouble
GetLeftBottom() const
304 { return wxPoint2DDouble( m_x
, m_y
+ m_height
) ; }
305 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
306 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
307 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
308 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
309 inline wxPoint2DDouble
GetRightTop() const
310 { return wxPoint2DDouble( m_x
+m_width
, m_y
) ; }
311 inline void SetRightTop( const wxPoint2DDouble
&pt
)
312 { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
313 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
314 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
315 inline wxPoint2DDouble
GetRightBottom() const
316 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
) ; }
317 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
318 { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
319 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
320 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
321 inline wxPoint2DDouble
GetCentre() const
322 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
323 inline void SetCentre( const wxPoint2DDouble
&pt
)
324 { MoveCentreTo( pt
) ; } // since this is impossible without moving...
325 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
326 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2) ; }
327 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
328 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
329 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
330 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
331 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
332 inline bool Contains( const wxPoint2DDouble
&pt
) const
333 { return GetOutcode( pt
) == wxInside
; }
334 inline bool Contains( const wxRect2DDouble
&rect
) const
335 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
336 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
337 inline bool IsEmpty() const
338 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
339 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
340 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
342 inline void Inset( wxDouble x
, wxDouble y
)
343 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
344 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
345 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
346 inline void Offset( const wxPoint2DDouble
&pt
)
347 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
349 void ConstrainTo( const wxRect2DDouble
&rect
);
351 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
352 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
354 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
355 inline void Intersect( const wxRect2DDouble
&otherRect
)
356 { Intersect( *this , otherRect
, this ) ; }
357 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
358 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
) ; return result
; }
359 bool Intersects( const wxRect2DDouble
&rect
) const ;
361 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
362 void Union( const wxRect2DDouble
&otherRect
)
363 { Union( *this , otherRect
, this ) ; }
364 void Union( const wxPoint2DDouble
&pt
) ;
365 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
366 { wxRect2DDouble result
; Union( *this , otherRect
, &result
) ; return result
; }
368 inline void Scale( wxDouble f
)
369 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
370 inline void Scale( wxInt32 num
, wxInt32 denum
)
371 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;
372 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;}
375 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
376 bool operator == (const wxRect2DDouble& rect);
377 bool operator != (const wxRect2DDouble& rect);
386 class WXDLLEXPORT wxPoint2DInt
390 wxPoint2DInt( wxInt32 x
, wxInt32 y
) ;
391 wxPoint2DInt( const wxPoint2DInt
&pt
) ;
392 wxPoint2DInt( const wxPoint
&pt
) ;
394 // two different conversions to integers, floor and rounding
395 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
396 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
398 wxDouble
GetVectorLength() ;
399 wxDouble
GetVectorAngle() ;
400 void SetVectorLength( wxDouble length
) ;
401 void SetVectorAngle( wxDouble degrees
) ;
402 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
403 // set the vector length to 1.0, preserving the angle
406 wxDouble
GetDistance( const wxPoint2DInt
&pt
) const ;
407 wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
408 wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
409 wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
411 // the reflection of this point
412 wxPoint2DInt
operator-() ;
414 wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
) ;
415 wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
) ;
416 wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
) ;
417 wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
) ;
418 wxPoint2DInt
& operator*=(wxDouble n
) ;
419 wxPoint2DInt
& operator*=(wxInt32 n
) ;
420 wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
) ;
421 wxPoint2DInt
& operator/=(wxDouble n
) ;
422 wxPoint2DInt
& operator/=(wxInt32 n
) ;
423 operator wxPoint() const ;
424 bool operator==(const wxPoint2DInt
& pt
) const ;
425 bool operator!=(const wxPoint2DInt
& pt
) const ;
427 void WriteTo( wxDataOutputStream
&stream
) const ;
428 void ReadFrom( wxDataInputStream
&stream
) ;
434 wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
435 wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
436 wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
437 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
438 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
439 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
440 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
441 wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
442 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
443 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
445 inline wxPoint2DInt::wxPoint2DInt()
451 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
457 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
463 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
469 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
471 *x
= (wxInt32
) floor( m_x
) ;
472 *y
= (wxInt32
) floor( m_y
) ;
475 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
477 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
478 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
481 inline wxDouble
wxPoint2DInt::GetVectorLength()
483 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
486 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
488 wxDouble before
= GetVectorLength() ;
489 m_x
= (wxInt32
)(m_x
* length
/ before
) ;
490 m_y
= (wxInt32
)(m_y
* length
/ before
) ;
493 inline void wxPoint2DInt::Normalize()
495 SetVectorLength( 1 ) ;
498 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
500 return sqrt( GetDistanceSquare( pt
) );
503 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
505 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
508 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
510 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
513 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
515 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
518 inline wxPoint2DInt::operator wxPoint() const
520 return wxPoint( m_x
, m_y
);
523 inline wxPoint2DInt
wxPoint2DInt::operator-()
525 return wxPoint2DInt( -m_x
, -m_y
);
528 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
535 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
542 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
549 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
556 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
563 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
565 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
568 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
570 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
573 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
575 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
578 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
580 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
584 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
586 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
589 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
591 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
594 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
596 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
599 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
601 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
604 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
606 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
609 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
611 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
614 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
616 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
619 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
621 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
624 // 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
625 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
626 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
628 class WXDLLEXPORT wxRect2DInt
631 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0 ; }
632 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
633 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
634 wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
635 wxRect2DInt(const wxRect2DInt
& rect
);
637 // single attribute accessors
639 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
640 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
642 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
643 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
645 inline wxInt32
GetLeft() const { return m_x
; }
646 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
647 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
648 inline wxInt32
GetTop() const { return m_y
; }
649 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
650 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
651 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
652 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
) ;}
653 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
654 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
655 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
656 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
658 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
) ; }
659 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
; }
660 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
661 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
) ; }
662 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
; }
663 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
664 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
) ; }
665 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
; }
666 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
667 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
) ; }
668 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
669 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
670 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
671 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
672 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) ; }
673 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
674 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
675 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
676 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
677 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
678 inline bool Contains( const wxPoint2DInt
&pt
) const
679 { return GetOutcode( pt
) == wxInside
; }
680 inline bool Contains( const wxRect2DInt
&rect
) const
681 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
682 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
683 inline bool IsEmpty() const
684 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
685 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
686 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
688 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
689 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
690 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
691 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
692 void ConstrainTo( const wxRect2DInt
&rect
) ;
693 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
695 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
696 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
697 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
) ; return result
; }
698 bool Intersects( const wxRect2DInt
&rect
) const ;
700 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
701 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ) ; }
702 void Union( const wxPoint2DInt
&pt
) ;
703 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
) ; return result
; }
705 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
706 inline void Scale( wxInt32 num
, wxInt32 denum
)
707 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;
708 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;}
710 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
711 bool operator == (const wxRect2DInt
& rect
);
712 bool operator != (const wxRect2DInt
& rect
);
714 void WriteTo( wxDataOutputStream
&stream
) const ;
715 void ReadFrom( wxDataInputStream
&stream
) ;
723 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
727 m_width
= r
.m_width
;
728 m_height
= r
.m_height
;
731 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
733 m_x
= wxMin( a
.m_x
, b
.m_x
) ;
734 m_y
= wxMin( a
.m_y
, b
.m_y
) ;
735 m_width
= abs( a
.m_x
- b
.m_x
) ;
736 m_height
= abs( a
.m_y
- b
.m_y
) ;
742 virtual void Transform( wxPoint2DInt
* pt
)const = 0 ;
743 virtual void Transform( wxRect2DInt
* r
) const ;
744 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const ;
745 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
747 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
748 virtual void InverseTransform( wxRect2DInt
* r
) const ;
749 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
750 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
753 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
754 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; Transform( &a
) ; Transform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
756 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
757 { wxPoint2DInt res
= pt
; Transform( &res
) ; return res
; }
759 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
760 { wxRect2DInt res
= r
; Transform( &res
) ; return res
; }
762 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
763 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; InverseTransform( &a
) ; InverseTransform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
765 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
766 { wxPoint2DInt res
= pt
; InverseTransform( &res
) ; return res
; }
768 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
769 { wxRect2DInt res
= r
; InverseTransform( &res
) ; return res
; }
772 #endif // wxUSE_GEOMETRY
774 #endif // _WX_GEOMETRY_H_