Fixed #166 (internal error when writing GDS file)

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.
This commit is contained in:
Matthias Koefferlein 2018-09-17 01:25:10 +02:00
parent 753e170a68
commit e9de4252fb
2 changed files with 21 additions and 4 deletions

View File

@ -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 ()
@ -179,7 +179,7 @@ public:
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;
@ -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) {
@ -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

View File

@ -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)");
}
}