1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common Geometry Classes
4 // Author: Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GEOMETRY_H_
13 #define _WX_GEOMETRY_H_
16 #pragma interface "geometry.h"
21 #ifndef wxUSE_GEOMETRY
22 #define wxUSE_GEOMETRY 0
28 #include "wx/gdicmn.h"
32 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
33 #elif defined( __WXMAC__ )
35 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
37 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
40 class wxDataInputStream
;
41 class wxDataOutputStream
;
43 // clipping from Cohen-Sutherland
54 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
56 class WXDLLEXPORT wxPoint2DDouble
60 wxPoint2DDouble( wxDouble x
, wxDouble y
) ;
61 wxPoint2DDouble( const wxPoint2DDouble
&pt
) ;
63 // two different conversions to integers, floor and rounding
64 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
65 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
67 wxDouble
GetVectorLength() ;
68 wxDouble
GetVectorAngle() ;
69 void SetVectorLength( wxDouble length
) ;
70 void SetVectorAngle( wxDouble degrees
) ;
71 void SetPolarCoordinates( wxDouble angle
, wxDouble length
) ;
72 // set the vector length to 1.0, preserving the angle
75 wxDouble
GetDistance( const wxPoint2DDouble
&pt
) ;
76 wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
) ;
77 wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
) ;
78 wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
) ;
80 // the reflection of this point
81 wxPoint2DDouble
operator-() ;
83 wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
) ;
84 wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
) ;
85 wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
) ;
86 wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
) ;
87 wxPoint2DDouble
& operator*=(wxDouble n
) ;
88 wxPoint2DDouble
& operator*=(wxInt32 n
) ;
89 wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
) ;
90 wxPoint2DDouble
& operator/=(wxDouble n
) ;
91 wxPoint2DDouble
& operator/=(wxInt32 n
) ;
93 bool operator==(const wxPoint2DDouble
& pt
) const ;
94 bool operator!=(const wxPoint2DDouble
& pt
) const ;
100 wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
101 wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
102 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
103 wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
) ;
104 wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
) ;
105 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
) ;
106 wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
107 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
) ;
108 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
) ;
109 wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
) ;
111 inline wxPoint2DDouble::wxPoint2DDouble()
117 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x
, wxDouble y
)
123 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble
&pt
)
129 inline void wxPoint2DDouble::GetFloor( wxInt32
*x
, wxInt32
*y
)
131 *x
= (wxInt32
) floor( m_x
) ;
132 *y
= (wxInt32
) floor( m_y
) ;
135 inline void wxPoint2DDouble::GetRounded( wxInt32
*x
, wxInt32
*y
)
137 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
138 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
141 inline wxDouble
wxPoint2DDouble::GetDistance( const wxPoint2DDouble
&pt
)
143 return sqrt( GetDistanceSquare( pt
) );
146 inline wxDouble
wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble
&pt
)
148 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
151 inline wxDouble
wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble
&vec
)
153 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
156 inline wxDouble
wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble
&vec
)
158 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
161 inline wxPoint2DDouble
wxPoint2DDouble::operator-()
163 return wxPoint2DDouble( -m_x
, -m_y
);
166 inline wxPoint2DDouble
& wxPoint2DDouble::operator=(const wxPoint2DDouble
& pt
)
173 inline wxPoint2DDouble
& wxPoint2DDouble::operator+=(const wxPoint2DDouble
& pt
)
180 inline wxPoint2DDouble
& wxPoint2DDouble::operator-=(const wxPoint2DDouble
& pt
)
187 inline wxPoint2DDouble
& wxPoint2DDouble::operator*=(const wxPoint2DDouble
& pt
)
194 inline wxPoint2DDouble
& wxPoint2DDouble::operator/=(const wxPoint2DDouble
& pt
)
201 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble
& pt
) const
203 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
206 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble
& pt
) const
208 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
211 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
213 return wxPoint2DDouble( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
216 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
218 return wxPoint2DDouble( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
222 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
224 return wxPoint2DDouble( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
227 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
)
229 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
232 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
)
234 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
237 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
)
239 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
242 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
)
244 return wxPoint2DDouble( pt
.m_x
* n
, pt
.m_y
* n
) ;
247 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
)
249 return wxPoint2DDouble( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
252 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
)
254 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
257 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxInt32 n
)
259 return wxPoint2DDouble( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
262 // 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
263 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
264 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
266 class WXDLLEXPORT wxRect2DDouble
269 wxRect2DDouble() { m_x
= m_y
= m_width
= m_height
= 0 ; }
270 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
271 wxRect2DDouble(const wxPoint2DDouble
& topLeft
, const wxPoint2DDouble
& bottomRight
);
272 wxRect2DDouble(const wxPoint2DDouble
& pos
, const wxSize
& size
);
273 wxRect2DDouble(const wxRect2DDouble
& rect
);
275 // single attribute accessors
277 inline wxPoint2DDouble
GetPosition() { return wxPoint2DDouble(m_x
, m_y
); }
278 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
280 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
281 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
283 inline wxDouble
GetLeft() const { return m_x
; }
284 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
285 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
286 inline wxDouble
GetTop() const { return m_y
; }
287 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
288 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
289 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
290 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
) ;}
291 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
292 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
293 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
294 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
296 inline wxPoint2DDouble
GetLeftTop() const { return wxPoint2DDouble( m_x
, m_y
) ; }
297 inline void SetLeftTop( const wxPoint2DDouble
&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
; }
298 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
299 inline wxPoint2DDouble
GetLeftBottom() const { return wxPoint2DDouble( m_x
, m_y
+ m_height
) ; }
300 inline void SetLeftBottom( const wxPoint2DDouble
&pt
) { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
301 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
302 inline wxPoint2DDouble
GetRightTop() const { return wxPoint2DDouble( m_x
+m_width
, m_y
) ; }
303 inline void SetRightTop( const wxPoint2DDouble
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
304 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
305 inline wxPoint2DDouble
GetRightBottom() const { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
) ; }
306 inline void SetRightBottom( const wxPoint2DDouble
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
307 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
308 inline wxPoint2DDouble
GetCentre() const { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
309 inline void SetCentre( const wxPoint2DDouble
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
310 inline void MoveCentreTo( const wxPoint2DDouble
&pt
) { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2) ; }
311 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
312 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
313 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
314 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
315 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
316 inline bool Contains( const wxPoint2DDouble
&pt
) const
317 { return GetOutcode( pt
) == wxInside
; }
318 inline bool Contains( const wxRect2DDouble
&rect
) const
319 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
320 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
321 inline bool IsEmpty() const
322 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
323 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
324 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
326 inline void Inset( wxDouble x
, wxDouble y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
327 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
328 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
329 inline void Offset( const wxPoint2DDouble
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
330 void ConstrainTo( const wxRect2DDouble
&rect
) ;
331 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
333 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
334 inline void Intersect( const wxRect2DDouble
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
335 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
) ; return result
; }
336 bool Intersects( const wxRect2DDouble
&rect
) const ;
338 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
) ;
339 void Union( const wxRect2DDouble
&otherRect
) { Union( *this , otherRect
, this ) ; }
340 void Union( const wxPoint2DDouble
&pt
) ;
341 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const { wxRect2DDouble result
; Union( *this , otherRect
, &result
) ; return result
; }
343 inline void Scale( wxDouble f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
344 inline void Scale( wxInt32 num
, wxInt32 denum
)
345 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;
346 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
) ; m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
) ;}
348 wxRect2DDouble
& operator = (const wxRect2DDouble
& rect
);
349 bool operator == (const wxRect2DDouble
& rect
);
350 bool operator != (const wxRect2DDouble
& rect
);
358 class WXDLLEXPORT wxPoint2DInt
362 wxPoint2DInt( wxInt32 x
, wxInt32 y
) ;
363 wxPoint2DInt( const wxPoint2DInt
&pt
) ;
364 wxPoint2DInt( const wxPoint
&pt
) ;
366 // two different conversions to integers, floor and rounding
367 void GetFloor( wxInt32
*x
, wxInt32
*y
) ;
368 void GetRounded( wxInt32
*x
, wxInt32
*y
) ;
370 wxDouble
GetVectorLength() ;
371 wxDouble
GetVectorAngle() ;
372 void SetVectorLength( wxDouble length
) ;
373 void SetVectorAngle( wxDouble degrees
) ;
374 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
) ;
375 // set the vector length to 1.0, preserving the angle
378 wxDouble
GetDistance( const wxPoint2DInt
&pt
) const ;
379 wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
380 wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
381 wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
383 // the reflection of this point
384 wxPoint2DInt
operator-() ;
386 wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
) ;
387 wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
) ;
388 wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
) ;
389 wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
) ;
390 wxPoint2DInt
& operator*=(wxDouble n
) ;
391 wxPoint2DInt
& operator*=(wxInt32 n
) ;
392 wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
) ;
393 wxPoint2DInt
& operator/=(wxDouble n
) ;
394 wxPoint2DInt
& operator/=(wxInt32 n
) ;
395 operator wxPoint() const ;
396 bool operator==(const wxPoint2DInt
& pt
) const ;
397 bool operator!=(const wxPoint2DInt
& pt
) const ;
399 void WriteTo( wxDataOutputStream
&stream
) const ;
400 void ReadFrom( wxDataInputStream
&stream
) ;
406 wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
407 wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
408 wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
409 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
410 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
) ;
411 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
412 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
) ;
413 wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
) ;
414 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
415 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
) ;
417 inline wxPoint2DInt::wxPoint2DInt()
423 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
429 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
435 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
441 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
443 *x
= (wxInt32
) floor( m_x
) ;
444 *y
= (wxInt32
) floor( m_y
) ;
447 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
449 *x
= (wxInt32
) floor( m_x
+ 0.5 ) ;
450 *y
= (wxInt32
) floor( m_y
+ 0.5) ;
453 inline wxDouble
wxPoint2DInt::GetVectorLength()
455 return sqrt( (m_x
)*(m_x
) + (m_y
)*(m_y
) ) ;
458 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
460 wxDouble before
= GetVectorLength() ;
461 m_x
= (wxInt32
)(m_x
* length
/ before
) ;
462 m_y
= (wxInt32
)(m_y
* length
/ before
) ;
465 inline void wxPoint2DInt::Normalize()
467 SetVectorLength( 1 ) ;
470 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
472 return sqrt( GetDistanceSquare( pt
) );
475 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
477 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) ) ;
480 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
482 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
) ;
485 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
487 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
) ;
490 inline wxPoint2DInt::operator wxPoint() const
492 return wxPoint( m_x
, m_y
);
495 inline wxPoint2DInt
wxPoint2DInt::operator-()
497 return wxPoint2DInt( -m_x
, -m_y
);
500 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
507 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
514 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
521 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
528 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
535 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
537 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
540 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
542 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
545 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
547 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
) ;
550 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
552 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
) ;
556 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
558 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
) ;
561 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
563 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
566 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
568 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
571 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
573 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
576 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
578 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
) ;
581 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
583 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
) ;
586 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
588 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
591 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
593 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
) ;
596 // 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
597 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
598 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
600 class WXDLLEXPORT wxRect2DInt
603 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0 ; }
604 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
605 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
606 wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
607 wxRect2DInt(const wxRect2DInt
& rect
);
609 // single attribute accessors
611 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
612 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
614 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
615 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
617 inline wxInt32
GetLeft() const { return m_x
; }
618 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
619 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
620 inline wxInt32
GetTop() const { return m_y
; }
621 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
622 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
623 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
624 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
) ;}
625 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
626 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
627 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
628 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
630 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
) ; }
631 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
; }
632 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
633 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
) ; }
634 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
; }
635 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
636 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
) ; }
637 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
; }
638 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
639 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
) ; }
640 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
) ; m_height
+= pt
.m_y
- (m_y
+m_height
) ;}
641 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
642 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ) ; }
643 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
) ; } // since this is impossible without moving...
644 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) ; }
645 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
646 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
647 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
648 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
649 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )) ; }
650 inline bool Contains( const wxPoint2DInt
&pt
) const
651 { return GetOutcode( pt
) == wxInside
; }
652 inline bool Contains( const wxRect2DInt
&rect
) const
653 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
654 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ) ; }
655 inline bool IsEmpty() const
656 { return ( m_width
<= 0 || m_height
<= 0 ) ; }
657 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
658 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
) ; }
660 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
661 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
662 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
663 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
664 void ConstrainTo( const wxRect2DInt
&rect
) ;
665 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
) ; }
667 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
668 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ) ; }
669 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
) ; return result
; }
670 bool Intersects( const wxRect2DInt
&rect
) const ;
672 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
) ;
673 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ) ; }
674 void Union( const wxPoint2DInt
&pt
) ;
675 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
) ; return result
; }
677 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
678 inline void Scale( wxInt32 num
, wxInt32 denum
)
679 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;
680 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
) ; m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
) ;}
682 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
683 bool operator == (const wxRect2DInt
& rect
);
684 bool operator != (const wxRect2DInt
& rect
);
686 void WriteTo( wxDataOutputStream
&stream
) const ;
687 void ReadFrom( wxDataInputStream
&stream
) ;
695 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
699 m_width
= r
.m_width
;
700 m_height
= r
.m_height
;
703 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
705 m_x
= wxMin( a
.m_x
, b
.m_x
) ;
706 m_y
= wxMin( a
.m_y
, b
.m_y
) ;
707 m_width
= abs( a
.m_x
- b
.m_x
) ;
708 m_height
= abs( a
.m_y
- b
.m_y
) ;
714 virtual void Transform( wxPoint2DInt
* pt
)const = 0 ;
715 virtual void Transform( wxRect2DInt
* r
) const ;
716 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const ;
717 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
719 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
720 virtual void InverseTransform( wxRect2DInt
* r
) const ;
721 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
722 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
725 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
726 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; Transform( &a
) ; Transform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
728 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
729 { wxPoint2DInt res
= pt
; Transform( &res
) ; return res
; }
731 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
732 { wxRect2DInt res
= r
; Transform( &res
) ; return res
; }
734 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
735 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom() ; InverseTransform( &a
) ; InverseTransform( &b
) ; *r
= wxRect2DInt( a
, b
) ; }
737 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
738 { wxPoint2DInt res
= pt
; InverseTransform( &res
) ; return res
; }
740 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
741 { wxRect2DInt res
= r
; InverseTransform( &res
) ; return res
; }
744 #endif // wxUSE_GEOMETRY
746 #endif // _WX_GEOMETRY_H_