From 737e12d6a4bc259a494bf0da53389a7903a27a02 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 22 Sep 2020 18:36:40 +0200 Subject: [PATCH] Added GSI tests. --- src/drc/drc/built-in-macros/_drc_layer.rb | 28 +++++----- testdata/ruby/dbRegionTest.rb | 64 +++++++++++++++++++++++ 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/src/drc/drc/built-in-macros/_drc_layer.rb b/src/drc/drc/built-in-macros/_drc_layer.rb index 359470cca..b5a7e2269 100644 --- a/src/drc/drc/built-in-macros/_drc_layer.rb +++ b/src/drc/drc/built-in-macros/_drc_layer.rb @@ -1673,7 +1673,7 @@ CODE # @name interacting # @brief Selects shapes or regions of self which touch or overlap shapes from the other region # @synopsis layer.interacting(other) - # @synopsis layer.interacting(other, count) + # @synopsis layer.interacting(other, min_count) # @synopsis layer.interacting(other, min_count, max_count) # @synopsis layer.interacting(other, min_count .. max_count) # This method selects all shapes or regions from self which touch or overlap shapes from the other @@ -1694,7 +1694,7 @@ CODE # @/tr # @/table # - # If a single count is given, shapes from self are selected only if they do interact with the given + # If a single count is given, shapes from self are selected only if they do interact at least with the given # number of (different) shapes from the other layer. If a min and max count is given, shapes from # self are selected only if they interact with min_count or more, but a maximum of max_count different shapes # from the other layer. Two polygons overlapping or touching at two locations are counted as single interactions. @@ -1709,7 +1709,7 @@ CODE # @name not_interacting # @brief Selects shapes or regions of self which do not touch or overlap shapes from the other region # @synopsis layer.not_interacting(other) - # @synopsis layer.not_interacting(other, count) + # @synopsis layer.not_interacting(other, min_count) # @synopsis layer.not_interacting(other, min_count, max_count) # @synopsis layer.not_interacting(other, min_count .. max_count) # This method selects all shapes or regions from self which do not touch or overlap shapes from the other @@ -1730,7 +1730,7 @@ CODE # @/tr # @/table # - # If a single count is given, shapes from self are selected only if they do not interact with the given + # If a single count is given, shapes from self are selected only if they interact with less than the given # number of (different) shapes from the other layer. If a min and max count is given, shapes from # self are selected only if they interact with less than min_count or more than max_count different shapes # from the other layer. Two polygons overlapping or touching at two locations are counted as single interactions. @@ -1745,7 +1745,7 @@ CODE # @name select_interacting # @brief Selects shapes or regions of self which touch or overlap shapes from the other region # @synopsis layer.select_interacting(other) - # @synopsis layer.select_interacting(other, count) + # @synopsis layer.select_interacting(other, min_count) # @synopsis layer.select_interacting(other, min_count, max_count) # @synopsis layer.select_interacting(other, min_count .. max_count) # This method selects all shapes or regions from self which touch or overlap shapes from the other @@ -1758,7 +1758,7 @@ CODE # with respect to other edges or polygons. Texts can be selected with respect to # polygons. Polygons can be selected with respect to edges, texts and other polygons. # - # If a single count is given, shapes from self are selected only if they do interact with the given + # If a single count is given, shapes from self are selected only if they do interact at least with the given # number of (different) shapes from the other layer. If a min and max count is given, shapes from # self are selected only if they interact with min_count or more, but a maximum of max_count different shapes # from the other layer. Two polygons overlapping or touching at two locations are counted as single interactions. @@ -1767,7 +1767,7 @@ CODE # @name select_not_interacting # @brief Selects shapes or regions of self which do not touch or overlap shapes from the other region # @synopsis layer.select_not_interacting(other) - # @synopsis layer.select_not_interacting(other, count) + # @synopsis layer.select_not_interacting(other, min_count) # @synopsis layer.select_not_interacting(other, min_count, max_count) # @synopsis layer.select_not_interacting(other, min_count .. max_count) # This method selects all shapes or regions from self which do not touch or overlap shapes from the other @@ -1780,7 +1780,7 @@ CODE # with respect to other edges or polygons. Texts can be selected with respect to # polygons. Polygons can be selected with respect to edges, texts and other polygons. # - # If a single count is given, shapes from self are selected only if they do not interact with the given + # If a single count is given, shapes from self are selected only if they interact with less than the given # number of (different) shapes from the other layer. If a min and max count is given, shapes from # self are selected only if they interact with less than min_count or more than max_count different shapes # from the other layer. Two polygons overlapping or touching at two locations are counted as single interactions. @@ -3301,16 +3301,20 @@ CODE elsif args.size == 1 a = args[0] if a.is_a?(Range) - if a.min.to_i <= 0 - raise("#{f}: min_count argument must be a positive, non-zero number") + if a.begin && a.begin.to_i <= 0 + raise("#{f}: lower bound of range must be a positive, non-zero number") + end + if a.end + return [(a.begin || 1).to_i, a.end.to_i] + else + return [(a.begin || 1).to_i] end - return [a.min.to_i, a.max.to_i] elsif !a.is_a?(1.class) raise("#{f}: count argument must be an integer number") elsif a <= 0 raise("#{f}: count argument must be a positive, non-zero number") else - return [a, a] + return [a] end elsif args.size == 2 amin = args[0] diff --git a/testdata/ruby/dbRegionTest.rb b/testdata/ruby/dbRegionTest.rb index d42efc90c..861b50629 100644 --- a/testdata/ruby/dbRegionTest.rb +++ b/testdata/ruby/dbRegionTest.rb @@ -512,6 +512,8 @@ class DBRegion_TestClass < TestBase r1.insert(RBA::Box::new(50, 70, 150, 270)) r1.insert(RBA::Box::new(100, 70, 250, 270)) r2 = RBA::Region::new(RBA::Box::new(-10, -20, 100, 200)) + r3 = RBA::Region::new(RBA::Box::new(150, 270, 160, 280)) + r3 += r2 assert_equal(r1.merged_semantics?, true) r1.merged_semantics = false @@ -520,19 +522,81 @@ class DBRegion_TestClass < TestBase assert_equal(r1.inside(r2).to_s, "(10,20;10,200;100,200;100,20)") assert_equal(r1.not_inside(r2).to_s, "(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") assert_equal(r1.interacting(r2).to_s, "(10,20;10,200;100,200;100,20);(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") + assert_equal(r1.interacting(r3, 1).to_s, "(10,20;10,200;100,200;100,20);(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") + assert_equal(r1.interacting(r3, 2).to_s, "(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") + assert_equal(r1.interacting(r3, 3).to_s, "") + assert_equal(r1.interacting(r3, 1, 1).to_s, "(10,20;10,200;100,200;100,20)") + assert_equal(r1.interacting(r3, 2, 2).to_s, "(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") assert_equal(r1.not_interacting(r2).to_s, "") + assert_equal(r1.not_interacting(r3, 1).to_s, "") + assert_equal(r1.not_interacting(r3, 2).to_s, "(10,20;10,200;100,200;100,20)") + assert_equal(r1.not_interacting(r3, 3).to_s, "(10,20;10,200;100,200;100,20);(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") + assert_equal(r1.not_interacting(r3, 1, 1).to_s, "(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") + assert_equal(r1.not_interacting(r3, 2, 2).to_s, "(10,20;10,200;100,200;100,20)") assert_equal(r1.overlapping(r2).to_s, "(10,20;10,200;100,200;100,20);(50,70;50,270;150,270;150,70)") assert_equal(r1.not_overlapping(r2).to_s, "(100,70;100,270;250,270;250,70)") assert_equal(r1.outside(r2).to_s, "(100,70;100,270;250,270;250,70)") assert_equal(r1.not_outside(r2).to_s, "(10,20;10,200;100,200;100,20);(50,70;50,270;150,270;150,70)") + e2 = RBA::Edges::new(RBA::Edge::new(-10, -20, 100, 200)) + e3 = RBA::Edges::new(RBA::Edge::new(150, 270, 160, 280)) + e3 += e2 + + assert_equal(r1.interacting(e2).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.interacting(e3, 1).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.interacting(e3, 2).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70)") + assert_equal(r1.interacting(e3, 3).to_s, "") + assert_equal(r1.interacting(e3, 1, 1).to_s, "(10,20;10,200;100,200;100,20)") + assert_equal(r1.interacting(e3, 2, 2).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70)") + assert_equal(r1.not_interacting(e2).to_s, "") + assert_equal(r1.not_interacting(e3, 1).to_s, "") + assert_equal(r1.not_interacting(e3, 2).to_s, "(10,20;10,200;100,200;100,20)") + assert_equal(r1.not_interacting(e3, 3).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.not_interacting(e3, 1, 1).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70)") + assert_equal(r1.not_interacting(e3, 2, 2).to_s, "(10,20;10,200;100,200;100,20)") + + t2 = RBA::Texts::new(RBA::Text::new("a", RBA::Trans::new(50, 100))) + t3 = RBA::Texts::new(RBA::Text::new("b", RBA::Trans::new(150, 270))) + t3 += t2 + + assert_equal(r1.interacting(t2).to_s, "(50,70;50,270;150,270;150,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.interacting(t3, 1).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.interacting(t3, 2).to_s, "(50,70;50,270;150,270;150,70)") + assert_equal(r1.interacting(t3, 3).to_s, "") + assert_equal(r1.interacting(t3, 1, 1).to_s, "(100,70;100,270;250,270;250,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.interacting(t3, 2, 2).to_s, "(50,70;50,270;150,270;150,70)") + assert_equal(r1.not_interacting(t2).to_s, "(100,70;100,270;250,270;250,70)") + assert_equal(r1.not_interacting(t3, 1).to_s, "") + assert_equal(r1.not_interacting(t3, 2).to_s, "(100,70;100,270;250,270;250,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.not_interacting(t3, 3).to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70);(10,20;10,200;100,200;100,20)") + assert_equal(r1.not_interacting(t3, 1, 1).to_s, "(50,70;50,270;150,270;150,70)") + assert_equal(r1.not_interacting(t3, 2, 2).to_s, "(100,70;100,270;250,270;250,70);(10,20;10,200;100,200;100,20)") + rr = r1.dup rr.select_interacting(r2) assert_equal(rr.to_s, "(10,20;10,200;100,200;100,20);(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") + rr = r1.dup + rr.select_interacting(r3, 2, 2) + assert_equal(rr.to_s, "(50,70;50,270;150,270;150,70);(100,70;100,270;250,270;250,70)") + rr = r1.dup + rr.select_interacting(e3, 2, 2) + assert_equal(rr.to_s, "(100,70;100,270;250,270;250,70);(50,70;50,270;150,270;150,70)") + rr = r1.dup + rr.select_interacting(t3, 2, 2) + assert_equal(rr.to_s, "(50,70;50,270;150,270;150,70)") rr = r1.dup rr.select_not_interacting(r2) assert_equal(rr.to_s, "") + rr = r1.dup + rr.select_not_interacting(r3, 2, 2) + assert_equal(rr.to_s, "(10,20;10,200;100,200;100,20)") + rr = r1.dup + rr.select_not_interacting(e3, 2, 2) + assert_equal(rr.to_s, "(10,20;10,200;100,200;100,20)") + rr = r1.dup + rr.select_not_interacting(t3, 2, 2) + assert_equal(rr.to_s, "(100,70;100,270;250,270;250,70);(10,20;10,200;100,200;100,20)") rr = r1.dup rr.select_overlapping(r2)