Debugging Layout#break_polygons etc.

This commit is contained in:
Matthias Koefferlein 2024-07-17 00:51:01 +02:00
parent a89e295349
commit b6cc636b05
2 changed files with 31 additions and 29 deletions

View File

@ -687,6 +687,31 @@ scale_and_snap (db::Layout &layout, db::Cell &cell, db::Coord g, db::Coord m, db
// ------------------------------------------------------------ // ------------------------------------------------------------
// break_polygons implementation // break_polygons implementation
static bool split_polygon (bool first, db::Polygon &poly, size_t max_vertex_count, double max_area_ratio, std::vector<db::Polygon> &parts)
{
if ((max_vertex_count > 0 && poly.vertices () > max_vertex_count) ||
(max_area_ratio > 0 && poly.area_ratio () > max_area_ratio)) {
std::vector<db::Polygon> sp;
db::split_polygon (poly, sp);
for (auto p = sp.begin (); p != sp.end (); ++p) {
split_polygon (false, *p, max_vertex_count, max_area_ratio, parts);
}
return true;
} else {
if (! first) {
parts.push_back (db::Polygon ());
parts.back ().swap (poly);
}
return false;
}
}
void void
break_polygons (db::Shapes &shapes, size_t max_vertex_count, double max_area_ratio) break_polygons (db::Shapes &shapes, size_t max_vertex_count, double max_area_ratio)
{ {
@ -694,34 +719,11 @@ break_polygons (db::Shapes &shapes, size_t max_vertex_count, double max_area_rat
std::vector<db::Shape> to_delete; std::vector<db::Shape> to_delete;
for (auto s = shapes.begin (db::ShapeIterator::Polygons | db::ShapeIterator::Paths); ! s.at_end (); ++s) { for (auto s = shapes.begin (db::ShapeIterator::Polygons | db::ShapeIterator::Paths); ! s.at_end (); ++s) {
db::Polygon poly;
std::vector<db::Polygon> polygons; s->instantiate (poly);
polygons.push_back (db::Polygon ()); if (split_polygon (true, poly, max_vertex_count, max_area_ratio, new_polygons)) {
s->instantiate (polygons.back ());
bool first = true;
while (! polygons.empty ()) {
std::vector<db::Polygon> split_polygons;
for (auto p = polygons.begin (); p != polygons.end (); ++p) {
if ((max_vertex_count > 0 && p->vertices () > max_vertex_count) ||
(max_area_ratio > 0 && p->area_ratio () > max_area_ratio)) {
if (first) {
to_delete.push_back (*s); to_delete.push_back (*s);
} }
db::split_polygon (*p, split_polygons);
} else if (! first) {
new_polygons.push_back (db::Polygon ());
new_polygons.back ().swap (*p);
}
}
first = false;
polygons.swap (split_polygons);
}
} }
shapes.erase_shapes (to_delete); shapes.erase_shapes (to_delete);

View File

@ -1967,7 +1967,7 @@ Class<db::Layout> decl_Layout ("db", "Layout",
"\n" "\n"
"This method has been introduced in version 0.26.1.\n" "This method has been introduced in version 0.26.1.\n"
) + ) +
gsi::method_ext ("break_polygons", &break_polygons1, gsi::arg ("max_vertex_count"), gsi::arg ("max_area_ratio", 0.0), gsi::method_ext ("break_polygons", &break_polygons1, gsi::arg ("max_vertex_count"), gsi::arg ("max_area_ratio"),
"@brief Breaks the polygons of the layout into smaller ones\n" "@brief Breaks the polygons of the layout into smaller ones\n"
"\n" "\n"
"There are two criteria for splitting a polygon: a polygon is split into parts with less then " "There are two criteria for splitting a polygon: a polygon is split into parts with less then "
@ -1987,7 +1987,7 @@ Class<db::Layout> decl_Layout ("db", "Layout",
"\n" "\n"
"This method has been introduced in version 0.29.5." "This method has been introduced in version 0.29.5."
) + ) +
gsi::method_ext ("break_polygons", &break_polygons2, gsi::arg ("layer"), gsi::arg ("max_vertex_count"), gsi::arg ("max_area_ratio", 0.0), gsi::method_ext ("break_polygons", &break_polygons2, gsi::arg ("layer"), gsi::arg ("max_vertex_count"), gsi::arg ("max_area_ratio"),
"@brief Breaks the polygons of the layer into smaller ones\n" "@brief Breaks the polygons of the layer into smaller ones\n"
"\n" "\n"
"This variant applies breaking to all cells and the given layer.\n" "This variant applies breaking to all cells and the given layer.\n"