From: Matthew Fernandez Date: Thu, 6 Jan 2022 05:50:53 +0000 (-0800) Subject: lib/mingle: rephrase some open coded hypotenuse calculations X-Git-Tag: 3.0.0~88^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=526ec124a18acff19e581ecf0d265bcc760e5135;p=graphviz lib/mingle: rephrase some open coded hypotenuse calculations Surprisingly every `sqrt` call in this file except one is a hypotenuse calculation that can be done more accurately. Maybe `hypot` was not widely available when this code was written. --- diff --git a/lib/mingle/ink.cpp b/lib/mingle/ink.cpp index ca22ff88b..8079f0980 100644 --- a/lib/mingle/ink.cpp +++ b/lib/mingle/ink.cpp @@ -58,13 +58,13 @@ static double sumLengths_avoid_bad_angle(point_t* points, int npoints, point_t e diff_x0 = end.x-meeting.x; diff_y0 = end.y-meeting.y; - len0 = sum = sqrt(diff_x0*diff_x0+diff_y0*diff_y0); + len0 = sum = hypot(diff_x0, diff_y0); // distance form each of 'points' till 'meeting' for (i=0; idim*e->npoints - e->dim]; targets[i].y = x[e->dim*e->npoints - e->dim + 1]; - (*ink0) += sqrt((sources[i].x - targets[i].x)*(sources[i].x - targets[i].x) + (sources[i].y - targets[i].y)*(sources[i].y - targets[i].y)); + (*ink0) += hypot(sources[i].x - targets[i].x, sources[i].y - targets[i].y); begin = addPoint (begin, scalePoint(sources[i], e->wgt)); end = addPoint (end, scalePoint(targets[i], e->wgt)); wgt += e->wgt; @@ -330,6 +330,6 @@ double ink1(pedge e){ x = e->x; xx = x[0] - x[e->dim*e->npoints - e->dim]; yy = x[1] - x[e->dim*e->npoints - e->dim + 1]; - ink0 += sqrt(xx*xx + yy*yy); + ink0 += hypot(xx, yy); return ink0; }