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(__APPLE__)
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__ )
34 #define wxMulDivInt32( a , b , c ) ( (wxInt32) ( ( (wxInt64)(a) * (wxInt64)(b) ) / (wxInt64)(c) ) )
36 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
39 class wxDataInputStream
;
40 class wxDataOutputStream
;
42 // clipping from Cohen-Sutherland
53 class WXDLLEXPORT wxPoint2DInt
56 inline wxPoint2DInt();
57 inline wxPoint2DInt( wxInt32 x
, wxInt32 y
);
58 inline wxPoint2DInt( const wxPoint2DInt
&pt
);
59 inline wxPoint2DInt( const wxPoint
&pt
);
61 // noops for this class, just return the coords
62 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
63 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
65 inline wxDouble
GetVectorLength() const;
66 wxDouble
GetVectorAngle() const;
67 inline void SetVectorLength( wxDouble length
);
68 void SetVectorAngle( wxDouble degrees
);
69 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
);
70 // set the vector length to 1.0, preserving the angle
71 inline void Normalize();
73 inline wxDouble
GetDistance( const wxPoint2DInt
&pt
) const;
74 inline wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
75 inline wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
76 inline wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
78 // the reflection of this point
79 inline wxPoint2DInt
operator-();
81 inline wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
);
82 inline wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
);
83 inline wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
);
84 inline wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
);
85 inline wxPoint2DInt
& operator*=(wxDouble n
);
86 inline wxPoint2DInt
& operator*=(wxInt32 n
);
87 inline wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
);
88 inline wxPoint2DInt
& operator/=(wxDouble n
);
89 inline wxPoint2DInt
& operator/=(wxInt32 n
);
90 inline operator wxPoint() const;
91 inline bool operator==(const wxPoint2DInt
& pt
) const;
92 inline bool operator!=(const wxPoint2DInt
& pt
) const;
95 void WriteTo( wxDataOutputStream
&stream
) const;
96 void ReadFrom( wxDataInputStream
&stream
);
97 #endif // wxUSE_STREAMS
103 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
104 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
105 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
106 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
107 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
108 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
109 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
110 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
111 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
112 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
114 inline wxPoint2DInt::wxPoint2DInt()
120 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
126 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
132 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
138 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
) const
146 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
) const
151 inline wxDouble
wxPoint2DInt::GetVectorLength() const
153 // cast needed MIPSpro compiler under SGI
154 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
157 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
159 wxDouble before
= GetVectorLength();
160 m_x
= (wxInt32
)(m_x
* length
/ before
);
161 m_y
= (wxInt32
)(m_y
* length
/ before
);
164 inline void wxPoint2DInt::Normalize()
166 SetVectorLength( 1 );
169 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
171 return sqrt( GetDistanceSquare( pt
) );
174 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
176 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
179 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
181 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
184 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
186 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
189 inline wxPoint2DInt::operator wxPoint() const
191 return wxPoint( m_x
, m_y
);
194 inline wxPoint2DInt
wxPoint2DInt::operator-()
196 return wxPoint2DInt( -m_x
, -m_y
);
199 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
206 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
213 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
220 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
227 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
234 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
236 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
239 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
241 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
244 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
246 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
249 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
251 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
255 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
257 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
260 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
262 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
265 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
267 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
270 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
272 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
275 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
277 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
280 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
282 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
285 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
287 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
);
290 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
292 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) );
295 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
297 class WXDLLEXPORT wxPoint2DDouble
300 inline wxPoint2DDouble();
301 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
302 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
303 wxPoint2DDouble( const wxPoint2DInt
&pt
)
304 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
305 wxPoint2DDouble( const wxPoint
&pt
)
306 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
308 // two different conversions to integers, floor and rounding
309 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
310 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
312 inline wxDouble
GetVectorLength() const;
313 wxDouble
GetVectorAngle() const ;
314 void SetVectorLength( wxDouble length
);
315 void SetVectorAngle( wxDouble degrees
);
316 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
317 // set the vector length to 1.0, preserving the angle
320 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
) const;
321 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) const;
322 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) const;
323 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) const;
325 // the reflection of this point
326 inline wxPoint2DDouble
operator-();
328 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
329 inline wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
);
330 inline wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
);
331 inline wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
);
332 inline wxPoint2DDouble
& operator*=(wxDouble n
);
333 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
334 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
335 inline wxPoint2DDouble
& operator/=(wxDouble n
);
336 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
338 inline bool operator==(const wxPoint2DDouble
& pt
) const;
339 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
345 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
346 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
347 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
348 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
349 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
350 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
351 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
352 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
353 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
354 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
356 inline wxPoint2DDouble::wxPoint2DDouble()
362 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
368 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
374 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
) const
376 *x
= (wxInt32
) floor( m_x
);
377 *y
= (wxInt32
) floor( m_y
);
380 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
) const
382 *x
= (wxInt32
) floor( m_x
+ 0.5 );
383 *y
= (wxInt32
) floor( m_y
+ 0.5);
386 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
388 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
391 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
393 wxDouble before
= GetVectorLength() ;
394 m_x
= (m_x
* length
/ before
) ;
395 m_y
= (m_y
* length
/ before
) ;
398 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
) const
400 return sqrt( GetDistanceSquare( pt
) );
403 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
) const
405 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
408 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
) const
410 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
413 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
) const
415 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
418 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
420 return wxPoint2DDouble( -m_x
, -m_y
);
423 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
430 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
437 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
444 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
451 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
458 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
460 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
463 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
465 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
468 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
470 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
473 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
475 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
479 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
481 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
484 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
486 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
489 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
491 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
494 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
496 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
499 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
501 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
504 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
506 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
509 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
511 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
514 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
516 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
519 // 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
520 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
521 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
523 class WXDLLEXPORT wxRect2DDouble
527 { m_x
= m_y
= m_width
= m_height
= 0; }
528 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
529 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
531 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
532 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
533 wxRect2DDouble(const wxRect2DDouble& rect);
535 // single attribute accessors
537 inline wxPoint2DDouble
GetPosition()
538 { return wxPoint2DDouble(m_x
, m_y
); }
539 inline wxSize
GetSize()
540 { return wxSize((int) m_width
, (int) m_height
); }
542 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
543 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
545 inline wxDouble
GetLeft() const { return m_x
; }
546 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
547 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
548 inline wxDouble
GetTop() const { return m_y
; }
549 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
550 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
551 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
552 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
553 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
554 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
555 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
556 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
558 inline wxPoint2DDouble
GetLeftTop() const
559 { return wxPoint2DDouble( m_x
, m_y
); }
560 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
561 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
562 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
563 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
564 inline wxPoint2DDouble
GetLeftBottom() const
565 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
566 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
567 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
568 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
569 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
570 inline wxPoint2DDouble
GetRightTop() const
571 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
572 inline void SetRightTop( const wxPoint2DDouble
&pt
)
573 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
574 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
575 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
576 inline wxPoint2DDouble
GetRightBottom() const
577 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
578 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
579 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
580 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
581 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
582 inline wxPoint2DDouble
GetCentre() const
583 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
584 inline void SetCentre( const wxPoint2DDouble
&pt
)
585 { MoveCentreTo( pt
); } // since this is impossible without moving...
586 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
587 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
588 inline wxOutCode
GetOutCode( const wxPoint2DDouble
&pt
) const
589 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
590 ( ( pt
.m_x
> m_x
+ m_width
) ? wxOutRight
: 0 ) +
591 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
592 ( ( pt
.m_y
> m_y
+ m_height
) ? wxOutBottom
: 0 )); }
593 inline wxOutCode
GetOutcode(const wxPoint2DDouble
&pt
) const
594 { return GetOutCode(pt
) ; }
595 inline bool Contains( const wxPoint2DDouble
&pt
) const
596 { return GetOutCode( pt
) == wxInside
; }
597 inline bool Contains( const wxRect2DDouble
&rect
) const
598 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
599 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
600 inline bool IsEmpty() const
601 { return ( m_width
<= 0 || m_height
<= 0 ); }
602 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
603 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
605 inline void Inset( wxDouble x
, wxDouble y
)
606 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
607 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
608 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
609 inline void Offset( const wxPoint2DDouble
&pt
)
610 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
612 void ConstrainTo( const wxRect2DDouble
&rect
);
614 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
615 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
617 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
618 inline void Intersect( const wxRect2DDouble
&otherRect
)
619 { Intersect( *this , otherRect
, this ); }
620 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
621 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
622 bool Intersects( const wxRect2DDouble
&rect
) const;
624 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
625 void Union( const wxRect2DDouble
&otherRect
)
626 { Union( *this , otherRect
, this ); }
627 void Union( const wxPoint2DDouble
&pt
);
628 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
629 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
631 inline void Scale( wxDouble f
)
632 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
633 inline void Scale( wxInt32 num
, wxInt32 denum
)
634 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
635 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
637 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
638 inline bool operator == (const wxRect2DDouble
& rect
)
639 { return (m_x
==rect
.m_x
&& m_y
==rect
.m_y
&& m_width
==rect
.m_width
&& m_height
==rect
.m_height
); }
640 inline bool operator != (const wxRect2DDouble
& rect
)
641 { return !(*this == rect
); }
650 // 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
651 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
652 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
654 class WXDLLEXPORT wxRect2DInt
657 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
658 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
659 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
660 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
661 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
662 inline wxRect2DInt(const wxRect2DInt
& rect
);
664 // single attribute accessors
666 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
667 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
669 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
670 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
672 inline wxInt32
GetLeft() const { return m_x
; }
673 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
674 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
675 inline wxInt32
GetTop() const { return m_y
; }
676 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
677 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
678 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
679 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
680 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
681 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
682 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
683 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
685 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
686 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
; }
687 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
688 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
689 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
; }
690 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
691 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
692 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
; }
693 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
694 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
695 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
696 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
697 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
698 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
699 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); }
700 inline wxOutCode
GetOutCode( const wxPoint2DInt
&pt
) const
701 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
702 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
703 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
704 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
705 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
706 { return GetOutCode( pt
) ; }
707 inline bool Contains( const wxPoint2DInt
&pt
) const
708 { return GetOutCode( pt
) == wxInside
; }
709 inline bool Contains( const wxRect2DInt
&rect
) const
710 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
711 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
712 inline bool IsEmpty() const
713 { return ( m_width
<= 0 || m_height
<= 0 ); }
714 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
715 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
717 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
718 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
719 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
720 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
721 void ConstrainTo( const wxRect2DInt
&rect
);
722 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
724 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
725 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
726 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
727 bool Intersects( const wxRect2DInt
&rect
) const;
729 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
730 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
731 void Union( const wxPoint2DInt
&pt
);
732 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
734 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
735 inline void Scale( wxInt32 num
, wxInt32 denum
)
736 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
737 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
739 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
740 bool operator == (const wxRect2DInt
& rect
) const;
741 bool operator != (const wxRect2DInt
& rect
) const;
744 void WriteTo( wxDataOutputStream
&stream
) const;
745 void ReadFrom( wxDataInputStream
&stream
);
746 #endif // wxUSE_STREAMS
754 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
759 m_height
= r
.m_height
;
762 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
764 m_x
= wxMin( a
.m_x
, b
.m_x
);
765 m_y
= wxMin( a
.m_y
, b
.m_y
);
766 m_width
= abs( a
.m_x
- b
.m_x
);
767 m_height
= abs( a
.m_y
- b
.m_y
);
770 inline bool wxRect2DInt::operator == (const wxRect2DInt
& rect
) const
772 return (m_x
==rect
.m_x
&& m_y
==rect
.m_y
&&
773 m_width
==rect
.m_width
&& m_height
==rect
.m_height
);
776 inline bool wxRect2DInt::operator != (const wxRect2DInt
& rect
) const
778 return !(*this == rect
);
784 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
785 virtual void Transform( wxRect2DInt
* r
) const;
786 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
787 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
789 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
790 virtual void InverseTransform( wxRect2DInt
* r
) const ;
791 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
792 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
795 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
796 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
798 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
799 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
801 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
802 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
804 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
805 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
807 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
808 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
810 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
811 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
814 #endif // wxUSE_GEOMETRY
816 #endif // _WX_GEOMETRY_H_