Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix line-clipping and add WKT-multiline. #2

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CuraEngineInfillGenerate/tiles/cont_honeycomb.wkt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
POLYGON ((866 2000, 1732 1500, 1732 500, 866 0, 0 500, 0 1500))
LINESTRING (866 0, 166 404, 166 1595, 866 2000)
LINESTRING (1830 404, 1834 404, 1834 1595)
POLYGON ((866 2000, 1732 1500, 1732 500, 866 0, 0 500, 0 1500, 866 2000))
MULTILINESTRING ((1334 404, 1334 1595), (866 0, 166 404, 166 1595, 866 2000))
6 changes: 6 additions & 0 deletions include/infill/content_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ std::tuple<std::vector<geometry::polyline<>>, std::vector<geometry::polygon_oute
boost::geometry::read_wkt(line, linestring);
linestrings.push_back(linestring);
}
if (line.starts_with("MULTILINESTRING"))
{
boost::geometry::model::multi_linestring<geometry::polyline<>> multilinestring;
boost::geometry::read_wkt(line, multilinestring);
linestrings.insert(linestrings.end(), multilinestring.begin(), multilinestring.end());
}
if (line.starts_with("POLYGON"))
{
geometry::polygon_outer<> polygon;
Expand Down
21 changes: 15 additions & 6 deletions include/infill/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,35 @@ static ClipperLib::IntPoint computeCoG(const auto& contour)
return cog;
}

static ClipperLib::Paths clip(const auto& polys, const std::vector<geometry::polygon_outer<>>& outer_contours)
static ClipperLib::Paths clip(const auto& polys, const bool& is_poly_closed, const std::vector<geometry::polygon_outer<>>& outer_contours)
{
ClipperLib::Clipper clipper;
ClipperLib::Paths outline_poly;
for (const auto& poly : outer_contours)
{
outline_poly.push_back(poly);
}
clipper.AddPaths(outline_poly, ClipperLib::PolyType::ptSubject, true);
clipper.AddPaths(outline_poly, ClipperLib::PolyType::ptClip, true);

ClipperLib::Paths grid_poly;
for (auto& poly : polys)
{
grid_poly.push_back(poly);
}
clipper.AddPaths(grid_poly, ClipperLib::PolyType::ptClip, true);
clipper.AddPaths(grid_poly, ClipperLib::PolyType::ptSubject, is_poly_closed);

ClipperLib::Paths result;
clipper.Execute(ClipperLib::ClipType::ctIntersection, result);
return result;
ClipperLib::Paths ret;
if (! is_poly_closed)
{
ClipperLib::PolyTree result;
clipper.Execute(ClipperLib::ClipType::ctIntersection, result);
ClipperLib::OpenPathsFromPolyTree(result, ret);
}
else
{
clipper.Execute(ClipperLib::ClipType::ctIntersection, ret);
}
return ret;
}

} // namespace infill::geometry
Expand Down
2 changes: 1 addition & 1 deletion include/infill/infill_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class InfillGenerator

// Cut the grid with the outer contour using Clipper
auto [lines, polys] = gridToPolygon(grid);
return { geometry::clip(lines, outer_contours), geometry::clip(polys, outer_contours) };
return { geometry::clip(lines, false, outer_contours), geometry::clip(polys, true, outer_contours) };
}
};

Expand Down