Fixed regression due to ExPolygonCollection to ExPolygons refactoring.

Fixed crashes in BridgeDetector due to unexpected implicit conversion
to a const temporary.
This commit is contained in:
bubnikv 2019-10-04 16:50:01 +02:00
parent 546ad99306
commit f8ff23638f
8 changed files with 29 additions and 26 deletions

View file

@ -6,9 +6,9 @@
namespace Slic3r { namespace Slic3r {
BridgeDetector::BridgeDetector( BridgeDetector::BridgeDetector(
ExPolygon _expolygon, ExPolygon _expolygon,
const ExPolygonCollection &_lower_slices, const ExPolygons &_lower_slices,
coord_t _spacing) : coord_t _spacing) :
// The original infill polygon, not inflated. // The original infill polygon, not inflated.
expolygons(expolygons_owned), expolygons(expolygons_owned),
// All surfaces of the object supporting this region. // All surfaces of the object supporting this region.
@ -20,9 +20,9 @@ BridgeDetector::BridgeDetector(
} }
BridgeDetector::BridgeDetector( BridgeDetector::BridgeDetector(
const ExPolygons &_expolygons, const ExPolygons &_expolygons,
const ExPolygonCollection &_lower_slices, const ExPolygons &_lower_slices,
coord_t _spacing) : coord_t _spacing) :
// The original infill polygon, not inflated. // The original infill polygon, not inflated.
expolygons(_expolygons), expolygons(_expolygons),
// All surfaces of the object supporting this region. // All surfaces of the object supporting this region.
@ -46,7 +46,11 @@ void BridgeDetector::initialize()
// Detect what edges lie on lower slices by turning bridge contour and holes // Detect what edges lie on lower slices by turning bridge contour and holes
// into polylines and then clipping them with each lower slice's contour. // into polylines and then clipping them with each lower slice's contour.
// Currently _edges are only used to set a candidate direction of the bridge (see bridge_direction_candidates()). // Currently _edges are only used to set a candidate direction of the bridge (see bridge_direction_candidates()).
this->_edges = intersection_pl(to_polylines(grown), this->lower_slices.contours()); Polygons contours;
contours.reserve(this->lower_slices.size());
for (const ExPolygon &expoly : this->lower_slices)
contours.push_back(expoly.contour);
this->_edges = intersection_pl(to_polylines(grown), contours);
#ifdef SLIC3R_DEBUG #ifdef SLIC3R_DEBUG
printf(" bridge has " PRINTF_ZU " support(s)\n", this->_edges.size()); printf(" bridge has " PRINTF_ZU " support(s)\n", this->_edges.size());
@ -54,7 +58,7 @@ void BridgeDetector::initialize()
// detect anchors as intersection between our bridge expolygon and the lower slices // detect anchors as intersection between our bridge expolygon and the lower slices
// safety offset required to avoid Clipper from detecting empty intersection while Boost actually found some edges // safety offset required to avoid Clipper from detecting empty intersection while Boost actually found some edges
this->_anchor_regions = intersection_ex(grown, to_polygons(this->lower_slices.expolygons), true); this->_anchor_regions = intersection_ex(grown, to_polygons(this->lower_slices), true);
/* /*
if (0) { if (0) {
@ -271,7 +275,7 @@ BridgeDetector::unsupported_edges(double angle, Polylines* unsupported) const
if (angle == -1) angle = this->angle; if (angle == -1) angle = this->angle;
if (angle == -1) return; if (angle == -1) return;
Polygons grown_lower = offset(this->lower_slices.expolygons, float(this->spacing)); Polygons grown_lower = offset(this->lower_slices, float(this->spacing));
for (ExPolygons::const_iterator it_expoly = this->expolygons.begin(); it_expoly != this->expolygons.end(); ++ it_expoly) { for (ExPolygons::const_iterator it_expoly = this->expolygons.begin(); it_expoly != this->expolygons.end(); ++ it_expoly) {
// get unsupported bridge edges (both contour and holes) // get unsupported bridge edges (both contour and holes)

View file

@ -3,7 +3,6 @@
#include "libslic3r.h" #include "libslic3r.h"
#include "ExPolygon.hpp" #include "ExPolygon.hpp"
#include "ExPolygonCollection.hpp"
#include <string> #include <string>
namespace Slic3r { namespace Slic3r {
@ -21,7 +20,7 @@ public:
// In case the caller gaves us the input polygons by a value, make a copy. // In case the caller gaves us the input polygons by a value, make a copy.
ExPolygons expolygons_owned; ExPolygons expolygons_owned;
// Lower slices, all regions. // Lower slices, all regions.
const ExPolygonCollection &lower_slices; const ExPolygons &lower_slices;
// Scaled extrusion width of the infill. // Scaled extrusion width of the infill.
coord_t spacing; coord_t spacing;
// Angle resolution for the brute force search of the best bridging angle. // Angle resolution for the brute force search of the best bridging angle.
@ -29,8 +28,8 @@ public:
// The final optimal angle. // The final optimal angle.
double angle; double angle;
BridgeDetector(ExPolygon _expolygon, const ExPolygonCollection &_lower_slices, coord_t _extrusion_width); BridgeDetector(ExPolygon _expolygon, const ExPolygons &_lower_slices, coord_t _extrusion_width);
BridgeDetector(const ExPolygons &_expolygons, const ExPolygonCollection &_lower_slices, coord_t _extrusion_width); BridgeDetector(const ExPolygons &_expolygons, const ExPolygons &_lower_slices, coord_t _extrusion_width);
// If bridge_direction_override != 0, then the angle is used instead of auto-detect. // If bridge_direction_override != 0, then the angle is used instead of auto-detect.
bool detect_angle(double bridge_direction_override = 0.); bool detect_angle(double bridge_direction_override = 0.);
Polygons coverage(double angle = -1) const; Polygons coverage(double angle = -1) const;

View file

@ -11,7 +11,7 @@ ExPolygonCollection::ExPolygonCollection(const ExPolygon &expolygon)
ExPolygonCollection::operator Points() const ExPolygonCollection::operator Points() const
{ {
Points points; Points points;
Polygons pp = *this; Polygons pp = (Polygons)*this;
for (Polygons::const_iterator poly = pp.begin(); poly != pp.end(); ++poly) { for (Polygons::const_iterator poly = pp.begin(); poly != pp.end(); ++poly) {
for (Points::const_iterator point = poly->points.begin(); point != poly->points.end(); ++point) for (Points::const_iterator point = poly->points.begin(); point != poly->points.end(); ++point)
points.push_back(*point); points.push_back(*point);

View file

@ -17,11 +17,11 @@ public:
ExPolygons expolygons; ExPolygons expolygons;
ExPolygonCollection() {} ExPolygonCollection() {}
ExPolygonCollection(const ExPolygon &expolygon); explicit ExPolygonCollection(const ExPolygon &expolygon);
ExPolygonCollection(const ExPolygons &expolygons) : expolygons(expolygons) {} explicit ExPolygonCollection(const ExPolygons &expolygons) : expolygons(expolygons) {}
operator Points() const; explicit operator Points() const;
operator Polygons() const; explicit operator Polygons() const;
operator ExPolygons&(); explicit operator ExPolygons&();
void scale(double factor); void scale(double factor);
void translate(double x, double y); void translate(double x, double y);
void rotate(double angle, const Point &center); void rotate(double angle, const Point &center);

View file

@ -14,12 +14,12 @@ namespace Slic3r {
void ExtrusionPath::intersect_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const void ExtrusionPath::intersect_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const
{ {
this->_inflate_collection(intersection_pl(this->polyline, collection), retval); this->_inflate_collection(intersection_pl(this->polyline, (Polygons)collection), retval);
} }
void ExtrusionPath::subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const void ExtrusionPath::subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const
{ {
this->_inflate_collection(diff_pl(this->polyline, collection), retval); this->_inflate_collection(diff_pl(this->polyline, (Polygons)collection), retval);
} }
void ExtrusionPath::clip_end(double distance) void ExtrusionPath::clip_end(double distance)

View file

@ -136,11 +136,11 @@ Polyline MotionPlanner::shortest_path(const Point &from, const Point &to)
if (! grown_env.contains(from)) { if (! grown_env.contains(from)) {
// delete second point while the line connecting first to third crosses the // delete second point while the line connecting first to third crosses the
// boundaries as many times as the current first to second // boundaries as many times as the current first to second
while (polyline.points.size() > 2 && intersection_ln(Line(from, polyline.points[2]), grown_env).size() == 1) while (polyline.points.size() > 2 && intersection_ln(Line(from, polyline.points[2]), (Polygons)grown_env).size() == 1)
polyline.points.erase(polyline.points.begin() + 1); polyline.points.erase(polyline.points.begin() + 1);
} }
if (! grown_env.contains(to)) if (! grown_env.contains(to))
while (polyline.points.size() > 2 && intersection_ln(Line(*(polyline.points.end() - 3), to), grown_env).size() == 1) while (polyline.points.size() > 2 && intersection_ln(Line(*(polyline.points.end() - 3), to), (Polygons)grown_env).size() == 1)
polyline.points.erase(polyline.points.end() - 2); polyline.points.erase(polyline.points.end() - 2);
} }

View file

@ -25,7 +25,7 @@ BridgeDetector::new(expolygon, lower_slices, extrusion_width)
ExPolygonCollection* lower_slices; ExPolygonCollection* lower_slices;
int extrusion_width; int extrusion_width;
CODE: CODE:
RETVAL = new BridgeDetector(*expolygon, *lower_slices, extrusion_width); RETVAL = new BridgeDetector(*expolygon, lower_slices->expolygons, extrusion_width);
OUTPUT: OUTPUT:
RETVAL RETVAL
@ -35,7 +35,7 @@ BridgeDetector::new_expolygons(expolygons, lower_slices, extrusion_width)
ExPolygonCollection* lower_slices; ExPolygonCollection* lower_slices;
int extrusion_width; int extrusion_width;
CODE: CODE:
RETVAL = new BridgeDetector(expolygons->expolygons, *lower_slices, extrusion_width); RETVAL = new BridgeDetector(expolygons->expolygons, lower_slices->expolygons, extrusion_width);
OUTPUT: OUTPUT:
RETVAL RETVAL

View file

@ -25,7 +25,7 @@
%code{% RETVAL = THIS->contains(*polyline); %}; %code{% RETVAL = THIS->contains(*polyline); %};
void simplify(double tolerance); void simplify(double tolerance);
Polygons polygons() Polygons polygons()
%code{% RETVAL = *THIS; %}; %code{% RETVAL = (Polygons)*THIS; %};
Clone<Polygon> convex_hull(); Clone<Polygon> convex_hull();
%{ %{