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_
16 #pragma interface "geometry.cpp"
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
59 inline wxPoint2DDouble();
60 inline wxPoint2DDouble( wxDouble x
, wxDouble y
);
61 inline wxPoint2DDouble( const wxPoint2DDouble
&pt
);
63 // two different conversions to integers, floor and rounding
64 inline void GetFloor( wxInt32
*x
, wxInt32
*y
);
65 inline void GetRounded( wxInt32
*x
, wxInt32
*y
);
67 inline wxDouble
GetVectorLength();
68 inline 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 inline wxDouble
GetDistance( const wxPoint2DDouble
&pt
);
76 inline wxDouble
GetDistanceSquare( const wxPoint2DDouble
&pt
);
77 inline wxDouble
GetDotProduct( const wxPoint2DDouble
&vec
);
78 inline wxDouble
GetCrossProduct( const wxPoint2DDouble
&vec
);
80 // the reflection of this point
81 inline wxPoint2DDouble
operator-();
83 inline wxPoint2DDouble
& operator=(const wxPoint2DDouble
& pt
);
84 inline wxPoint2DDouble
& operator+=(const wxPoint2DDouble
& pt
);
85 inline wxPoint2DDouble
& operator-=(const wxPoint2DDouble
& pt
);
86 inline wxPoint2DDouble
& operator*=(const wxPoint2DDouble
& pt
);
87 inline wxPoint2DDouble
& operator*=(wxDouble n
);
88 inline wxPoint2DDouble
& operator*=(wxInt32 n
);
89 inline wxPoint2DDouble
& operator/=(const wxPoint2DDouble
& pt
);
90 inline wxPoint2DDouble
& operator/=(wxDouble n
);
91 inline wxPoint2DDouble
& operator/=(wxInt32 n
);
93 inline bool operator==(const wxPoint2DDouble
& pt
) const;
94 inline bool operator!=(const wxPoint2DDouble
& pt
) const;
100 inline wxPoint2DDouble
operator+(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
101 inline wxPoint2DDouble
operator-(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
102 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
103 inline wxPoint2DDouble
operator*(wxDouble n
, const wxPoint2DDouble
& pt
);
104 inline wxPoint2DDouble
operator*(wxInt32 n
, const wxPoint2DDouble
& pt
);
105 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxDouble n
);
106 inline wxPoint2DDouble
operator*(const wxPoint2DDouble
& pt
, wxInt32 n
);
107 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt1
, const wxPoint2DDouble
& pt2
);
108 inline wxPoint2DDouble
operator/(const wxPoint2DDouble
& pt
, wxDouble n
);
109 inline 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
270 { m_x
= m_y
= m_width
= m_height
= 0; }
271 wxRect2DDouble(wxDouble x
, wxDouble y
, wxDouble w
, wxDouble h
)
272 { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
274 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
275 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
276 wxRect2DDouble(const wxRect2DDouble& rect);
278 // single attribute accessors
280 inline wxPoint2DDouble
GetPosition()
281 { return wxPoint2DDouble(m_x
, m_y
); }
282 inline wxSize
GetSize()
283 { return wxSize((int) m_width
, (int) m_height
); }
285 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
286 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
288 inline wxDouble
GetLeft() const { return m_x
; }
289 inline void SetLeft( wxDouble n
) { m_width
+= m_x
- n
; m_x
= n
; }
290 inline void MoveLeftTo( wxDouble n
) { m_x
= n
; }
291 inline wxDouble
GetTop() const { return m_y
; }
292 inline void SetTop( wxDouble n
) { m_height
+= m_y
- n
; m_y
= n
; }
293 inline void MoveTopTo( wxDouble n
) { m_y
= n
; }
294 inline wxDouble
GetBottom() const { return m_y
+ m_height
; }
295 inline void SetBottom( wxDouble n
) { m_height
+= n
- (m_y
+m_height
);}
296 inline void MoveBottomTo( wxDouble n
) { m_y
= n
- m_height
; }
297 inline wxDouble
GetRight() const { return m_x
+ m_width
; }
298 inline void SetRight( wxDouble n
) { m_width
+= n
- (m_x
+m_width
) ; }
299 inline void MoveRightTo( wxDouble n
) { m_x
= n
- m_width
; }
301 inline wxPoint2DDouble
GetLeftTop() const
302 { return wxPoint2DDouble( m_x
, m_y
); }
303 inline void SetLeftTop( const wxPoint2DDouble
&pt
)
304 { m_width
+= m_x
- pt
.m_x
; m_height
+= m_y
- pt
.m_y
; m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
305 inline void MoveLeftTopTo( const wxPoint2DDouble
&pt
)
306 { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
307 inline wxPoint2DDouble
GetLeftBottom() const
308 { return wxPoint2DDouble( m_x
, m_y
+ m_height
); }
309 inline void SetLeftBottom( const wxPoint2DDouble
&pt
)
310 { m_width
+= m_x
- pt
.m_x
; m_height
+= pt
.m_y
- (m_y
+m_height
) ; m_x
= pt
.m_x
; }
311 inline void MoveLeftBottomTo( const wxPoint2DDouble
&pt
)
312 { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
313 inline wxPoint2DDouble
GetRightTop() const
314 { return wxPoint2DDouble( m_x
+m_width
, m_y
); }
315 inline void SetRightTop( const wxPoint2DDouble
&pt
)
316 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= m_y
- pt
.m_y
; m_y
= pt
.m_y
; }
317 inline void MoveRightTopTo( const wxPoint2DDouble
&pt
)
318 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
319 inline wxPoint2DDouble
GetRightBottom() const
320 { return wxPoint2DDouble( m_x
+m_width
, m_y
+ m_height
); }
321 inline void SetRightBottom( const wxPoint2DDouble
&pt
)
322 { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
323 inline void MoveRightBottomTo( const wxPoint2DDouble
&pt
)
324 { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
325 inline wxPoint2DDouble
GetCentre() const
326 { return wxPoint2DDouble( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
327 inline void SetCentre( const wxPoint2DDouble
&pt
)
328 { MoveCentreTo( pt
); } // since this is impossible without moving...
329 inline void MoveCentreTo( const wxPoint2DDouble
&pt
)
330 { m_x
+= pt
.m_x
- (m_x
+m_width
/2) , m_y
+= pt
.m_y
-(m_y
+m_height
/2); }
331 inline wxOutCode
GetOutcode( const wxPoint2DDouble
&pt
) const
332 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
333 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
334 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
335 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
336 inline bool Contains( const wxPoint2DDouble
&pt
) const
337 { return GetOutcode( pt
) == wxInside
; }
338 inline bool Contains( const wxRect2DDouble
&rect
) const
339 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
340 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
341 inline bool IsEmpty() const
342 { return ( m_width
<= 0 || m_height
<= 0 ); }
343 inline bool HaveEqualSize( const wxRect2DDouble
&rect
) const
344 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
346 inline void Inset( wxDouble x
, wxDouble y
)
347 { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
348 inline void Inset( wxDouble left
, wxDouble top
,wxDouble right
, wxDouble bottom
)
349 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
350 inline void Offset( const wxPoint2DDouble
&pt
)
351 { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
353 void ConstrainTo( const wxRect2DDouble
&rect
);
355 inline wxPoint2DDouble
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
)
356 { return wxPoint2DDouble( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
358 static void Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
359 inline void Intersect( const wxRect2DDouble
&otherRect
)
360 { Intersect( *this , otherRect
, this ); }
361 inline wxRect2DDouble
CreateIntersection( const wxRect2DDouble
&otherRect
) const
362 { wxRect2DDouble result
; Intersect( *this , otherRect
, &result
); return result
; }
363 bool Intersects( const wxRect2DDouble
&rect
) const;
365 static void Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
);
366 void Union( const wxRect2DDouble
&otherRect
)
367 { Union( *this , otherRect
, this ); }
368 void Union( const wxPoint2DDouble
&pt
);
369 inline wxRect2DDouble
CreateUnion( const wxRect2DDouble
&otherRect
) const
370 { wxRect2DDouble result
; Union( *this , otherRect
, &result
); return result
; }
372 inline void Scale( wxDouble f
)
373 { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
374 inline void Scale( wxInt32 num
, wxInt32 denum
)
375 { m_x
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_y
*= ((wxDouble
)num
)/((wxDouble
)denum
);
376 m_width
*= ((wxDouble
)num
)/((wxDouble
)denum
); m_height
*= ((wxDouble
)num
)/((wxDouble
)denum
);}
379 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
380 bool operator == (const wxRect2DDouble& rect);
381 bool operator != (const wxRect2DDouble& rect);
390 class WXDLLEXPORT wxPoint2DInt
393 inline wxPoint2DInt();
394 inline wxPoint2DInt( wxInt32 x
, wxInt32 y
);
395 inline wxPoint2DInt( const wxPoint2DInt
&pt
);
396 inline wxPoint2DInt( const wxPoint
&pt
);
398 // noops for this class, just return the coords
399 inline void GetFloor( wxInt32
*x
, wxInt32
*y
);
400 inline void GetRounded( wxInt32
*x
, wxInt32
*y
);
402 inline wxDouble
GetVectorLength();
403 wxDouble
GetVectorAngle();
404 inline void SetVectorLength( wxDouble length
);
405 void SetVectorAngle( wxDouble degrees
);
406 void SetPolarCoordinates( wxInt32 angle
, wxInt32 length
);
407 // set the vector length to 1.0, preserving the angle
408 inline void Normalize();
410 inline wxDouble
GetDistance( const wxPoint2DInt
&pt
) const;
411 inline wxDouble
GetDistanceSquare( const wxPoint2DInt
&pt
) const;
412 inline wxInt32
GetDotProduct( const wxPoint2DInt
&vec
) const;
413 inline wxInt32
GetCrossProduct( const wxPoint2DInt
&vec
) const;
415 // the reflection of this point
416 inline wxPoint2DInt
operator-();
418 inline wxPoint2DInt
& operator=(const wxPoint2DInt
& pt
);
419 inline wxPoint2DInt
& operator+=(const wxPoint2DInt
& pt
);
420 inline wxPoint2DInt
& operator-=(const wxPoint2DInt
& pt
);
421 inline wxPoint2DInt
& operator*=(const wxPoint2DInt
& pt
);
422 inline wxPoint2DInt
& operator*=(wxDouble n
);
423 inline wxPoint2DInt
& operator*=(wxInt32 n
);
424 inline wxPoint2DInt
& operator/=(const wxPoint2DInt
& pt
);
425 inline wxPoint2DInt
& operator/=(wxDouble n
);
426 inline wxPoint2DInt
& operator/=(wxInt32 n
);
427 inline operator wxPoint() const;
428 inline bool operator==(const wxPoint2DInt
& pt
) const;
429 inline bool operator!=(const wxPoint2DInt
& pt
) const;
431 void WriteTo( wxDataOutputStream
&stream
) const;
432 void ReadFrom( wxDataInputStream
&stream
);
438 wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
439 wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
440 wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
441 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
442 wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
);
443 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
444 wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
);
445 wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
);
446 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
447 wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
);
449 inline wxPoint2DInt::wxPoint2DInt()
455 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x
, wxInt32 y
)
461 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt
&pt
)
467 inline wxPoint2DInt::wxPoint2DInt( const wxPoint
&pt
)
473 inline void wxPoint2DInt::GetFloor( wxInt32
*x
, wxInt32
*y
)
481 inline void wxPoint2DInt::GetRounded( wxInt32
*x
, wxInt32
*y
)
486 inline wxDouble
wxPoint2DInt::GetVectorLength()
488 // cast needed MIPSpro compiler under SGI
489 return sqrt( (double)(m_x
)*(m_x
) + (m_y
)*(m_y
) );
492 inline void wxPoint2DInt::SetVectorLength( wxDouble length
)
494 wxDouble before
= GetVectorLength();
495 m_x
= (wxInt32
)(m_x
* length
/ before
);
496 m_y
= (wxInt32
)(m_y
* length
/ before
);
499 inline void wxPoint2DInt::Normalize()
501 SetVectorLength( 1 );
504 inline wxDouble
wxPoint2DInt::GetDistance( const wxPoint2DInt
&pt
) const
506 return sqrt( GetDistanceSquare( pt
) );
509 inline wxDouble
wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt
&pt
) const
511 return ( (pt
.m_x
-m_x
)*(pt
.m_x
-m_x
) + (pt
.m_y
-m_y
)*(pt
.m_y
-m_y
) );
514 inline wxInt32
wxPoint2DInt::GetDotProduct( const wxPoint2DInt
&vec
) const
516 return ( m_x
* vec
.m_x
+ m_y
* vec
.m_y
);
519 inline wxInt32
wxPoint2DInt::GetCrossProduct( const wxPoint2DInt
&vec
) const
521 return ( m_x
* vec
.m_y
- vec
.m_x
* m_y
);
524 inline wxPoint2DInt::operator wxPoint() const
526 return wxPoint( m_x
, m_y
);
529 inline wxPoint2DInt
wxPoint2DInt::operator-()
531 return wxPoint2DInt( -m_x
, -m_y
);
534 inline wxPoint2DInt
& wxPoint2DInt::operator=(const wxPoint2DInt
& pt
)
541 inline wxPoint2DInt
& wxPoint2DInt::operator+=(const wxPoint2DInt
& pt
)
548 inline wxPoint2DInt
& wxPoint2DInt::operator-=(const wxPoint2DInt
& pt
)
555 inline wxPoint2DInt
& wxPoint2DInt::operator*=(const wxPoint2DInt
& pt
)
562 inline wxPoint2DInt
& wxPoint2DInt::operator/=(const wxPoint2DInt
& pt
)
569 inline bool wxPoint2DInt::operator==(const wxPoint2DInt
& pt
) const
571 return m_x
== pt
.m_x
&& m_y
== pt
.m_y
;
574 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt
& pt
) const
576 return m_x
!= pt
.m_x
|| m_y
!= pt
.m_y
;
579 inline wxPoint2DInt
operator+(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
581 return wxPoint2DInt( pt1
.m_x
+ pt2
.m_x
, pt1
.m_y
+ pt2
.m_y
);
584 inline wxPoint2DInt
operator-(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
586 return wxPoint2DInt( pt1
.m_x
- pt2
.m_x
, pt1
.m_y
- pt2
.m_y
);
590 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
592 return wxPoint2DInt( pt1
.m_x
* pt2
.m_x
, pt1
.m_y
* pt2
.m_y
);
595 inline wxPoint2DInt
operator*(wxInt32 n
, const wxPoint2DInt
& pt
)
597 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
600 inline wxPoint2DInt
operator*(wxDouble n
, const wxPoint2DInt
& pt
)
602 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
605 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxInt32 n
)
607 return wxPoint2DInt( pt
.m_x
* n
, pt
.m_y
* n
);
610 inline wxPoint2DInt
operator*(const wxPoint2DInt
& pt
, wxDouble n
)
612 return wxPoint2DInt( (int) (pt
.m_x
* n
) , (int) (pt
.m_y
* n
) );
615 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt1
, const wxPoint2DInt
& pt2
)
617 return wxPoint2DInt( pt1
.m_x
/ pt2
.m_x
, pt1
.m_y
/ pt2
.m_y
);
620 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxInt32 n
)
622 return wxPoint2DInt( pt
.m_x
/ n
, pt
.m_y
/ n
);
625 inline wxPoint2DInt
operator/(const wxPoint2DInt
& pt
, wxDouble n
)
627 return wxPoint2DInt( (int) (pt
.m_x
/ n
) , (int) (pt
.m_y
/ n
) );
630 // 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
631 // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
632 // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
634 class WXDLLEXPORT wxRect2DInt
637 wxRect2DInt() { m_x
= m_y
= m_width
= m_height
= 0; }
638 wxRect2DInt(wxInt32 x
, wxInt32 y
, wxInt32 w
, wxInt32 h
) { m_x
= x
; m_y
= y
; m_width
= w
; m_height
= h
; }
639 wxRect2DInt(const wxPoint2DInt
& topLeft
, const wxPoint2DInt
& bottomRight
);
640 inline wxRect2DInt(const wxPoint2DInt
& pos
, const wxSize
& size
);
641 inline wxRect2DInt(const wxRect2DInt
& rect
);
643 // single attribute accessors
645 inline wxPoint2DInt
GetPosition() { return wxPoint2DInt(m_x
, m_y
); }
646 inline wxSize
GetSize() { return wxSize(m_width
, m_height
); }
648 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
649 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
651 inline wxInt32
GetLeft() const { return m_x
; }
652 inline void SetLeft( wxInt32 n
) { m_width
+= m_x
- n
; m_x
= n
; }
653 inline void MoveLeftTo( wxInt32 n
) { m_x
= n
; }
654 inline wxInt32
GetTop() const { return m_y
; }
655 inline void SetTop( wxInt32 n
) { m_height
+= m_y
- n
; m_y
= n
; }
656 inline void MoveTopTo( wxInt32 n
) { m_y
= n
; }
657 inline wxInt32
GetBottom() const { return m_y
+ m_height
; }
658 inline void SetBottom( wxInt32 n
) { m_height
+= n
- (m_y
+m_height
);}
659 inline void MoveBottomTo( wxInt32 n
) { m_y
= n
- m_height
; }
660 inline wxInt32
GetRight() const { return m_x
+ m_width
; }
661 inline void SetRight( wxInt32 n
) { m_width
+= n
- (m_x
+m_width
) ; }
662 inline void MoveRightTo( wxInt32 n
) { m_x
= n
- m_width
; }
664 inline wxPoint2DInt
GetLeftTop() const { return wxPoint2DInt( m_x
, m_y
); }
665 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
; }
666 inline void MoveLeftTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
; }
667 inline wxPoint2DInt
GetLeftBottom() const { return wxPoint2DInt( m_x
, m_y
+ m_height
); }
668 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
; }
669 inline void MoveLeftBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
; m_y
= pt
.m_y
- m_height
; }
670 inline wxPoint2DInt
GetRightTop() const { return wxPoint2DInt( m_x
+m_width
, m_y
); }
671 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
; }
672 inline void MoveRightTopTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
; }
673 inline wxPoint2DInt
GetRightBottom() const { return wxPoint2DInt( m_x
+m_width
, m_y
+ m_height
); }
674 inline void SetRightBottom( const wxPoint2DInt
&pt
) { m_width
+= pt
.m_x
- ( m_x
+ m_width
); m_height
+= pt
.m_y
- (m_y
+m_height
);}
675 inline void MoveRightBottomTo( const wxPoint2DInt
&pt
) { m_x
= pt
.m_x
- m_width
; m_y
= pt
.m_y
- m_height
; }
676 inline wxPoint2DInt
GetCentre() const { return wxPoint2DInt( m_x
+m_width
/2 , m_y
+m_height
/2 ); }
677 inline void SetCentre( const wxPoint2DInt
&pt
) { MoveCentreTo( pt
); } // since this is impossible without moving...
678 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); }
679 inline wxOutCode
GetOutcode( const wxPoint2DInt
&pt
) const
680 { return (wxOutCode
) (( ( pt
.m_x
< m_x
) ? wxOutLeft
: 0 ) +
681 ( ( pt
.m_x
>= m_x
+ m_width
) ? wxOutRight
: 0 ) +
682 ( ( pt
.m_y
< m_y
) ? wxOutTop
: 0 ) +
683 ( ( pt
.m_y
>= m_y
+ m_height
) ? wxOutBottom
: 0 )); }
684 inline bool Contains( const wxPoint2DInt
&pt
) const
685 { return GetOutcode( pt
) == wxInside
; }
686 inline bool Contains( const wxRect2DInt
&rect
) const
687 { return ( ( ( m_x
<= rect
.m_x
) && ( rect
.m_x
+ rect
.m_width
<= m_x
+ m_width
) ) &&
688 ( ( m_y
<= rect
.m_y
) && ( rect
.m_y
+ rect
.m_height
<= m_y
+ m_height
) ) ); }
689 inline bool IsEmpty() const
690 { return ( m_width
<= 0 || m_height
<= 0 ); }
691 inline bool HaveEqualSize( const wxRect2DInt
&rect
) const
692 { return ( rect
.m_width
== m_width
&& rect
.m_height
== m_height
); }
694 inline void Inset( wxInt32 x
, wxInt32 y
) { m_x
+= x
; m_y
+= y
; m_width
-= 2 * x
; m_height
-= 2 * y
; }
695 inline void Inset( wxInt32 left
, wxInt32 top
,wxInt32 right
, wxInt32 bottom
)
696 { m_x
+= left
; m_y
+= top
; m_width
-= left
+ right
; m_height
-= top
+ bottom
;}
697 inline void Offset( const wxPoint2DInt
&pt
) { m_x
+= pt
.m_x
; m_y
+= pt
.m_y
; }
698 void ConstrainTo( const wxRect2DInt
&rect
);
699 inline wxPoint2DInt
Interpolate( wxInt32 widthfactor
, wxInt32 heightfactor
) { return wxPoint2DInt( m_x
+ m_width
* widthfactor
, m_y
+ m_height
* heightfactor
); }
701 static void Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
702 inline void Intersect( const wxRect2DInt
&otherRect
) { Intersect( *this , otherRect
, this ); }
703 inline wxRect2DInt
CreateIntersection( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Intersect( *this , otherRect
, &result
); return result
; }
704 bool Intersects( const wxRect2DInt
&rect
) const;
706 static void Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
);
707 void Union( const wxRect2DInt
&otherRect
) { Union( *this , otherRect
, this ); }
708 void Union( const wxPoint2DInt
&pt
);
709 inline wxRect2DInt
CreateUnion( const wxRect2DInt
&otherRect
) const { wxRect2DInt result
; Union( *this , otherRect
, &result
); return result
; }
711 inline void Scale( wxInt32 f
) { m_x
*= f
; m_y
*= f
; m_width
*= f
; m_height
*= f
;}
712 inline void Scale( wxInt32 num
, wxInt32 denum
)
713 { m_x
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_y
*= ((wxInt32
)num
)/((wxInt32
)denum
);
714 m_width
*= ((wxInt32
)num
)/((wxInt32
)denum
); m_height
*= ((wxInt32
)num
)/((wxInt32
)denum
);}
716 wxRect2DInt
& operator = (const wxRect2DInt
& rect
);
717 bool operator == (const wxRect2DInt
& rect
);
718 bool operator != (const wxRect2DInt
& rect
);
720 void WriteTo( wxDataOutputStream
&stream
) const;
721 void ReadFrom( wxDataInputStream
&stream
);
729 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt
&r
)
734 m_height
= r
.m_height
;
737 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt
&a
, const wxPoint2DInt
&b
)
739 m_x
= wxMin( a
.m_x
, b
.m_x
);
740 m_y
= wxMin( a
.m_y
, b
.m_y
);
741 m_width
= abs( a
.m_x
- b
.m_x
);
742 m_height
= abs( a
.m_y
- b
.m_y
);
748 virtual void Transform( wxPoint2DInt
* pt
)const = 0;
749 virtual void Transform( wxRect2DInt
* r
) const;
750 virtual wxPoint2DInt
Transform( const wxPoint2DInt
&pt
) const;
751 virtual wxRect2DInt
Transform( const wxRect2DInt
&r
) const ;
753 virtual void InverseTransform( wxPoint2DInt
* pt
) const = 0;
754 virtual void InverseTransform( wxRect2DInt
* r
) const ;
755 virtual wxPoint2DInt
InverseTransform( const wxPoint2DInt
&pt
) const ;
756 virtual wxRect2DInt
InverseTransform( const wxRect2DInt
&r
) const ;
759 inline void wxTransform2D::Transform( wxRect2DInt
* r
) const
760 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); Transform( &a
); Transform( &b
); *r
= wxRect2DInt( a
, b
); }
762 inline wxPoint2DInt
wxTransform2D::Transform( const wxPoint2DInt
&pt
) const
763 { wxPoint2DInt res
= pt
; Transform( &res
); return res
; }
765 inline wxRect2DInt
wxTransform2D::Transform( const wxRect2DInt
&r
) const
766 { wxRect2DInt res
= r
; Transform( &res
); return res
; }
768 inline void wxTransform2D::InverseTransform( wxRect2DInt
* r
) const
769 { wxPoint2DInt a
= r
->GetLeftTop() , b
= r
->GetRightBottom(); InverseTransform( &a
); InverseTransform( &b
); *r
= wxRect2DInt( a
, b
); }
771 inline wxPoint2DInt
wxTransform2D::InverseTransform( const wxPoint2DInt
&pt
) const
772 { wxPoint2DInt res
= pt
; InverseTransform( &res
); return res
; }
774 inline wxRect2DInt
wxTransform2D::InverseTransform( const wxRect2DInt
&r
) const
775 { wxRect2DInt res
= r
; InverseTransform( &res
); return res
; }
778 #endif // wxUSE_GEOMETRY
780 #endif // _WX_GEOMETRY_H_