]>
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"
31 #include "wx/geometry.h"
32 #include "wx/datstrm.h"
44 // for the following calculations always remember
45 // that the right and bottom edges are not part of a rect
47 bool wxRect2DDouble::Intersects( const wxRect2DDouble
&rect
) const
49 wxDouble left
,right
,bottom
,top
;
50 left
= wxMax ( m_x
, rect
.m_x
) ;
51 right
= wxMin ( m_x
+m_width
, rect
.m_x
+ rect
.m_width
) ;
52 top
= wxMax ( m_y
, rect
.m_y
) ;
53 bottom
= wxMin ( m_y
+m_height
, rect
.m_y
+ rect
.m_height
) ;
55 if ( left
< right
&& top
< bottom
)
62 void wxRect2DDouble::Intersect( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
)
64 wxDouble left
,right
,bottom
,top
;
65 left
= wxMax ( src1
.m_x
, src2
.m_x
) ;
66 right
= wxMin ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
67 top
= wxMax ( src1
.m_y
, src2
.m_y
) ;
68 bottom
= wxMin ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
70 if ( left
< right
&& top
< bottom
)
74 dest
->m_width
= right
- left
;
75 dest
->m_height
= bottom
- top
;
79 dest
->m_width
= dest
->m_height
= 0 ;
83 void wxRect2DDouble::Union( const wxRect2DDouble
&src1
, const wxRect2DDouble
&src2
, wxRect2DDouble
*dest
)
85 wxDouble left
,right
,bottom
,top
;
87 left
= wxMin ( src1
.m_x
, src2
.m_x
) ;
88 right
= wxMax ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
89 top
= wxMin ( src1
.m_y
, src2
.m_y
) ;
90 bottom
= wxMax ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
94 dest
->m_width
= right
- left
;
95 dest
->m_height
= bottom
- top
;
98 void wxRect2DDouble::Union( const wxPoint2DDouble
&pt
)
100 wxDouble x
= pt
.m_x
;
101 wxDouble y
= pt
.m_y
;
107 else if ( x
< m_x
+ m_width
)
120 else if ( y
< m_y
+ m_height
)
130 void wxRect2DDouble::ConstrainTo( const wxRect2DDouble
&rect
)
132 if ( GetLeft() < rect
.GetLeft() )
133 SetLeft( rect
.GetLeft() ) ;
135 if ( GetRight() > rect
.GetRight() )
136 SetRight( rect
.GetRight() ) ;
138 if ( GetBottom() > rect
.GetBottom() )
139 SetBottom( rect
.GetBottom() ) ;
141 if ( GetTop() < rect
.GetTop() )
142 SetTop( rect
.GetTop() ) ;
147 // for the following calculations always remember
148 // that the right and bottom edges are not part of a rect
152 void wxPoint2DInt::WriteTo( wxDataOutputStream
&stream
) const
154 stream
.Write32( m_x
) ;
155 stream
.Write32( m_y
) ;
158 void wxPoint2DInt::ReadFrom( wxDataInputStream
&stream
)
160 m_x
= stream
.Read32() ;
161 m_y
= stream
.Read32() ;
164 wxDouble
wxPoint2DInt::GetVectorAngle()
180 wxDouble deg
= atan2( m_y
, m_x
) * 180 / 3.14159265359 ;
191 bool wxRect2DInt::Intersects( const wxRect2DInt
&rect
) const
193 wxInt32 left
,right
,bottom
,top
;
194 left
= wxMax ( m_x
, rect
.m_x
) ;
195 right
= wxMin ( m_x
+m_width
, rect
.m_x
+ rect
.m_width
) ;
196 top
= wxMax ( m_y
, rect
.m_y
) ;
197 bottom
= wxMin ( m_y
+m_height
, rect
.m_y
+ rect
.m_height
) ;
199 if ( left
< right
&& top
< bottom
)
206 void wxRect2DInt::Intersect( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
)
208 wxInt32 left
,right
,bottom
,top
;
209 left
= wxMax ( src1
.m_x
, src2
.m_x
) ;
210 right
= wxMin ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
211 top
= wxMax ( src1
.m_y
, src2
.m_y
) ;
212 bottom
= wxMin ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
214 if ( left
< right
&& top
< bottom
)
218 dest
->m_width
= right
- left
;
219 dest
->m_height
= bottom
- top
;
223 dest
->m_width
= dest
->m_height
= 0 ;
227 void wxRect2DInt::Union( const wxRect2DInt
&src1
, const wxRect2DInt
&src2
, wxRect2DInt
*dest
)
229 wxInt32 left
,right
,bottom
,top
;
231 left
= wxMin ( src1
.m_x
, src2
.m_x
) ;
232 right
= wxMax ( src1
.m_x
+src1
.m_width
, src2
.m_x
+ src2
.m_width
) ;
233 top
= wxMin ( src1
.m_y
, src2
.m_y
) ;
234 bottom
= wxMax ( src1
.m_y
+src1
.m_height
, src2
.m_y
+ src2
.m_height
) ;
238 dest
->m_width
= right
- left
;
239 dest
->m_height
= bottom
- top
;
242 void wxRect2DInt::Union( const wxPoint2DInt
&pt
)
251 else if ( x
< m_x
+ m_width
)
264 else if ( y
< m_y
+ m_height
)
274 void wxRect2DInt::ConstrainTo( const wxRect2DInt
&rect
)
276 if ( GetLeft() < rect
.GetLeft() )
277 SetLeft( rect
.GetLeft() ) ;
279 if ( GetRight() > rect
.GetRight() )
280 SetRight( rect
.GetRight() ) ;
282 if ( GetBottom() > rect
.GetBottom() )
283 SetBottom( rect
.GetBottom() ) ;
285 if ( GetTop() < rect
.GetTop() )
286 SetTop( rect
.GetTop() ) ;
289 wxRect2DInt
& wxRect2DInt::operator=( const wxRect2DInt
&r
)
293 m_width
= r
.m_width
;
294 m_height
= r
.m_height
;
298 void wxRect2DInt::WriteTo( wxDataOutputStream
&stream
) const
300 stream
.Write32( m_x
) ;
301 stream
.Write32( m_y
) ;
302 stream
.Write32( m_width
) ;
303 stream
.Write32( m_height
) ;
306 void wxRect2DInt::ReadFrom( wxDataInputStream
&stream
)
308 m_x
= stream
.Read32() ;
309 m_y
= stream
.Read32() ;
310 m_width
= stream
.Read32() ;
311 m_height
= stream
.Read32() ;
314 #endif // wxUSE_GEOMETRY