From 3f8113e40476766def1069d779be2caf8d3630ec Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 26 Dec 2020 23:55:50 +0100 Subject: [PATCH] WIP: Updated some test, debugging --- src/db/db/dbHierProcessor.cc | 167 ++++++++++++++++++++--------- src/db/unit_tests/dbRegionTests.cc | 11 +- 2 files changed, 128 insertions(+), 50 deletions(-) diff --git a/src/db/db/dbHierProcessor.cc b/src/db/db/dbHierProcessor.cc index 8a819278c..246a54752 100644 --- a/src/db/db/dbHierProcessor.cc +++ b/src/db/db/dbHierProcessor.cc @@ -1905,57 +1905,51 @@ local_processor::run_flat (const db::Shapes *subject_shapes, const s run_flat (generic_shape_iterator (subject_shapes), is, op, result_shapes); } -namespace { +namespace +{ template -struct scan_shape2shape_same_layer_flat +struct interaction_registration_shape1_scanner_combo { - void - operator () (unsigned int, shape_interactions &, db::Coord) const + interaction_registration_shape1_scanner_combo (shape_interactions *, unsigned int) { - // cannot have different types on the same layer + // can't have self-interactions with different types tl_assert (false); } + + void insert (const TS *, unsigned int) + { + // nothing here. + } + + void process (db::Coord) + { + // nothing here. + } }; template -struct scan_shape2shape_same_layer_flat +struct interaction_registration_shape1_scanner_combo { - void - operator () (unsigned int intruder_layer, shape_interactions &interactions, db::Coord dist) const + interaction_registration_shape1_scanner_combo (shape_interactions *interactions, unsigned int intruder_layer_index) + : m_scanner (), m_rec (interactions, intruder_layer_index) { - db::box_scanner scanner; - interaction_registration_shape1 rec (&interactions, intruder_layer); - - for (typename shape_interactions::subject_iterator s = interactions.begin_subjects (); s != interactions.end_subjects (); ++s) { - scanner.insert (&s->second, s->first); - } - - scanner.process (rec, dist, db::box_convert ()); + // .. nothing yet .. } -}; -template -struct scan_shape2shape_different_layers_flat -{ - void - operator () (const generic_shape_iterator &intruders, const db::Box &common_box, unsigned int intruder_layer, shape_interactions &interactions, db::Coord dist) const + void insert (const T *shape, unsigned int id) { - db::box_scanner2 scanner; - interaction_registration_shape2shape rec (0 /*layout*/, &interactions, intruder_layer); - - for (typename shape_interactions::subject_iterator s = interactions.begin_subjects (); s != interactions.end_subjects (); ++s) { - scanner.insert1 (&s->second, s->first); - } - - addressable_shape_delivery ii (intruders.confined (common_box, true)); - for (; !ii.at_end (); ++ii) { - scanner.insert2 (ii.operator-> (), interactions.next_id ()); - } - - scanner.process (rec, dist, db::box_convert (), db::box_convert ()); - + m_scanner.insert (shape, id); } + + void process (db::Coord dist) + { + m_scanner.process (m_rec, dist, db::box_convert ()); + } + +private: + db::box_scanner m_scanner; + interaction_registration_shape1 m_rec; }; } @@ -2004,24 +1998,101 @@ local_processor::run_flat (const generic_shape_iterator &subject } else { - box_convert bcs; + if (needs_isolated_subjects) { - addressable_shape_delivery is (subjects); - for ( ; !is.at_end (); ++is) { - const TS *shape = is.operator-> (); - if (needs_isolated_subjects || bcs (*shape).overlaps (common_box)) { + addressable_shape_delivery is (subjects); + for ( ; !is.at_end (); ++is) { + const TS *shape = is.operator-> (); unsigned int id = interactions.next_id (); interactions.add_subject (id, *shape); } - } - unsigned int il_index = 0; - for (typename std::vector >::const_iterator il = intruders.begin (); il != intruders.end (); ++il, ++il_index) { - if (*il == subjects) { - scan_shape2shape_same_layer_flat () (il_index, interactions, op->dist ()); - } else { - scan_shape2shape_different_layers_flat () (*il, common_box, il_index, interactions, op->dist ()); + unsigned int il_index = 0; + for (typename std::vector >::const_iterator il = intruders.begin (); il != intruders.end (); ++il, ++il_index) { + + if (*il == subjects) { + + interaction_registration_shape1_scanner_combo scanner (&interactions, il_index); + + for (typename shape_interactions::subject_iterator s = interactions.begin_subjects (); s != interactions.end_subjects (); ++s) { + scanner.insert (&s->second, s->first); + } + + scanner.process (dist); + + } else { + + + db::box_scanner2 scanner; + interaction_registration_shape2shape rec (0 /*layout*/, &interactions, il_index); + + for (typename shape_interactions::subject_iterator s = interactions.begin_subjects (); s != interactions.end_subjects (); ++s) { + scanner.insert1 (&s->second, s->first); + } + + addressable_shape_delivery ii ((*il).confined (common_box, true)); + for (; !ii.at_end (); ++ii) { + scanner.insert2 (ii.operator-> (), interactions.next_id ()); + } + + scanner.process (rec, dist, db::box_convert (), db::box_convert ()); + + } } + + } else { + + unsigned int id_first = 0; + + { + // allocate a range of IDs for the subjects + generic_shape_iterator is (subjects); + if (! is.at_end ()) { + id_first = interactions.next_id (); + while (! (++is).at_end ()) { + interactions.next_id (); + } + } + } + + unsigned int il_index = 0; + for (typename std::vector >::const_iterator il = intruders.begin (); il != intruders.end (); ++il, ++il_index) { + + if (*il == subjects) { + + interaction_registration_shape1_scanner_combo scanner (&interactions, il_index); + + addressable_shape_delivery is (subjects.confined (common_box, true)); + unsigned int id = id_first; + + for ( ; ! is.at_end (); ++is, ++id) { + scanner.insert (is.operator-> (), id); + } + + scanner.process (dist); + + } else { + + db::box_scanner2 scanner; + interaction_registration_shape2shape rec (0 /*layout*/, &interactions, il_index); + + addressable_shape_delivery is (subjects.confined (common_box, true)); + unsigned int id = id_first; + + for ( ; ! is.at_end (); ++is, ++id) { + scanner.insert1 (is.operator-> (), id); + } + + addressable_shape_delivery ii ((*il).confined (common_box, true)); + for (; !ii.at_end (); ++ii) { + scanner.insert2 (ii.operator-> (), interactions.next_id ()); + } + + scanner.process (rec, dist, db::box_convert (), db::box_convert ()); + + } + } + } } diff --git a/src/db/unit_tests/dbRegionTests.cc b/src/db/unit_tests/dbRegionTests.cc index 3707a1b19..62e8190d4 100644 --- a/src/db/unit_tests/dbRegionTests.cc +++ b/src/db/unit_tests/dbRegionTests.cc @@ -580,7 +580,14 @@ TEST(15d) r.insert (db::Box (db::Point (600, 200), db::Point (700, 300))); r.insert (db::Box (db::Point (0, 140), db::Point (350, 160))); - EXPECT_EQ (r.space_check (120, db::RegionCheckOptions (false, db::Projection)).to_string (), "(300,100;400,100)/(400,200;300,200);(300,160;350,160)/(350,200;300,200);(0,160;100,160)/(100,200;0,200);(350,140;300,140)/(300,100;350,100);(0,100;100,100)/(100,140;0,140);(600,100;700,100)/(700,200;600,200)"); + EXPECT_EQ (r.space_check (120, db::RegionCheckOptions (false, db::Projection)).to_string (), + "(600,100;700,100)/(700,200;600,200);" + "(300,160;350,160)/(350,200;300,200);" + "(0,100;100,100)/(100,140;0,140);" + "(300,100;350,100)/(350,140;300,140);" + "(300,100;400,100)/(400,200;300,200);" + "(100,200;0,200)/(0,160;100,160)" + ); } TEST(15e) @@ -1235,7 +1242,7 @@ TEST(20) { db::Region r1 (db::RecursiveShapeIterator (ly, ly.cell (top), l2)); EXPECT_EQ (r1.has_valid_polygons (), false); - EXPECT_EQ (r1.space_check (30).to_string (), "(60,20;70,20)/(92,40;80,40);(70,20;70,12)/(80,40;80,48);(60,10;60,20)/(40,40;40,10)"); + EXPECT_EQ (r1.space_check (30).to_string (), "(70,20;70,12)/(80,40;80,48);(60,20;70,20)/(92,40;80,40);(40,40;40,10)/(60,10;60,20)"); EXPECT_EQ (r1.space_check (2).to_string (), ""); }