diff --git a/src/db/gsiDeclDbEdgePairs.cc b/src/db/gsiDeclDbEdgePairs.cc index dc770405b..eda6fc438 100644 --- a/src/db/gsiDeclDbEdgePairs.cc +++ b/src/db/gsiDeclDbEdgePairs.cc @@ -131,6 +131,13 @@ static db::Edges second_edges (const db::EdgePairs *ep) return e; } +static void insert_e (db::EdgePairs *e, const db::EdgePairs &a) +{ + for (db::EdgePairs::const_iterator p = a.begin (); p != a.end (); ++p) { + e->insert (*p); + } +} + Class decl_EdgePairs ("EdgePairs", constructor ("new", &new_v, "@brief Default constructor\n" @@ -259,6 +266,11 @@ Class decl_EdgePairs ("EdgePairs", "\n" "@return The transformed edge pair collection.\n" ) + + method_ext ("insert", &insert_e, + "@brief Inserts all edge pairs from the other edge pair collection into this edge pair collection\n" + "@args edge_pairs\n" + "This method has been introduced in version 0.25." + ) + method_ext ("edges", &edges, "@brief Decomposes the edge pairs into single edges\n" "@return An edge collection containing the individual edges\n" diff --git a/src/db/gsiDeclDbEdges.cc b/src/db/gsiDeclDbEdges.cc index c67f58045..c06f3cc15 100644 --- a/src/db/gsiDeclDbEdges.cc +++ b/src/db/gsiDeclDbEdges.cc @@ -328,6 +328,40 @@ static int projection_metrics () return db::Projection; } +static void insert_r (db::Edges *e, const db::Region &a) +{ + for (db::Region::const_iterator p = a.begin (); ! p.at_end (); ++p) { + e->insert (*p); + } +} + +static void insert_e (db::Edges *e, const db::Edges &a) +{ + for (db::Edges::const_iterator p = a.begin (); ! p.at_end (); ++p) { + e->insert (*p); + } +} + +template +static void insert_st (db::Edges *e, const db::Shapes &a, const Trans &t) +{ + for (db::Shapes::shape_iterator p = a.begin (db::ShapeIterator::Polygons | db::ShapeIterator::Boxes | db::ShapeIterator::Paths); !p.at_end (); ++p) { + db::Polygon poly; + p->polygon (poly); + e->insert (poly.transformed (t)); + } + for (db::Shapes::shape_iterator p = a.begin (db::ShapeIterator::Edges); !p.at_end (); ++p) { + db::Edge edge; + p->edge (edge); + e->insert (edge.transformed (t)); + } +} + +static void insert_s (db::Edges *e, const db::Shapes &a) +{ + insert_st (e, a, db::UnitTrans ()); +} + Class dec_Edges ("Edges", constructor ("new", &new_v, "@brief Default constructor\n" @@ -488,7 +522,44 @@ Class dec_Edges ("Edges", "\n" "Inserts the edges that form the contour of the path into the edge collection.\n" ) + - method_ext ("insert", &insert_si, + method_ext ("insert", &insert_e, + "@brief Inserts all edges from the other edge collection into this one\n" + "@args edges\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_r, + "@brief Inserts a region\n" + "@args region\n" + "Inserts the edges that form the contours of the polygons from the region into the edge collection.\n" + "\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_s, + "@brief Inserts all edges from the shape collection into this edge collection\n" + "@args shapes\n" + "This method takes each edge from the shape collection and " + "insertes it into the region. \"Polygon-like\" objects are inserted as edges forming the contours of the polygons.\n" + "Text objects are ignored.\n" + "\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_st, + "@brief Inserts all edges from the shape collection into this edge collection (with transformation)\n" + "@args shapes\n" + "This method acts as the version without transformation, but will apply the given " + "transformation before inserting the edges.\n" + "\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_st, + "@brief Inserts all edges from the shape collection into this edge collection with complex transformation\n" + "@args shapes\n" + "This method acts as the version without transformation, but will apply the given " + "complex transformation before inserting the edges.\n" + "\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_si, "@brief Inserts all shapes delivered by the recursive shape iterator into this edge collection\n" "@args shape_iterator\n" "\n" diff --git a/src/db/gsiDeclDbRegion.cc b/src/db/gsiDeclDbRegion.cc index f765c6247..ef3ab8bb8 100644 --- a/src/db/gsiDeclDbRegion.cc +++ b/src/db/gsiDeclDbRegion.cc @@ -255,6 +255,28 @@ static void insert_a (db::Region *r, const std::vector &a) } } +static void insert_r (db::Region *r, const db::Region &a) +{ + for (db::Region::const_iterator p = a.begin (); ! p.at_end (); ++p) { + r->insert (*p); + } +} + +template +static void insert_st (db::Region *r, const db::Shapes &a, const Trans &t) +{ + for (db::Shapes::shape_iterator p = a.begin (db::ShapeIterator::Polygons | db::ShapeIterator::Boxes | db::ShapeIterator::Paths); !p.at_end (); ++p) { + db::Polygon poly; + p->polygon (poly); + r->insert (poly.transformed (t)); + } +} + +static void insert_s (db::Region *r, const db::Shapes &a) +{ + insert_st (r, a, db::UnitTrans ()); +} + static void insert_si (db::Region *r, db::RecursiveShapeIterator si) { while (! si.at_end ()) { @@ -1067,6 +1089,40 @@ Class decl_Region ("Region", "@brief Inserts all polygons from the array into this region\n" "@args array\n" ) + + method_ext ("insert", &insert_r, + "@brief Inserts all polygons from the other region into this region\n" + "@args region\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_s, + "@brief Inserts all polygons from the shape collection into this region\n" + "@args shapes\n" + "This method takes each \"polygon-like\" shape from the shape collection and " + "insertes this shape into the region. Paths and boxes are converted to polygons during this process. " + "Edges and text objects are ignored.\n" + "\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_st, + "@brief Inserts all polygons from the shape collection into this region with transformation\n" + "@args shapes\n" + "This method takes each \"polygon-like\" shape from the shape collection and " + "insertes this shape into the region after applying the given transformation. " + "Paths and boxes are converted to polygons during this process. " + "Edges and text objects are ignored.\n" + "\n" + "This method has been introduced in version 0.25." + ) + + method_ext ("insert", &insert_st, + "@brief Inserts all polygons from the shape collection into this region with complex transformation\n" + "@args shapes\n" + "This method takes each \"polygon-like\" shape from the shape collection and " + "insertes this shape into the region after applying the given complex transformation. " + "Paths and boxes are converted to polygons during this process. " + "Edges and text objects are ignored.\n" + "\n" + "This method has been introduced in version 0.25." + ) + method_ext ("extents", &extents0, "@brief Returns a region with the bounding boxes of the polygons\n" "This method will return a region consisting of the bounding boxes of the polygons.\n" diff --git a/testdata/ruby/dbEdgePairsTest.rb b/testdata/ruby/dbEdgePairsTest.rb index b47a64ad0..f4b05ed17 100644 --- a/testdata/ruby/dbEdgePairsTest.rb +++ b/testdata/ruby/dbEdgePairsTest.rb @@ -63,6 +63,12 @@ class DBEdgePairs_TestClass < TestBase assert_equal(r.size, 0) assert_equal(r.bbox.to_s, "()") + ep = RBA::EdgePairs::new + e = RBA::EdgePairs::new + e.insert(RBA::EdgePair::new(RBA::Edge::new(0, 0, 0, 100), RBA::Edge::new(-10, 0, -20, 50))) + ep.insert(e) + assert_equal(ep.to_s, "(0,0;0,100)/(-10,0;-20,50)") + end # Basics diff --git a/testdata/ruby/dbEdgesTest.rb b/testdata/ruby/dbEdgesTest.rb index 7010e4539..c6eb7b776 100644 --- a/testdata/ruby/dbEdgesTest.rb +++ b/testdata/ruby/dbEdgesTest.rb @@ -204,6 +204,48 @@ class DBEdges_TestClass < TestBase r.insert(ly.begin_shapes(c1.cell_index, l1), RBA::ICplxTrans::new(10, 20)) assert_equal(r.to_s(30), "(0,0;0,40);(0,40;20,40);(20,40;20,0);(20,0;0,0);(0,100;0,140);(0,140;20,140);(20,140;20,100);(20,100;0,100);(200,100;200,140);(200,140;220,140);(220,140;220,100);(220,100;200,100)") + r = RBA::Edges::new + rr = RBA::Edges::new + rr.insert(RBA::Edge::new(10, 20, 100, 200)) + r.insert(rr) + assert_equal(r.to_s, "(10,20;100,200)") + + r = RBA::Edges::new + rr = RBA::Region::new + rr.insert(RBA::Box::new(10, 20, 100, 200)) + r.insert(rr) + assert_equal(r.to_s, "(10,20;10,200);(10,200;100,200);(100,200;100,20);(100,20;10,20)") + + r = RBA::Edges::new + s = RBA::Shapes::new + s.insert(RBA::Edge::new(10, 20, 100, 200)) + r.insert(s) + assert_equal(r.to_s, "(10,20;100,200)") + + r = RBA::Edges::new + s = RBA::Shapes::new + s.insert(RBA::Polygon::new(RBA::Box::new(10, 20, 100, 200))) + r.insert(s) + assert_equal(r.to_s, "(10,20;10,200);(10,200;100,200);(100,200;100,20);(100,20;10,20)") + + r = RBA::Edges::new + s = RBA::Shapes::new + s.insert(RBA::Text::new("ABC", RBA::Trans::new)) + r.insert(s) + assert_equal(r.to_s, "") + + r = RBA::Edges::new + s = RBA::Shapes::new + s.insert(RBA::Edge::new(10, 20, 100, 200)) + r.insert(s, RBA::Trans::new(1, 1)) + assert_equal(r.to_s, "(11,21;101,201)") + + r = RBA::Edges::new + s = RBA::Shapes::new + s.insert(RBA::Edge::new(10, 20, 100, 200)) + r.insert(s, RBA::ICplxTrans::new(RBA::Trans::new(1, 1))) + assert_equal(r.to_s, "(11,21;101,201)") + end # Merge, booleans diff --git a/testdata/ruby/dbRegionTest.rb b/testdata/ruby/dbRegionTest.rb index 062e0dbb5..d59529d29 100644 --- a/testdata/ruby/dbRegionTest.rb +++ b/testdata/ruby/dbRegionTest.rb @@ -184,6 +184,42 @@ class DBRegion_TestClass < TestBase r.insert(ly.begin_shapes(c1.cell_index, l1), RBA::ICplxTrans::new(10, 20)) assert_equal(r.to_s, "(0,0;0,40;20,40;20,0);(0,100;0,140;20,140;20,100);(200,100;200,140;220,140;220,100)") + r = RBA::Region::new + rr = RBA::Region::new + rr.insert(RBA::Box::new(10, 20, 100, 200)) + r.insert(rr) + assert_equal(r.to_s, "(10,20;10,200;100,200;100,20)") + + r = RBA::Region::new + s = RBA::Shapes::new + s.insert(RBA::Box::new(10, 20, 100, 200)) + r.insert(s) + assert_equal(r.to_s, "(10,20;10,200;100,200;100,20)") + + r = RBA::Region::new + s = RBA::Shapes::new + s.insert(RBA::Polygon::new(RBA::Box::new(10, 20, 100, 200))) + r.insert(s) + assert_equal(r.to_s, "(10,20;10,200;100,200;100,20)") + + r = RBA::Region::new + s = RBA::Shapes::new + s.insert(RBA::Edge::new(10, 20, 100, 200)) + r.insert(s) + assert_equal(r.to_s, "") + + r = RBA::Region::new + s = RBA::Shapes::new + s.insert(RBA::Box::new(10, 20, 100, 200)) + r.insert(s, RBA::Trans::new(1, 1)) + assert_equal(r.to_s, "(11,21;11,201;101,201;101,21)") + + r = RBA::Region::new + s = RBA::Shapes::new + s.insert(RBA::Box::new(10, 20, 100, 200)) + r.insert(s, RBA::ICplxTrans::new(RBA::Trans::new(1, 1))) + assert_equal(r.to_s, "(11,21;11,201;101,201;101,21)") + end # Booleans