]>
git.saurik.com Git - wxWidgets.git/blob - src/common/geometry.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common Geometry Classes
4 // Author: Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma interface "geometry.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
29 #include "wx/geometry.h"
30 #include "wx/datstrm.h"
42 // for the following calculations always remember
43 // that the right and bottom edges are not part of a rect
45 bool wxRect2DDouble::Intersects( const wxRect2DDouble
&rect
) const
47 wxDouble left
,right
,bottom
,top
;
48 left
= wxMax ( m_x
, rect
.m_x
) ;
49 right
= wxMin ( m_x
+m_width
, rect
.m_x
+ rect
.m_width
) ;
50 top
= wxMax ( m_y
, rect
.m_y
) ;
51 bottom
= wxMin ( m_y
+m_height
, rect
.m_y
+ rect
.m_height
) ;
53 if ( left
< right
&& top
< bottom
)
60 void wxRect2DDouble::Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
)
62 wxDouble left
,right
,bottom
,top
;
63 left
= wxMax ( src1
.m_x
, src2
.m_x
) ;
64 right
= wxMin ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
65 top
= wxMax ( src1
.m_y
, src2
.m_y
) ;
66 bottom
= wxMin ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
68 if ( left
< right
&& top
< bottom
)
72 dest
->m_width
= right
- left
;
73 dest
->m_height
= bottom
- top
;
77 dest
->m_width
= dest
->m_height
= 0 ;
81 void wxRect2DDouble::Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
)
83 wxDouble left
,right
,bottom
,top
;
85 left
= wxMin ( src1
.m_x
, src2
.m_x
) ;
86 right
= wxMax ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
87 top
= wxMin ( src1
.m_y
, src2
.m_y
) ;
88 bottom
= wxMax ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
92 dest
->m_width
= right
- left
;
93 dest
->m_height
= bottom
- top
;
96 void wxRect2DDouble::Union( const wxPoint2DDouble
&pt
)
105 else if ( x
< m_x
+ m_width
)
118 else if ( y
< m_y
+ m_height
)
128 void wxRect2DDouble::ConstrainTo( const wxRect2DDouble
&rect
)
130 if ( GetLeft() < rect
.GetLeft() )
131 SetLeft( rect
.GetLeft() ) ;
133 if ( GetRight() > rect
.GetRight() )
134 SetRight( rect
.GetRight() ) ;
136 if ( GetBottom() > rect
.GetBottom() )
137 SetBottom( rect
.GetBottom() ) ;
139 if ( GetTop() < rect
.GetTop() )
140 SetTop( rect
.GetTop() ) ;
145 // for the following calculations always remember
146 // that the right and bottom edges are not part of a rect
150 void wxPoint2DInt::WriteTo( wxDataOutputStream
&stream
) const
152 stream
.Write32( m_x
) ;
153 stream
.Write32( m_y
) ;
156 void wxPoint2DInt::ReadFrom( wxDataInputStream
&stream
)
158 m_x
= stream
.Read32() ;
159 m_y
= stream
.Read32() ;
162 wxDouble
wxPoint2DInt::GetVectorAngle()
178 wxDouble deg
= atan2( m_y
, m_x
) * 180 / 3.14159265359 ;
189 bool wxRect2DInt::Intersects( const wxRect2DInt
&rect
) const
191 wxInt32 left
,right
,bottom
,top
;
192 left
= wxMax ( m_x
, rect
.m_x
) ;
193 right
= wxMin ( m_x
+m_width
, rect
.m_x
+ rect
.m_width
) ;
194 top
= wxMax ( m_y
, rect
.m_y
) ;
195 bottom
= wxMin ( m_y
+m_height
, rect
.m_y
+ rect
.m_height
) ;
197 if ( left
< right
&& top
< bottom
)
204 void wxRect2DInt::Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
)
206 wxInt32 left
,right
,bottom
,top
;
207 left
= wxMax ( src1
.m_x
, src2
.m_x
) ;
208 right
= wxMin ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
209 top
= wxMax ( src1
.m_y
, src2
.m_y
) ;
210 bottom
= wxMin ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
212 if ( left
< right
&& top
< bottom
)
216 dest
->m_width
= right
- left
;
217 dest
->m_height
= bottom
- top
;
221 dest
->m_width
= dest
->m_height
= 0 ;
225 void wxRect2DInt::Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
)
227 wxInt32 left
,right
,bottom
,top
;
229 left
= wxMin ( src1
.m_x
, src2
.m_x
) ;
230 right
= wxMax ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
231 top
= wxMin ( src1
.m_y
, src2
.m_y
) ;
232 bottom
= wxMax ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
236 dest
->m_width
= right
- left
;
237 dest
->m_height
= bottom
- top
;
240 void wxRect2DInt::Union( const wxPoint2DInt
&pt
)
249 else if ( x
< m_x
+ m_width
)
262 else if ( y
< m_y
+ m_height
)
272 void wxRect2DInt::ConstrainTo( const wxRect2DInt
&rect
)
274 if ( GetLeft() < rect
.GetLeft() )
275 SetLeft( rect
.GetLeft() ) ;
277 if ( GetRight() > rect
.GetRight() )
278 SetRight( rect
.GetRight() ) ;
280 if ( GetBottom() > rect
.GetBottom() )
281 SetBottom( rect
.GetBottom() ) ;
283 if ( GetTop() < rect
.GetTop() )
284 SetTop( rect
.GetTop() ) ;
287 wxRect2DInt
& wxRect2DInt::operator=( const wxRect2DInt
&r
)
291 m_width
= r
.m_width
;
292 m_height
= r
.m_height
;
296 void wxRect2DInt::WriteTo( wxDataOutputStream
&stream
) const
298 stream
.Write32( m_x
) ;
299 stream
.Write32( m_y
) ;
300 stream
.Write32( m_width
) ;
301 stream
.Write32( m_height
) ;
304 void wxRect2DInt::ReadFrom( wxDataInputStream
&stream
)
306 m_x
= stream
.Read32() ;
307 m_y
= stream
.Read32() ;
308 m_width
= stream
.Read32() ;
309 m_height
= stream
.Read32() ;