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"
23 class WXDLLIMPEXP_FWD_BASE wxDataInputStream
;
24 class WXDLLIMPEXP_FWD_BASE wxDataOutputStream
;
26 // clipping from Cohen-Sutherland
37 class WXDLLIMPEXP_CORE wxPoint2DInt
40 inline wxPoint2DInt();
41 inline wxPoint2DInt( wxInt32 x
, wxInt32 y
);
42 inline wxPoint2DInt( const wxPoint2DInt
&pt
);
43 inline wxPoint2DInt( const wxPoint
&pt
);
45 // noops for this class, just return the coords
46 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
47 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
49 inline wxDouble
GetVectorLength() const;
50 wxDouble
GetVectorAngle() const;
51 inline void SetVectorLength( wxDouble length
);
52 void SetVectorAngle( wxDouble degrees
);
53 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
);
54 // set the vector length to 1.0, preserving the angle
55 inline void Normalize();
57 inline wxDouble
GetDistance( const wxPoint2DInt
&pt
) const;
58 inline wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
59 inline wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
60 inline wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
62 // the reflection of this point
63 inline wxPoint2DInt
operator-();
65 inline wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
);
66 inline wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
);
67 inline wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
);
68 inline wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
);
69 inline wxPoint2DInt
& operator*=(wxDouble n
);
70 inline wxPoint2DInt
& operator*=(wxInt32 n
);
71 inline wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
);
72 inline wxPoint2DInt
& operator/=(wxDouble n
);
73 inline wxPoint2DInt
& operator/=(wxInt32 n
);
74 inline operator wxPoint() const;
75 inline bool operator==(const wxPoint2DInt
& pt
) const;
76 inline bool operator!=(const wxPoint2DInt
& pt
) const;
79 void WriteTo( wxDataOutputStream
&stream
) const;
80 void ReadFrom( wxDataInputStream
&stream
);
81 #endif // wxUSE_STREAMS
87 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
88 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
89 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
90 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
91 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
92 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
93 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
94 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
95 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
96 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
98 inline wxPoint2DInt::wxPoint2DInt()
104 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
110 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
116 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
122 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
) const
130 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
) const
135 inline wxDouble
wxPoint2DInt::GetVectorLength() const
137 // cast needed MIPSpro compiler under SGI
138 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
141 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
143 wxDouble before
= GetVectorLength();
144 m_x
= (wxInt32
)(m_x
* length
/ before
);
145 m_y
= (wxInt32
)(m_y
* length
/ before
);
148 inline void wxPoint2DInt::Normalize()
150 SetVectorLength( 1 );
153 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
155 return sqrt( GetDistanceSquare( pt
) );
158 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
160 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
163 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
165 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
168 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
170 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
173 inline wxPoint2DInt::operator wxPoint() const
175 return wxPoint( m_x
, m_y
);
178 inline wxPoint2DInt
wxPoint2DInt::operator-()
180 return wxPoint2DInt( -m_x
, -m_y
);
183 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
193 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
200 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
207 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
214 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
221 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
223 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
226 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
228 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
231 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
233 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.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
);
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*(wxInt32 n
, const wxPoint2DInt
& pt
)
249 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
252 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
254 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
257 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
259 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
262 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
264 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
267 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
269 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
272 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
274 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
);
277 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
279 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) );
282 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
284 class WXDLLIMPEXP_CORE wxPoint2DDouble
287 inline wxPoint2DDouble();
288 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
289 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
290 wxPoint2DDouble( const wxPoint2DInt
&pt
)
291 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
292 wxPoint2DDouble( const wxPoint
&pt
)
293 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
295 // two different conversions to integers, floor and rounding
296 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
297 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
299 inline wxDouble
GetVectorLength() const;
300 wxDouble
GetVectorAngle() const ;
301 void SetVectorLength( wxDouble length
);
302 void SetVectorAngle( wxDouble degrees
);
303 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
304 // set the vector length to 1.0, preserving the angle
307 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
) const;
308 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) const;
309 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) const;
310 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) const;
312 // the reflection of this point
313 inline wxPoint2DDouble
operator-();
315 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
316 inline wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
);
317 inline wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
);
318 inline wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
);
319 inline wxPoint2DDouble
& operator*=(wxDouble n
);
320 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
321 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
322 inline wxPoint2DDouble
& operator/=(wxDouble n
);
323 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
325 inline bool operator==(const wxPoint2DDouble
& pt
) const;
326 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
332 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
333 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
334 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
335 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
336 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
337 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
338 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
339 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
340 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
341 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
343 inline wxPoint2DDouble::wxPoint2DDouble()
349 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
355 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
361 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
) const
363 *x
= (wxInt32
) floor( m_x
);
364 *y
= (wxInt32
) floor( m_y
);
367 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
) const
369 *x
= (wxInt32
) floor( m_x
+ 0.5 );
370 *y
= (wxInt32
) floor( m_y
+ 0.5);
373 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
375 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
378 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
380 wxDouble before
= GetVectorLength() ;
381 m_x
= (m_x
* length
/ before
) ;
382 m_y
= (m_y
* length
/ before
) ;
385 inline void wxPoint2DDouble::Normalize()
387 SetVectorLength( 1 );
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
)
425 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
432 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
439 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
446 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
453 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
455 return wxIsSameDouble(m_x
, pt
.m_x
) && wxIsSameDouble(m_y
, pt
.m_y
);
458 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
460 return !(*this == pt
);
463 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
465 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.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
);
474 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
476 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
479 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
481 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
484 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
486 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
489 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
491 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
494 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
496 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
499 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
501 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
504 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
506 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
509 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
511 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
514 // 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
515 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
516 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
518 class WXDLLIMPEXP_CORE wxRect2DDouble
522 { m_x
= m_y
= m_width
= m_height
= 0; }
523 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
524 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
526 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
527 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
528 wxRect2DDouble(const wxRect2DDouble& rect);
530 // single attribute accessors
532 inline wxPoint2DDouble
GetPosition()
533 { return wxPoint2DDouble(m_x
, m_y
); }
534 inline wxSize
GetSize()
535 { return wxSize((int) m_width
, (int) m_height
); }
537 // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
538 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
540 inline wxDouble
GetLeft() const { return m_x
; }
541 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
542 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
543 inline wxDouble
GetTop() const { return m_y
; }
544 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
545 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
546 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
547 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
548 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
549 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
550 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
551 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
553 inline wxPoint2DDouble
GetLeftTop() const
554 { return wxPoint2DDouble( m_x
, m_y
); }
555 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
556 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
557 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
558 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
559 inline wxPoint2DDouble
GetLeftBottom() const
560 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
561 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
562 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
563 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
564 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
565 inline wxPoint2DDouble
GetRightTop() const
566 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
567 inline void SetRightTop( const wxPoint2DDouble
&pt
)
568 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
569 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
570 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
571 inline wxPoint2DDouble
GetRightBottom() const
572 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
573 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
574 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
575 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
576 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
577 inline wxPoint2DDouble
GetCentre() const
578 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
579 inline void SetCentre( const wxPoint2DDouble
&pt
)
580 { MoveCentreTo( pt
); } // since this is impossible without moving...
581 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
582 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
583 inline wxOutCode
GetOutCode( const wxPoint2DDouble
&pt
) const
584 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
585 ( ( pt
.m_x
> m_x
+ m_width
) ? wxOutRight
: 0 ) +
586 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
587 ( ( pt
.m_y
> m_y
+ m_height
) ? wxOutBottom
: 0 )); }
588 inline wxOutCode
GetOutcode(const wxPoint2DDouble
&pt
) const
589 { return GetOutCode(pt
) ; }
590 inline bool Contains( const wxPoint2DDouble
&pt
) const
591 { return GetOutCode( pt
) == wxInside
; }
592 inline bool Contains( const wxRect2DDouble
&rect
) const
593 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
594 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
595 inline bool IsEmpty() const
596 { return m_width
<= 0 || m_height
<= 0; }
597 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
598 { return wxIsSameDouble(rect
.m_width
, m_width
) && wxIsSameDouble(rect
.m_height
, m_height
); }
600 inline void Inset( wxDouble x
, wxDouble y
)
601 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
602 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
603 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
604 inline void Offset( const wxPoint2DDouble
&pt
)
605 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
607 void ConstrainTo( const wxRect2DDouble
&rect
);
609 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
610 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
612 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
613 inline void Intersect( const wxRect2DDouble
&otherRect
)
614 { Intersect( *this , otherRect
, this ); }
615 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
616 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
617 bool Intersects( const wxRect2DDouble
&rect
) const;
619 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
620 void Union( const wxRect2DDouble
&otherRect
)
621 { Union( *this , otherRect
, this ); }
622 void Union( const wxPoint2DDouble
&pt
);
623 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
624 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
626 inline void Scale( wxDouble f
)
627 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
628 inline void Scale( wxInt32 num
, wxInt32 denum
)
629 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
630 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
632 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
633 inline bool operator == (const wxRect2DDouble
& rect
) const
634 { return wxIsSameDouble(m_x
, rect
.m_x
) && wxIsSameDouble(m_y
, rect
.m_y
) && HaveEqualSize(rect
); }
635 inline bool operator != (const wxRect2DDouble
& rect
) const
636 { return !(*this == rect
); }
645 // 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
646 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
647 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
649 class WXDLLIMPEXP_CORE wxRect2DInt
652 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
653 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
654 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
655 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
656 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
657 inline wxRect2DInt(const wxRect2DInt
& rect
);
659 // single attribute accessors
661 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
662 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
664 // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
665 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
667 inline wxInt32
GetLeft() const { return m_x
; }
668 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
669 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
670 inline wxInt32
GetTop() const { return m_y
; }
671 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
672 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
673 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
674 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
675 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
676 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
677 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
678 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
680 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
681 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
; }
682 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
683 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
684 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
; }
685 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
686 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
687 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
; }
688 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
689 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
690 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
691 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
692 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
693 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
694 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); }
695 inline wxOutCode
GetOutCode( const wxPoint2DInt
&pt
) const
696 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
697 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
698 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
699 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
700 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
701 { return GetOutCode( pt
) ; }
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
) const;
736 bool operator != (const wxRect2DInt
& rect
) const;
739 void WriteTo( wxDataOutputStream
&stream
) const;
740 void ReadFrom( wxDataInputStream
&stream
);
741 #endif // wxUSE_STREAMS
749 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
754 m_height
= r
.m_height
;
757 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
759 m_x
= wxMin( a
.m_x
, b
.m_x
);
760 m_y
= wxMin( a
.m_y
, b
.m_y
);
761 m_width
= abs( a
.m_x
- b
.m_x
);
762 m_height
= abs( a
.m_y
- b
.m_y
);
765 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
& pos
, const wxSize
& size
)
773 inline bool wxRect2DInt::operator == (const wxRect2DInt
& rect
) const
775 return (m_x
==rect
.m_x
&& m_y
==rect
.m_y
&&
776 m_width
==rect
.m_width
&& m_height
==rect
.m_height
);
779 inline bool wxRect2DInt::operator != (const wxRect2DInt
& rect
) const
781 return !(*this == rect
);
787 virtual ~wxTransform2D() { }
788 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
789 virtual void Transform( wxRect2DInt
* r
) const;
790 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
791 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
793 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
794 virtual void InverseTransform( wxRect2DInt
* r
) const ;
795 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
796 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
799 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
800 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
802 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
803 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
805 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
806 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
808 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
809 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
811 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
812 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
814 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
815 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
818 #endif // wxUSE_GEOMETRY
820 #endif // _WX_GEOMETRY_H_