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 WXDLLEXPORT 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
)
190 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
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 bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
220 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
223 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
225 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
228 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
230 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
233 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
235 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
239 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
241 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
244 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
246 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
249 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
251 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
254 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
256 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
259 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
261 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
264 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
266 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
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 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
281 class WXDLLEXPORT wxPoint2DDouble
284 inline wxPoint2DDouble();
285 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
286 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
287 wxPoint2DDouble( const wxPoint2DInt
&pt
)
288 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
289 wxPoint2DDouble( const wxPoint
&pt
)
290 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
292 // two different conversions to integers, floor and rounding
293 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
294 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
296 inline wxDouble
GetVectorLength() const;
297 wxDouble
GetVectorAngle() const ;
298 void SetVectorLength( wxDouble length
);
299 void SetVectorAngle( wxDouble degrees
);
300 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
301 // set the vector length to 1.0, preserving the angle
304 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
) const;
305 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) const;
306 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) const;
307 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) const;
309 // the reflection of this point
310 inline wxPoint2DDouble
operator-();
312 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
313 inline wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
);
314 inline wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
);
315 inline wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
);
316 inline wxPoint2DDouble
& operator*=(wxDouble n
);
317 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
318 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
319 inline wxPoint2DDouble
& operator/=(wxDouble n
);
320 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
322 inline bool operator==(const wxPoint2DDouble
& pt
) const;
323 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
329 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
330 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
331 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
332 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
333 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
334 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
335 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
336 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
337 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
338 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
340 inline wxPoint2DDouble::wxPoint2DDouble()
346 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
352 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
358 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
) const
360 *x
= (wxInt32
) floor( m_x
);
361 *y
= (wxInt32
) floor( m_y
);
364 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
) const
366 *x
= (wxInt32
) floor( m_x
+ 0.5 );
367 *y
= (wxInt32
) floor( m_y
+ 0.5);
370 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
372 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
375 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
377 wxDouble before
= GetVectorLength() ;
378 m_x
= (m_x
* length
/ before
) ;
379 m_y
= (m_y
* length
/ before
) ;
382 inline void wxPoint2DDouble::Normalize()
384 SetVectorLength( 1 );
387 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
) const
389 return sqrt( GetDistanceSquare( pt
) );
392 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
) const
394 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
397 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
) const
399 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
402 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
) const
404 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
407 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
409 return wxPoint2DDouble( -m_x
, -m_y
);
412 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
419 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
426 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
433 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
440 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
447 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
449 return wxIsSameDouble(m_x
, pt
.m_x
) && wxIsSameDouble(m_y
, pt
.m_y
);
452 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
454 return !(*this == pt
);
457 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
459 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
462 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
464 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
);
473 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
475 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
478 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
480 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
483 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
485 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
488 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
490 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
493 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
495 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
498 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
500 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
503 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
505 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
508 // 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
509 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
510 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
512 class WXDLLEXPORT wxRect2DDouble
516 { m_x
= m_y
= m_width
= m_height
= 0; }
517 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
518 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
520 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
521 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
522 wxRect2DDouble(const wxRect2DDouble& rect);
524 // single attribute accessors
526 inline wxPoint2DDouble
GetPosition()
527 { return wxPoint2DDouble(m_x
, m_y
); }
528 inline wxSize
GetSize()
529 { return wxSize((int) m_width
, (int) m_height
); }
531 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
532 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
534 inline wxDouble
GetLeft() const { return m_x
; }
535 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
536 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
537 inline wxDouble
GetTop() const { return m_y
; }
538 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
539 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
540 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
541 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
542 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
543 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
544 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
545 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
547 inline wxPoint2DDouble
GetLeftTop() const
548 { return wxPoint2DDouble( m_x
, m_y
); }
549 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
550 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
551 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
552 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
553 inline wxPoint2DDouble
GetLeftBottom() const
554 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
555 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
556 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
557 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
558 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
559 inline wxPoint2DDouble
GetRightTop() const
560 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
561 inline void SetRightTop( const wxPoint2DDouble
&pt
)
562 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
563 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
564 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
565 inline wxPoint2DDouble
GetRightBottom() const
566 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
567 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
568 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
569 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
570 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
571 inline wxPoint2DDouble
GetCentre() const
572 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
573 inline void SetCentre( const wxPoint2DDouble
&pt
)
574 { MoveCentreTo( pt
); } // since this is impossible without moving...
575 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
576 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
577 inline wxOutCode
GetOutCode( const wxPoint2DDouble
&pt
) const
578 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
579 ( ( pt
.m_x
> m_x
+ m_width
) ? wxOutRight
: 0 ) +
580 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
581 ( ( pt
.m_y
> m_y
+ m_height
) ? wxOutBottom
: 0 )); }
582 inline wxOutCode
GetOutcode(const wxPoint2DDouble
&pt
) const
583 { return GetOutCode(pt
) ; }
584 inline bool Contains( const wxPoint2DDouble
&pt
) const
585 { return GetOutCode( pt
) == wxInside
; }
586 inline bool Contains( const wxRect2DDouble
&rect
) const
587 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
588 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
589 inline bool IsEmpty() const
590 { return m_width
<= 0 || m_height
<= 0; }
591 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
592 { return wxIsSameDouble(rect
.m_width
, m_width
) && wxIsSameDouble(rect
.m_height
, m_height
); }
594 inline void Inset( wxDouble x
, wxDouble y
)
595 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
596 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
597 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
598 inline void Offset( const wxPoint2DDouble
&pt
)
599 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
601 void ConstrainTo( const wxRect2DDouble
&rect
);
603 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
604 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
606 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
607 inline void Intersect( const wxRect2DDouble
&otherRect
)
608 { Intersect( *this , otherRect
, this ); }
609 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
610 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
611 bool Intersects( const wxRect2DDouble
&rect
) const;
613 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
614 void Union( const wxRect2DDouble
&otherRect
)
615 { Union( *this , otherRect
, this ); }
616 void Union( const wxPoint2DDouble
&pt
);
617 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
618 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
620 inline void Scale( wxDouble f
)
621 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
622 inline void Scale( wxInt32 num
, wxInt32 denum
)
623 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
624 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
626 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
627 inline bool operator == (const wxRect2DDouble
& rect
) const
628 { return wxIsSameDouble(m_x
, rect
.m_x
) && wxIsSameDouble(m_y
, rect
.m_y
) && HaveEqualSize(rect
); }
629 inline bool operator != (const wxRect2DDouble
& rect
) const
630 { return !(*this == rect
); }
639 // 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
640 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
641 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
643 class WXDLLEXPORT wxRect2DInt
646 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
647 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
648 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
649 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
650 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
651 inline wxRect2DInt(const wxRect2DInt
& rect
);
653 // single attribute accessors
655 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
656 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
658 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
659 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
661 inline wxInt32
GetLeft() const { return m_x
; }
662 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
663 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
664 inline wxInt32
GetTop() const { return m_y
; }
665 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
666 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
667 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
668 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
669 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
670 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
671 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
672 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
674 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
675 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
; }
676 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
677 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
678 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
; }
679 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
680 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
681 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
; }
682 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
683 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
684 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
685 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
686 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
687 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
688 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); }
689 inline wxOutCode
GetOutCode( const wxPoint2DInt
&pt
) const
690 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
691 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
692 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
693 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
694 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
695 { return GetOutCode( pt
) ; }
696 inline bool Contains( const wxPoint2DInt
&pt
) const
697 { return GetOutCode( pt
) == wxInside
; }
698 inline bool Contains( const wxRect2DInt
&rect
) const
699 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
700 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
701 inline bool IsEmpty() const
702 { return ( m_width
<= 0 || m_height
<= 0 ); }
703 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
704 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
706 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
707 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
708 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
709 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
710 void ConstrainTo( const wxRect2DInt
&rect
);
711 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
713 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
714 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
715 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
716 bool Intersects( const wxRect2DInt
&rect
) const;
718 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
719 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
720 void Union( const wxPoint2DInt
&pt
);
721 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
723 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
724 inline void Scale( wxInt32 num
, wxInt32 denum
)
725 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
726 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
728 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
729 bool operator == (const wxRect2DInt
& rect
) const;
730 bool operator != (const wxRect2DInt
& rect
) const;
733 void WriteTo( wxDataOutputStream
&stream
) const;
734 void ReadFrom( wxDataInputStream
&stream
);
735 #endif // wxUSE_STREAMS
743 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
748 m_height
= r
.m_height
;
751 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
753 m_x
= wxMin( a
.m_x
, b
.m_x
);
754 m_y
= wxMin( a
.m_y
, b
.m_y
);
755 m_width
= abs( a
.m_x
- b
.m_x
);
756 m_height
= abs( a
.m_y
- b
.m_y
);
759 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
& pos
, const wxSize
& size
)
767 inline bool wxRect2DInt::operator == (const wxRect2DInt
& rect
) const
769 return (m_x
==rect
.m_x
&& m_y
==rect
.m_y
&&
770 m_width
==rect
.m_width
&& m_height
==rect
.m_height
);
773 inline bool wxRect2DInt::operator != (const wxRect2DInt
& rect
) const
775 return !(*this == rect
);
781 virtual ~wxTransform2D() { }
782 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
783 virtual void Transform( wxRect2DInt
* r
) const;
784 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
785 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
787 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
788 virtual void InverseTransform( wxRect2DInt
* r
) const ;
789 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
790 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
793 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
794 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
796 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
797 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
799 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
800 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
802 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
803 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
805 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
806 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
808 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
809 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
812 #endif // wxUSE_GEOMETRY
814 #endif // _WX_GEOMETRY_H_