Skip to content

Commit

Permalink
Fixed #166 (internal error when writing GDS file)
Browse files Browse the repository at this point in the history
This fix consists of computing the intersection
points in the split procedure with higher resolution
to avoid topology changes due to snapping on the cut
line.
  • Loading branch information
klayoutmatthias committed Sep 16, 2018
1 parent 753e170 commit e9de425
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/db/db/dbPolygonTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ struct cut_polygon_edge
{
typedef typename PointType::coord_type coord_type;
typedef typename db::edge<coord_type> edge_type;
typedef typename db::coord_traits<coord_type>::area_type projection_type;
typedef double projection_type;

cut_polygon_edge ()
: contour (-1), index (0), projected (0), point (), last_point ()
Expand Down Expand Up @@ -179,7 +179,7 @@ struct loose_end_struct

bool operator< (const loose_end_struct<CuttingEdgeType> &other) const
{
if (proj () != other.proj ()) {
if (! db::coord_traits<double>::equal (proj (), other.proj ())) {
return proj () < other.proj ();
} else {
return db::vprod_sign (edge (), other.edge ()) > 0;
Expand All @@ -196,13 +196,13 @@ static bool _cut_polygon_internal (const PolygonType &input, const Edge &line, C
typedef db::edge<coord_type> edge_type;
typedef cut_polygon_edge<point_type> cut_polygon_edge_type;
typedef cut_polygon_segment<cut_polygon_edge_type> cutting_segment_type;
typedef typename db::coord_traits<coord_type>::area_type projection_type;

bool do_hole_assignment = (input.holes () > 0);
std::vector <PolygonType> hull_polygons;
std::vector <PolygonType> hole_polygons;

std::vector<cutting_segment_type> cutting_segments;
double line_length = line.double_length ();

for (unsigned int nc = 0; nc < input.holes () + 1; ++nc) {

Expand All @@ -229,7 +229,7 @@ static bool _cut_polygon_internal (const PolygonType &input, const Edge &line, C
int s1 = line.side_of (e.p1 ());
int s2 = line.side_of (e.p2 ());

projection_type p = db::sprod (ip.second - line.p1 (), line.p2 () - line.p1 ());
double p = line_length * double (db::vprod (e.p1 () - line.p1 (), e.d ())) / double (db::vprod (line.d (), e.d ()));

if (s1 < 0 && s2 >= 0) {
// right -> left or on edge
Expand Down
17 changes: 17 additions & 0 deletions src/db/unit_tests/dbPolygonTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2241,3 +2241,20 @@ TEST(403)
EXPECT_EQ (right_of.size (), size_t (0));
}
}

// issue 166
TEST(404)
{
db::Polygon poly;
std::string s ("(390,0;438,936;176,874;0,832;438,937;541,961;821,102)");
tl::Extractor ex (s.c_str ());
ex.read (poly);

std::vector<db::Polygon> sp;
db::split_polygon (poly, sp);
EXPECT_EQ (sp.size (), size_t (2));
if (sp.size () >= 2) {
EXPECT_EQ (sp[0].to_string (), "(390,0;438,936;390,925;438,937;541,961;821,102)");
EXPECT_EQ (sp[1].to_string (), "(0,832;176,874;390,925)");
}
}

0 comments on commit e9de425

Please sign in to comment.