Skip to content

Commit 6405aaa

Browse files
committed
Use accumulate to make code more explicit
CURA-11978
1 parent 2c5bd6d commit 6405aaa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/LayerPlan.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,13 +2168,17 @@ LayerPlan::TravelDurations LayerPlan::computeTravelDurations(const GCodeExport&
21682168
{
21692169
const Velocity& travel_speed = path.config.getSpeed();
21702170
Point2LL start_position = gcode.getPosition().toPoint2LL();
2171-
for (const Point3LL& travel_point : path.points)
2172-
{
2173-
const Point2LL travel_point_2d = travel_point.toPoint2LL();
2174-
const coord_t travel_segment_length = vSize(travel_point_2d - start_position);
2175-
travel_durations.travel += (travel_segment_length / travel_speed) / 1000.0;
2176-
start_position = travel_point_2d;
2177-
}
2171+
const coord_t travel_distance = ranges::accumulate(
2172+
path.points,
2173+
0,
2174+
[&start_position](const coord_t total_distance, const Point3LL& travel_point)
2175+
{
2176+
const Point2LL travel_point_2d = travel_point.toPoint2LL();
2177+
const coord_t travel_segment_length = vSize(travel_point_2d - start_position);
2178+
start_position = travel_point_2d;
2179+
return total_distance + travel_segment_length;
2180+
});
2181+
travel_durations.travel = (travel_distance / travel_speed) / 1000.0;
21782182
}
21792183

21802184
return travel_durations;

0 commit comments

Comments
 (0)