clumsy repair of duplicate regions for range >= 2 (RF_MARK)

This commit is contained in:
Enno Rehling 2016-09-24 11:20:33 +02:00
parent c755c1d69e
commit 9eb376e0e5
2 changed files with 27 additions and 1 deletions

View File

@ -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;
}

View File

@ -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);