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