]> granicus.if.org Git - graphviz/commitdiff
pathplan: remove duplicated variable in 'splinefits'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Nov 2022 17:52:08 +0000 (09:52 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Nov 2022 22:51:26 +0000 (14:51 -0800)
`a` and `b` in this function were always the same value. So we can reduce this
computation to using a single variable.

lib/pathplan/route.c

index e42306a1cebb71220fb4bcf7e7ee57cfa251a16e..8eecef3393eba455954e2c7d39423d51bbc95f55 100644 (file)
@@ -208,21 +208,21 @@ static int splinefits(Pedge_t * edges, int edgen, Ppoint_t pa,
                      Ppoint_t * inps, int inpn)
 {
     Ppoint_t sps[4];
-    double a, b;
+    double a;
     int pi;
     int forceflag;
     int first = 1;
 
     forceflag = (inpn == 2 ? 1 : 0);
 
-    a = b = 4;
+    a = 4;
     for (;;) {
        sps[0].x = pa.x;
        sps[0].y = pa.y;
        sps[1].x = pa.x + a * va.x / 3.0;
        sps[1].y = pa.y + a * va.y / 3.0;
-       sps[2].x = pb.x - b * vb.x / 3.0;
-       sps[2].y = pb.y - b * vb.y / 3.0;
+       sps[2].x = pb.x - a * vb.x / 3.0;
+       sps[2].y = pb.y - a * vb.y / 3.0;
        sps[3].x = pb.x;
        sps[3].y = pb.y;
 
@@ -245,11 +245,11 @@ static int splinefits(Pedge_t * edges, int edgen, Ppoint_t pa,
            for (pi = 1; pi < 4; pi++)
                ops[opl].x = sps[pi].x, ops[opl++].y = sps[pi].y;
 #if defined(DEBUG) && DEBUG >= 1
-           fprintf(stderr, "success: %f %f\n", a, b);
+           fprintf(stderr, "success: %f %f\n", a, a);
 #endif
            return 1;
        }
-       if (a == 0 && b == 0) {
+       if (a == 0) {
            if (forceflag) {
                if (growops(opl + 4) < 0) {
                    return -1;
@@ -257,16 +257,16 @@ static int splinefits(Pedge_t * edges, int edgen, Ppoint_t pa,
                for (pi = 1; pi < 4; pi++)
                    ops[opl].x = sps[pi].x, ops[opl++].y = sps[pi].y;
 #if defined(DEBUG) && DEBUG >= 1
-               fprintf(stderr, "forced straight line: %f %f\n", a, b);
+               fprintf(stderr, "forced straight line: %f %f\n", a, a);
 #endif
                return 1;
            }
            break;
        }
        if (a > .01)
-           a /= 2, b /= 2;
+           a /= 2;
        else
-           a = b = 0;
+           a = 0;
     }
 #if defined(DEBUG) && DEBUG >= 1
     fprintf(stderr, "failure\n");