From 9eb376e0e5b4fe640a0490919c4b5e80d1196d99 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Sep 2016 11:20:33 +0200 Subject: [PATCH] clumsy repair of duplicate regions for range >= 2 (RF_MARK) --- src/reports.c | 7 ++++++- src/reports.test.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/reports.c b/src/reports.c index 3e67f2f2b..be8693e95 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1118,6 +1118,7 @@ int get_regions_distance_arr(region *rc, int radius, region *result[], int size) if (size>n) { result[n++] = rc; + fset(rc, RF_MARK); } for (i = 0; i != n; ++i) { region *r; @@ -1134,8 +1135,9 @@ int get_regions_distance_arr(region *rc, int radius, region *result[], int size) r = adj[d]; if (r) { if (size > n) { - if (dist < distance(rc, r)) { + if (!fval(r, RF_MARK) && dist < distance(rc, r)) { result[n++] = r; + fset(r, RF_MARK); } } else { @@ -1145,6 +1147,9 @@ int get_regions_distance_arr(region *rc, int radius, region *result[], int size) } } } + for (i = 0; i != n; ++i) { + freset(result[i], RF_MARK); + } return n; } diff --git a/src/reports.test.c b/src/reports.test.c index ffa2d215c..bef1047d8 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -425,6 +425,26 @@ static void test_seen_travelthru(CuTest *tc) { test_cleanup(); } +static void test_region_distance_max(CuTest *tc) { + region *r; + region *result[64]; + int x, y; + test_setup(); + r = test_create_region(0, 0, 0); + for (x=-3;x<=3;++x) { + for (y = -3; y <= 3; ++y) { + if (x != 0 || y != 0) { + test_create_region(x, y, 0); + } + } + } + CuAssertIntEquals(tc, 1, get_regions_distance_arr(r, 0, result, 64)); + CuAssertIntEquals(tc, 7, get_regions_distance_arr(r, 1, result, 64)); + CuAssertIntEquals(tc, 19, get_regions_distance_arr(r, 2, result, 64)); + CuAssertIntEquals(tc, 37, get_regions_distance_arr(r, 3, result, 64)); + test_cleanup(); +} + static void test_region_distance(CuTest *tc) { region *r; region *result[8]; @@ -465,6 +485,7 @@ CuSuite *get_reports_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_region_distance); + SUITE_ADD_TEST(suite, test_region_distance_max); SUITE_ADD_TEST(suite, test_region_distance_ql); SUITE_ADD_TEST(suite, test_prepare_report); SUITE_ADD_TEST(suite, test_seen_neighbours);