New import methods for Region, EdgePairs and Edges

Region: insert of other regions, shape collections (with transformation)
Edges: insert of other edge collections, regions, shape collections (with transformation)
EdgePairs: insert of other edge pair collections
This commit is contained in:
Matthias Koefferlein 2017-07-16 22:25:08 +02:00
parent 43359195ea
commit db5ac31ada
6 changed files with 224 additions and 1 deletions

View File

@ -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<db::EdgePairs> decl_EdgePairs ("EdgePairs",
constructor ("new", &new_v,
"@brief Default constructor\n"
@ -259,6 +266,11 @@ Class<db::EdgePairs> 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"

View File

@ -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 <class Trans>
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<db::Edges> dec_Edges ("Edges",
constructor ("new", &new_v,
"@brief Default constructor\n"
@ -488,7 +522,44 @@ Class<db::Edges> 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<db::Trans>,
"@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<db::ICplxTrans>,
"@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"

View File

@ -255,6 +255,28 @@ static void insert_a (db::Region *r, const std::vector <db::Polygon> &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 <class Trans>
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<db::Region> 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<db::Trans>,
"@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<db::ICplxTrans>,
"@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"

View File

@ -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

View File

@ -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

View File

@ -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