From b3356e3aff34a4ab94778e7f6a8db43f9135296c Mon Sep 17 00:00:00 2001 From: Franklin Wei Date: Fri, 21 Dec 2018 22:13:13 -0500 Subject: puzzles: resync with upstream This brings the code to upstream commit 3ece3d6 (I've made my own Rockbox- specific changes on top of that). Changes include using C99 `bool' throughout, and minor logic fixes for some puzzles. Change-Id: Ie823e73ae49a8ee1de411d6d406df2ba835af541 --- apps/plugins/puzzles/src/grid.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'apps/plugins/puzzles/src/grid.c') diff --git a/apps/plugins/puzzles/src/grid.c b/apps/plugins/puzzles/src/grid.c index b5e6bb0..89bde18 100644 --- a/apps/plugins/puzzles/src/grid.c +++ b/apps/plugins/puzzles/src/grid.c @@ -386,11 +386,11 @@ static void grid_trim_vigorously(grid *g) */ dots = snewn(g->num_dots, int); for (i = 0; i < g->num_dots; i++) { - dots[i] = TRUE; + dots[i] = 1; for (j = 0; j < g->num_dots; j++) { if ((dotpairs[i*g->num_dots+j] >= 0) ^ (dotpairs[j*g->num_dots+i] >= 0)) - dots[i] = FALSE; /* non-duplicated edge: coastal dot */ + dots[i] = 0; /* non-duplicated edge: coastal dot */ } } @@ -435,14 +435,14 @@ static void grid_trim_vigorously(grid *g) dots[i] = 0; for (i = 0; i < g->num_faces; i++) { grid_face *f = g->faces + i; - int keep = FALSE; + bool keep = false; for (k = 0; k < f->order; k++) if (dsf_canonify(dsf, f->dots[k] - g->dots) == j) - keep = TRUE; + keep = true; if (keep) { - faces[i] = TRUE; + faces[i] = 1; for (k = 0; k < f->order; k++) - dots[f->dots[k]-g->dots] = TRUE; + dots[f->dots[k]-g->dots] = 1; } } @@ -700,7 +700,7 @@ static void grid_make_consistent(grid *g) * that face (see diagram). */ /* clockwise search */ - while (TRUE) { + while (true) { grid_face *f = d->faces[current_face1]; grid_edge *e; int j; @@ -737,7 +737,7 @@ static void grid_make_consistent(grid *g) continue; /* this dot is complete, move on to next dot */ /* anticlockwise search */ - while (TRUE) { + while (true) { grid_face *f = d->faces[current_face2]; grid_edge *e; int j; @@ -813,7 +813,7 @@ static void grid_face_add_new(grid *g, int face_size) for (i = 0; i < face_size; i++) new_face->dots[i] = NULL; new_face->edges = NULL; - new_face->has_incentre = FALSE; + new_face->has_incentre = false; g->num_faces++; } /* Assumes dot list has enough space */ @@ -862,13 +862,13 @@ static void grid_face_set_dot(grid *g, grid_dot *d, int position) /* * Helper routines for grid_find_incentre. */ -static int solve_2x2_matrix(double mx[4], double vin[2], double vout[2]) +static bool solve_2x2_matrix(double mx[4], double vin[2], double vout[2]) { double inv[4]; double det; det = (mx[0]*mx[3] - mx[1]*mx[2]); if (det == 0) - return FALSE; + return false; inv[0] = mx[3] / det; inv[1] = -mx[1] / det; @@ -878,9 +878,9 @@ static int solve_2x2_matrix(double mx[4], double vin[2], double vout[2]) vout[0] = inv[0]*vin[0] + inv[1]*vin[1]; vout[1] = inv[2]*vin[0] + inv[3]*vin[1]; - return TRUE; + return true; } -static int solve_3x3_matrix(double mx[9], double vin[3], double vout[3]) +static bool solve_3x3_matrix(double mx[9], double vin[3], double vout[3]) { double inv[9]; double det; @@ -888,7 +888,7 @@ static int solve_3x3_matrix(double mx[9], double vin[3], double vout[3]) det = (mx[0]*mx[4]*mx[8] + mx[1]*mx[5]*mx[6] + mx[2]*mx[3]*mx[7] - mx[0]*mx[5]*mx[7] - mx[1]*mx[3]*mx[8] - mx[2]*mx[4]*mx[6]); if (det == 0) - return FALSE; + return false; inv[0] = (mx[4]*mx[8] - mx[5]*mx[7]) / det; inv[1] = (mx[2]*mx[7] - mx[1]*mx[8]) / det; @@ -904,7 +904,7 @@ static int solve_3x3_matrix(double mx[9], double vin[3], double vout[3]) vout[1] = inv[3]*vin[0] + inv[4]*vin[1] + inv[5]*vin[2]; vout[2] = inv[6]*vin[0] + inv[7]*vin[1] + inv[8]*vin[2]; - return TRUE; + return true; } void grid_find_incentre(grid_face *f) @@ -1239,7 +1239,8 @@ void grid_find_incentre(grid_face *f) * _positive_ epsilon in both the x- and * y-direction.) */ - int e, in = 0; + int e; + bool in = false; for (e = 0; e < f->order; e++) { int xs = f->edges[e]->dot1->x; int xe = f->edges[e]->dot2->x; @@ -1265,7 +1266,7 @@ void grid_find_incentre(grid_face *f) denom = -denom; } if ((x - xs) * denom >= (y - ys) * num) - in ^= 1; + in = !in; } } @@ -1364,7 +1365,7 @@ void grid_find_incentre(grid_face *f) assert(bestdist > 0); - f->has_incentre = TRUE; + f->has_incentre = true; f->ix = xbest + 0.5; /* round to nearest */ f->iy = ybest + 0.5; } @@ -1611,11 +1612,11 @@ static grid *grid_new_triangular(int width, int height, const char *desc) f1->edges = NULL; f1->order = 3; f1->dots = snewn(f1->order, grid_dot*); - f1->has_incentre = FALSE; + f1->has_incentre = false; f2->edges = NULL; f2->order = 3; f2->dots = snewn(f2->order, grid_dot*); - f2->has_incentre = FALSE; + f2->has_incentre = false; /* face descriptions depend on whether the row-number is * odd or even */ -- cgit v1.1