1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common Geometry Classes
4 // Author: Stefan Csomor
7 // Copyright: (c) 1999 Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GEOMETRY_H_
12 #define _WX_GEOMETRY_H_
19 #include "wx/gdicmn.h"
22 class WXDLLIMPEXP_FWD_BASE wxDataInputStream
;
23 class WXDLLIMPEXP_FWD_BASE wxDataOutputStream
;
25 // clipping from Cohen-Sutherland
36 class WXDLLIMPEXP_CORE wxPoint2DInt
39 inline wxPoint2DInt();
40 inline wxPoint2DInt( wxInt32 x
, wxInt32 y
);
41 inline wxPoint2DInt( const wxPoint2DInt
&pt
);
42 inline wxPoint2DInt( const wxPoint
&pt
);
44 // noops for this class, just return the coords
45 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
46 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
48 inline wxDouble
GetVectorLength() const;
49 wxDouble
GetVectorAngle() const;
50 inline void SetVectorLength( wxDouble length
);
51 void SetVectorAngle( wxDouble degrees
);
52 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
);
53 // set the vector length to 1.0, preserving the angle
54 inline void Normalize();
56 inline wxDouble
GetDistance( const wxPoint2DInt
&pt
) const;
57 inline wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
58 inline wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
59 inline wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
61 // the reflection of this point
62 inline wxPoint2DInt
operator-();
64 inline wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
);
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*=(wxDouble n
);
69 inline wxPoint2DInt
& operator*=(wxInt32 n
);
70 inline wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
);
71 inline wxPoint2DInt
& operator/=(wxDouble n
);
72 inline wxPoint2DInt
& operator/=(wxInt32 n
);
73 inline operator wxPoint() const;
74 inline bool operator==(const wxPoint2DInt
& pt
) const;
75 inline bool operator!=(const wxPoint2DInt
& pt
) const;
78 void WriteTo( wxDataOutputStream
&stream
) const;
79 void ReadFrom( wxDataInputStream
&stream
);
80 #endif // wxUSE_STREAMS
86 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
87 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
88 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
89 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
90 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
91 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
92 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
94 inline wxPoint2DInt::wxPoint2DInt()
100 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
106 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
112 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
118 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
) const
126 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
) const
131 inline wxDouble
wxPoint2DInt::GetVectorLength() const
133 // cast needed MIPSpro compiler under SGI
134 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
137 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
139 wxDouble before
= GetVectorLength();
140 m_x
= (wxInt32
)(m_x
* length
/ before
);
141 m_y
= (wxInt32
)(m_y
* length
/ before
);
144 inline void wxPoint2DInt::Normalize()
146 SetVectorLength( 1 );
149 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
151 return sqrt( GetDistanceSquare( pt
) );
154 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
156 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
159 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
161 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
164 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
166 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
169 inline wxPoint2DInt::operator wxPoint() const
171 return wxPoint( m_x
, m_y
);
174 inline wxPoint2DInt
wxPoint2DInt::operator-()
176 return wxPoint2DInt( -m_x
, -m_y
);
179 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
189 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
196 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
203 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
210 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
217 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
219 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
222 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
224 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
227 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
229 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
232 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
234 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
238 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
240 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
243 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
245 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
248 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
250 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
253 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
255 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
258 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
260 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
263 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
265 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
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 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
280 class WXDLLIMPEXP_CORE wxPoint2DDouble
283 inline wxPoint2DDouble();
284 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
285 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
286 wxPoint2DDouble( const wxPoint2DInt
&pt
)
287 { m_x
= (wxDouble
) pt
.m_x
; m_y
= (wxDouble
) pt
.m_y
; }
288 wxPoint2DDouble( const wxPoint
&pt
)
289 { m_x
= (wxDouble
) pt
.x
; m_y
= (wxDouble
) pt
.y
; }
291 // two different conversions to integers, floor and rounding
292 inline void GetFloor( wxInt32
*x
, wxInt32
*y
) const;
293 inline void GetRounded( wxInt32
*x
, wxInt32
*y
) const;
295 inline wxDouble
GetVectorLength() const;
296 wxDouble
GetVectorAngle() const ;
297 void SetVectorLength( wxDouble length
);
298 void SetVectorAngle( wxDouble degrees
);
299 void SetPolarCoordinates( wxDouble angle
, wxDouble length
);
300 // set the vector length to 1.0, preserving the angle
303 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
) const;
304 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) const;
305 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) const;
306 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) const;
308 // the reflection of this point
309 inline wxPoint2DDouble
operator-();
311 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
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*=(wxDouble n
);
316 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
317 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
318 inline wxPoint2DDouble
& operator/=(wxDouble n
);
319 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
321 inline bool operator==(const wxPoint2DDouble
& pt
) const;
322 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
328 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
329 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
330 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
331 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
332 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
333 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
334 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
335 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
336 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
337 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
);
339 inline wxPoint2DDouble::wxPoint2DDouble()
345 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
351 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
357 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
) const
359 *x
= (wxInt32
) floor( m_x
);
360 *y
= (wxInt32
) floor( m_y
);
363 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
) const
365 *x
= (wxInt32
) floor( m_x
+ 0.5 );
366 *y
= (wxInt32
) floor( m_y
+ 0.5);
369 inline wxDouble
wxPoint2DDouble::GetVectorLength() const
371 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
374 inline void wxPoint2DDouble::SetVectorLength( wxDouble length
)
376 wxDouble before
= GetVectorLength() ;
377 m_x
= (m_x
* length
/ before
) ;
378 m_y
= (m_y
* length
/ before
) ;
381 inline void wxPoint2DDouble::Normalize()
383 SetVectorLength( 1 );
386 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
) const
388 return sqrt( GetDistanceSquare( pt
) );
391 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
) const
393 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
396 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
) const
398 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
401 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
) const
403 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
406 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
408 return wxPoint2DDouble( -m_x
, -m_y
);
411 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
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 bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
451 return wxIsSameDouble(m_x
, pt
.m_x
) && wxIsSameDouble(m_y
, pt
.m_y
);
454 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
456 return !(*this == pt
);
459 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
461 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
464 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
466 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
470 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
472 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
475 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
477 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
480 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
482 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
485 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
487 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
490 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
492 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
);
495 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
497 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
500 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
502 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
505 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
507 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
);
510 // 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
511 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
512 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
514 class WXDLLIMPEXP_CORE wxRect2DDouble
518 { m_x
= m_y
= m_width
= m_height
= 0; }
519 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
520 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
522 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
523 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
524 wxRect2DDouble(const wxRect2DDouble& rect);
526 // single attribute accessors
528 wxPoint2DDouble
GetPosition() const
529 { return wxPoint2DDouble(m_x
, m_y
); }
530 wxSize
GetSize() const
531 { return wxSize((int) m_width
, (int) m_height
); }
533 // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
534 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
536 inline wxDouble
GetLeft() const { return m_x
; }
537 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
538 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
539 inline wxDouble
GetTop() const { return m_y
; }
540 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
541 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
542 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
543 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
544 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
545 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
546 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
547 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
549 inline wxPoint2DDouble
GetLeftTop() const
550 { return wxPoint2DDouble( m_x
, m_y
); }
551 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
552 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
553 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
554 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
555 inline wxPoint2DDouble
GetLeftBottom() const
556 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
557 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
558 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
559 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
560 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
561 inline wxPoint2DDouble
GetRightTop() const
562 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
563 inline void SetRightTop( const wxPoint2DDouble
&pt
)
564 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
565 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
566 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
567 inline wxPoint2DDouble
GetRightBottom() const
568 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
569 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
570 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
571 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
572 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
573 inline wxPoint2DDouble
GetCentre() const
574 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
575 inline void SetCentre( const wxPoint2DDouble
&pt
)
576 { MoveCentreTo( pt
); } // since this is impossible without moving...
577 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
578 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
579 inline wxOutCode
GetOutCode( const wxPoint2DDouble
&pt
) const
580 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
581 ( ( pt
.m_x
> m_x
+ m_width
) ? wxOutRight
: 0 ) +
582 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
583 ( ( pt
.m_y
> m_y
+ m_height
) ? wxOutBottom
: 0 )); }
584 inline wxOutCode
GetOutcode(const wxPoint2DDouble
&pt
) const
585 { return GetOutCode(pt
) ; }
586 inline bool Contains( const wxPoint2DDouble
&pt
) const
587 { return GetOutCode( pt
) == wxInside
; }
588 inline bool Contains( const wxRect2DDouble
&rect
) const
589 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
590 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
591 inline bool IsEmpty() const
592 { return m_width
<= 0 || m_height
<= 0; }
593 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
594 { return wxIsSameDouble(rect
.m_width
, m_width
) && wxIsSameDouble(rect
.m_height
, m_height
); }
596 inline void Inset( wxDouble x
, wxDouble y
)
597 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
598 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
599 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
600 inline void Offset( const wxPoint2DDouble
&pt
)
601 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
603 void ConstrainTo( const wxRect2DDouble
&rect
);
605 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
606 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
608 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
609 inline void Intersect( const wxRect2DDouble
&otherRect
)
610 { Intersect( *this , otherRect
, this ); }
611 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
612 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
613 bool Intersects( const wxRect2DDouble
&rect
) const;
615 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
616 void Union( const wxRect2DDouble
&otherRect
)
617 { Union( *this , otherRect
, this ); }
618 void Union( const wxPoint2DDouble
&pt
);
619 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
620 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
622 inline void Scale( wxDouble f
)
623 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
624 inline void Scale( wxInt32 num
, wxInt32 denum
)
625 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
626 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
628 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
629 inline bool operator == (const wxRect2DDouble
& rect
) const
630 { return wxIsSameDouble(m_x
, rect
.m_x
) && wxIsSameDouble(m_y
, rect
.m_y
) && HaveEqualSize(rect
); }
631 inline bool operator != (const wxRect2DDouble
& rect
) const
632 { return !(*this == rect
); }
641 // 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
642 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
643 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
645 class WXDLLIMPEXP_CORE wxRect2DInt
648 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
649 wxRect2DInt( const wxRect
& r
) { m_x
= r
.x
; m_y
= r
.y
; m_width
= r
.width
; m_height
= r
.height
; }
650 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
651 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
652 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
653 inline wxRect2DInt(const wxRect2DInt
& rect
);
655 // single attribute accessors
657 wxPoint2DInt
GetPosition() const { return wxPoint2DInt(m_x
, m_y
); }
658 wxSize
GetSize() const { return wxSize(m_width
, m_height
); }
660 // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
661 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
663 inline wxInt32
GetLeft() const { return m_x
; }
664 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
665 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
666 inline wxInt32
GetTop() const { return m_y
; }
667 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
668 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
669 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
670 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
671 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
672 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
673 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
674 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
676 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
677 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
; }
678 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
679 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
680 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
; }
681 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
682 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
683 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
; }
684 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
685 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
686 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
687 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
688 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
689 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
690 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); }
691 inline wxOutCode
GetOutCode( const wxPoint2DInt
&pt
) const
692 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
693 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
694 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
695 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
696 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
697 { return GetOutCode( pt
) ; }
698 inline bool Contains( const wxPoint2DInt
&pt
) const
699 { return GetOutCode( pt
) == wxInside
; }
700 inline bool Contains( const wxRect2DInt
&rect
) const
701 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
702 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
703 inline bool IsEmpty() const
704 { return ( m_width
<= 0 || m_height
<= 0 ); }
705 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
706 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
708 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
709 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
710 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
711 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
712 void ConstrainTo( const wxRect2DInt
&rect
);
713 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
715 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
716 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
717 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
718 bool Intersects( const wxRect2DInt
&rect
) const;
720 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
721 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
722 void Union( const wxPoint2DInt
&pt
);
723 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
725 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
726 inline void Scale( wxInt32 num
, wxInt32 denum
)
727 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
728 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
730 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
731 bool operator == (const wxRect2DInt
& rect
) const;
732 bool operator != (const wxRect2DInt
& rect
) const;
735 void WriteTo( wxDataOutputStream
&stream
) const;
736 void ReadFrom( wxDataInputStream
&stream
);
737 #endif // wxUSE_STREAMS
745 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
750 m_height
= r
.m_height
;
753 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
755 m_x
= wxMin( a
.m_x
, b
.m_x
);
756 m_y
= wxMin( a
.m_y
, b
.m_y
);
757 m_width
= abs( a
.m_x
- b
.m_x
);
758 m_height
= abs( a
.m_y
- b
.m_y
);
761 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
& pos
, const wxSize
& size
)
769 inline bool wxRect2DInt::operator == (const wxRect2DInt
& rect
) const
771 return (m_x
==rect
.m_x
&& m_y
==rect
.m_y
&&
772 m_width
==rect
.m_width
&& m_height
==rect
.m_height
);
775 inline bool wxRect2DInt::operator != (const wxRect2DInt
& rect
) const
777 return !(*this == rect
);
780 class WXDLLIMPEXP_CORE wxTransform2D
783 virtual ~wxTransform2D() { }
784 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
785 virtual void Transform( wxRect2DInt
* r
) const;
786 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
787 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
789 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
790 virtual void InverseTransform( wxRect2DInt
* r
) const ;
791 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
792 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
796 #endif // wxUSE_GEOMETRY
798 #endif // _WX_GEOMETRY_H_