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;
94 void WriteTo( wxDataOutputStream
&stream
) const;
95 void ReadFrom( wxDataInputStream
&stream
);
101 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
102 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
103 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
104 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
105 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
106 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
107 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
108 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
109 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
110 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
112 inline wxPoint2DInt::wxPoint2DInt()
118 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
124 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
130 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
136 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
) const
144 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
) const
149 inline wxDouble
wxPoint2DInt::GetVectorLength() const
151 // cast needed MIPSpro compiler under SGI
152 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
155 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
157 wxDouble before
= GetVectorLength();
158 m_x
= (wxInt32
)(m_x
* length
/ before
);
159 m_y
= (wxInt32
)(m_y
* length
/ before
);
162 inline void wxPoint2DInt::Normalize()
164 SetVectorLength( 1 );
167 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
169 return sqrt( GetDistanceSquare( pt
) );
172 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
174 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
177 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
179 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
182 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
184 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
187 inline wxPoint2DInt::operator wxPoint() const
189 return wxPoint( m_x
, m_y
);
192 inline wxPoint2DInt
wxPoint2DInt::operator-()
194 return wxPoint2DInt( -m_x
, -m_y
);
197 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
204 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
211 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
218 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
225 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
232 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
234 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
237 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
239 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
242 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
244 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
247 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
249 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
253 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
255 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
258 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
260 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
263 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
265 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
268 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
270 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
273 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
275 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
278 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
280 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
283 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
285 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
);
288 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
290 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) );
293 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
295 class WXDLLEXPORT wxPoint2DDouble
298 inline wxPoint2DDouble();
299 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
300 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
301 wxPoint2DDouble( const wxPoint2DInt
&pt
)
302 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
303 wxPoint2DDouble( const wxPoint
&pt
)
304 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
306 // two different conversions to integers, floor and rounding
307 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
308 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
310 inline wxDouble
GetVectorLength() const;
311 wxDouble
GetVectorAngle() const ;
312 void SetVectorLength( wxDouble length
);
313 void SetVectorAngle( wxDouble degrees
);
314 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
315 // set the vector length to 1.0, preserving the angle
318 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
) const;
319 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) const;
320 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) const;
321 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) const;
323 // the reflection of this point
324 inline wxPoint2DDouble
operator-();
326 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
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*=(wxDouble n
);
331 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
332 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
333 inline wxPoint2DDouble
& operator/=(wxDouble n
);
334 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
336 inline bool operator==(const wxPoint2DDouble
& pt
) const;
337 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
343 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
344 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
345 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
346 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
347 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
348 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
349 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
350 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
351 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
352 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
354 inline wxPoint2DDouble::wxPoint2DDouble()
360 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
366 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
372 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
) const
374 *x
= (wxInt32
) floor( m_x
);
375 *y
= (wxInt32
) floor( m_y
);
378 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
) const
380 *x
= (wxInt32
) floor( m_x
+ 0.5 );
381 *y
= (wxInt32
) floor( m_y
+ 0.5);
384 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
386 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
389 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
391 wxDouble before
= GetVectorLength() ;
392 m_x
= (m_x
* length
/ before
) ;
393 m_y
= (m_y
* length
/ before
) ;
396 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
) const
398 return sqrt( GetDistanceSquare( pt
) );
401 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
) const
403 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
406 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
) const
408 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
411 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
) const
413 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
416 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
418 return wxPoint2DDouble( -m_x
, -m_y
);
421 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
428 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
435 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
442 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
449 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
456 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
458 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
461 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
463 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
466 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
468 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
471 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
473 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
477 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
479 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
482 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
484 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
487 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
489 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
492 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
494 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
497 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
499 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
502 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
504 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
507 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
509 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
512 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
514 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
517 // 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
518 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
519 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
521 class WXDLLEXPORT wxRect2DDouble
525 { m_x
= m_y
= m_width
= m_height
= 0; }
526 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
527 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
529 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
530 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
531 wxRect2DDouble(const wxRect2DDouble& rect);
533 // single attribute accessors
535 inline wxPoint2DDouble
GetPosition()
536 { return wxPoint2DDouble(m_x
, m_y
); }
537 inline wxSize
GetSize()
538 { return wxSize((int) m_width
, (int) m_height
); }
540 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
541 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
543 inline wxDouble
GetLeft() const { return m_x
; }
544 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
545 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
546 inline wxDouble
GetTop() const { return m_y
; }
547 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
548 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
549 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
550 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
551 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
552 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
553 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
554 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
556 inline wxPoint2DDouble
GetLeftTop() const
557 { return wxPoint2DDouble( m_x
, m_y
); }
558 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
559 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
560 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
561 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
562 inline wxPoint2DDouble
GetLeftBottom() const
563 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
564 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
565 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
566 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
567 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
568 inline wxPoint2DDouble
GetRightTop() const
569 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
570 inline void SetRightTop( const wxPoint2DDouble
&pt
)
571 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
572 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
573 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
574 inline wxPoint2DDouble
GetRightBottom() const
575 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
576 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
577 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
578 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
579 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
580 inline wxPoint2DDouble
GetCentre() const
581 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
582 inline void SetCentre( const wxPoint2DDouble
&pt
)
583 { MoveCentreTo( pt
); } // since this is impossible without moving...
584 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
585 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
586 inline wxOutCode
GetOutCode( const wxPoint2DDouble
&pt
) const
587 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
588 ( ( pt
.m_x
> m_x
+ m_width
) ? wxOutRight
: 0 ) +
589 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
590 ( ( pt
.m_y
> m_y
+ m_height
) ? wxOutBottom
: 0 )); }
591 inline wxOutCode
GetOutcode(const wxPoint2DDouble
&pt
) const
592 { return GetOutCode(pt
) ; }
593 inline bool Contains( const wxPoint2DDouble
&pt
) const
594 { return GetOutCode( pt
) == wxInside
; }
595 inline bool Contains( const wxRect2DDouble
&rect
) const
596 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
597 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
598 inline bool IsEmpty() const
599 { return ( m_width
<= 0 || m_height
<= 0 ); }
600 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
601 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
603 inline void Inset( wxDouble x
, wxDouble y
)
604 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
605 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
606 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
607 inline void Offset( const wxPoint2DDouble
&pt
)
608 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
610 void ConstrainTo( const wxRect2DDouble
&rect
);
612 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
613 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
615 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
616 inline void Intersect( const wxRect2DDouble
&otherRect
)
617 { Intersect( *this , otherRect
, this ); }
618 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
619 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
620 bool Intersects( const wxRect2DDouble
&rect
) const;
622 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
623 void Union( const wxRect2DDouble
&otherRect
)
624 { Union( *this , otherRect
, this ); }
625 void Union( const wxPoint2DDouble
&pt
);
626 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
627 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
629 inline void Scale( wxDouble f
)
630 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
631 inline void Scale( wxInt32 num
, wxInt32 denum
)
632 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
633 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
636 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
637 bool operator == (const wxRect2DDouble& rect);
638 bool operator != (const wxRect2DDouble& rect);
648 // 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
649 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
650 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
652 class WXDLLEXPORT wxRect2DInt
655 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
656 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
657 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
658 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
659 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
660 inline wxRect2DInt(const wxRect2DInt
& rect
);
662 // single attribute accessors
664 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
665 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
667 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
668 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
670 inline wxInt32
GetLeft() const { return m_x
; }
671 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
672 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
673 inline wxInt32
GetTop() const { return m_y
; }
674 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
675 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
676 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
677 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
678 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
679 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
680 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
681 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
683 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
684 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
; }
685 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
686 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
687 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
; }
688 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
689 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
690 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
; }
691 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
692 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
693 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
694 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
695 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
696 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
697 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); }
698 inline wxOutCode
GetOutCode( const wxPoint2DInt
&pt
) const
699 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
700 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
701 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
702 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
703 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
704 { return GetOutCode( pt
) ; }
705 inline bool Contains( const wxPoint2DInt
&pt
) const
706 { return GetOutCode( pt
) == wxInside
; }
707 inline bool Contains( const wxRect2DInt
&rect
) const
708 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
709 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
710 inline bool IsEmpty() const
711 { return ( m_width
<= 0 || m_height
<= 0 ); }
712 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
713 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
715 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
716 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
717 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
718 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
719 void ConstrainTo( const wxRect2DInt
&rect
);
720 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
722 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
723 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
724 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
725 bool Intersects( const wxRect2DInt
&rect
) const;
727 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
728 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
729 void Union( const wxPoint2DInt
&pt
);
730 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
732 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
733 inline void Scale( wxInt32 num
, wxInt32 denum
)
734 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
735 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
737 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
738 bool operator == (const wxRect2DInt
& rect
);
739 bool operator != (const wxRect2DInt
& rect
);
741 void WriteTo( wxDataOutputStream
&stream
) const;
742 void ReadFrom( wxDataInputStream
&stream
);
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
);
769 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
770 virtual void Transform( wxRect2DInt
* r
) const;
771 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
772 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
774 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
775 virtual void InverseTransform( wxRect2DInt
* r
) const ;
776 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
777 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
780 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
781 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
783 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
784 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
786 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
787 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
789 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
790 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
792 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
793 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
795 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
796 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
799 #endif // wxUSE_GEOMETRY
801 #endif // _WX_GEOMETRY_H_