]> granicus.if.org Git - graphviz/commitdiff
remove dead code in get_centroid
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 26 Jun 2021 03:12:54 +0000 (20:12 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 30 Jun 2021 02:35:21 +0000 (19:35 -0700)
The preceding return statement ensures none of the latter part of the function
is reachable. This was introduced in 05674ae147c14ec4ec74b2b6771e04e0c82209b8
and seemingly never noticed.

This commit also drops now-unused variables, as well as the static qualifier
from sum. It is not clear to me what the purpose of making sum static was. It is
a small struct and both its fields are overwritten immediately when entering
this function, so there is no value to retaining it across calls or
BSS-allocating it.

lib/common/routespl.c

index 3e9e8e1faeaf7c4b02bdd070dc9c833dd6b7e5f0..eceb0052f16101a9efd38cea854492d1f88a15b9 100644 (file)
@@ -821,25 +821,11 @@ static void printpath(path * pp)
 
 static pointf get_centroid(Agraph_t *g)
 {
-    int     cnt = 0;
-    static pointf   sum = {0.0, 0.0};
-    static Agraph_t *save;
-    Agnode_t *n;
+    pointf sum = {0.0, 0.0};
 
     sum.x = (GD_bb(g).LL.x + GD_bb(g).UR.x) / 2.0;
     sum.y = (GD_bb(g).LL.y + GD_bb(g).UR.y) / 2.0;
     return sum;
-
-    if (save == g) return sum;
-    save = g;
-    for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
-        sum.x += ND_pos(n)[0];
-        sum.y += ND_pos(n)[1];
-        cnt++;
-    }
-    sum.x /= cnt;
-    sum.y /= cnt;
-    return sum;
 }
 
 //generic vector structure