[4/4] gdiplus: change atan2 to gdiplus_arctan2

Evan Stade estade at gmail.com
Fri Jul 20 19:50:14 CDT 2007


Hi,

Changelog:
*introduce new helper function that always gives the correct quadrant
*changed calls to atan2 to gdiplus_atan2

 dlls/gdiplus/gdiplus.c         |   11 ++++++++++-
 dlls/gdiplus/gdiplus_private.h |    1 +
 dlls/gdiplus/graphics.c        |   11 ++++-------
 3 files changed, 15 insertions(+), 8 deletions(-)
-- 
Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/gdiplus.c b/dlls/gdiplus/gdiplus.c
index e821b18..ee1c49b 100644
--- a/dlls/gdiplus/gdiplus.c
+++ b/dlls/gdiplus/gdiplus.c
@@ -154,7 +154,7 @@ static void unstretch_angle(REAL * angle
     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 71cfe39..c872481 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -30,6 +30,7 @@ #define MAX_ARC_PTS (13)
 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 b12ddf8..0594c57 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -146,14 +146,11 @@ static void draw_cap(HDC hdc, COLORREF c
     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
         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;
 
-- 
1.4.1


More information about the wine-patches mailing list