From: Matthew Fernandez Date: Wed, 5 May 2021 03:05:07 +0000 (-0700) Subject: replace hypotenuse calculation with call to hypot in various copies of GCarrow X-Git-Tag: 2.47.2~16^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c18a78c0b6cdd2808eeb16b1ccaa57320a58695;p=graphviz replace hypotenuse calculation with call to hypot in various copies of GCarrow The function hypot is available in C99 and has the potential to compute the same operation more efficiently and with greater precision. --- diff --git a/cmd/lefty/ws/gtk/gcanvas.c b/cmd/lefty/ws/gtk/gcanvas.c index 4d0771818..5c1bdcbc6 100644 --- a/cmd/lefty/ws/gtk/gcanvas.c +++ b/cmd/lefty/ws/gtk/gcanvas.c @@ -12,6 +12,7 @@ #include "common.h" #include "g.h" #include "gcommon.h" +#include #include #define WCU widget->u.c @@ -426,7 +427,7 @@ int GCarrow(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap) if (pd.x == 0 && pd.y == 0) return 0; tangent = atan2((double) pd.y, (double) pd.x); - if ((l = sqrt((double) (pd.x * pd.x + pd.y * pd.y))) > 30) + if ((l = hypot(pd.x, pd.y)) > 30) l = 30; pa.x = l * cos(tangent + M_PI / 7) + pp2.x; pa.y = l * sin(tangent + M_PI / 7) + pp2.y; diff --git a/cmd/lefty/ws/mswin32/gcanvas.c b/cmd/lefty/ws/mswin32/gcanvas.c index 47f839c7d..cb8aad840 100644 --- a/cmd/lefty/ws/mswin32/gcanvas.c +++ b/cmd/lefty/ws/mswin32/gcanvas.c @@ -14,6 +14,7 @@ #include "g.h" #include "gcommon.h" #include "mem.h" +#include #include #define WCU widget->u.c @@ -464,7 +465,7 @@ int GCarrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) { if (pd.x == 0 && pd.y == 0) return 0; tangent = atan2 ((double) pd.y, (double) pd.x); - if ((l = sqrt ((double) (pd.x * pd.x + pd.y * pd.y))) > 30) + if ((l = hypot(pd.x, pd.y)) > 30) l = 30; pa.x = l * cos (tangent + M_PI / 7) + pp2.x; pa.y = l * sin (tangent + M_PI / 7) + pp2.y; diff --git a/cmd/lefty/ws/mswin32/gpcanvas.c b/cmd/lefty/ws/mswin32/gpcanvas.c index d9bc1725f..6c500d768 100644 --- a/cmd/lefty/ws/mswin32/gpcanvas.c +++ b/cmd/lefty/ws/mswin32/gpcanvas.c @@ -14,6 +14,7 @@ #include "g.h" #include "gcommon.h" #include "mem.h" +#include #include #define WPU widget->u.p @@ -446,7 +447,7 @@ int GParrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) { if (pd.x == 0 && pd.y == 0) return 0; tangent = atan2 ((double) pd.y, (double) pd.x); - if ((l = sqrt ((double) (pd.x * pd.x + pd.y * pd.y))) > 30) + if ((l = hypot(pd.x, pd.y)) > 30) l = 30; pa.x = l * cos (tangent + M_PI / 7) + pp2.x; pa.y = l * sin (tangent + M_PI / 7) + pp2.y; diff --git a/cmd/lefty/ws/x11/gcanvas.c b/cmd/lefty/ws/x11/gcanvas.c index 0466f982f..7215ffd98 100644 --- a/cmd/lefty/ws/x11/gcanvas.c +++ b/cmd/lefty/ws/x11/gcanvas.c @@ -17,6 +17,7 @@ #ifdef FEATURE_GMAP #include #endif +#include #include #define WCU widget->u.c @@ -566,7 +567,7 @@ int GCarrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) { if (pd.x == 0 && pd.y == 0) return 0; tangent = atan2 ((double) pd.y, (double) pd.x); - if ((l = sqrt ((double) (pd.x * pd.x + pd.y * pd.y))) > 30) + if ((l = hypot(pd.x, pd.y)) > 30) l = 30; pa.x = l * cos (tangent + M_PI / 7) + pp2.x; pa.y = l * sin (tangent + M_PI / 7) + pp2.y; diff --git a/cmd/lefty/ws/x11/gpcanvas.c b/cmd/lefty/ws/x11/gpcanvas.c index 876ad4305..a314b2ce2 100644 --- a/cmd/lefty/ws/x11/gpcanvas.c +++ b/cmd/lefty/ws/x11/gpcanvas.c @@ -14,6 +14,7 @@ #include "g.h" #include "gcommon.h" #include "mem.h" +#include #include #define PSDPI 300.0 @@ -355,7 +356,7 @@ int GParrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) { if (pd.x == 0 && pd.y == 0) return 0; tangent = atan2 ((double) pd.y, (double) pd.x); - if ((l = sqrt ((double) (pd.x * pd.x + pd.y * pd.y))) < 30) + if ((l = hypot(pd.x, pd.y)) < 30) l = 30; pa.x = l * cos (tangent + M_PI / 7) + pp2.x; pa.y = l * sin (tangent + M_PI / 7) + pp2.y;