From c532a3a7e69bf0e237a6f6db2d5c32c62eaa5d6f Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 2 Mar 2024 19:32:51 +0100 Subject: [PATCH] WIP --- src/db/db/dbAsIfFlatEdges.cc | 11 ++++------- src/db/db/dbDeepEdges.cc | 12 ++++++++---- src/db/db/dbEdgesUtils.h | 2 ++ src/db/unit_tests/dbEdgesUtilsTests.cc | 20 ++++++++++++++++++++ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/db/db/dbAsIfFlatEdges.cc b/src/db/db/dbAsIfFlatEdges.cc index 0e9c25ad8..3b54be908 100644 --- a/src/db/db/dbAsIfFlatEdges.cc +++ b/src/db/db/dbAsIfFlatEdges.cc @@ -150,7 +150,7 @@ AsIfFlatEdges::selected_interacting_generic (const Region &other, EdgeInteractio std::vector > others; // NOTE: with counting the other region needs to be merged - others.push_back (counting ? other.begin_merged () : other.begin ()); + others.push_back (counting || mode == EdgesInside ? other.begin_merged () : other.begin ()); proc.run_flat (edges, others, std::vector (), &op, oph.results ()); @@ -162,7 +162,6 @@ AsIfFlatEdges::selected_interacting_generic (const Edges &other, EdgeInteraction { min_count = std::max (size_t (1), min_count); - // @@@ // shortcuts if (max_count < min_count || other.empty () || empty ()) { return ((mode == EdgesOutside) == inverse) ? new EmptyEdges () : clone (); @@ -182,7 +181,7 @@ AsIfFlatEdges::selected_interacting_generic (const Edges &other, EdgeInteraction std::vector > others; // NOTE: with counting the other edge collection needs to be merged - others.push_back (counting ? other.begin_merged () : other.begin ()); + others.push_back (counting || mode == EdgesInside ? other.begin_merged () : other.begin ()); proc.run_flat (edges, others, std::vector (), &op, oph.results ()); @@ -194,7 +193,6 @@ AsIfFlatEdges::selected_interacting_pair_generic (const Region &other, EdgeInter { min_count = std::max (size_t (1), min_count); - // @@@ // shortcuts if (max_count < min_count || other.empty () || empty ()) { if (mode != EdgesOutside) { @@ -218,7 +216,7 @@ AsIfFlatEdges::selected_interacting_pair_generic (const Region &other, EdgeInter std::vector > others; // NOTE: with counting the other region needs to be merged - others.push_back (counting ? other.begin_merged () : other.begin ()); + others.push_back (counting || mode == EdgesInside ? other.begin_merged () : other.begin ()); proc.run_flat (edges, others, std::vector (), &op, oph.results ()); @@ -230,7 +228,6 @@ AsIfFlatEdges::selected_interacting_pair_generic (const Edges &other, EdgeIntera { min_count = std::max (size_t (1), min_count); - // @@@ // shortcuts if (max_count < min_count || other.empty () || empty ()) { if (mode != EdgesOutside) { @@ -254,7 +251,7 @@ AsIfFlatEdges::selected_interacting_pair_generic (const Edges &other, EdgeIntera std::vector > others; // NOTE: with counting the other edge collection needs to be merged - others.push_back (counting ? other.begin_merged () : other.begin ()); + others.push_back (counting || mode == EdgesInside ? other.begin_merged () : other.begin ()); proc.run_flat (edges, others, std::vector (), &op, oph.results ()); diff --git a/src/db/db/dbDeepEdges.cc b/src/db/db/dbDeepEdges.cc index 80e90ebe8..955f17c91 100644 --- a/src/db/db/dbDeepEdges.cc +++ b/src/db/db/dbDeepEdges.cc @@ -1357,7 +1357,8 @@ RegionDelegate *DeepEdges::extended (coord_type ext_b, coord_type ext_e, coord_t EdgesDelegate * DeepEdges::selected_interacting_generic (const Region &other, EdgeInteractionMode mode, bool inverse, size_t min_count, size_t max_count) const { - // @@@ + min_count = std::max (size_t (1), min_count); + std::unique_ptr dr_holder; const db::DeepRegion *other_deep = dynamic_cast (other.delegate ()); if (! other_deep) { @@ -1384,7 +1385,8 @@ DeepEdges::selected_interacting_generic (const Region &other, EdgeInteractionMod std::pair DeepEdges::selected_interacting_pair_generic (const Region &other, EdgeInteractionMode mode, size_t min_count, size_t max_count) const { - // @@@ + min_count = std::max (size_t (1), min_count); + std::unique_ptr dr_holder; const db::DeepRegion *other_deep = dynamic_cast (other.delegate ()); if (! other_deep) { @@ -1417,7 +1419,8 @@ DeepEdges::selected_interacting_pair_generic (const Region &other, EdgeInteracti EdgesDelegate * DeepEdges::selected_interacting_generic (const Edges &other, EdgeInteractionMode mode, bool inverse, size_t min_count, size_t max_count) const { - // @@@ + min_count = std::max (size_t (1), min_count); + std::unique_ptr dr_holder; const db::DeepEdges *other_deep = dynamic_cast (other.delegate ()); if (! other_deep) { @@ -1444,7 +1447,8 @@ DeepEdges::selected_interacting_generic (const Edges &other, EdgeInteractionMode std::pair DeepEdges::selected_interacting_pair_generic (const Edges &other, EdgeInteractionMode mode, size_t min_count, size_t max_count) const { - // @@@ + min_count = std::max (size_t (1), min_count); + std::unique_ptr dr_holder; const db::DeepEdges *other_deep = dynamic_cast (other.delegate ()); if (! other_deep) { diff --git a/src/db/db/dbEdgesUtils.h b/src/db/db/dbEdgesUtils.h index c58fd598f..531a18fca 100644 --- a/src/db/db/dbEdgesUtils.h +++ b/src/db/db/dbEdgesUtils.h @@ -344,6 +344,7 @@ public: { // NOTE: "counting" does not really make much sense in Outside mode ... m_counting = !(min_count == 1 && max_count == std::numeric_limits::max ()); + tl_assert (!m_counting || mode != EdgesOutside); } void finish (const db::Edge *o, size_t p) @@ -450,6 +451,7 @@ public: { // NOTE: "counting" does not really make much sense in Outside mode ... m_counting = !(min_count == 1 && max_count == std::numeric_limits::max ()); + tl_assert (!m_counting || mode != EdgesOutside); } void finish (const OutputType *o) diff --git a/src/db/unit_tests/dbEdgesUtilsTests.cc b/src/db/unit_tests/dbEdgesUtilsTests.cc index 86a0ad53d..bf201b5f1 100644 --- a/src/db/unit_tests/dbEdgesUtilsTests.cc +++ b/src/db/unit_tests/dbEdgesUtilsTests.cc @@ -83,5 +83,25 @@ TEST(1) EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (0, 11), db::Point (10, 11)), db::Polygon (db::Box (0, 0, 10, 10))), true); EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (0, 5), db::Point (10, 5)), db::Polygon (db::Box (0, 0, 10, 10))), false); EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-5, 5), db::Point (15, 5)), db::Polygon (db::Box (0, 0, 10, 10))), false); + EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-10, 5), db::Point (0, 5)), db::Polygon (db::Box (0, 0, 10, 10))), true); + EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-10, 0), db::Point (10, 0)), db::Polygon (db::Box (0, 0, 10, 10))), true); + + db::Point pts[] = { + db::Point (0, 0), + db::Point (0, 10), + db::Point (20, 10), + db::Point (20, -10), + db::Point (10, -10), + db::Point (10, 0) + }; + + db::Polygon poly; + poly.assign_hull (pts + 0, pts + sizeof(pts) / sizeof(pts[0])); + + EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-10, 10), db::Point (20, 10)), poly), true); + EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-10, -10), db::Point (20, -10)), poly), true); + EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-10, 0), db::Point (11, 0)), poly), false); + EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-10, 0), db::Point (10, 0)), poly), true); + EXPECT_EQ (db::edge_is_outside (db::Edge (db::Point (-10, 0), db::Point (9, 0)), poly), true); }