mirror of https://github.com/CGAL/cgal
Allow comparison with a "correct" result in the test suite
Add tests for dangling edge/isolated vertex situations.
This commit is contained in:
parent
f0cb2e9617
commit
3dc6e24623
|
|
@ -0,0 +1,11 @@
|
|||
4
|
||||
-1 -1
|
||||
7 -1
|
||||
7 7
|
||||
-1 7
|
||||
1
|
||||
4
|
||||
2 2
|
||||
2 4
|
||||
4 4
|
||||
4 2
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
4
|
||||
-1 -1
|
||||
7 -1
|
||||
7 7
|
||||
-1 7
|
||||
|
|
@ -53,4 +53,13 @@ bool read_polygon (const char *filename, CGAL::Polygon_2<Kernel>& pgn)
|
|||
return (true);
|
||||
}
|
||||
|
||||
template <class Kernel>
|
||||
bool read_polygon_with_holes (const char *filename, CGAL::Polygon_with_holes_2<Kernel>& pgn)
|
||||
{
|
||||
std::ifstream ifile(filename);
|
||||
ifile >> pgn;
|
||||
// TODO: what can go wrong?
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
./data/rooms_part1.dat ./data/rooms_part2.dat -sohg
|
||||
./data/comb_part1.dat ./data/comb_part2.dat -sohg
|
||||
./data/fork_part1.dat ./data/fork_part2.dat -soh
|
||||
./data/knife_part1.dat ./data/knife_part2.dat -so
|
||||
./data/mchain_part1.dat ./data/mchain_part2.dat -sh
|
||||
./data/random_part1.dat ./data/random_part2.dat -sg
|
||||
./data/wheels_part1.dat ./data/wheels_part2.dat -hg
|
||||
./data/r35975_part1.dat ./data/r35975_part2.dat -sohg
|
||||
./data/r38305_part1.dat ./data/r38305_part2.dat -sohg
|
||||
./data/D.dat ./data/E.dat -sohg
|
||||
./data/F.dat ./data/G.dat -sohg
|
||||
./data/F.dat ./data/E.dat -sohg
|
||||
./data/F.dat ./data/D.dat -sohg
|
||||
./data/F.dat ./data/A.dat -sohg
|
||||
./data/A.dat ./data/G.dat -sohg
|
||||
./data/B.dat ./data/G.dat -sohg
|
||||
./data/dangling_edge_part1.dat ./data/dangling_edge_part2.dat -sohg
|
||||
./data/isolated_vertex_part1.dat ./data/isolated_vertex_part2.dat -sohg
|
||||
compare ./data/rooms_part1.dat ./data/rooms_part2.dat
|
||||
compare ./data/comb_part1.dat ./data/comb_part2.dat
|
||||
compare ./data/knife_part1.dat ./data/knife_part2.dat
|
||||
compare ./data/mchain_part1.dat ./data/mchain_part2.dat
|
||||
compare ./data/random_part1.dat ./data/random_part2.dat
|
||||
compare ./data/wheels_part1.dat ./data/wheels_part2.dat
|
||||
compare ./data/r35975_part1.dat ./data/r35975_part2.dat
|
||||
compare ./data/r38305_part1.dat ./data/r38305_part2.dat
|
||||
compare ./data/D.dat ./data/E.dat
|
||||
compare ./data/F.dat ./data/G.dat
|
||||
compare ./data/F.dat ./data/E.dat
|
||||
compare ./data/F.dat ./data/D.dat
|
||||
compare ./data/F.dat ./data/A.dat
|
||||
compare ./data/A.dat ./data/G.dat
|
||||
compare ./data/B.dat ./data/G.dat
|
||||
verify ./data/dangling_edge_part1.dat ./data/dangling_edge_part2.dat ./data/dangling_edge_result.dat
|
||||
verify ./data/isolated_vertex_part1.dat ./data/isolated_vertex_part2.dat ./data/isolated_vertex_result.dat
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@ int main (int argc, char **argv)
|
|||
{
|
||||
// Read the input file. Because of the structure of the *.cmd file
|
||||
// (which is concatenated to the command line) we need to get all the
|
||||
// inputs in one command line. This is the reason we read triplets/pairs of
|
||||
// arguments. Each triplet/double is one input for the program.
|
||||
// inputs in one command line. This is the reason we read triplets/quadruplets of
|
||||
// arguments. Each triplet/quadruplet is one input for the program.
|
||||
if (argc < 3)
|
||||
{
|
||||
std::cerr << "Usage: " << argv[0] << ". The input are triplets of:"
|
||||
<< " <polygon#1> <polygon#2> [decomposition flags]"
|
||||
std::cerr << "Usage: " << argv[0] << ". The input are triplets/quadruplets of:"
|
||||
<< "<compare|verify> <polygon#1> <polygon#2> [polygon#3]"
|
||||
<< std::endl;
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -58,37 +58,35 @@ int main (int argc, char **argv)
|
|||
int i = 1;
|
||||
while (i < argc)
|
||||
{
|
||||
bool verify = strcmp(argv[i], "verify") == 0;
|
||||
|
||||
// Read the polygons from the input files.
|
||||
Polygon_2 pgn1, pgn2;
|
||||
Polygon_with_holes_2 result;
|
||||
|
||||
if (! read_polygon (argv[i], pgn1))
|
||||
{
|
||||
std::cerr << "Failed to read: <" << argv[i] << ">." << std::endl;
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (! read_polygon (argv[i+1], pgn2))
|
||||
if (! read_polygon (argv[i+1], pgn1))
|
||||
{
|
||||
std::cerr << "Failed to read: <" << argv[i+1] << ">." << std::endl;
|
||||
return (1);
|
||||
}
|
||||
|
||||
std::cout << "Testing " << argv[i] << " and " << argv[i+1] << std::endl;
|
||||
|
||||
// Read the decomposition flags.
|
||||
bool use_ssab = true;
|
||||
bool use_opt = true;
|
||||
bool use_hm = true;
|
||||
bool use_greene = true;
|
||||
|
||||
if (i+2 < argc && argv[i+2][0] == '-')
|
||||
if (! read_polygon (argv[i+2], pgn2))
|
||||
{
|
||||
use_ssab = (std::strchr (argv[i+2], 's') != NULL);
|
||||
use_opt = (std::strchr (argv[i+2], 'o') != NULL);
|
||||
use_hm = (std::strchr (argv[i+2], 'h') != NULL);
|
||||
use_greene = (std::strchr (argv[i+2], 'g') != NULL);
|
||||
std::cerr << "Failed to read: <" << argv[i+2] << ">." << std::endl;
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
if (verify)
|
||||
{
|
||||
if (! read_polygon_with_holes (argv[i+3], result))
|
||||
{
|
||||
std::cerr << "Failed to read: <" << argv[i+3] << ">." << std::endl;
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Testing " << argv[i+1] << " and " << argv[i+2] << std::endl;
|
||||
|
||||
// Compute the Minkowski sum using the convolution method.
|
||||
Polygon_with_holes_2 sum_conv;
|
||||
|
||||
|
|
@ -96,17 +94,34 @@ int main (int argc, char **argv)
|
|||
sum_conv = minkowski_sum_2 (pgn1, pgn2);
|
||||
std::cout << "Done." << std::endl;
|
||||
|
||||
Polygon_with_holes_2 sum_conv_new;
|
||||
std::cout << "Using the reduced convolution method ... ";
|
||||
sum_conv_new = minkowski_sum_2_new (pgn1, pgn2);
|
||||
if (are_equal (sum_conv, sum_conv_new))
|
||||
if (verify)
|
||||
{
|
||||
if (are_equal (result, sum_conv))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
result = sum_conv;
|
||||
}
|
||||
|
||||
Polygon_with_holes_2 sum_conv_new;
|
||||
std::cout << "Using the reduced convolution method ... ";
|
||||
sum_conv_new = minkowski_sum_2_new (pgn1, pgn2);
|
||||
if (are_equal (result, sum_conv_new))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Define auxiliary polygon-decomposition objects.
|
||||
|
|
@ -116,70 +131,60 @@ int main (int argc, char **argv)
|
|||
CGAL::Greene_convex_decomposition_2<Kernel> greene_decomp;
|
||||
Polygon_with_holes_2 sum_decomp;
|
||||
|
||||
if (use_ssab)
|
||||
std::cout << "Using the small-side angle-bisector decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, ssab_decomp);
|
||||
if (are_equal (result, sum_decomp))
|
||||
{
|
||||
std::cout << "Using the small-side angle-bisector decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, ssab_decomp);
|
||||
if (are_equal (sum_conv, sum_decomp))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
|
||||
if (use_opt)
|
||||
{
|
||||
std::cout << "Using the optimal convex decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, opt_decomp);
|
||||
if (are_equal (sum_conv, sum_decomp))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (use_hm)
|
||||
{
|
||||
std::cout << "Using the Hertel--Mehlhorn decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, hm_approx_decomp);
|
||||
if (are_equal (sum_conv, sum_decomp))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (use_greene)
|
||||
{
|
||||
std::cout << "Using the Greene decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, greene_decomp);
|
||||
if (are_equal (sum_conv, sum_decomp))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (i+2 < argc && argv[i+2][0] == '-')
|
||||
i += 3;
|
||||
else
|
||||
i += 2;
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Using the optimal convex decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, opt_decomp);
|
||||
if (are_equal (result, sum_decomp))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Using the Hertel--Mehlhorn decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, hm_approx_decomp);
|
||||
if (are_equal (result, sum_decomp))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Using the Greene decomposition ... ";
|
||||
sum_decomp = minkowski_sum_2 (pgn1, pgn2, greene_decomp);
|
||||
if (are_equal (result, sum_decomp))
|
||||
{
|
||||
std::cout << "OK." << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "ERROR (different result)." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verify)
|
||||
{
|
||||
i += 4;
|
||||
}
|
||||
else
|
||||
i += 3;
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue