FIX: can't merge paths with different attributes

jira:NONE

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I0c853de6b1938c7e2addbaab5a45b35daf5a32fa
This commit is contained in:
xun.zhang 2024-09-12 14:10:33 +08:00 committed by Lane.Wei
parent 8df9311c87
commit 43e4569f55
3 changed files with 33 additions and 22 deletions

View File

@ -66,6 +66,19 @@ void ExtrusionPath::polygons_covered_by_spacing(Polygons &out, const float scale
polygons_append(out, offset(this->polyline, 0.5f * float(flow.scaled_spacing()) + scaled_epsilon));
}
bool ExtrusionPath::can_merge(const ExtrusionPath& other)
{
return overhang_degree == other.overhang_degree &&
curve_degree==other.curve_degree &&
mm3_per_mm == other.mm3_per_mm &&
width == other.width &&
height == other.height &&
m_can_reverse == other.m_can_reverse &&
m_role == other.m_role &&
m_no_extrusion == other.m_no_extrusion &&
smooth_speed == other.smooth_speed;
}
void ExtrusionMultiPath::reverse()
{
for (ExtrusionPath &path : this->paths)

View File

@ -285,6 +285,8 @@ public:
void set_reverse() override { m_can_reverse = false; }
bool can_reverse() const override { return m_can_reverse; }
bool can_merge(const ExtrusionPath& other);
private:
void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const;
bool m_can_reverse = true;

View File

@ -4677,41 +4677,37 @@ ExtrusionPaths GCode::split_and_mapping_speed(double &other_path_v, double &fina
ExtrusionPaths GCode::merge_same_speed_paths(const ExtrusionPaths &paths)
{
ExtrusionPaths output_paths;
std::optional<ExtrusionPath> merged_path;
size_t path_idx = 0;
int merge_start = 0;
ExtrusionPath merge_path;
for (; path_idx < paths.size(); path_idx++) {
for(size_t path_idx=0;path_idx<paths.size();++path_idx){
ExtrusionPath path = paths[path_idx];
path.smooth_speed = get_path_speed(path);
path.smooth_speed = get_path_speed(path);
// 100% overhang speed will not to set smooth speed
if (path.role() == erOverhangPerimeter) {
if (!merge_path.empty()) {
output_paths.push_back(std::move(merge_path));
merge_path.polyline.clear();
if(path.role() == erOverhangPerimeter){
if(merged_path.has_value()){
output_paths.push_back(std::move(*merged_path));
merged_path=std::nullopt;
}
output_paths.push_back(std::move(path));
merge_start = path_idx + 1;
output_paths.emplace_back(path);
continue;
}
if (merge_start == path_idx) {
merge_path = path;
if(!merged_path.has_value()){
merged_path=path;
continue;
}
// merge path with same speed
if (merge_path.smooth_speed == path.smooth_speed) {
merge_path.polyline.append(path.polyline);
} else {
output_paths.push_back(std::move(merge_path));
merge_path = path;
if(merged_path->can_merge(path)){
merged_path->polyline.append(path.polyline);
}
else{
output_paths.push_back(std::move(*merged_path));
merged_path = path;
}
}
if (!merge_path.empty() && merge_start < paths.size())
output_paths.push_back(std::move(merge_path));
if(merged_path.has_value())
output_paths.push_back(std::move(*merged_path));
return output_paths;
}