From: Ben Harris Date: Fri, 15 Oct 2021 13:24:09 +0000 (+0100) Subject: Pull out common subexpression of conditions in adjust_weight X-Git-Tag: bedstead-002.003~14 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=43a560f2301f4484e57791ead22879749fb5f994;p=bedstead-debian.git Pull out common subexpression of conditions in adjust_weight 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. --- diff --git a/bedstead.c b/bedstead.c index fc1b078..8899b0a 100644 --- a/bedstead.c +++ b/bedstead.c @@ -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++) {