ENH: optimize bridge detect to choose short direction

For some corner case, the bridge detect may choose the long
distance rathan than the short distance.

Calculate the percentage of archored lines and choose
the shortest length

Signed-off-by: salt.wei <salt.wei@bambulab.com>
Change-Id: Ia74842f3135681373f649a014c270a1b9d1755e7
This commit is contained in:
salt.wei 2022-12-06 15:52:24 +08:00 committed by Lane.Wei
parent 1c02449201
commit 14417bf176
2 changed files with 10 additions and 4 deletions

View file

@ -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;