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