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_
16 #pragma interface "geometry.cpp"
21 #ifndef wxUSE_GEOMETRY
22 #define wxUSE_GEOMETRY 0
28 #include "wx/gdicmn.h"
32 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
33 #elif defined( __WXMAC__ )
35 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
37 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
40 class wxDataInputStream
;
41 class wxDataOutputStream
;
43 // clipping from Cohen-Sutherland
54 class WXDLLEXPORT wxPoint2DInt
57 inline wxPoint2DInt();
58 inline wxPoint2DInt( wxInt32 x
, wxInt32 y
);
59 inline wxPoint2DInt( const wxPoint2DInt
&pt
);
60 inline wxPoint2DInt( const wxPoint
&pt
);
62 // noops for this class, just return the coords
63 inline void GetFloor( wxInt32
*x
, wxInt32
*y
);
64 inline void GetRounded( wxInt32
*x
, wxInt32
*y
);
66 inline wxDouble
GetVectorLength();
67 wxDouble
GetVectorAngle();
68 inline void SetVectorLength( wxDouble length
);
69 void SetVectorAngle( wxDouble degrees
);
70 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
);
71 // set the vector length to 1.0, preserving the angle
72 inline void Normalize();
74 inline wxDouble
GetDistance( const wxPoint2DInt
&pt
) const;
75 inline wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
76 inline wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
77 inline wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
79 // the reflection of this point
80 inline wxPoint2DInt
operator-();
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*=(const wxPoint2DInt
& pt
);
86 inline wxPoint2DInt
& operator*=(wxDouble n
);
87 inline wxPoint2DInt
& operator*=(wxInt32 n
);
88 inline wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
);
89 inline wxPoint2DInt
& operator/=(wxDouble n
);
90 inline wxPoint2DInt
& operator/=(wxInt32 n
);
91 inline operator wxPoint() const;
92 inline bool operator==(const wxPoint2DInt
& pt
) const;
93 inline bool operator!=(const wxPoint2DInt
& pt
) const;
95 void WriteTo( wxDataOutputStream
&stream
) const;
96 void ReadFrom( wxDataInputStream
&stream
);
102 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
103 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
104 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
105 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
106 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
107 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
108 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
109 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
110 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
111 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
113 inline wxPoint2DInt::wxPoint2DInt()
119 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
125 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
131 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
137 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
145 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
150 inline wxDouble
wxPoint2DInt::GetVectorLength()
152 // cast needed MIPSpro compiler under SGI
153 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
156 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
158 wxDouble before
= GetVectorLength();
159 m_x
= (wxInt32
)(m_x
* length
/ before
);
160 m_y
= (wxInt32
)(m_y
* length
/ before
);
163 inline void wxPoint2DInt::Normalize()
165 SetVectorLength( 1 );
168 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
170 return sqrt( GetDistanceSquare( pt
) );
173 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
175 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
178 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
180 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
183 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
185 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
188 inline wxPoint2DInt::operator wxPoint() const
190 return wxPoint( m_x
, m_y
);
193 inline wxPoint2DInt
wxPoint2DInt::operator-()
195 return wxPoint2DInt( -m_x
, -m_y
);
198 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
205 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
212 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
219 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
226 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
233 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
235 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
238 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
240 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
243 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
245 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
248 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
250 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
254 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
256 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
259 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
261 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
264 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
266 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
269 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
271 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
274 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
276 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
279 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
281 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
284 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
286 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
);
289 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
291 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) );
294 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
296 class WXDLLEXPORT wxPoint2DDouble
299 inline wxPoint2DDouble();
300 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
301 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
302 wxPoint2DDouble( const wxPoint2DInt
&pt
)
303 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
304 wxPoint2DDouble( const wxPoint
&pt
)
305 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
307 // two different conversions to integers, floor and rounding
308 inline void GetFloor( wxInt32
*x
, wxInt32
*y
);
309 inline void GetRounded( wxInt32
*x
, wxInt32
*y
);
311 inline wxDouble
GetVectorLength() const;
312 wxDouble
GetVectorAngle() const ;
313 void SetVectorLength( wxDouble length
);
314 void SetVectorAngle( wxDouble degrees
);
315 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
316 // set the vector length to 1.0, preserving the angle
319 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
);
320 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
);
321 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
);
322 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
);
324 // the reflection of this point
325 inline wxPoint2DDouble
operator-();
327 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
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*=(wxDouble n
);
332 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
333 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
334 inline wxPoint2DDouble
& operator/=(wxDouble n
);
335 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
337 inline bool operator==(const wxPoint2DDouble
& pt
) const;
338 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
344 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
345 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
346 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
347 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
348 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
349 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
350 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
351 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
352 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
353 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
355 inline wxPoint2DDouble::wxPoint2DDouble()
361 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
367 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
373 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
)
375 *x
= (wxInt32
) floor( m_x
);
376 *y
= (wxInt32
) floor( m_y
);
379 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
)
381 *x
= (wxInt32
) floor( m_x
+ 0.5 );
382 *y
= (wxInt32
) floor( m_y
+ 0.5);
385 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
387 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
390 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
392 wxDouble before
= GetVectorLength() ;
393 m_x
= (m_x
* length
/ before
) ;
394 m_y
= (m_y
* length
/ before
) ;
397 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
)
399 return sqrt( GetDistanceSquare( pt
) );
402 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
)
404 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
407 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
)
409 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
412 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
)
414 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
417 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
419 return wxPoint2DDouble( -m_x
, -m_y
);
422 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
429 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
436 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
443 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
450 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
457 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
459 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
462 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
464 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
467 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
469 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
472 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
474 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
478 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
480 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
483 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
485 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
488 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
490 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
493 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
495 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
498 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
500 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
503 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
505 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
508 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
510 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
513 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
515 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
518 // 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
519 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
520 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
522 class WXDLLEXPORT wxRect2DDouble
526 { m_x
= m_y
= m_width
= m_height
= 0; }
527 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
528 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
530 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
531 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
532 wxRect2DDouble(const wxRect2DDouble& rect);
534 // single attribute accessors
536 inline wxPoint2DDouble
GetPosition()
537 { return wxPoint2DDouble(m_x
, m_y
); }
538 inline wxSize
GetSize()
539 { return wxSize((int) m_width
, (int) m_height
); }
541 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
542 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
544 inline wxDouble
GetLeft() const { return m_x
; }
545 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
546 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
547 inline wxDouble
GetTop() const { return m_y
; }
548 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
549 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
550 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
551 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
552 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
553 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
554 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
555 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
557 inline wxPoint2DDouble
GetLeftTop() const
558 { return wxPoint2DDouble( m_x
, m_y
); }
559 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
560 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
561 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
562 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
563 inline wxPoint2DDouble
GetLeftBottom() const
564 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
565 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
566 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
567 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
568 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
569 inline wxPoint2DDouble
GetRightTop() const
570 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
571 inline void SetRightTop( const wxPoint2DDouble
&pt
)
572 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
573 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
574 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
575 inline wxPoint2DDouble
GetRightBottom() const
576 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
577 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
578 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
579 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
580 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
581 inline wxPoint2DDouble
GetCentre() const
582 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
583 inline void SetCentre( const wxPoint2DDouble
&pt
)
584 { MoveCentreTo( pt
); } // since this is impossible without moving...
585 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
586 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
587 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
588 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
589 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
590 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
591 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
592 inline bool Contains( const wxPoint2DDouble
&pt
) const
593 { return GetOutcode( pt
) == wxInside
; }
594 inline bool Contains( const wxRect2DDouble
&rect
) const
595 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
596 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
597 inline bool IsEmpty() const
598 { return ( m_width
<= 0 || m_height
<= 0 ); }
599 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
600 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
602 inline void Inset( wxDouble x
, wxDouble y
)
603 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
604 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
605 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
606 inline void Offset( const wxPoint2DDouble
&pt
)
607 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
609 void ConstrainTo( const wxRect2DDouble
&rect
);
611 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
612 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
614 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
615 inline void Intersect( const wxRect2DDouble
&otherRect
)
616 { Intersect( *this , otherRect
, this ); }
617 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
618 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
619 bool Intersects( const wxRect2DDouble
&rect
) const;
621 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
622 void Union( const wxRect2DDouble
&otherRect
)
623 { Union( *this , otherRect
, this ); }
624 void Union( const wxPoint2DDouble
&pt
);
625 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
626 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
628 inline void Scale( wxDouble f
)
629 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
630 inline void Scale( wxInt32 num
, wxInt32 denum
)
631 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
632 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
635 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
636 bool operator == (const wxRect2DDouble& rect);
637 bool operator != (const wxRect2DDouble& rect);
647 // 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
648 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
649 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
651 class WXDLLEXPORT wxRect2DInt
654 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
655 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
656 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
657 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
658 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
659 inline wxRect2DInt(const wxRect2DInt
& rect
);
661 // single attribute accessors
663 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
664 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
666 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
667 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
669 inline wxInt32
GetLeft() const { return m_x
; }
670 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
671 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
672 inline wxInt32
GetTop() const { return m_y
; }
673 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
674 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
675 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
676 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
677 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
678 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
679 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
680 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
682 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
683 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
; }
684 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
685 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
686 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
; }
687 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
688 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
689 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
; }
690 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
691 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
692 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
693 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
694 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
695 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
696 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); }
697 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
698 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
699 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
700 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
701 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
702 inline bool Contains( const wxPoint2DInt
&pt
) const
703 { return GetOutcode( pt
) == wxInside
; }
704 inline bool Contains( const wxRect2DInt
&rect
) const
705 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
706 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
707 inline bool IsEmpty() const
708 { return ( m_width
<= 0 || m_height
<= 0 ); }
709 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
710 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
712 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
713 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
714 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
715 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
716 void ConstrainTo( const wxRect2DInt
&rect
);
717 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
719 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
720 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
721 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
722 bool Intersects( const wxRect2DInt
&rect
) const;
724 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
725 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
726 void Union( const wxPoint2DInt
&pt
);
727 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
729 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
730 inline void Scale( wxInt32 num
, wxInt32 denum
)
731 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
732 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
734 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
735 bool operator == (const wxRect2DInt
& rect
);
736 bool operator != (const wxRect2DInt
& rect
);
738 void WriteTo( wxDataOutputStream
&stream
) const;
739 void ReadFrom( wxDataInputStream
&stream
);
747 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
752 m_height
= r
.m_height
;
755 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
757 m_x
= wxMin( a
.m_x
, b
.m_x
);
758 m_y
= wxMin( a
.m_y
, b
.m_y
);
759 m_width
= abs( a
.m_x
- b
.m_x
);
760 m_height
= abs( a
.m_y
- b
.m_y
);
766 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
767 virtual void Transform( wxRect2DInt
* r
) const;
768 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
769 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
771 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
772 virtual void InverseTransform( wxRect2DInt
* r
) const ;
773 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
774 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
777 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
778 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
780 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
781 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
783 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
784 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
786 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
787 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
789 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
790 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
792 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
793 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
796 #endif // wxUSE_GEOMETRY
798 #endif // _WX_GEOMETRY_H_