chiark / gitweb /
Pull out common subexpression of conditions in adjust_weight
authorBen Harris <bjh21@bjh21.me.uk>
Fri, 15 Oct 2021 13:24:09 +0000 (14:24 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Fri, 15 Oct 2021 13:24:09 +0000 (14:24 +0100)
By having short names for the co-ordinates of the points we're
considering, we can make the conditions easier to read, which will
help as the conditions become more complex.

bedstead.c

index fc1b078997d58cfd86c18d47469bdfeb83f59cc8..8899b0a5b4c2f57cc466c549ddafc47e4e9016c0 100644 (file)
@@ -2748,7 +2748,7 @@ emit_path()
 static void
 adjust_weight()
 {
-       int i;
+       int i, X, Y, PX, PY, NX, NY, W = weight->weight;
        point *p;
        struct vec moves[MAXPOINTS];
 
@@ -2757,20 +2757,21 @@ adjust_weight()
                if (p->next == NULL) continue;
                assert(p->prev != NULL);
                moves[i].x = moves[i].y = 0;
+               X = p->v.x; Y = p->v.y;
+               PX = p->prev->v.x; PY = p->prev->v.y;
+               NX = p->next->v.x; NY = p->next->v.y;
                /* Move left-edge points horizontally */
-               if (p->prev->v.y <= p->v.y && p->v.y <= p->next->v.y)
-                       moves[i].x -= weight->weight;
+               if (PY <= Y && Y <= NY)
+                       moves[i].x -= W;
                /* Move top inner corner points along NE/SW diagonal */
-               if (p->prev->v.y < p->v.y && p->v.y > p->next->v.y &&
-                   p->prev->v.x > p->v.x && p->v.x > p->next->v.x) {
-                       moves[i].x -= weight->weight/2;
-                       moves[i].y -= weight->weight/2;
+               if (PY < Y && Y > NY && PX > X && X > NX) {
+                       moves[i].x -= W/2;
+                       moves[i].y -= W/2;
                }
                /* Move bottom inner corner points along NW/SE diagonal */
-               if (p->prev->v.y > p->v.y && p->v.y < p->next->v.y &&
-                   p->prev->v.x < p->v.x && p->v.x < p->next->v.x) {
-                       moves[i].x -= weight->weight/2;
-                       moves[i].y += weight->weight/2;
+               if (PY > Y && Y < NY && PX < X && X < NX) {
+                       moves[i].x -= W/2;
+                       moves[i].y += W/2;
                }
        }
        for (i = 0; i < nextpoint; i++) {