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