]> git.saurik.com Git - wxWidgets.git/blob - include/wx/geometry.h
added wxGetMultiChoice() (which refuses to work for some reason - will fix
[wxWidgets.git] / include / wx / geometry.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: geometry.h
3 // Purpose: Common Geometry Classes
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 08/05/99
7 // RCS-ID:
8 // Copyright: (c)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GEOMETRY_H_
13 #define _WX_GEOMETRY_H_
14
15 #ifdef __GNUG__
16 #pragma interface "geometry.h"
17 #endif
18
19 #include "wx/defs.h"
20
21 #ifndef wxUSE_GEOMETRY
22 #define wxUSE_GEOMETRY 0
23 #endif
24
25 #if wxUSE_GEOMETRY
26
27 #include "wx/utils.h"
28 #include "wx/gdicmn.h"
29 #include <math.h>
30
31 #ifdef __WXMSW__
32 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
33 #elif defined( __WXMAC__ )
34 #include "Math64.h"
35 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
36 #else
37 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
38 #endif
39
40 class wxDataInputStream ;
41 class wxDataOutputStream ;
42
43 // clipping from Cohen-Sutherland
44
45 enum wxOutCode
46 {
47 wxInside = 0x00 ,
48 wxOutLeft = 0x01 ,
49 wxOutRight = 0x02 ,
50 wxOutTop = 0x08 ,
51 wxOutBottom = 0x04
52 } ;
53
54 // wxPoint2Ds represent a point or a vector in a 2d coordinate system
55
56 class WXDLLEXPORT wxPoint2DDouble
57 {
58 public :
59 wxPoint2DDouble();
60 wxPoint2DDouble( wxDouble x , wxDouble y ) ;
61 wxPoint2DDouble( const wxPoint2DDouble &pt ) ;
62
63 // two different conversions to integers, floor and rounding
64 void GetFloor( wxInt32 *x , wxInt32 *y ) ;
65 void GetRounded( wxInt32 *x , wxInt32 *y ) ;
66
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
73 void Normalize() ;
74
75 wxDouble GetDistance( const wxPoint2DDouble &pt ) ;
76 wxDouble GetDistanceSquare( const wxPoint2DDouble &pt ) ;
77 wxDouble GetDotProduct( const wxPoint2DDouble &vec ) ;
78 wxDouble GetCrossProduct( const wxPoint2DDouble &vec ) ;
79
80 // the reflection of this point
81 wxPoint2DDouble operator-() ;
82
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) ;
92
93 bool operator==(const wxPoint2DDouble& pt) const ;
94 bool operator!=(const wxPoint2DDouble& pt) const ;
95
96 wxDouble m_x ;
97 wxDouble m_y ;
98 } ;
99
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) ;
110
111 inline wxPoint2DDouble::wxPoint2DDouble()
112 {
113 m_x = 0.0 ;
114 m_y = 0.0 ;
115 }
116
117 inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y )
118 {
119 m_x = x ;
120 m_y = y ;
121 }
122
123 inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt )
124 {
125 m_x = pt.m_x ;
126 m_y = pt.m_y ;
127 }
128
129 inline void wxPoint2DDouble::GetFloor( wxInt32 *x , wxInt32 *y )
130 {
131 *x = (wxInt32) floor( m_x ) ;
132 *y = (wxInt32) floor( m_y ) ;
133 }
134
135 inline void wxPoint2DDouble::GetRounded( wxInt32 *x , wxInt32 *y )
136 {
137 *x = (wxInt32) floor( m_x + 0.5 ) ;
138 *y = (wxInt32) floor( m_y + 0.5) ;
139 }
140
141 inline wxDouble wxPoint2DDouble::GetDistance( const wxPoint2DDouble &pt )
142 {
143 return sqrt( GetDistanceSquare( pt ) );
144 }
145
146 inline wxDouble wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble &pt )
147 {
148 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ;
149 }
150
151 inline wxDouble wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble &vec )
152 {
153 return ( m_x * vec.m_x + m_y * vec.m_y ) ;
154 }
155
156 inline wxDouble wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble &vec )
157 {
158 return ( m_x * vec.m_y - vec.m_x * m_y ) ;
159 }
160
161 inline wxPoint2DDouble wxPoint2DDouble::operator-()
162 {
163 return wxPoint2DDouble( -m_x, -m_y);
164 }
165
166 inline wxPoint2DDouble& wxPoint2DDouble::operator=(const wxPoint2DDouble& pt)
167 {
168 m_x = pt.m_x ;
169 m_y = pt.m_y;
170 return *this ;
171 }
172
173 inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt)
174 {
175 m_x = m_x + pt.m_x ;
176 m_y = m_y + pt.m_y;
177 return *this ;
178 }
179
180 inline wxPoint2DDouble& wxPoint2DDouble::operator-=(const wxPoint2DDouble& pt)
181 {
182 m_x = m_x - pt.m_x ;
183 m_y = m_y - pt.m_y;
184 return *this ;
185 }
186
187 inline wxPoint2DDouble& wxPoint2DDouble::operator*=(const wxPoint2DDouble& pt)
188 {
189 m_x = m_x + pt.m_x ;
190 m_y = m_y + pt.m_y;
191 return *this ;
192 }
193
194 inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt)
195 {
196 m_x = m_x - pt.m_x ;
197 m_y = m_y - pt.m_y;
198 return *this ;
199 }
200
201 inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const
202 {
203 return m_x == pt.m_x && m_y == pt.m_y;
204 }
205
206 inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const
207 {
208 return m_x != pt.m_x || m_y != pt.m_y;
209 }
210
211 inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
212 {
213 return wxPoint2DDouble( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ;
214 }
215
216 inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
217 {
218 return wxPoint2DDouble( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ;
219 }
220
221
222 inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
223 {
224 return wxPoint2DDouble( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ;
225 }
226
227 inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt)
228 {
229 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
230 }
231
232 inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt)
233 {
234 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
235 }
236
237 inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n)
238 {
239 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
240 }
241
242 inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n)
243 {
244 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
245 }
246
247 inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
248 {
249 return wxPoint2DDouble( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ;
250 }
251
252 inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n)
253 {
254 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ;
255 }
256
257 inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n)
258 {
259 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ;
260 }
261
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.
265
266 class WXDLLEXPORT wxRect2DDouble
267 {
268 public:
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);
274
275 // single attribute accessors
276
277 inline wxPoint2DDouble GetPosition() { return wxPoint2DDouble(m_x, m_y); }
278 inline wxSize GetSize() { return wxSize(m_width, m_height); }
279
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
282
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 ; }
295
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 ) ; }
325
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 ) ; }
332
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 ;
337
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 ; }
342
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) ;}
347
348 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
349 bool operator == (const wxRect2DDouble& rect);
350 bool operator != (const wxRect2DDouble& rect);
351
352 wxDouble m_x ;
353 wxDouble m_y ;
354 wxDouble m_width;
355 wxDouble m_height;
356 };
357
358 class WXDLLEXPORT wxPoint2DInt
359 {
360 public :
361 wxPoint2DInt();
362 wxPoint2DInt( wxInt32 x , wxInt32 y ) ;
363 wxPoint2DInt( const wxPoint2DInt &pt ) ;
364 wxPoint2DInt( const wxPoint &pt ) ;
365
366 // two different conversions to integers, floor and rounding
367 void GetFloor( wxInt32 *x , wxInt32 *y ) ;
368 void GetRounded( wxInt32 *x , wxInt32 *y ) ;
369
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
376 void Normalize() ;
377
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;
382
383 // the reflection of this point
384 wxPoint2DInt operator-() ;
385
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 ;
398
399 void WriteTo( wxDataOutputStream &stream ) const ;
400 void ReadFrom( wxDataInputStream &stream ) ;
401
402 wxInt32 m_x ;
403 wxInt32 m_y ;
404 } ;
405
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) ;
416
417 inline wxPoint2DInt::wxPoint2DInt()
418 {
419 m_x = 0 ;
420 m_y = 0 ;
421 }
422
423 inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
424 {
425 m_x = x ;
426 m_y = y ;
427 }
428
429 inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
430 {
431 m_x = pt.m_x ;
432 m_y = pt.m_y ;
433 }
434
435 inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt )
436 {
437 m_x = pt.x ;
438 m_y = pt.y ;
439 }
440
441 inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y )
442 {
443 *x = (wxInt32) floor( m_x ) ;
444 *y = (wxInt32) floor( m_y ) ;
445 }
446
447 inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y )
448 {
449 *x = (wxInt32) floor( m_x + 0.5 ) ;
450 *y = (wxInt32) floor( m_y + 0.5) ;
451 }
452
453 inline wxDouble wxPoint2DInt::GetVectorLength()
454 {
455 return sqrt( (m_x)*(m_x) + (m_y)*(m_y) ) ;
456 }
457
458 inline void wxPoint2DInt::SetVectorLength( wxDouble length )
459 {
460 wxDouble before = GetVectorLength() ;
461 m_x = (wxInt32)(m_x * length / before) ;
462 m_y = (wxInt32)(m_y * length / before) ;
463 }
464
465 inline void wxPoint2DInt::Normalize()
466 {
467 SetVectorLength( 1 ) ;
468 }
469
470 inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const
471 {
472 return sqrt( GetDistanceSquare( pt ) );
473 }
474
475 inline wxDouble wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt &pt ) const
476 {
477 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ;
478 }
479
480 inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const
481 {
482 return ( m_x * vec.m_x + m_y * vec.m_y ) ;
483 }
484
485 inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const
486 {
487 return ( m_x * vec.m_y - vec.m_x * m_y ) ;
488 }
489
490 inline wxPoint2DInt::operator wxPoint() const
491 {
492 return wxPoint( m_x, m_y);
493 }
494
495 inline wxPoint2DInt wxPoint2DInt::operator-()
496 {
497 return wxPoint2DInt( -m_x, -m_y);
498 }
499
500 inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt)
501 {
502 m_x = pt.m_x ;
503 m_y = pt.m_y;
504 return *this ;
505 }
506
507 inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt)
508 {
509 m_x = m_x + pt.m_x ;
510 m_y = m_y + pt.m_y;
511 return *this ;
512 }
513
514 inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt)
515 {
516 m_x = m_x - pt.m_x ;
517 m_y = m_y - pt.m_y;
518 return *this ;
519 }
520
521 inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
522 {
523 m_x = m_x + pt.m_x ;
524 m_y = m_y + pt.m_y;
525 return *this ;
526 }
527
528 inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
529 {
530 m_x = m_x - pt.m_x ;
531 m_y = m_y - pt.m_y;
532 return *this ;
533 }
534
535 inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const
536 {
537 return m_x == pt.m_x && m_y == pt.m_y;
538 }
539
540 inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const
541 {
542 return m_x != pt.m_x || m_y != pt.m_y;
543 }
544
545 inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
546 {
547 return wxPoint2DInt( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ;
548 }
549
550 inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
551 {
552 return wxPoint2DInt( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ;
553 }
554
555
556 inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
557 {
558 return wxPoint2DInt( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ;
559 }
560
561 inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
562 {
563 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
564 }
565
566 inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
567 {
568 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
569 }
570
571 inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n)
572 {
573 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
574 }
575
576 inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n)
577 {
578 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
579 }
580
581 inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
582 {
583 return wxPoint2DInt( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ;
584 }
585
586 inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n)
587 {
588 return wxPoint2DInt( pt.m_x / n , pt.m_y / n ) ;
589 }
590
591 inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n)
592 {
593 return wxPoint2DInt( pt.m_x / n , pt.m_y / n ) ;
594 }
595
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.
599
600 class WXDLLEXPORT wxRect2DInt
601 {
602 public:
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);
608
609 // single attribute accessors
610
611 inline wxPoint2DInt GetPosition() { return wxPoint2DInt(m_x, m_y); }
612 inline wxSize GetSize() { return wxSize(m_width, m_height); }
613
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
616
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 ; }
629
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 ) ; }
659
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 ) ; }
666
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 ;
671
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 ; }
676
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) ;}
681
682 wxRect2DInt& operator = (const wxRect2DInt& rect);
683 bool operator == (const wxRect2DInt& rect);
684 bool operator != (const wxRect2DInt& rect);
685
686 void WriteTo( wxDataOutputStream &stream ) const ;
687 void ReadFrom( wxDataInputStream &stream ) ;
688
689 wxInt32 m_x ;
690 wxInt32 m_y ;
691 wxInt32 m_width;
692 wxInt32 m_height;
693 };
694
695 inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r )
696 {
697 m_x = r.m_x ;
698 m_y = r.m_y ;
699 m_width = r.m_width ;
700 m_height = r.m_height ;
701 }
702
703 inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b)
704 {
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 ) ;
709 }
710
711 class wxTransform2D
712 {
713 public :
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 ;
718
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 ;
723 } ;
724
725 inline void wxTransform2D::Transform( wxRect2DInt* r ) const
726 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; Transform( &a ) ; Transform( &b ) ; *r = wxRect2DInt( a , b ) ; }
727
728 inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const
729 { wxPoint2DInt res = pt ; Transform( &res ) ; return res ; }
730
731 inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const
732 { wxRect2DInt res = r ; Transform( &res ) ; return res ; }
733
734 inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const
735 { wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; InverseTransform( &a ) ; InverseTransform( &b ) ; *r = wxRect2DInt( a , b ) ; }
736
737 inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const
738 { wxPoint2DInt res = pt ; InverseTransform( &res ) ; return res ; }
739
740 inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const
741 { wxRect2DInt res = r ; InverseTransform( &res ) ; return res ; }
742
743
744 #endif // wxUSE_GEOMETRY
745
746 #endif // _WX_GEOMETRY_H_