even more test cases

This commit is contained in:
Laurent Rineau 2023-05-09 12:35:09 +02:00
parent 4a0b1477f9
commit 6325190a73
1 changed files with 106 additions and 70 deletions

View File

@ -36,26 +36,14 @@ void insert(DT& dt, Point_it first, Point_it end) {
dt.insert(*first);
}
}
// trick to avoid a conflict with CGAL-5.6
// -> specialization of Output_rep for `CC_iterator` *and* `My`
struct My {};
template <class DSC, bool Const >
class CGAL::Output_rep<CGAL::internal::CC_iterator<DSC, Const>, My > {
protected:
using CC_iterator = CGAL::internal::CC_iterator<DSC, Const>;
using Compact_container = typename CC_iterator::CC;
using Time_stamper = typename Compact_container::Time_stamper;
CC_iterator it;
public:
Output_rep( const CC_iterator it) : it(it) {}
std::ostream& operator()( std::ostream& out) const {
return out << '#' << it->time_stamp();
}
};
auto display_vert(Vertex_handle v) {
std::stringstream os;
os.precision(17);
os << CGAL::IO::oformat(v, My()) << "=(" << v->point() << ")";
if(v->time_stamp() == 0) {
os << "inf";
} else {
os << '#' << v->time_stamp() << "=(" << v->point() << ")";
}
return os.str();
};
template <typename Simplex>
@ -108,14 +96,14 @@ auto debug_simplex(Simplex simplex) {
static const std::vector<Point_3> bbox_points =
{
{ -10.1, -10, -10 },
{ -10.2, 10, -10 },
{ 10.3, 10, -10 },
{ 10.4, -10, -10 },
{ -10.5, -10, 10 },
{ -10.6, 10, 10 },
{ 10.7, 10, 10 },
{ 10.8, -10, 10 },
{ -10.1, -10, -10.08 },
{ -10.2, 10, -10.07 },
{ 10.3, 10, -10.06 },
{ 10.4, -10, -10.05 },
{ -10.5, -10, 10.04 },
{ -10.6, 10, 10.03 },
{ 10.7, 10, 10.02 },
{ 10.8, -10, 10.01 },
};
DT dt;
@ -172,19 +160,24 @@ bool test_vfefv(bool with_bbox = false)
bool test_a_simple_tetrahedron() {
std::cerr << "## test_a_simple_tetrahedron()\n";
DT dt2;
dt2.insert({0, 0, 0});
dt2.insert({1, 0, 0});
dt2.insert({0, 1, 0});
dt2.insert({0, 0, 1});
bool ok = true;
auto test = [&](Point_3 a, Point_3 b, bool with_bbox, std::string expected_result) {
bool exception_thrown = false;
dt.clear();
dt.insert({0, 0, 0});
dt.insert({1, 0, 0});
dt.insert({0, 1, 0});
dt.insert({0, 0, 1});
if(with_bbox) insert(dt, bbox_points.begin(), bbox_points.end());
result_string.clear();
auto test = [&](Point_3 a, Point_3 b, std::string expected_result) {
// This test function calls `do_test` with four configurations:
// - with [ab] and [ba],
// - and with or without a bbox around the central tetrahedron.
dt = dt2;
auto do_test = [&](Point_3 a, Point_3 b, bool with_bbox, std::string expected_result) {
std::cerr << "### Case " << expected_result;
if(with_bbox) std::cerr << " with bbox";
std::cerr << '\n';
std::cerr << "from (" << a << ") to (" << b << ")\n";
bool exception_thrown = false;
result_string.clear();
try {
for(auto s: dt.segment_traverser_simplices(a, b)) {
visit_simplex(s);
@ -196,33 +189,76 @@ bool test_a_simple_tetrahedron() {
e.message().c_str());
exception_thrown = true;
}
if(result_string != expected_result || exception_thrown) {
std::cerr << "test_a_simple_tetrahedron failed on case " << expected_result
<< (with_bbox ? " with bbox\n" : "\n");
ok = false;
}
if(result_string != expected_result) {
std::cerr << "test_a_simple_tetrahedron failed\n";
std::cerr << " result_string is " << result_string << " instead of "
<< expected_result << '\n';
ok = false;
}
if(exception_thrown) {
std::cerr << "test_a_simple_tetrahedron failed\n";
std::cerr << " exception thrown\n";
ok = false;
}
};
std::string expected_result_reversed{expected_result.rbegin(), expected_result.rend()};
do_test(a, b, false, expected_result);
do_test(b, a, false, expected_result_reversed);
std::replace(expected_result.begin(), expected_result.end(), 'I', '3');
std::replace(expected_result_reversed.begin(), expected_result_reversed.end(), 'I', '3');
insert(dt, bbox_points.begin(), bbox_points.end());
do_test(a, b, true, expected_result);
do_test(b, a, true, expected_result_reversed);
};
test({ 0, 0, 0}, { 1, 0, 0}, false, "010");
test({ 0, 0, 0}, { 2, 0, 0}, false, "010I");
test({-1, 0, 0}, { 2, 0, 0}, false, "I010I");
test({ 0, 0, 0}, {.5, .5, 0}, false, "021");
test({ 0, 0, 0}, { 1, 1, 0}, false, "021I");
test({-1, -1, 0}, { 1, 1, 0}, false, "I021I");
// queries entering by a vertex and exiting by a vertex, on the line (x,0,0)
test({ 0, 0, 0}, {.5, 0, 0}, "01");
test({ 0, 0, 0}, { 1, 0, 0}, "010");
test({ 0, 0, 0}, { 2, 0, 0}, "010I");
test({-1, 0, 0}, { 2, 0, 0}, "I010I");
test({-1, 0, 0}, { 1, 0, 0}, "I010");
test({-1, 0, 0}, {.5, 0, 0}, "I01");
test({ 0, 0, 0}, { 1, 0, 0}, true, "010");
test({ 0, 0, 0}, { 2, 0, 0}, true, "0103");
test({-1, 0, 0}, { 2, 0, 0}, true, "30103");
test({ 0, 0, 0}, {.5, .5, 0}, true, "021");
test({ 0, 0, 0}, { 1, 1, 0}, true, "0213");
test({-1, -1, 0}, { 1, 1, 0}, true, "30213");
// queries entering by a vertex and exiting by an edge, on the line (x,x,0) (y==x)
test({ 0, 0, 0}, {.2, .2, 0}, "02");
test({ 0, 0, 0}, {.5, .5, 0}, "021");
test({ 0, 0, 0}, { 1, 1, 0}, "021I");
test({-1, -1, 0}, { 1, 1, 0}, "I021I");
test({-1, -1, 0}, {.5, .5, 0}, "I021");
test({-1, -1, 0}, {.2, .2, 0}, "I02");
// queries entering by a vertex and exiting by a facet, one the line x==y==0.25-0.25z
test({ 0, 0, 1}, { .25, .25, .25}, "03");
test({ 0, 0, 1}, { .25, .25, 0}, "032");
test({ 0, 0, 1}, { .5, .5, -1 }, "032I");
test({-.25,-.25, 2}, { .5, .5, -1 }, "I032I");
test({-.25,-.25, 2}, { .25, .25, 0}, "I032");
test({-.25,-.25, 2}, { .05, .05, .8}, "I03");
// queries entering by an edge and exiting by an edge, on the line (x,.5,0)
test({ 0, .5, 0}, {.2, .5, 0}, "12");
test({ 0, .5, 0}, {.5, .5, 0}, "121");
test({ 0, .5, 0}, { 1, .5, 0}, "121I");
test({-1, .5, 0}, { 1, .5, 0}, "I121I");
test({-1, .5, 0}, {.5, .5, 0}, "I121");
test({-1, .5, 0}, {.2, .5, 0}, "I12");
// queries entering by an edge and exiting by a facet, on the line (x, .25-x, x)
test({ 0, .25, 0}, { .20, .05, .20}, "13");
test({ 0, .25, 0}, { .25, 0, .25}, "132");
test({ 0, .25, 0}, { .5 ,-.25, .5 }, "132I");
test({-.5, .75,-.5}, { .5 ,-.25, .5 }, "I132I");
test({-.5, .75,-.5}, { .25, 0, .25}, "I132");
test({-.5, .75,-.5}, { .20, .05, .20}, "I13");
// queries entering by a facet and exiting by a facet, on the line (x,.5-x,.2)
test({ 0, .5, .2}, {.2, .3, .2}, "23");
test({ 0, .5, .2}, {.5, 0, .2}, "232");
test({ 0, .5, .2}, { 1,-.5, .2}, "232I");
test({-1,1.5, .2}, { 1, .5, .2}, "I232I");
test({-1,1.5, .2}, {.5, 0, .2}, "I232");
test({-1,1.5, .2}, {.2, .3, .2}, "I23");
return ok;
}