]> granicus.if.org Git - graphviz/commitdiff
replace hypotenuse calculations in bend with calls to hypot
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 5 May 2021 03:49:45 +0000 (20:49 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 12 May 2021 01:46:36 +0000 (18:46 -0700)
The function hypot is available in C99 and has the potential to compute the same
operation more efficiently and with greater precision.

lib/common/routespl.c

index 6b1456c4c7de00acaba2e681a712ff84c9f7d1b5..fe81e12a570900d4b6a1e592b1e9a1af702235c9 100644 (file)
@@ -1149,12 +1149,12 @@ static void bend(pointf spl[4], pointf centroid)
     midpt.y = (spl[0].y + spl[3].y)/2.0;
     dx = (spl[3].x - spl[0].x);
     dy = (spl[3].y - spl[0].y);
-    dist = sqrt(dx*dx + dy*dy);
+    dist = hypot(dx, dy);
     r = dist/5.0;
     {
         double vX = centroid.x - midpt.x;
         double vY = centroid.y - midpt.y;
-        double magV = sqrt(vX*vX + vY*vY);
+        double magV = hypot(vX, vY);
        if (magV == 0) return;  /* if midpoint == centroid, don't divide by zero */
         a.x = midpt.x - vX / magV * r;      /* + would be closest point */
         a.y = midpt.y - vY / magV * r;