diff --git a/src/libslic3r/BridgeDetector.cpp b/src/libslic3r/BridgeDetector.cpp index 03d671db4..a60f45f11 100644 --- a/src/libslic3r/BridgeDetector.cpp +++ b/src/libslic3r/BridgeDetector.cpp @@ -122,6 +122,7 @@ bool BridgeDetector::detect_angle(double bridge_direction_override) double max_length = 0; { Lines clipped_lines = intersection_ln(lines, clip_area); + size_t archored_line_num = 0; for (size_t i = 0; i < clipped_lines.size(); ++i) { const Line &line = clipped_lines[i]; if (expolygons_contain(this->_anchor_regions, line.a) && expolygons_contain(this->_anchor_regions, line.b)) { @@ -129,8 +130,12 @@ bool BridgeDetector::detect_angle(double bridge_direction_override) double len = line.length(); total_length += len; max_length = std::max(max_length, len); + archored_line_num++; } - } + } + if (clipped_lines.size() > 0 && archored_line_num > 0) { + candidates[i_angle].archored_percent = (double)archored_line_num / (double)clipped_lines.size(); + } } if (total_length == 0.) continue; @@ -155,7 +160,7 @@ bool BridgeDetector::detect_angle(double bridge_direction_override) // if any other direction is within extrusion width of coverage, prefer it if shorter // TODO: There are two options here - within width of the angle with most coverage, or within width of the currently perferred? size_t i_best = 0; - for (size_t i = 1; i < candidates.size() && candidates[i_best].coverage - candidates[i].coverage < this->spacing; ++ i) + for (size_t i = 1; i < candidates.size() && abs(candidates[i_best].archored_percent - candidates[i].archored_percent) < EPSILON; ++ i) if (candidates[i].max_length < candidates[i_best].max_length) i_best = i; diff --git a/src/libslic3r/BridgeDetector.hpp b/src/libslic3r/BridgeDetector.hpp index e97dd45c4..d422949cd 100644 --- a/src/libslic3r/BridgeDetector.hpp +++ b/src/libslic3r/BridgeDetector.hpp @@ -44,15 +44,16 @@ private: void initialize(); struct BridgeDirection { - BridgeDirection(double a = -1.) : angle(a), coverage(0.), max_length(0.) {} + BridgeDirection(double a = -1.) : angle(a), coverage(0.), max_length(0.), archored_percent(0.){} // the best direction is the one causing most lines to be bridged (thus most coverage) bool operator<(const BridgeDirection &other) const { // Initial sort by coverage only - comparator must obey strict weak ordering - return this->coverage > other.coverage; + return this->archored_percent > other.archored_percent; }; double angle; double coverage; double max_length; + double archored_percent; }; // Get possible briging direction candidates.