]> granicus.if.org Git - graphviz/commitdiff
replace hypotenuse calculation with a call to hypot
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 5 May 2021 03:40:51 +0000 (20:40 -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/arrows.c

index 645df22dc8b679b709a2a4bcae58903ecfb375a0..8f3b2c22f47a3a13506868b2c55aea58fe4f5142 100644 (file)
@@ -708,7 +708,7 @@ boxf arrow_bb(pointf p, pointf u, double arrowsize, int flag)
     u.x -= p.x;
     u.y -= p.y;
     /* the EPSILONs are to keep this stable as length of u approaches 0.0 */
-    s = ARROW_LENGTH * arrowsize / (sqrt(u.x * u.x + u.y * u.y) + EPSILON);
+    s = ARROW_LENGTH * arrowsize / (hypot(u.x, u.y) + EPSILON);
     u.x += (u.x >= 0.0) ? EPSILON : -EPSILON;
     u.y += (u.y >= 0.0) ? EPSILON : -EPSILON;
     u.x *= s;