diff --git a/src/db/db/gsiDeclDbRegion.cc b/src/db/db/gsiDeclDbRegion.cc index 11b80b936..53da87933 100644 --- a/src/db/db/gsiDeclDbRegion.cc +++ b/src/db/db/gsiDeclDbRegion.cc @@ -1379,6 +1379,16 @@ rasterize1 (const db::Region *region, const db::Point &origin, const db::Vector return rasterize2 (region, origin, pixel_size, pixel_size, nx, ny); } +static tl::Variant nth (const db::Region *region, size_t n) +{ + const db::Polygon *poly = region->nth (n); + if (! poly) { + return tl::Variant (); + } else { + return tl::Variant (db::PolygonWithProperties (*poly, region->nth_prop_id (n))); + } +} + static db::generic_shape_iterator begin_region (const db::Region *region) { return db::generic_shape_iterator (db::make_wp_iter (region->delegate ()->begin ())); @@ -4103,14 +4113,16 @@ Class decl_Region (decl_dbShapeCollection, "db", "Region", "This returns the raw polygons if merged semantics is disabled or the merged ones if merged semantics is enabled.\n" "Starting with version 0.30, the iterator delivers a RegionWithProperties object." ) + - method ("[]", &db::Region::nth, gsi::arg ("n"), + method_ext ("[]", &nth, gsi::arg ("n"), "@brief Returns the nth polygon of the region\n" "\n" "This method returns nil if the index is out of range. It is available for flat regions only - i.e. " "those for which \\has_valid_polygons? is true. Use \\flatten to explicitly flatten a region.\n" "This method returns the raw polygon (not merged polygons, even if merged semantics is enabled).\n" "\n" - "The \\each iterator is the more general approach to access the polygons." + "The \\each iterator is the more general approach to access the polygons.\n" + "\n" + "Since version 0.30.1, this method returns a \\PolygonWithProperties object." ) + method ("flatten", &db::Region::flatten, "@brief Explicitly flattens a region\n" diff --git a/src/gsi/unit_tests/gsiExpressionTests.cc b/src/gsi/unit_tests/gsiExpressionTests.cc index 105383e92..a395a73d9 100644 --- a/src/gsi/unit_tests/gsiExpressionTests.cc +++ b/src/gsi/unit_tests/gsiExpressionTests.cc @@ -898,4 +898,3 @@ TEST(17) "it.add_value(17.5)").execute (); } - diff --git a/testdata/ruby/dbRegionTest.rb b/testdata/ruby/dbRegionTest.rb index 5f8588f8b..e92798056 100644 --- a/testdata/ruby/dbRegionTest.rb +++ b/testdata/ruby/dbRegionTest.rb @@ -226,10 +226,14 @@ class DBRegion_TestClass < TestBase r.flatten assert_equal(r.has_valid_polygons?, true) - assert_equal(r[1].to_s, "(-10,80;-10,120;10,120;10,80)") + assert_equal(r[1].to_s, "(-10,80;-10,120;10,120;10,80) props={}") assert_equal(r[4].to_s, "") assert_equal(r.bbox.to_s, "(-10,-20;210,120)") assert_equal(r.is_merged?, false) + + r = RBA::Region::new + r.insert(RBA::PolygonWithProperties::new(RBA::Box::new(0, 0, 10, 20), { 1 => 'value' })) + assert_equal(r[0].to_s, "(0,0;0,20;10,20;10,0) props={1=>value}") r = RBA::Region::new(ly.begin_shapes(c1.cell_index, l2), "*") assert_equal(csort(r.to_s), csort("(-11,-21;-11,-19;-9,-19;-9,-21);(9,19;9,21;11,21;11,19);(-11,79;-11,81;-9,81;-9,79);(9,119;9,121;11,121;11,119);(189,79;189,81;191,81;191,79);(209,119;209,121;211,121;211,119)"))