Backported #10494 (Possible wrong result of sqrt-function in wxDC::DoDrawArc, caused by integer-overflow)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@62121 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2009-09-25 11:59:20 +00:00
parent 8cc53ff56b
commit b04369c5e9

View File

@@ -676,9 +676,12 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1,
wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc)
{
double dx = xc - x1;
double dy = yc - y1;
wxCoord r = (wxCoord)sqrt(dx*dx + dy*dy);
#ifdef __WXWINCE__
// Slower emulation since WinCE doesn't support Pie and Arc
double r = sqrt( (x1-xc)*(x1-xc) + (y1-yc)*(y1-yc) );
double sa = acos((x1-xc)/r)/M_PI*180; // between 0 and 180
if( y1>yc ) sa = -sa; // below center
double ea = atan2(yc-y2, x2-xc)/M_PI*180;
@@ -689,11 +692,6 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1,
wxColourChanger cc(*this); // needed for wxSTIPPLE_MASK_OPAQUE handling
double dx = xc - x1;
double dy = yc - y1;
double radius = (double)sqrt(dx*dx+dy*dy);
wxCoord r = (wxCoord)radius;
// treat the special case of full circle separately
if ( x1 == x2 && y1 == y2 )
{
@@ -707,7 +705,9 @@ void wxDC::DoDrawArc(wxCoord x1, wxCoord y1,
wxCoord yy2 = YLOG2DEV(y2);
wxCoord xxc = XLOG2DEV(xc);
wxCoord yyc = YLOG2DEV(yc);
wxCoord ray = (wxCoord) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1)));
dx = xxc - xx1;
dy = yyc - yy1;
wxCoord ray = (wxCoord)sqrt(dx*dx + dy*dy);
wxCoord xxx1 = (wxCoord) (xxc-ray);
wxCoord yyy1 = (wxCoord) (yyc-ray);
@@ -1125,13 +1125,13 @@ void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,d
// Swap start and end positions if the end angle is less than the start angle.
if (ea < sa) {
int temp;
temp = rx2;
rx2 = rx1;
rx1 = temp;
temp = ry2;
ry2 = ry1;
ry1 = temp;
int temp;
temp = rx2;
rx2 = rx1;
rx1 = temp;
temp = ry2;
ry2 = ry1;
ry1 = temp;
}
// draw pie with NULL_PEN first and then outline otherwise a line is