diff options
author | Ghostkeeper <rubend@tutanota.com> | 2022-05-13 18:52:40 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2022-05-13 18:52:40 +0300 |
commit | 94a656d8e29d9603d01dad9b3a9b610faea90c10 (patch) | |
tree | e0dd1fad6cb00aa85f7cff7bdb6779e3bd16e8c4 | |
parent | ed7d72835e6884b2caa67287cedf590e4ddcb2db (diff) |
Factor out finding of the next extrusion moveCURA-8708_remove_travel_acceleration_jerk
This was some repeating code that was both duplicate and inefficient.
Contributes to issue CURA-8708.
-rw-r--r-- | src/LayerPlan.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index b943c7e59..c63e51789 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -1736,6 +1736,16 @@ void LayerPlan::writeGCode(GCodeExport& gcode) continue; } + //In some cases we want to find the next non-travel move. + size_t next_extrusion_idx = path_idx + 1; + if((acceleration_enabled && !acceleration_travel_enabled) || (jerk_enabled && !jerk_travel_enabled)) + { + while(next_extrusion_idx < paths.size() && paths[next_extrusion_idx].config->isTravelPath()) + { + ++next_extrusion_idx; + } + } + if (acceleration_enabled) { if (path.config->isTravelPath()) @@ -1747,12 +1757,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) else { //Use the acceleration of the first non-travel move *after* the travel. - size_t future_path_idx = path_idx + 1; - while(future_path_idx < paths.size() && paths[future_path_idx].config->isTravelPath()) - { - ++future_path_idx; - } - if(future_path_idx >= paths.size()) //Only travel moves for the remainder of the layer. + if(next_extrusion_idx >= paths.size()) //Only travel moves for the remainder of the layer. { if(static_cast<bool>(next_layer_acc_jerk)) { @@ -1761,7 +1766,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) } else { - gcode.writeTravelAcceleration(paths[future_path_idx].config->getAcceleration()); + gcode.writeTravelAcceleration(paths[next_extrusion_idx].config->getAcceleration()); } } } @@ -1779,12 +1784,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) else { //Use the jerk of the first non-travel move *after* the travel. - size_t future_path_idx = path_idx + 1; - while(future_path_idx < paths.size() && paths[future_path_idx].config->isTravelPath()) - { - ++future_path_idx; - } - if(future_path_idx >= paths.size()) //Only travel moves for the remainder of the layer. + if(next_extrusion_idx >= paths.size()) //Only travel moves for the remainder of the layer. { if(static_cast<bool>(next_layer_acc_jerk)) { @@ -1793,7 +1793,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) } else { - gcode.writeJerk(paths[future_path_idx].config->getJerk()); + gcode.writeJerk(paths[next_extrusion_idx].config->getJerk()); } } } |