Fixed a potential issue when using the db::Shape edge iterator on a non-existing hull in SimplePolygon.

This commit is contained in:
Matthias Koefferlein 2017-08-10 01:53:35 +02:00
parent 46fc42b65c
commit 7c59235889
4 changed files with 71 additions and 26 deletions

View File

@ -194,7 +194,8 @@ done
# Run Tests
set +e
TESTSRC=. TESTTMP=$build/testtmp $target/ut_runner -a >$build/ut_runner.xml
echo "Running unit tests .."
TESTSRC=. TESTTMP=$build/testtmp $target/ut_runner -a | tee $build/ut_runner.xml
set -e
# ----------------------------------------------------------

View File

@ -200,53 +200,95 @@ private:
iterator_type m_type;
struct contour_f {
unsigned int operator() () const
{
return 0;
}
template <class Iter>
unsigned int operator() (const Iter &iter) const
{
return iter.contour ();
}
};
struct at_end_f {
bool operator() () const
{
return true;
}
template <class Iter>
bool operator() (const Iter &iter) const
{
return iter.at_end ();
}
};
struct inc_f {
bool operator() () const
{
return false;
}
template <class Iter>
bool operator() (Iter &iter) const
{
iter.operator++ ();
return false;
}
}
};
struct dec_f {
bool operator() () const
{
return false;
}
template <class Iter>
bool operator() (Iter &iter) const
{
iter.operator-- ();
return false;
}
};
struct deref_f {
edge_type operator() () const
{
return edge_type ();
}
template <class Iter>
edge_type operator() (const Iter &iter) const
{
return iter.operator* ();
}
}
};
struct at_begin_f {
bool operator() () const
{
return true;
}
template <class Iter>
bool operator() (const Iter &iter) const
{
return iter.at_begin ();
}
}
};
template <class Ret, class Func>
@ -259,8 +301,10 @@ private:
return f (*((const polygon_ref_edge_iterator_type *) m_d.iter));
} else if (m_type == SimplePolygon) {
return f (*((const simple_polygon_edge_iterator_type *) m_d.iter));
} else {
} else if (m_type == SimplePolygonRef) {
return f (*((const simple_polygon_ref_edge_iterator_type *) m_d.iter));
} else {
return f ();
}
}
@ -274,8 +318,10 @@ private:
return f (*((polygon_ref_edge_iterator_type *) m_d.iter));
} else if (m_type == SimplePolygon) {
return f (*((simple_polygon_edge_iterator_type *) m_d.iter));
} else {
} else if (m_type == SimplePolygonRef) {
return f (*((simple_polygon_ref_edge_iterator_type *) m_d.iter));
} else {
return f ();
}
}
};

View File

@ -233,16 +233,16 @@ void run_test2 (ut::TestBase *_this, size_t n, double ff, db::Coord spread, bool
}
if (interactions != tr.interactions) {
std::cerr << "Interactions in 'brute force' but not in 'box-scanner':" << std::endl;
tl::info << "Interactions in 'brute force' but not in 'box-scanner':";
for (std::set<std::pair<size_t, size_t> >::const_iterator i = interactions.begin (); i != interactions.end (); ++i) {
if (tr.interactions.find (*i) == tr.interactions.end ()) {
std::cerr << " " << i->first << "-" << i->second << std::endl;
tl::info << " " << i->first << "-" << i->second;
}
}
std::cerr << "Interactions in 'box-scanner' but not in 'brute force':" << std::endl;
tl::info << "Interactions in 'box-scanner' but not in 'brute force':";
for (std::set<std::pair<size_t, size_t> >::const_iterator i = tr.interactions.begin (); i != tr.interactions.end (); ++i) {
if (interactions.find (*i) == interactions.end ()) {
std::cerr << " " << i->first << "-" << i->second << std::endl;
tl::info << " " << i->first << "-" << i->second;
}
}
}
@ -528,16 +528,16 @@ void run_test11 (ut::TestBase *_this, size_t n, double ff, db::Coord spread, boo
}
if (clusters != bf_clusters) {
std::cerr << "Clusters in 'brute force' but not in 'box-scanner':" << std::endl;
tl::info << "Clusters in 'brute force' but not in 'box-scanner':";
for (std::set<std::set<size_t > >::const_iterator i = bf_clusters.begin (); i != bf_clusters.end (); ++i) {
if (clusters.find (*i) == clusters.end ()) {
std::cerr << " " << c2s (*i) << std::endl;
tl::info << " " << c2s (*i);
}
}
std::cerr << "Clusters in 'box-scanner' but not in 'brute force':" << std::endl;
tl::info << "Clusters in 'box-scanner' but not in 'brute force':";
for (std::set<std::set<size_t > >::const_iterator i = clusters.begin (); i != clusters.end (); ++i) {
if (bf_clusters.find (*i) == bf_clusters.end ()) {
std::cerr << " " << c2s (*i) << std::endl;
tl::info << " " << c2s (*i);
}
}
}

View File

@ -404,7 +404,6 @@ TEST(9)
ea.insert (*i);
}
// std::cerr << "Interacting edges: " << ea.size () << std::endl;
EXPECT_NE (ea.size (), size_t (0));
// brute force
@ -417,16 +416,16 @@ TEST(9)
}
if (ea != eb) {
std::cerr << "In implementation but not in brute-force:" << std::endl;
tl::info << "In implementation but not in brute-force:";
for (std::set<db::Edge>::const_iterator i = ea.begin (); i != ea.end (); ++i) {
if (eb.find (*i) == eb.end ()) {
std::cerr << " " << i->to_string () << std::endl;
tl::info << " " << i->to_string ();
}
}
std::cerr << "In brute-force but not in implementation:" << std::endl;
tl::info << "In brute-force but not in implementation:";
for (std::set<db::Edge>::const_iterator i = eb.begin (); i != eb.end (); ++i) {
if (ea.find (*i) == ea.end ()) {
std::cerr << " " << i->to_string () << std::endl;
tl::info << " " << i->to_string ();
}
}
EXPECT_EQ (true, false);
@ -465,7 +464,6 @@ TEST(10)
ea.insert (*i);
}
// std::cerr << "Interacting edges: " << ea.size () << std::endl;
EXPECT_NE (ea.size (), size_t (0));
// brute force
@ -479,20 +477,20 @@ TEST(10)
}
if (ea != eb) {
std::cerr << "Boxes:" << std::endl;
tl::info << "Boxes:";
for (db::Region::const_iterator j = r.begin (); ! j.at_end (); ++j) {
std::cerr << " " << j->to_string () << std::endl;
tl::info << " " << j->to_string ();
}
std::cerr << "In implementation but not in brute-force:" << std::endl;
tl::info << "In implementation but not in brute-force:";
for (std::set<db::Edge>::const_iterator i = ea.begin (); i != ea.end (); ++i) {
if (eb.find (*i) == eb.end ()) {
std::cerr << " " << i->to_string () << std::endl;
tl::info << " " << i->to_string ();
}
}
std::cerr << "In brute-force but not in implementation:" << std::endl;
tl::info << "In brute-force but not in implementation:";
for (std::set<db::Edge>::const_iterator i = eb.begin (); i != eb.end (); ++i) {
if (ea.find (*i) == ea.end ()) {
std::cerr << " " << i->to_string () << std::endl;
tl::info << " " << i->to_string ();
}
}
EXPECT_EQ (true, false);