Remove new/delete keywords from ClipperUtils.cpp
This commit is contained in:
parent
76a8ec3d9e
commit
bc023c2d51
@ -59,14 +59,12 @@ ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input, Slic3r::ExPolyg
|
|||||||
|
|
||||||
// perform union
|
// perform union
|
||||||
clipper.AddPaths(input, ClipperLib::ptSubject, true);
|
clipper.AddPaths(input, ClipperLib::ptSubject, true);
|
||||||
ClipperLib::PolyTree* polytree = new ClipperLib::PolyTree();
|
ClipperLib::PolyTree polytree;
|
||||||
clipper.Execute(ClipperLib::ctUnion, *polytree, ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd); // offset results work with both EvenOdd and NonZero
|
clipper.Execute(ClipperLib::ctUnion, polytree, ClipperLib::pftEvenOdd, ClipperLib::pftEvenOdd); // offset results work with both EvenOdd and NonZero
|
||||||
|
|
||||||
// write to ExPolygons object
|
// write to ExPolygons object
|
||||||
output.clear();
|
output.clear();
|
||||||
PolyTreeToExPolygons(*polytree, output);
|
PolyTreeToExPolygons(polytree, output);
|
||||||
|
|
||||||
delete polytree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -168,12 +166,11 @@ offset(const Slic3r::Polylines &polylines, Slic3r::Polygons &retval, const float
|
|||||||
double scale, ClipperLib::JoinType joinType, double miterLimit)
|
double scale, ClipperLib::JoinType joinType, double miterLimit)
|
||||||
{
|
{
|
||||||
// perform offset
|
// perform offset
|
||||||
ClipperLib::Paths* output = new ClipperLib::Paths();
|
ClipperLib::Paths output;
|
||||||
offset(polylines, *output, delta, scale, joinType, miterLimit);
|
offset(polylines, output, delta, scale, joinType, miterLimit);
|
||||||
|
|
||||||
// convert into ExPolygons
|
// convert into ExPolygons
|
||||||
ClipperPaths_to_Slic3rMultiPoints(*output, retval);
|
ClipperPaths_to_Slic3rMultiPoints(output, retval);
|
||||||
delete output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -199,12 +196,11 @@ offset_ex(const Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const fl
|
|||||||
double scale, ClipperLib::JoinType joinType, double miterLimit)
|
double scale, ClipperLib::JoinType joinType, double miterLimit)
|
||||||
{
|
{
|
||||||
// perform offset
|
// perform offset
|
||||||
ClipperLib::Paths* output = new ClipperLib::Paths();
|
ClipperLib::Paths output;
|
||||||
offset(polygons, *output, delta, scale, joinType, miterLimit);
|
offset(polygons, output, delta, scale, joinType, miterLimit);
|
||||||
|
|
||||||
// convert into ExPolygons
|
// convert into ExPolygons
|
||||||
ClipperPaths_to_Slic3rExPolygons(*output, retval);
|
ClipperPaths_to_Slic3rExPolygons(output, retval);
|
||||||
delete output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -245,12 +241,11 @@ offset2(const Slic3r::Polygons &polygons, Slic3r::Polygons &retval, const float
|
|||||||
const float delta2, const double scale, const ClipperLib::JoinType joinType, const double miterLimit)
|
const float delta2, const double scale, const ClipperLib::JoinType joinType, const double miterLimit)
|
||||||
{
|
{
|
||||||
// perform offset
|
// perform offset
|
||||||
ClipperLib::Paths* output = new ClipperLib::Paths();
|
ClipperLib::Paths output;
|
||||||
offset2(polygons, *output, delta1, delta2, scale, joinType, miterLimit);
|
offset2(polygons, output, delta1, delta2, scale, joinType, miterLimit);
|
||||||
|
|
||||||
// convert into ExPolygons
|
// convert into ExPolygons
|
||||||
ClipperPaths_to_Slic3rMultiPoints(*output, retval);
|
ClipperPaths_to_Slic3rMultiPoints(output, retval);
|
||||||
delete output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -258,12 +253,11 @@ offset2_ex(const Slic3r::Polygons &polygons, Slic3r::ExPolygons &retval, const f
|
|||||||
const float delta2, const double scale, const ClipperLib::JoinType joinType, const double miterLimit)
|
const float delta2, const double scale, const ClipperLib::JoinType joinType, const double miterLimit)
|
||||||
{
|
{
|
||||||
// perform offset
|
// perform offset
|
||||||
ClipperLib::Paths* output = new ClipperLib::Paths();
|
ClipperLib::Paths output;
|
||||||
offset2(polygons, *output, delta1, delta2, scale, joinType, miterLimit);
|
offset2(polygons, output, delta1, delta2, scale, joinType, miterLimit);
|
||||||
|
|
||||||
// convert into ExPolygons
|
// convert into ExPolygons
|
||||||
ClipperPaths_to_Slic3rExPolygons(*output, retval);
|
ClipperPaths_to_Slic3rExPolygons(output, retval);
|
||||||
delete output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -271,17 +265,16 @@ void _clipper_do(const ClipperLib::ClipType clipType, const Slic3r::Polygons &su
|
|||||||
const Slic3r::Polygons &clip, T &retval, const ClipperLib::PolyFillType fillType, const bool safety_offset_)
|
const Slic3r::Polygons &clip, T &retval, const ClipperLib::PolyFillType fillType, const bool safety_offset_)
|
||||||
{
|
{
|
||||||
// read input
|
// read input
|
||||||
ClipperLib::Paths* input_subject = new ClipperLib::Paths();
|
ClipperLib::Paths input_subject, input_clip;
|
||||||
ClipperLib::Paths* input_clip = new ClipperLib::Paths();
|
Slic3rMultiPoints_to_ClipperPaths(subject, input_subject);
|
||||||
Slic3rMultiPoints_to_ClipperPaths(subject, *input_subject);
|
Slic3rMultiPoints_to_ClipperPaths(clip, input_clip);
|
||||||
Slic3rMultiPoints_to_ClipperPaths(clip, *input_clip);
|
|
||||||
|
|
||||||
// perform safety offset
|
// perform safety offset
|
||||||
if (safety_offset_) {
|
if (safety_offset_) {
|
||||||
if (clipType == ClipperLib::ctUnion) {
|
if (clipType == ClipperLib::ctUnion) {
|
||||||
safety_offset(input_subject);
|
safety_offset(&input_subject);
|
||||||
} else {
|
} else {
|
||||||
safety_offset(input_clip);
|
safety_offset(&input_clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,10 +283,8 @@ void _clipper_do(const ClipperLib::ClipType clipType, const Slic3r::Polygons &su
|
|||||||
clipper.Clear();
|
clipper.Clear();
|
||||||
|
|
||||||
// add polygons
|
// add polygons
|
||||||
clipper.AddPaths(*input_subject, ClipperLib::ptSubject, true);
|
clipper.AddPaths(input_subject, ClipperLib::ptSubject, true);
|
||||||
delete input_subject;
|
clipper.AddPaths(input_clip, ClipperLib::ptClip, true);
|
||||||
clipper.AddPaths(*input_clip, ClipperLib::ptClip, true);
|
|
||||||
delete input_clip;
|
|
||||||
|
|
||||||
// perform operation
|
// perform operation
|
||||||
clipper.Execute(clipType, retval, fillType, fillType);
|
clipper.Execute(clipType, retval, fillType, fillType);
|
||||||
@ -327,12 +318,11 @@ void _clipper(ClipperLib::ClipType clipType, const Slic3r::Polygons &subject,
|
|||||||
const Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset_)
|
const Slic3r::Polygons &clip, Slic3r::Polygons &retval, bool safety_offset_)
|
||||||
{
|
{
|
||||||
// perform operation
|
// perform operation
|
||||||
ClipperLib::Paths* output = new ClipperLib::Paths();
|
ClipperLib::Paths output;
|
||||||
_clipper_do<ClipperLib::Paths>(clipType, subject, clip, *output, ClipperLib::pftNonZero, safety_offset_);
|
_clipper_do<ClipperLib::Paths>(clipType, subject, clip, output, ClipperLib::pftNonZero, safety_offset_);
|
||||||
|
|
||||||
// convert into Polygons
|
// convert into Polygons
|
||||||
ClipperPaths_to_Slic3rMultiPoints(*output, retval);
|
ClipperPaths_to_Slic3rMultiPoints(output, retval);
|
||||||
delete output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _clipper(ClipperLib::ClipType clipType, const Slic3r::Polygons &subject,
|
void _clipper(ClipperLib::ClipType clipType, const Slic3r::Polygons &subject,
|
||||||
@ -508,26 +498,21 @@ static void traverse_pt(ClipperLib::PolyNodes &nodes, Slic3r::Polygons &retval)
|
|||||||
void simplify_polygons(const Slic3r::Polygons &subject, Slic3r::Polygons &retval, bool preserve_collinear)
|
void simplify_polygons(const Slic3r::Polygons &subject, Slic3r::Polygons &retval, bool preserve_collinear)
|
||||||
{
|
{
|
||||||
// convert into Clipper polygons
|
// convert into Clipper polygons
|
||||||
ClipperLib::Paths* input_subject = new ClipperLib::Paths();
|
ClipperLib::Paths input_subject, output;
|
||||||
Slic3rMultiPoints_to_ClipperPaths(subject, *input_subject);
|
Slic3rMultiPoints_to_ClipperPaths(subject, input_subject);
|
||||||
|
|
||||||
ClipperLib::Paths* output = new ClipperLib::Paths();
|
|
||||||
|
|
||||||
if (preserve_collinear) {
|
if (preserve_collinear) {
|
||||||
ClipperLib::Clipper c;
|
ClipperLib::Clipper c;
|
||||||
c.PreserveCollinear(true);
|
c.PreserveCollinear(true);
|
||||||
c.StrictlySimple(true);
|
c.StrictlySimple(true);
|
||||||
c.AddPaths(*input_subject, ClipperLib::ptSubject, true);
|
c.AddPaths(input_subject, ClipperLib::ptSubject, true);
|
||||||
c.Execute(ClipperLib::ctUnion, *output, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
|
c.Execute(ClipperLib::ctUnion, output, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
|
||||||
} else {
|
} else {
|
||||||
ClipperLib::SimplifyPolygons(*input_subject, *output, ClipperLib::pftNonZero);
|
ClipperLib::SimplifyPolygons(input_subject, output, ClipperLib::pftNonZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete input_subject;
|
|
||||||
|
|
||||||
// convert into Slic3r polygons
|
// convert into Slic3r polygons
|
||||||
ClipperPaths_to_Slic3rMultiPoints(*output, retval);
|
ClipperPaths_to_Slic3rMultiPoints(output, retval);
|
||||||
delete output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void simplify_polygons(const Slic3r::Polygons &subject, Slic3r::ExPolygons &retval, bool preserve_collinear)
|
void simplify_polygons(const Slic3r::Polygons &subject, Slic3r::ExPolygons &retval, bool preserve_collinear)
|
||||||
|
Loading…
Reference in New Issue
Block a user