1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common Geometry Classes
4 // Author: Stefan Csomor
8 // Copyright: (c) 1999 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GEOMETRY_H_
13 #define _WX_GEOMETRY_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "geometry.h"
24 #include "wx/gdicmn.h"
28 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
29 #elif defined( __WXMAC__ )
30 #define wxMulDivInt32( a , b , c ) ( (wxInt32) ( ( (wxInt64)(a) * (wxInt64)(b) ) / (wxInt64)(c) ) )
32 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
35 class WXDLLIMPEXP_BASE wxDataInputStream
;
36 class WXDLLIMPEXP_BASE wxDataOutputStream
;
38 // clipping from Cohen-Sutherland
49 class WXDLLEXPORT wxPoint2DInt
52 inline wxPoint2DInt();
53 inline wxPoint2DInt( wxInt32 x
, wxInt32 y
);
54 inline wxPoint2DInt( const wxPoint2DInt
&pt
);
55 inline wxPoint2DInt( const wxPoint
&pt
);
57 // noops for this class, just return the coords
58 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
59 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
61 inline wxDouble
GetVectorLength() const;
62 wxDouble
GetVectorAngle() const;
63 inline void SetVectorLength( wxDouble length
);
64 void SetVectorAngle( wxDouble degrees
);
65 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
);
66 // set the vector length to 1.0, preserving the angle
67 inline void Normalize();
69 inline wxDouble
GetDistance( const wxPoint2DInt
&pt
) const;
70 inline wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
71 inline wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
72 inline wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
74 // the reflection of this point
75 inline wxPoint2DInt
operator-();
77 inline wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
);
78 inline wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
);
79 inline wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
);
80 inline wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
);
81 inline wxPoint2DInt
& operator*=(wxDouble n
);
82 inline wxPoint2DInt
& operator*=(wxInt32 n
);
83 inline wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
);
84 inline wxPoint2DInt
& operator/=(wxDouble n
);
85 inline wxPoint2DInt
& operator/=(wxInt32 n
);
86 inline operator wxPoint() const;
87 inline bool operator==(const wxPoint2DInt
& pt
) const;
88 inline bool operator!=(const wxPoint2DInt
& pt
) const;
91 void WriteTo( wxDataOutputStream
&stream
) const;
92 void ReadFrom( wxDataInputStream
&stream
);
93 #endif // wxUSE_STREAMS
99 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
100 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
101 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
102 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
103 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
104 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
105 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
106 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
107 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
108 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
110 inline wxPoint2DInt::wxPoint2DInt()
116 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
122 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
128 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
134 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
) const
142 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
) const
147 inline wxDouble
wxPoint2DInt::GetVectorLength() const
149 // cast needed MIPSpro compiler under SGI
150 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
153 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
155 wxDouble before
= GetVectorLength();
156 m_x
= (wxInt32
)(m_x
* length
/ before
);
157 m_y
= (wxInt32
)(m_y
* length
/ before
);
160 inline void wxPoint2DInt::Normalize()
162 SetVectorLength( 1 );
165 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
167 return sqrt( GetDistanceSquare( pt
) );
170 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
172 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
175 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
177 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
180 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
182 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
185 inline wxPoint2DInt::operator wxPoint() const
187 return wxPoint( m_x
, m_y
);
190 inline wxPoint2DInt
wxPoint2DInt::operator-()
192 return wxPoint2DInt( -m_x
, -m_y
);
195 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
202 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
209 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
216 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
223 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
230 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
232 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
235 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
237 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
240 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
242 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
245 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
247 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
251 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
253 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
256 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
258 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
261 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
263 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
266 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
268 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
271 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
273 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
276 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
278 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
281 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
283 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
);
286 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
288 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) );
291 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
293 class WXDLLEXPORT wxPoint2DDouble
296 inline wxPoint2DDouble();
297 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
298 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
299 wxPoint2DDouble( const wxPoint2DInt
&pt
)
300 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
301 wxPoint2DDouble( const wxPoint
&pt
)
302 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
304 // two different conversions to integers, floor and rounding
305 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
306 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
308 inline wxDouble
GetVectorLength() const;
309 wxDouble
GetVectorAngle() const ;
310 void SetVectorLength( wxDouble length
);
311 void SetVectorAngle( wxDouble degrees
);
312 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
313 // set the vector length to 1.0, preserving the angle
316 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
) const;
317 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) const;
318 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) const;
319 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) const;
321 // the reflection of this point
322 inline wxPoint2DDouble
operator-();
324 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
325 inline wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
);
326 inline wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
);
327 inline wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
);
328 inline wxPoint2DDouble
& operator*=(wxDouble n
);
329 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
330 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
331 inline wxPoint2DDouble
& operator/=(wxDouble n
);
332 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
334 inline bool operator==(const wxPoint2DDouble
& pt
) const;
335 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
341 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
342 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
343 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
344 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
345 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
346 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
347 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
348 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
349 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
350 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
352 inline wxPoint2DDouble::wxPoint2DDouble()
358 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
364 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
370 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
) const
372 *x
= (wxInt32
) floor( m_x
);
373 *y
= (wxInt32
) floor( m_y
);
376 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
) const
378 *x
= (wxInt32
) floor( m_x
+ 0.5 );
379 *y
= (wxInt32
) floor( m_y
+ 0.5);
382 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
384 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
387 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
389 wxDouble before
= GetVectorLength() ;
390 m_x
= (m_x
* length
/ before
) ;
391 m_y
= (m_y
* length
/ before
) ;
394 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
) const
396 return sqrt( GetDistanceSquare( pt
) );
399 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
) const
401 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
404 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
) const
406 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
409 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
) const
411 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
414 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
416 return wxPoint2DDouble( -m_x
, -m_y
);
419 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
426 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
433 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
440 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
447 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
454 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
456 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
459 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
461 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
464 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
466 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
469 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
471 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
475 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
477 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
480 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
482 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
485 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
487 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
490 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
492 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
495 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
497 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
500 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
502 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
505 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
507 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
510 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
512 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
515 // 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
516 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
517 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
519 class WXDLLEXPORT wxRect2DDouble
523 { m_x
= m_y
= m_width
= m_height
= 0; }
524 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
525 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
527 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
528 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
529 wxRect2DDouble(const wxRect2DDouble& rect);
531 // single attribute accessors
533 inline wxPoint2DDouble
GetPosition()
534 { return wxPoint2DDouble(m_x
, m_y
); }
535 inline wxSize
GetSize()
536 { return wxSize((int) m_width
, (int) m_height
); }
538 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
539 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
541 inline wxDouble
GetLeft() const { return m_x
; }
542 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
543 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
544 inline wxDouble
GetTop() const { return m_y
; }
545 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
546 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
547 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
548 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
549 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
550 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
551 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
552 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
554 inline wxPoint2DDouble
GetLeftTop() const
555 { return wxPoint2DDouble( m_x
, m_y
); }
556 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
557 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
558 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
559 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
560 inline wxPoint2DDouble
GetLeftBottom() const
561 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
562 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
563 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
564 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
565 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
566 inline wxPoint2DDouble
GetRightTop() const
567 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
568 inline void SetRightTop( const wxPoint2DDouble
&pt
)
569 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
570 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
571 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
572 inline wxPoint2DDouble
GetRightBottom() const
573 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
574 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
575 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
576 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
577 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
578 inline wxPoint2DDouble
GetCentre() const
579 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
580 inline void SetCentre( const wxPoint2DDouble
&pt
)
581 { MoveCentreTo( pt
); } // since this is impossible without moving...
582 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
583 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
584 inline wxOutCode
GetOutCode( const wxPoint2DDouble
&pt
) const
585 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
586 ( ( pt
.m_x
> m_x
+ m_width
) ? wxOutRight
: 0 ) +
587 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
588 ( ( pt
.m_y
> m_y
+ m_height
) ? wxOutBottom
: 0 )); }
589 inline wxOutCode
GetOutcode(const wxPoint2DDouble
&pt
) const
590 { return GetOutCode(pt
) ; }
591 inline bool Contains( const wxPoint2DDouble
&pt
) const
592 { return GetOutCode( pt
) == wxInside
; }
593 inline bool Contains( const wxRect2DDouble
&rect
) const
594 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
595 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
596 inline bool IsEmpty() const
597 { return ( m_width
<= 0 || m_height
<= 0 ); }
598 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
599 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
601 inline void Inset( wxDouble x
, wxDouble y
)
602 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
603 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
604 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
605 inline void Offset( const wxPoint2DDouble
&pt
)
606 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
608 void ConstrainTo( const wxRect2DDouble
&rect
);
610 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
611 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
613 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
614 inline void Intersect( const wxRect2DDouble
&otherRect
)
615 { Intersect( *this , otherRect
, this ); }
616 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
617 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
618 bool Intersects( const wxRect2DDouble
&rect
) const;
620 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
621 void Union( const wxRect2DDouble
&otherRect
)
622 { Union( *this , otherRect
, this ); }
623 void Union( const wxPoint2DDouble
&pt
);
624 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
625 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
627 inline void Scale( wxDouble f
)
628 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
629 inline void Scale( wxInt32 num
, wxInt32 denum
)
630 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
631 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
633 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
634 inline bool operator == (const wxRect2DDouble
& rect
)
635 { return (m_x
==rect
.m_x
&& m_y
==rect
.m_y
&& m_width
==rect
.m_width
&& m_height
==rect
.m_height
); }
636 inline bool operator != (const wxRect2DDouble
& rect
)
637 { return !(*this == rect
); }
646 // 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
647 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
648 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
650 class WXDLLEXPORT wxRect2DInt
653 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
654 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
655 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
656 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
657 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
658 inline wxRect2DInt(const wxRect2DInt
& rect
);
660 // single attribute accessors
662 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
663 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
665 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
666 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
668 inline wxInt32
GetLeft() const { return m_x
; }
669 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
670 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
671 inline wxInt32
GetTop() const { return m_y
; }
672 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
673 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
674 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
675 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
676 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
677 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
678 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
679 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
681 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
682 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
; }
683 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
684 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
685 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
; }
686 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
687 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
688 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
; }
689 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
690 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
691 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
692 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
693 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
694 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
695 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); }
696 inline wxOutCode
GetOutCode( const wxPoint2DInt
&pt
) const
697 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
698 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
699 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
700 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
701 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
702 { return GetOutCode( pt
) ; }
703 inline bool Contains( const wxPoint2DInt
&pt
) const
704 { return GetOutCode( pt
) == wxInside
; }
705 inline bool Contains( const wxRect2DInt
&rect
) const
706 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
707 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
708 inline bool IsEmpty() const
709 { return ( m_width
<= 0 || m_height
<= 0 ); }
710 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
711 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
713 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
714 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
715 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
716 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
717 void ConstrainTo( const wxRect2DInt
&rect
);
718 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
720 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
721 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
722 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
723 bool Intersects( const wxRect2DInt
&rect
) const;
725 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
726 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
727 void Union( const wxPoint2DInt
&pt
);
728 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
730 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
731 inline void Scale( wxInt32 num
, wxInt32 denum
)
732 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
733 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
735 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
736 bool operator == (const wxRect2DInt
& rect
) const;
737 bool operator != (const wxRect2DInt
& rect
) const;
740 void WriteTo( wxDataOutputStream
&stream
) const;
741 void ReadFrom( wxDataInputStream
&stream
);
742 #endif // wxUSE_STREAMS
750 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
755 m_height
= r
.m_height
;
758 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
760 m_x
= wxMin( a
.m_x
, b
.m_x
);
761 m_y
= wxMin( a
.m_y
, b
.m_y
);
762 m_width
= abs( a
.m_x
- b
.m_x
);
763 m_height
= abs( a
.m_y
- b
.m_y
);
766 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
& pos
, const wxSize
& size
)
774 inline bool wxRect2DInt::operator == (const wxRect2DInt
& rect
) const
776 return (m_x
==rect
.m_x
&& m_y
==rect
.m_y
&&
777 m_width
==rect
.m_width
&& m_height
==rect
.m_height
);
780 inline bool wxRect2DInt::operator != (const wxRect2DInt
& rect
) const
782 return !(*this == rect
);
788 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
789 virtual void Transform( wxRect2DInt
* r
) const;
790 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
791 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
793 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
794 virtual void InverseTransform( wxRect2DInt
* r
) const ;
795 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
796 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
799 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
800 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
802 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
803 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
805 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
806 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
808 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
809 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
811 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
812 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
814 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
815 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
818 #endif // wxUSE_GEOMETRY
820 #endif // _WX_GEOMETRY_H_