diff --git a/dlls/gdiplus/gdiplus.c b/dlls/gdiplus/gdiplus.c index e821b183970..ee1c49bc86b 100644 --- a/dlls/gdiplus/gdiplus.c +++ b/dlls/gdiplus/gdiplus.c @@ -154,7 +154,7 @@ static void unstretch_angle(REAL * angle, REAL rad_x, REAL rad_y) if(cos(*angle) == 0 || sin(*angle) == 0) return; - stretched = atan2(sin(*angle) / rad_y, cos(*angle) / rad_x); + stretched = gdiplus_atan2(sin(*angle) / rad_y, cos(*angle) / rad_x); revs_off = roundr(*angle / (2.0 * M_PI)) - roundr(stretched / (2.0 * M_PI)); stretched += ((REAL)revs_off) * M_PI * 2.0; *angle = stretched; @@ -212,3 +212,12 @@ COLORREF ARGB2COLORREF(ARGB color) (color & 0x00ff00) + ((color & 0xff0000) >> 16); } + +/* Like atan2, but puts angle in correct quadrant if dx is 0. */ +FLOAT gdiplus_atan2(FLOAT dy, FLOAT dx) +{ + if((dx == 0.0) && (dy != 0.0)) + return dy > 0.0 ? M_PI_2 : -M_PI_2; + + return atan2(dy, dx); +} diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index 71cfe394929..c8724814d84 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -30,6 +30,7 @@ COLORREF ARGB2COLORREF(ARGB color); extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2, REAL startAngle, REAL sweepAngle); +extern FLOAT gdiplus_atan2(FLOAT dy, FLOAT dx); static inline INT roundr(REAL x) { diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index b12ddf8e372..0594c57a367 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -146,14 +146,11 @@ static void draw_cap(HDC hdc, COLORREF color, GpLineCap cap, REAL size, INT i, count; LOGBRUSH lb; - if(x2 != x1) - theta = atan2(y2 - y1, x2 - x1); - else if(y2 != y1){ - theta = M_PI_2 * (y2 > y1 ? 1.0 : -1.0); - } - else + if((x1 == x2) && (y1 == y2)) return; + theta = gdiplus_atan2(y2 - y1, x2 - x1); + brush = CreateSolidBrush(color); lb.lbStyle = BS_SOLID; lb.lbColor = color; @@ -327,7 +324,7 @@ static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL per return; dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent; - theta = (*x2 == x1 ? M_PI_2 : atan2((*y2 - y1), (*x2 - x1))); + theta = gdiplus_atan2((*y2 - y1), (*x2 - x1)); dx = cos(theta) * dist; dy = sin(theta) * dist;