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_
20 #include "wx/gdicmn.h"
24 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
25 #elif defined( __WXMAC__ )
26 #define wxMulDivInt32( a , b , c ) ( (wxInt32) ( ( (wxInt64)(a) * (wxInt64)(b) ) / (wxInt64)(c) ) )
28 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
31 class WXDLLIMPEXP_BASE wxDataInputStream
;
32 class WXDLLIMPEXP_BASE wxDataOutputStream
;
34 // clipping from Cohen-Sutherland
45 class WXDLLEXPORT wxPoint2DInt
48 inline wxPoint2DInt();
49 inline wxPoint2DInt( wxInt32 x
, wxInt32 y
);
50 inline wxPoint2DInt( const wxPoint2DInt
&pt
);
51 inline wxPoint2DInt( const wxPoint
&pt
);
53 // noops for this class, just return the coords
54 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
55 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
57 inline wxDouble
GetVectorLength() const;
58 wxDouble
GetVectorAngle() const;
59 inline void SetVectorLength( wxDouble length
);
60 void SetVectorAngle( wxDouble degrees
);
61 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
);
62 // set the vector length to 1.0, preserving the angle
63 inline void Normalize();
65 inline wxDouble
GetDistance( const wxPoint2DInt
&pt
) const;
66 inline wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
67 inline wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
68 inline wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
70 // the reflection of this point
71 inline wxPoint2DInt
operator-();
73 inline wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
);
74 inline wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
);
75 inline wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
);
76 inline wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
);
77 inline wxPoint2DInt
& operator*=(wxDouble n
);
78 inline wxPoint2DInt
& operator*=(wxInt32 n
);
79 inline wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
);
80 inline wxPoint2DInt
& operator/=(wxDouble n
);
81 inline wxPoint2DInt
& operator/=(wxInt32 n
);
82 inline operator wxPoint() const;
83 inline bool operator==(const wxPoint2DInt
& pt
) const;
84 inline bool operator!=(const wxPoint2DInt
& pt
) const;
87 void WriteTo( wxDataOutputStream
&stream
) const;
88 void ReadFrom( wxDataInputStream
&stream
);
89 #endif // wxUSE_STREAMS
95 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
96 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
97 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
98 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
99 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
100 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
101 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
102 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
103 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
104 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
106 inline wxPoint2DInt::wxPoint2DInt()
112 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
118 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
124 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
130 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
) const
138 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
) const
143 inline wxDouble
wxPoint2DInt::GetVectorLength() const
145 // cast needed MIPSpro compiler under SGI
146 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
149 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
151 wxDouble before
= GetVectorLength();
152 m_x
= (wxInt32
)(m_x
* length
/ before
);
153 m_y
= (wxInt32
)(m_y
* length
/ before
);
156 inline void wxPoint2DInt::Normalize()
158 SetVectorLength( 1 );
161 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
163 return sqrt( GetDistanceSquare( pt
) );
166 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
168 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
171 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
173 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
176 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
178 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
181 inline wxPoint2DInt::operator wxPoint() const
183 return wxPoint( m_x
, m_y
);
186 inline wxPoint2DInt
wxPoint2DInt::operator-()
188 return wxPoint2DInt( -m_x
, -m_y
);
191 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
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 bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
228 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
231 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
233 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
236 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
238 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
241 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
243 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
);
252 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
254 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
257 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
259 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
262 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
264 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
267 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
269 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
272 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
274 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
277 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
279 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
);
282 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
284 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) );
287 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
289 class WXDLLEXPORT wxPoint2DDouble
292 inline wxPoint2DDouble();
293 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
294 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
295 wxPoint2DDouble( const wxPoint2DInt
&pt
)
296 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
297 wxPoint2DDouble( const wxPoint
&pt
)
298 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
300 // two different conversions to integers, floor and rounding
301 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
302 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
304 inline wxDouble
GetVectorLength() const;
305 wxDouble
GetVectorAngle() const ;
306 void SetVectorLength( wxDouble length
);
307 void SetVectorAngle( wxDouble degrees
);
308 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
309 // set the vector length to 1.0, preserving the angle
312 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
) const;
313 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) const;
314 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) const;
315 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) const;
317 // the reflection of this point
318 inline wxPoint2DDouble
operator-();
320 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
321 inline wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
);
322 inline wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
);
323 inline wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
);
324 inline wxPoint2DDouble
& operator*=(wxDouble n
);
325 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
326 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
327 inline wxPoint2DDouble
& operator/=(wxDouble n
);
328 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
330 inline bool operator==(const wxPoint2DDouble
& pt
) const;
331 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
337 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
338 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
339 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
340 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
341 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
342 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
343 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
344 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
345 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
346 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
348 inline wxPoint2DDouble::wxPoint2DDouble()
354 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
360 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
366 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
) const
368 *x
= (wxInt32
) floor( m_x
);
369 *y
= (wxInt32
) floor( m_y
);
372 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
) const
374 *x
= (wxInt32
) floor( m_x
+ 0.5 );
375 *y
= (wxInt32
) floor( m_y
+ 0.5);
378 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
380 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
383 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
385 wxDouble before
= GetVectorLength() ;
386 m_x
= (m_x
* length
/ before
) ;
387 m_y
= (m_y
* length
/ before
) ;
390 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
) const
392 return sqrt( GetDistanceSquare( pt
) );
395 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
) const
397 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
400 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
) const
402 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
405 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
) const
407 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
410 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
412 return wxPoint2DDouble( -m_x
, -m_y
);
415 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
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 bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
452 return wxIsSameDouble(m_x
, pt
.m_x
) && wxIsSameDouble(m_y
, pt
.m_y
);
455 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
457 return !(*this == pt
);
460 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
462 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
465 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
467 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
);
476 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
478 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
481 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
483 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
486 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
488 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
491 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
493 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
496 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
498 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
501 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
503 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
506 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
508 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
511 // 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
512 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
513 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
515 class WXDLLEXPORT wxRect2DDouble
519 { m_x
= m_y
= m_width
= m_height
= 0; }
520 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
521 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
523 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
524 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
525 wxRect2DDouble(const wxRect2DDouble& rect);
527 // single attribute accessors
529 inline wxPoint2DDouble
GetPosition()
530 { return wxPoint2DDouble(m_x
, m_y
); }
531 inline wxSize
GetSize()
532 { return wxSize((int) m_width
, (int) m_height
); }
534 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
535 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
537 inline wxDouble
GetLeft() const { return m_x
; }
538 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
539 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
540 inline wxDouble
GetTop() const { return m_y
; }
541 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
542 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
543 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
544 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
545 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
546 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
547 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
548 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
550 inline wxPoint2DDouble
GetLeftTop() const
551 { return wxPoint2DDouble( m_x
, m_y
); }
552 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
553 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
554 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
555 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
556 inline wxPoint2DDouble
GetLeftBottom() const
557 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
558 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
559 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
560 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
561 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
562 inline wxPoint2DDouble
GetRightTop() const
563 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
564 inline void SetRightTop( const wxPoint2DDouble
&pt
)
565 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
566 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
567 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
568 inline wxPoint2DDouble
GetRightBottom() const
569 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
570 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
571 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
572 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
573 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
574 inline wxPoint2DDouble
GetCentre() const
575 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
576 inline void SetCentre( const wxPoint2DDouble
&pt
)
577 { MoveCentreTo( pt
); } // since this is impossible without moving...
578 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
579 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
580 inline wxOutCode
GetOutCode( const wxPoint2DDouble
&pt
) const
581 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
582 ( ( pt
.m_x
> m_x
+ m_width
) ? wxOutRight
: 0 ) +
583 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
584 ( ( pt
.m_y
> m_y
+ m_height
) ? wxOutBottom
: 0 )); }
585 inline wxOutCode
GetOutcode(const wxPoint2DDouble
&pt
) const
586 { return GetOutCode(pt
) ; }
587 inline bool Contains( const wxPoint2DDouble
&pt
) const
588 { return GetOutCode( pt
) == wxInside
; }
589 inline bool Contains( const wxRect2DDouble
&rect
) const
590 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
591 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
592 inline bool IsEmpty() const
593 { return m_width
<= 0 || m_height
<= 0; }
594 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
595 { return wxIsSameDouble(rect
.m_width
, m_width
) && wxIsSameDouble(rect
.m_height
, m_height
); }
597 inline void Inset( wxDouble x
, wxDouble y
)
598 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
599 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
600 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
601 inline void Offset( const wxPoint2DDouble
&pt
)
602 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
604 void ConstrainTo( const wxRect2DDouble
&rect
);
606 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
607 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
609 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
610 inline void Intersect( const wxRect2DDouble
&otherRect
)
611 { Intersect( *this , otherRect
, this ); }
612 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
613 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
614 bool Intersects( const wxRect2DDouble
&rect
) const;
616 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
617 void Union( const wxRect2DDouble
&otherRect
)
618 { Union( *this , otherRect
, this ); }
619 void Union( const wxPoint2DDouble
&pt
);
620 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
621 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
623 inline void Scale( wxDouble f
)
624 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
625 inline void Scale( wxInt32 num
, wxInt32 denum
)
626 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
627 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
629 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
630 inline bool operator == (const wxRect2DDouble
& rect
) const
631 { return wxIsSameDouble(m_x
, rect
.m_x
) && wxIsSameDouble(m_y
, rect
.m_y
) && HaveEqualSize(rect
); }
632 inline bool operator != (const wxRect2DDouble
& rect
) const
633 { return !(*this == rect
); }
642 // 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
643 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
644 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
646 class WXDLLEXPORT wxRect2DInt
649 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
650 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
651 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
652 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
653 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
654 inline wxRect2DInt(const wxRect2DInt
& rect
);
656 // single attribute accessors
658 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
659 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
661 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
662 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
664 inline wxInt32
GetLeft() const { return m_x
; }
665 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
666 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
667 inline wxInt32
GetTop() const { return m_y
; }
668 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
669 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
670 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
671 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
672 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
673 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
674 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
675 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
677 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
678 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
; }
679 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
680 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
681 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
; }
682 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
683 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
684 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
; }
685 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
686 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
687 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
688 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
689 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
690 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
691 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); }
692 inline wxOutCode
GetOutCode( const wxPoint2DInt
&pt
) const
693 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
694 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
695 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
696 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
697 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
698 { return GetOutCode( pt
) ; }
699 inline bool Contains( const wxPoint2DInt
&pt
) const
700 { return GetOutCode( pt
) == wxInside
; }
701 inline bool Contains( const wxRect2DInt
&rect
) const
702 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
703 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
704 inline bool IsEmpty() const
705 { return ( m_width
<= 0 || m_height
<= 0 ); }
706 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
707 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
709 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
710 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
711 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
712 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
713 void ConstrainTo( const wxRect2DInt
&rect
);
714 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
716 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
717 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
718 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
719 bool Intersects( const wxRect2DInt
&rect
) const;
721 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
722 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
723 void Union( const wxPoint2DInt
&pt
);
724 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
726 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
727 inline void Scale( wxInt32 num
, wxInt32 denum
)
728 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
729 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
731 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
732 bool operator == (const wxRect2DInt
& rect
) const;
733 bool operator != (const wxRect2DInt
& rect
) const;
736 void WriteTo( wxDataOutputStream
&stream
) const;
737 void ReadFrom( wxDataInputStream
&stream
);
738 #endif // wxUSE_STREAMS
746 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
751 m_height
= r
.m_height
;
754 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
756 m_x
= wxMin( a
.m_x
, b
.m_x
);
757 m_y
= wxMin( a
.m_y
, b
.m_y
);
758 m_width
= abs( a
.m_x
- b
.m_x
);
759 m_height
= abs( a
.m_y
- b
.m_y
);
762 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
& pos
, const wxSize
& size
)
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 ~wxTransform2D() { }
785 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
786 virtual void Transform( wxRect2DInt
* r
) const;
787 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
788 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
790 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
791 virtual void InverseTransform( wxRect2DInt
* r
) const ;
792 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
793 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
796 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
797 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
799 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
800 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
802 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
803 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
805 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
806 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
808 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
809 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
811 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
812 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
815 #endif // wxUSE_GEOMETRY
817 #endif // _WX_GEOMETRY_H_