2013-07-16 18:09:53 +00:00
|
|
|
#ifndef slic3r_ClipperUtils_hpp_
|
|
|
|
#define slic3r_ClipperUtils_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include <libslic3r.h>
|
2013-07-16 18:09:53 +00:00
|
|
|
#include "clipper.hpp"
|
2013-07-16 19:04:14 +00:00
|
|
|
#include "ExPolygon.hpp"
|
|
|
|
#include "Polygon.hpp"
|
2013-11-23 17:29:25 +00:00
|
|
|
#include "Surface.hpp"
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2013-08-26 23:26:44 +00:00
|
|
|
// import these wherever we're included
|
|
|
|
using ClipperLib::jtMiter;
|
|
|
|
using ClipperLib::jtRound;
|
|
|
|
using ClipperLib::jtSquare;
|
|
|
|
|
2013-07-16 18:09:53 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
// legacy code from Clipper documentation
|
2013-07-16 19:04:14 +00:00
|
|
|
void AddOuterPolyNodeToExPolygons(ClipperLib::PolyNode& polynode, Slic3r::ExPolygons& expolygons);
|
|
|
|
void PolyTreeToExPolygons(ClipperLib::PolyTree& polytree, Slic3r::ExPolygons& expolygons);
|
2013-07-16 18:09:53 +00:00
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2016-12-13 20:30:56 +00:00
|
|
|
ClipperLib::Path Slic3rMultiPoint_to_ClipperPath(const Slic3r::MultiPoint &input);
|
|
|
|
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polygons &input);
|
|
|
|
ClipperLib::Paths Slic3rMultiPoints_to_ClipperPaths(const Polylines &input);
|
2016-12-13 21:13:02 +00:00
|
|
|
Slic3r::Polygon ClipperPath_to_Slic3rPolygon(const ClipperLib::Path &input);
|
|
|
|
Slic3r::Polyline ClipperPath_to_Slic3rPolyline(const ClipperLib::Path &input);
|
2016-12-13 20:30:56 +00:00
|
|
|
Slic3r::Polygons ClipperPaths_to_Slic3rPolygons(const ClipperLib::Paths &input);
|
|
|
|
Slic3r::Polylines ClipperPaths_to_Slic3rPolylines(const ClipperLib::Paths &input);
|
2016-12-13 18:22:23 +00:00
|
|
|
Slic3r::ExPolygons ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input);
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2013-11-20 10:35:58 +00:00
|
|
|
// offset Polygons
|
2016-12-13 18:39:20 +00:00
|
|
|
ClipperLib::Paths _offset(ClipperLib::Path &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit);
|
|
|
|
ClipperLib::Paths _offset(ClipperLib::Paths &&input, ClipperLib::EndType endType, const float delta, ClipperLib::JoinType joinType, double miterLimit);
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
2016-12-13 20:30:56 +00:00
|
|
|
{ return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polygon), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); }
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons offset(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
2016-12-13 20:30:56 +00:00
|
|
|
{ return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); }
|
2016-10-20 11:04:23 +00:00
|
|
|
|
2013-11-20 10:35:58 +00:00
|
|
|
// offset Polylines
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons offset(const Slic3r::Polyline &polyline, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3)
|
2016-12-13 20:30:56 +00:00
|
|
|
{ return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polyline), ClipperLib::etOpenButt, delta, joinType, miterLimit)); }
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons offset(const Slic3r::Polylines &polylines, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtSquare, double miterLimit = 3)
|
2016-12-13 20:30:56 +00:00
|
|
|
{ return ClipperPaths_to_Slic3rPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polylines), ClipperLib::etOpenButt, delta, joinType, miterLimit)); }
|
2016-12-13 18:22:23 +00:00
|
|
|
|
|
|
|
// offset expolygons and surfaces
|
|
|
|
ClipperLib::Paths _offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType, double miterLimit);
|
|
|
|
ClipperLib::Paths _offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType, double miterLimit);
|
|
|
|
inline Slic3r::Polygons offset(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
2016-12-13 20:30:56 +00:00
|
|
|
{ return ClipperPaths_to_Slic3rPolygons(_offset(expolygon, delta, joinType, miterLimit)); }
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons offset(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
2016-12-13 20:30:56 +00:00
|
|
|
{ return ClipperPaths_to_Slic3rPolygons(_offset(expolygons, delta, joinType, miterLimit)); }
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::ExPolygons offset_ex(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
|
|
|
{ return ClipperPaths_to_Slic3rExPolygons(_offset(Slic3rMultiPoint_to_ClipperPath(polygon), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); }
|
|
|
|
inline Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
|
|
|
{ return ClipperPaths_to_Slic3rExPolygons(_offset(Slic3rMultiPoints_to_ClipperPaths(polygons), ClipperLib::etClosedPolygon, delta, joinType, miterLimit)); }
|
|
|
|
inline Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygon &expolygon, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
|
|
|
{ return ClipperPaths_to_Slic3rExPolygons(_offset(expolygon, delta, joinType, miterLimit)); }
|
|
|
|
inline Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygons &expolygons, const float delta, ClipperLib::JoinType joinType = ClipperLib::jtMiter, double miterLimit = 3)
|
|
|
|
{ return ClipperPaths_to_Slic3rExPolygons(_offset(expolygons, delta, joinType, miterLimit)); }
|
|
|
|
|
|
|
|
ClipperLib::Paths _offset2(const Slic3r::Polygons &polygons, const float delta1,
|
2016-11-28 16:33:17 +00:00
|
|
|
const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2013-07-16 22:48:29 +00:00
|
|
|
double miterLimit = 3);
|
2015-07-23 13:53:02 +00:00
|
|
|
Slic3r::Polygons offset2(const Slic3r::Polygons &polygons, const float delta1,
|
2016-11-28 16:33:17 +00:00
|
|
|
const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2015-07-23 13:53:02 +00:00
|
|
|
double miterLimit = 3);
|
|
|
|
Slic3r::ExPolygons offset2_ex(const Slic3r::Polygons &polygons, const float delta1,
|
2016-11-28 16:33:17 +00:00
|
|
|
const float delta2, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2015-07-23 13:53:02 +00:00
|
|
|
double miterLimit = 3);
|
2013-07-16 18:36:27 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
Slic3r::Polygons _clipper(ClipperLib::ClipType clipType,
|
|
|
|
const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
|
|
|
Slic3r::ExPolygons _clipper_ex(ClipperLib::ClipType clipType,
|
|
|
|
const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
|
|
|
Slic3r::Polylines _clipper_pl(ClipperLib::ClipType clipType,
|
|
|
|
const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
|
|
|
Slic3r::Polylines _clipper_pl(ClipperLib::ClipType clipType,
|
|
|
|
const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
|
|
|
Slic3r::Lines _clipper_ln(ClipperLib::ClipType clipType,
|
|
|
|
const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
|
|
|
|
|
|
|
// diff
|
|
|
|
inline Slic3r::Polygons
|
|
|
|
diff(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper(ClipperLib::ctDifference, subject, clip, safety_offset_);
|
|
|
|
}
|
2013-07-16 23:21:30 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::ExPolygons
|
|
|
|
diff_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ex(ClipperLib::ctDifference, subject, clip, safety_offset_);
|
|
|
|
}
|
2014-12-24 09:20:55 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::ExPolygons
|
|
|
|
diff_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ex(ClipperLib::ctDifference, to_polygons(subject), to_polygons(clip), safety_offset_);
|
|
|
|
}
|
2015-10-26 22:23:03 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons
|
|
|
|
diff(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper(ClipperLib::ctDifference, to_polygons(subject), to_polygons(clip), safety_offset_);
|
|
|
|
}
|
2015-07-23 13:53:02 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polylines
|
|
|
|
diff_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
2016-12-08 18:02:16 +00:00
|
|
|
{
|
2016-12-13 18:22:23 +00:00
|
|
|
return _clipper_pl(ClipperLib::ctDifference, subject, clip, safety_offset_);
|
2016-12-08 18:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polylines
|
|
|
|
diff_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
2016-12-08 18:02:16 +00:00
|
|
|
{
|
2016-12-13 18:22:23 +00:00
|
|
|
return _clipper_pl(ClipperLib::ctDifference, subject, clip, safety_offset_);
|
2016-12-08 18:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Lines
|
|
|
|
diff_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ln(ClipperLib::ctDifference, subject, clip, safety_offset_);
|
|
|
|
}
|
2013-11-21 13:15:38 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
// intersection
|
|
|
|
inline Slic3r::Polygons
|
|
|
|
intersection(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
2016-12-08 18:02:16 +00:00
|
|
|
{
|
2016-12-13 18:22:23 +00:00
|
|
|
return _clipper(ClipperLib::ctIntersection, subject, clip, safety_offset_);
|
2016-12-08 18:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::ExPolygons
|
|
|
|
intersection_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
2016-12-08 18:02:16 +00:00
|
|
|
{
|
2016-12-13 18:22:23 +00:00
|
|
|
return _clipper_ex(ClipperLib::ctIntersection, subject, clip, safety_offset_);
|
2016-12-08 18:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::ExPolygons
|
|
|
|
intersection_ex(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ex(ClipperLib::ctIntersection, to_polygons(subject), to_polygons(clip), safety_offset_);
|
|
|
|
}
|
2015-12-21 13:46:35 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons
|
|
|
|
intersection(const Slic3r::ExPolygons &subject, const Slic3r::ExPolygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper(ClipperLib::ctIntersection, to_polygons(subject), to_polygons(clip), safety_offset_);
|
|
|
|
}
|
2015-07-23 13:53:02 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polylines
|
|
|
|
intersection_pl(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_pl(ClipperLib::ctIntersection, subject, clip, safety_offset_);
|
|
|
|
}
|
2014-11-09 14:27:34 +00:00
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
inline Slic3r::Polylines
|
|
|
|
intersection_pl(const Slic3r::Polylines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
2016-12-13 18:22:23 +00:00
|
|
|
return _clipper_pl(ClipperLib::ctIntersection, subject, clip, safety_offset_);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Slic3r::Lines
|
|
|
|
intersection_ln(const Slic3r::Lines &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ln(ClipperLib::ctIntersection, subject, clip, safety_offset_);
|
2016-12-08 18:02:16 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
// union
|
|
|
|
inline Slic3r::Polygons
|
|
|
|
union_(const Slic3r::Polygons &subject, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper(ClipperLib::ctUnion, subject, Slic3r::Polygons(), safety_offset_);
|
|
|
|
}
|
2013-07-16 23:21:30 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::Polygons
|
|
|
|
union_(const Slic3r::Polygons &subject, const Slic3r::Polygons &subject2, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper(ClipperLib::ctUnion, subject, subject2, safety_offset_);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Slic3r::ExPolygons
|
|
|
|
union_ex(const Slic3r::Polygons &subject, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ex(ClipperLib::ctUnion, subject, Slic3r::Polygons(), safety_offset_);
|
|
|
|
}
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
inline Slic3r::ExPolygons
|
|
|
|
union_ex(const Slic3r::ExPolygons &subject, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ex(ClipperLib::ctUnion, to_polygons(subject), Slic3r::Polygons(), safety_offset_);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Slic3r::ExPolygons
|
|
|
|
union_ex(const Slic3r::Surfaces &subject, bool safety_offset_ = false)
|
|
|
|
{
|
|
|
|
return _clipper_ex(ClipperLib::ctUnion, to_polygons(subject), Slic3r::Polygons(), safety_offset_);
|
|
|
|
}
|
2015-07-23 13:53:02 +00:00
|
|
|
|
2014-11-09 14:27:34 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
ClipperLib::PolyTree union_pt(const Slic3r::Polygons &subject, bool safety_offset_ = false);
|
|
|
|
Slic3r::Polygons union_pt_chained(const Slic3r::Polygons &subject, bool safety_offset_ = false);
|
|
|
|
void traverse_pt(ClipperLib::PolyNodes &nodes, Slic3r::Polygons* retval);
|
2013-08-26 16:37:19 +00:00
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
/* OTHER */
|
|
|
|
Slic3r::Polygons simplify_polygons(const Slic3r::Polygons &subject, bool preserve_collinear = false);
|
|
|
|
Slic3r::ExPolygons simplify_polygons_ex(const Slic3r::Polygons &subject, bool preserve_collinear = false);
|
2013-08-08 00:10:34 +00:00
|
|
|
|
2014-05-08 09:07:37 +00:00
|
|
|
void safety_offset(ClipperLib::Paths* paths);
|
2013-08-26 15:58:37 +00:00
|
|
|
|
2016-11-23 14:51:47 +00:00
|
|
|
Polygons top_level_islands(const Slic3r::Polygons &polygons);
|
|
|
|
|
2013-07-16 18:09:53 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 18:22:23 +00:00
|
|
|
#endif
|