]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/geometry.h
Updated ten thousand macros for new event type code.
[wxWidgets.git] / include / wx / geometry.h
... / ...
CommitLineData
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.cpp"
17#endif
18
19#include "wx/defs.h"
20
21#if wxUSE_GEOMETRY
22
23#include "wx/utils.h"
24#include "wx/gdicmn.h"
25#include <math.h>
26
27#ifdef __WXMSW__
28 #define wxMulDivInt32( a , b , c ) ::MulDiv( a , b , c )
29#elif defined( __WXMAC__ )
30 #include "Math64.h"
31 #define wxMulDivInt32( a , b , c ) S32Set( S64Div( S64Multiply( S64Set(a) , S64Set(b) ) , S64Set(c) ) )
32#else
33 #define wxMulDivInt32( a , b , c ) ((wxInt32)((a)*(((wxDouble)b)/((wxDouble)c))))
34#endif
35
36class wxDataInputStream ;
37class wxDataOutputStream ;
38
39// clipping from Cohen-Sutherland
40
41enum wxOutCode
42{
43 wxInside = 0x00 ,
44 wxOutLeft = 0x01 ,
45 wxOutRight = 0x02 ,
46 wxOutTop = 0x08 ,
47 wxOutBottom = 0x04
48} ;
49
50// wxPoint2Ds represent a point or a vector in a 2d coordinate system
51
52class WXDLLEXPORT wxPoint2DDouble
53{
54public :
55 wxPoint2DDouble();
56 wxPoint2DDouble( wxDouble x , wxDouble y ) ;
57 wxPoint2DDouble( const wxPoint2DDouble &pt ) ;
58
59 // two different conversions to integers, floor and rounding
60 void GetFloor( wxInt32 *x , wxInt32 *y ) ;
61 void GetRounded( wxInt32 *x , wxInt32 *y ) ;
62
63 wxDouble GetVectorLength() ;
64 wxDouble GetVectorAngle() ;
65 void SetVectorLength( wxDouble length ) ;
66 void SetVectorAngle( wxDouble degrees ) ;
67 void SetPolarCoordinates( wxDouble angle , wxDouble length ) ;
68 // set the vector length to 1.0, preserving the angle
69 void Normalize() ;
70
71 wxDouble GetDistance( const wxPoint2DDouble &pt ) ;
72 wxDouble GetDistanceSquare( const wxPoint2DDouble &pt ) ;
73 wxDouble GetDotProduct( const wxPoint2DDouble &vec ) ;
74 wxDouble GetCrossProduct( const wxPoint2DDouble &vec ) ;
75
76 // the reflection of this point
77 wxPoint2DDouble operator-() ;
78
79 wxPoint2DDouble& operator=(const wxPoint2DDouble& pt) ;
80 wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt) ;
81 wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt) ;
82 wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt) ;
83 wxPoint2DDouble& operator*=(wxDouble n) ;
84 wxPoint2DDouble& operator*=(wxInt32 n) ;
85 wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt) ;
86 wxPoint2DDouble& operator/=(wxDouble n) ;
87 wxPoint2DDouble& operator/=(wxInt32 n) ;
88
89 bool operator==(const wxPoint2DDouble& pt) const ;
90 bool operator!=(const wxPoint2DDouble& pt) const ;
91
92 wxDouble m_x ;
93 wxDouble m_y ;
94} ;
95
96wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
97wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
98wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
99wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt) ;
100wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt) ;
101wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n) ;
102wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n) ;
103wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2) ;
104wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n) ;
105wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n) ;
106
107inline wxPoint2DDouble::wxPoint2DDouble()
108{
109 m_x = 0.0 ;
110 m_y = 0.0 ;
111}
112
113inline wxPoint2DDouble::wxPoint2DDouble( wxDouble x , wxDouble y )
114{
115 m_x = x ;
116 m_y = y ;
117}
118
119inline wxPoint2DDouble::wxPoint2DDouble( const wxPoint2DDouble &pt )
120{
121 m_x = pt.m_x ;
122 m_y = pt.m_y ;
123}
124
125inline void wxPoint2DDouble::GetFloor( wxInt32 *x , wxInt32 *y )
126{
127 *x = (wxInt32) floor( m_x ) ;
128 *y = (wxInt32) floor( m_y ) ;
129}
130
131inline void wxPoint2DDouble::GetRounded( wxInt32 *x , wxInt32 *y )
132{
133 *x = (wxInt32) floor( m_x + 0.5 ) ;
134 *y = (wxInt32) floor( m_y + 0.5) ;
135}
136
137inline wxDouble wxPoint2DDouble::GetDistance( const wxPoint2DDouble &pt )
138{
139 return sqrt( GetDistanceSquare( pt ) );
140}
141
142inline wxDouble wxPoint2DDouble::GetDistanceSquare( const wxPoint2DDouble &pt )
143{
144 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ;
145}
146
147inline wxDouble wxPoint2DDouble::GetDotProduct( const wxPoint2DDouble &vec )
148{
149 return ( m_x * vec.m_x + m_y * vec.m_y ) ;
150}
151
152inline wxDouble wxPoint2DDouble::GetCrossProduct( const wxPoint2DDouble &vec )
153{
154 return ( m_x * vec.m_y - vec.m_x * m_y ) ;
155}
156
157inline wxPoint2DDouble wxPoint2DDouble::operator-()
158{
159 return wxPoint2DDouble( -m_x, -m_y);
160}
161
162inline wxPoint2DDouble& wxPoint2DDouble::operator=(const wxPoint2DDouble& pt)
163{
164 m_x = pt.m_x ;
165 m_y = pt.m_y;
166 return *this ;
167}
168
169inline wxPoint2DDouble& wxPoint2DDouble::operator+=(const wxPoint2DDouble& pt)
170{
171 m_x = m_x + pt.m_x ;
172 m_y = m_y + pt.m_y;
173 return *this ;
174}
175
176inline wxPoint2DDouble& wxPoint2DDouble::operator-=(const wxPoint2DDouble& pt)
177{
178 m_x = m_x - pt.m_x ;
179 m_y = m_y - pt.m_y;
180 return *this ;
181}
182
183inline wxPoint2DDouble& wxPoint2DDouble::operator*=(const wxPoint2DDouble& pt)
184{
185 m_x = m_x * pt.m_x ;
186 m_y = m_y * pt.m_y;
187 return *this ;
188}
189
190inline wxPoint2DDouble& wxPoint2DDouble::operator/=(const wxPoint2DDouble& pt)
191{
192 m_x = m_x / pt.m_x ;
193 m_y = m_y / pt.m_y;
194 return *this ;
195}
196
197inline bool wxPoint2DDouble::operator==(const wxPoint2DDouble& pt) const
198{
199 return m_x == pt.m_x && m_y == pt.m_y;
200}
201
202inline bool wxPoint2DDouble::operator!=(const wxPoint2DDouble& pt) const
203{
204 return m_x != pt.m_x || m_y != pt.m_y;
205}
206
207inline wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
208{
209 return wxPoint2DDouble( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ;
210}
211
212inline wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
213{
214 return wxPoint2DDouble( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ;
215}
216
217
218inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
219{
220 return wxPoint2DDouble( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ;
221}
222
223inline wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt)
224{
225 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
226}
227
228inline wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt)
229{
230 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
231}
232
233inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n)
234{
235 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
236}
237
238inline wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n)
239{
240 return wxPoint2DDouble( pt.m_x * n , pt.m_y * n ) ;
241}
242
243inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2)
244{
245 return wxPoint2DDouble( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ;
246}
247
248inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n)
249{
250 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ;
251}
252
253inline wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n)
254{
255 return wxPoint2DDouble( pt.m_x / n , pt.m_y / n ) ;
256}
257
258// 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
259// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
260// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
261
262class WXDLLEXPORT wxRect2DDouble
263{
264public:
265 wxRect2DDouble()
266 { m_x = m_y = m_width = m_height = 0 ; }
267 wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h)
268 { m_x = x ; m_y = y ; m_width = w ; m_height = h ; }
269/*
270 wxRect2DDouble(const wxPoint2DDouble& topLeft, const wxPoint2DDouble& bottomRight);
271 wxRect2DDouble(const wxPoint2DDouble& pos, const wxSize& size);
272 wxRect2DDouble(const wxRect2DDouble& rect);
273*/
274 // single attribute accessors
275
276 inline wxPoint2DDouble GetPosition()
277 { return wxPoint2DDouble(m_x, m_y); }
278 inline wxSize GetSize()
279 { return wxSize(m_width, m_height); }
280
281 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
282 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
283
284 inline wxDouble GetLeft() const { return m_x; }
285 inline void SetLeft( wxDouble n ) { m_width += m_x - n ; m_x = n ; }
286 inline void MoveLeftTo( wxDouble n ) { m_x = n ; }
287 inline wxDouble GetTop() const { return m_y; }
288 inline void SetTop( wxDouble n ) { m_height += m_y - n ; m_y = n ; }
289 inline void MoveTopTo( wxDouble n ) { m_y = n ; }
290 inline wxDouble GetBottom() const { return m_y + m_height; }
291 inline void SetBottom( wxDouble n ) { m_height += n - (m_y+m_height) ;}
292 inline void MoveBottomTo( wxDouble n ) { m_y = n - m_height ; }
293 inline wxDouble GetRight() const { return m_x + m_width; }
294 inline void SetRight( wxDouble n ) { m_width += n - (m_x+m_width) ; }
295 inline void MoveRightTo( wxDouble n ) { m_x = n - m_width ; }
296
297 inline wxPoint2DDouble GetLeftTop() const
298 { return wxPoint2DDouble( m_x , m_y ) ; }
299 inline void SetLeftTop( const wxPoint2DDouble &pt )
300 { m_width += m_x - pt.m_x ; m_height += m_y - pt.m_y ; m_x = pt.m_x ; m_y = pt.m_y ; }
301 inline void MoveLeftTopTo( const wxPoint2DDouble &pt )
302 { m_x = pt.m_x ; m_y = pt.m_y ; }
303 inline wxPoint2DDouble GetLeftBottom() const
304 { return wxPoint2DDouble( m_x , m_y + m_height ) ; }
305 inline void SetLeftBottom( const wxPoint2DDouble &pt )
306 { m_width += m_x - pt.m_x ; m_height += pt.m_y - (m_y+m_height) ; m_x = pt.m_x ; }
307 inline void MoveLeftBottomTo( const wxPoint2DDouble &pt )
308 { m_x = pt.m_x ; m_y = pt.m_y - m_height; }
309 inline wxPoint2DDouble GetRightTop() const
310 { return wxPoint2DDouble( m_x+m_width , m_y ) ; }
311 inline void SetRightTop( const wxPoint2DDouble &pt )
312 { m_width += pt.m_x - ( m_x + m_width ) ; m_height += m_y - pt.m_y ; m_y = pt.m_y ; }
313 inline void MoveRightTopTo( const wxPoint2DDouble &pt )
314 { m_x = pt.m_x - m_width ; m_y = pt.m_y ; }
315 inline wxPoint2DDouble GetRightBottom() const
316 { return wxPoint2DDouble( m_x+m_width , m_y + m_height ) ; }
317 inline void SetRightBottom( const wxPoint2DDouble &pt )
318 { m_width += pt.m_x - ( m_x + m_width ) ; m_height += pt.m_y - (m_y+m_height) ;}
319 inline void MoveRightBottomTo( const wxPoint2DDouble &pt )
320 { m_x = pt.m_x - m_width ; m_y = pt.m_y - m_height; }
321 inline wxPoint2DDouble GetCentre() const
322 { return wxPoint2DDouble( m_x+m_width/2 , m_y+m_height/2 ) ; }
323 inline void SetCentre( const wxPoint2DDouble &pt )
324 { MoveCentreTo( pt ) ; } // since this is impossible without moving...
325 inline void MoveCentreTo( const wxPoint2DDouble &pt )
326 { m_x += pt.m_x - (m_x+m_width/2) , m_y += pt.m_y -(m_y+m_height/2) ; }
327 inline wxOutCode GetOutcode( const wxPoint2DDouble &pt ) const
328 { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
329 ( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) +
330 ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
331 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )) ; }
332 inline bool Contains( const wxPoint2DDouble &pt ) const
333 { return GetOutcode( pt ) == wxInside ; }
334 inline bool Contains( const wxRect2DDouble &rect ) const
335 { return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
336 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ) ; }
337 inline bool IsEmpty() const
338 { return ( m_width <= 0 || m_height <= 0 ) ; }
339 inline bool HaveEqualSize( const wxRect2DDouble &rect ) const
340 { return ( rect.m_width == m_width && rect.m_height == m_height ) ; }
341
342 inline void Inset( wxDouble x , wxDouble y )
343 { m_x += x ; m_y += y ; m_width -= 2 * x ; m_height -= 2 * y ; }
344 inline void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom )
345 { m_x += left ; m_y += top ; m_width -= left + right ; m_height -= top + bottom ;}
346 inline void Offset( const wxPoint2DDouble &pt )
347 { m_x += pt.m_x ; m_y += pt.m_y ; }
348
349 void ConstrainTo( const wxRect2DDouble &rect );
350
351 inline wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor )
352 { return wxPoint2DDouble( m_x + m_width * widthfactor , m_y + m_height * heightfactor ) ; }
353
354 static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ) ;
355 inline void Intersect( const wxRect2DDouble &otherRect )
356 { Intersect( *this , otherRect , this ) ; }
357 inline wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const
358 { wxRect2DDouble result ; Intersect( *this , otherRect , &result) ; return result ; }
359 bool Intersects( const wxRect2DDouble &rect ) const ;
360
361 static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest ) ;
362 void Union( const wxRect2DDouble &otherRect )
363 { Union( *this , otherRect , this ) ; }
364 void Union( const wxPoint2DDouble &pt ) ;
365 inline wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const
366 { wxRect2DDouble result ; Union( *this , otherRect , &result) ; return result ; }
367
368 inline void Scale( wxDouble f )
369 { m_x *= f ; m_y *= f ; m_width *= f ; m_height *= f ;}
370 inline void Scale( wxInt32 num , wxInt32 denum )
371 { m_x *= ((wxDouble)num)/((wxDouble)denum) ; m_y *= ((wxDouble)num)/((wxDouble)denum) ;
372 m_width *= ((wxDouble)num)/((wxDouble)denum) ; m_height *= ((wxDouble)num)/((wxDouble)denum) ;}
373
374/*
375 wxRect2DDouble& operator = (const wxRect2DDouble& rect);
376 bool operator == (const wxRect2DDouble& rect);
377 bool operator != (const wxRect2DDouble& rect);
378*/
379
380 wxDouble m_x;
381 wxDouble m_y ;
382 wxDouble m_width;
383 wxDouble m_height;
384};
385
386class WXDLLEXPORT wxPoint2DInt
387{
388public :
389 wxPoint2DInt();
390 wxPoint2DInt( wxInt32 x , wxInt32 y ) ;
391 wxPoint2DInt( const wxPoint2DInt &pt ) ;
392 wxPoint2DInt( const wxPoint &pt ) ;
393
394 // two different conversions to integers, floor and rounding
395 void GetFloor( wxInt32 *x , wxInt32 *y ) ;
396 void GetRounded( wxInt32 *x , wxInt32 *y ) ;
397
398 wxDouble GetVectorLength() ;
399 wxDouble GetVectorAngle() ;
400 void SetVectorLength( wxDouble length ) ;
401 void SetVectorAngle( wxDouble degrees ) ;
402 void SetPolarCoordinates( wxInt32 angle , wxInt32 length ) ;
403 // set the vector length to 1.0, preserving the angle
404 void Normalize() ;
405
406 wxDouble GetDistance( const wxPoint2DInt &pt ) const ;
407 wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const;
408 wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const;
409 wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const;
410
411 // the reflection of this point
412 wxPoint2DInt operator-() ;
413
414 wxPoint2DInt& operator=(const wxPoint2DInt& pt) ;
415 wxPoint2DInt& operator+=(const wxPoint2DInt& pt) ;
416 wxPoint2DInt& operator-=(const wxPoint2DInt& pt) ;
417 wxPoint2DInt& operator*=(const wxPoint2DInt& pt) ;
418 wxPoint2DInt& operator*=(wxDouble n) ;
419 wxPoint2DInt& operator*=(wxInt32 n) ;
420 wxPoint2DInt& operator/=(const wxPoint2DInt& pt) ;
421 wxPoint2DInt& operator/=(wxDouble n) ;
422 wxPoint2DInt& operator/=(wxInt32 n) ;
423 operator wxPoint() const ;
424 bool operator==(const wxPoint2DInt& pt) const ;
425 bool operator!=(const wxPoint2DInt& pt) const ;
426
427 void WriteTo( wxDataOutputStream &stream ) const ;
428 void ReadFrom( wxDataInputStream &stream ) ;
429
430 wxInt32 m_x ;
431 wxInt32 m_y ;
432} ;
433
434wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
435wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
436wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
437wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt) ;
438wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt) ;
439wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n) ;
440wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n) ;
441wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2) ;
442wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n) ;
443wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n) ;
444
445inline wxPoint2DInt::wxPoint2DInt()
446{
447 m_x = 0 ;
448 m_y = 0 ;
449}
450
451inline wxPoint2DInt::wxPoint2DInt( wxInt32 x , wxInt32 y )
452{
453 m_x = x ;
454 m_y = y ;
455}
456
457inline wxPoint2DInt::wxPoint2DInt( const wxPoint2DInt &pt )
458{
459 m_x = pt.m_x ;
460 m_y = pt.m_y ;
461}
462
463inline wxPoint2DInt::wxPoint2DInt( const wxPoint &pt )
464{
465 m_x = pt.x ;
466 m_y = pt.y ;
467}
468
469inline void wxPoint2DInt::GetFloor( wxInt32 *x , wxInt32 *y )
470{
471 *x = (wxInt32) floor( m_x ) ;
472 *y = (wxInt32) floor( m_y ) ;
473}
474
475inline void wxPoint2DInt::GetRounded( wxInt32 *x , wxInt32 *y )
476{
477 *x = (wxInt32) floor( m_x + 0.5 ) ;
478 *y = (wxInt32) floor( m_y + 0.5) ;
479}
480
481inline wxDouble wxPoint2DInt::GetVectorLength()
482{
483 return sqrt( (m_x)*(m_x) + (m_y)*(m_y) ) ;
484}
485
486inline void wxPoint2DInt::SetVectorLength( wxDouble length )
487{
488 wxDouble before = GetVectorLength() ;
489 m_x = (wxInt32)(m_x * length / before) ;
490 m_y = (wxInt32)(m_y * length / before) ;
491}
492
493inline void wxPoint2DInt::Normalize()
494{
495 SetVectorLength( 1 ) ;
496}
497
498inline wxDouble wxPoint2DInt::GetDistance( const wxPoint2DInt &pt ) const
499{
500 return sqrt( GetDistanceSquare( pt ) );
501}
502
503inline wxDouble wxPoint2DInt::GetDistanceSquare( const wxPoint2DInt &pt ) const
504{
505 return ( (pt.m_x-m_x)*(pt.m_x-m_x) + (pt.m_y-m_y)*(pt.m_y-m_y) ) ;
506}
507
508inline wxInt32 wxPoint2DInt::GetDotProduct( const wxPoint2DInt &vec ) const
509{
510 return ( m_x * vec.m_x + m_y * vec.m_y ) ;
511}
512
513inline wxInt32 wxPoint2DInt::GetCrossProduct( const wxPoint2DInt &vec ) const
514{
515 return ( m_x * vec.m_y - vec.m_x * m_y ) ;
516}
517
518inline wxPoint2DInt::operator wxPoint() const
519{
520 return wxPoint( m_x, m_y);
521}
522
523inline wxPoint2DInt wxPoint2DInt::operator-()
524{
525 return wxPoint2DInt( -m_x, -m_y);
526}
527
528inline wxPoint2DInt& wxPoint2DInt::operator=(const wxPoint2DInt& pt)
529{
530 m_x = pt.m_x ;
531 m_y = pt.m_y;
532 return *this ;
533}
534
535inline wxPoint2DInt& wxPoint2DInt::operator+=(const wxPoint2DInt& pt)
536{
537 m_x = m_x + pt.m_x ;
538 m_y = m_y + pt.m_y;
539 return *this ;
540}
541
542inline wxPoint2DInt& wxPoint2DInt::operator-=(const wxPoint2DInt& pt)
543{
544 m_x = m_x - pt.m_x ;
545 m_y = m_y - pt.m_y;
546 return *this ;
547}
548
549inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
550{
551 m_x = m_x + pt.m_x ;
552 m_y = m_y + pt.m_y;
553 return *this ;
554}
555
556inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
557{
558 m_x = m_x - pt.m_x ;
559 m_y = m_y - pt.m_y;
560 return *this ;
561}
562
563inline bool wxPoint2DInt::operator==(const wxPoint2DInt& pt) const
564{
565 return m_x == pt.m_x && m_y == pt.m_y;
566}
567
568inline bool wxPoint2DInt::operator!=(const wxPoint2DInt& pt) const
569{
570 return m_x != pt.m_x || m_y != pt.m_y;
571}
572
573inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
574{
575 return wxPoint2DInt( pt1.m_x + pt2.m_x , pt1.m_y + pt2.m_y ) ;
576}
577
578inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
579{
580 return wxPoint2DInt( pt1.m_x - pt2.m_x , pt1.m_y - pt2.m_y ) ;
581}
582
583
584inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
585{
586 return wxPoint2DInt( pt1.m_x * pt2.m_x , pt1.m_y * pt2.m_y ) ;
587}
588
589inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
590{
591 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
592}
593
594inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
595{
596 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
597}
598
599inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n)
600{
601 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
602}
603
604inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n)
605{
606 return wxPoint2DInt( pt.m_x * n , pt.m_y * n ) ;
607}
608
609inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
610{
611 return wxPoint2DInt( pt1.m_x / pt2.m_x , pt1.m_y / pt2.m_y ) ;
612}
613
614inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n)
615{
616 return wxPoint2DInt( pt.m_x / n , pt.m_y / n ) ;
617}
618
619inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n)
620{
621 return wxPoint2DInt( pt.m_x / n , pt.m_y / n ) ;
622}
623
624// 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
625// top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
626// left <= x < right and top <= m_y < bottom , thus it is a half open interval.
627
628class WXDLLEXPORT wxRect2DInt
629{
630public:
631 wxRect2DInt() { m_x = m_y = m_width = m_height = 0 ; }
632 wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h) { m_x = x ; m_y = y ; m_width = w ; m_height = h ; }
633 wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight);
634 wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size);
635 wxRect2DInt(const wxRect2DInt& rect);
636
637 // single attribute accessors
638
639 inline wxPoint2DInt GetPosition() { return wxPoint2DInt(m_x, m_y); }
640 inline wxSize GetSize() { return wxSize(m_width, m_height); }
641
642 // for the edge and corner accessors there are two setters conterparts, the Set.. functions keep the other corners at their
643 // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners apropriately
644
645 inline wxInt32 GetLeft() const { return m_x; }
646 inline void SetLeft( wxInt32 n ) { m_width += m_x - n ; m_x = n ; }
647 inline void MoveLeftTo( wxInt32 n ) { m_x = n ; }
648 inline wxInt32 GetTop() const { return m_y; }
649 inline void SetTop( wxInt32 n ) { m_height += m_y - n ; m_y = n ; }
650 inline void MoveTopTo( wxInt32 n ) { m_y = n ; }
651 inline wxInt32 GetBottom() const { return m_y + m_height; }
652 inline void SetBottom( wxInt32 n ) { m_height += n - (m_y+m_height) ;}
653 inline void MoveBottomTo( wxInt32 n ) { m_y = n - m_height ; }
654 inline wxInt32 GetRight() const { return m_x + m_width; }
655 inline void SetRight( wxInt32 n ) { m_width += n - (m_x+m_width) ; }
656 inline void MoveRightTo( wxInt32 n ) { m_x = n - m_width ; }
657
658 inline wxPoint2DInt GetLeftTop() const { return wxPoint2DInt( m_x , m_y ) ; }
659 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 ; }
660 inline void MoveLeftTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x ; m_y = pt.m_y ; }
661 inline wxPoint2DInt GetLeftBottom() const { return wxPoint2DInt( m_x , m_y + m_height ) ; }
662 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 ; }
663 inline void MoveLeftBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x ; m_y = pt.m_y - m_height; }
664 inline wxPoint2DInt GetRightTop() const { return wxPoint2DInt( m_x+m_width , m_y ) ; }
665 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 ; }
666 inline void MoveRightTopTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y ; }
667 inline wxPoint2DInt GetRightBottom() const { return wxPoint2DInt( m_x+m_width , m_y + m_height ) ; }
668 inline void SetRightBottom( const wxPoint2DInt &pt ) { m_width += pt.m_x - ( m_x + m_width ) ; m_height += pt.m_y - (m_y+m_height) ;}
669 inline void MoveRightBottomTo( const wxPoint2DInt &pt ) { m_x = pt.m_x - m_width ; m_y = pt.m_y - m_height; }
670 inline wxPoint2DInt GetCentre() const { return wxPoint2DInt( m_x+m_width/2 , m_y+m_height/2 ) ; }
671 inline void SetCentre( const wxPoint2DInt &pt ) { MoveCentreTo( pt ) ; } // since this is impossible without moving...
672 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) ; }
673 inline wxOutCode GetOutcode( const wxPoint2DInt &pt ) const
674 { return (wxOutCode) (( ( pt.m_x < m_x ) ? wxOutLeft : 0 ) +
675 ( ( pt.m_x >= m_x + m_width ) ? wxOutRight : 0 ) +
676 ( ( pt.m_y < m_y ) ? wxOutTop : 0 ) +
677 ( ( pt.m_y >= m_y + m_height ) ? wxOutBottom : 0 )) ; }
678 inline bool Contains( const wxPoint2DInt &pt ) const
679 { return GetOutcode( pt ) == wxInside ; }
680 inline bool Contains( const wxRect2DInt &rect ) const
681 { return ( ( ( m_x <= rect.m_x ) && ( rect.m_x + rect.m_width <= m_x + m_width ) ) &&
682 ( ( m_y <= rect.m_y ) && ( rect.m_y + rect.m_height <= m_y + m_height ) ) ) ; }
683 inline bool IsEmpty() const
684 { return ( m_width <= 0 || m_height <= 0 ) ; }
685 inline bool HaveEqualSize( const wxRect2DInt &rect ) const
686 { return ( rect.m_width == m_width && rect.m_height == m_height ) ; }
687
688 inline void Inset( wxInt32 x , wxInt32 y ) { m_x += x ; m_y += y ; m_width -= 2 * x ; m_height -= 2 * y ; }
689 inline void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom )
690 { m_x += left ; m_y += top ; m_width -= left + right ; m_height -= top + bottom ;}
691 inline void Offset( const wxPoint2DInt &pt ) { m_x += pt.m_x ; m_y += pt.m_y ; }
692 void ConstrainTo( const wxRect2DInt &rect ) ;
693 inline wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor ) { return wxPoint2DInt( m_x + m_width * widthfactor , m_y + m_height * heightfactor ) ; }
694
695 static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ) ;
696 inline void Intersect( const wxRect2DInt &otherRect ) { Intersect( *this , otherRect , this ) ; }
697 inline wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const { wxRect2DInt result ; Intersect( *this , otherRect , &result) ; return result ; }
698 bool Intersects( const wxRect2DInt &rect ) const ;
699
700 static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest ) ;
701 void Union( const wxRect2DInt &otherRect ) { Union( *this , otherRect , this ) ; }
702 void Union( const wxPoint2DInt &pt ) ;
703 inline wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const { wxRect2DInt result ; Union( *this , otherRect , &result) ; return result ; }
704
705 inline void Scale( wxInt32 f ) { m_x *= f ; m_y *= f ; m_width *= f ; m_height *= f ;}
706 inline void Scale( wxInt32 num , wxInt32 denum )
707 { m_x *= ((wxInt32)num)/((wxInt32)denum) ; m_y *= ((wxInt32)num)/((wxInt32)denum) ;
708 m_width *= ((wxInt32)num)/((wxInt32)denum) ; m_height *= ((wxInt32)num)/((wxInt32)denum) ;}
709
710 wxRect2DInt& operator = (const wxRect2DInt& rect);
711 bool operator == (const wxRect2DInt& rect);
712 bool operator != (const wxRect2DInt& rect);
713
714 void WriteTo( wxDataOutputStream &stream ) const ;
715 void ReadFrom( wxDataInputStream &stream ) ;
716
717 wxInt32 m_x ;
718 wxInt32 m_y ;
719 wxInt32 m_width;
720 wxInt32 m_height;
721};
722
723inline wxRect2DInt::wxRect2DInt( const wxRect2DInt &r )
724{
725 m_x = r.m_x ;
726 m_y = r.m_y ;
727 m_width = r.m_width ;
728 m_height = r.m_height ;
729}
730
731inline wxRect2DInt::wxRect2DInt( const wxPoint2DInt &a , const wxPoint2DInt &b)
732{
733 m_x = wxMin( a.m_x , b.m_x ) ;
734 m_y = wxMin( a.m_y , b.m_y ) ;
735 m_width = abs( a.m_x - b.m_x ) ;
736 m_height = abs( a.m_y - b.m_y ) ;
737}
738
739class wxTransform2D
740{
741public :
742 virtual void Transform( wxPoint2DInt* pt )const = 0 ;
743 virtual void Transform( wxRect2DInt* r ) const ;
744 virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const ;
745 virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ;
746
747 virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
748 virtual void InverseTransform( wxRect2DInt* r ) const ;
749 virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
750 virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
751} ;
752
753inline void wxTransform2D::Transform( wxRect2DInt* r ) const
754{ wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; Transform( &a ) ; Transform( &b ) ; *r = wxRect2DInt( a , b ) ; }
755
756inline wxPoint2DInt wxTransform2D::Transform( const wxPoint2DInt &pt ) const
757{ wxPoint2DInt res = pt ; Transform( &res ) ; return res ; }
758
759inline wxRect2DInt wxTransform2D::Transform( const wxRect2DInt &r ) const
760{ wxRect2DInt res = r ; Transform( &res ) ; return res ; }
761
762inline void wxTransform2D::InverseTransform( wxRect2DInt* r ) const
763{ wxPoint2DInt a = r->GetLeftTop() , b = r->GetRightBottom() ; InverseTransform( &a ) ; InverseTransform( &b ) ; *r = wxRect2DInt( a , b ) ; }
764
765inline wxPoint2DInt wxTransform2D::InverseTransform( const wxPoint2DInt &pt ) const
766{ wxPoint2DInt res = pt ; InverseTransform( &res ) ; return res ; }
767
768inline wxRect2DInt wxTransform2D::InverseTransform( const wxRect2DInt &r ) const
769{ wxRect2DInt res = r ; InverseTransform( &res ) ; return res ; }
770
771
772#endif // wxUSE_GEOMETRY
773
774#endif // _WX_GEOMETRY_H_