From bdbeb34158a28cc0d042bdee587c7751ee966019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Fri, 16 Aug 2024 08:35:49 -0400 Subject: [PATCH] Accumulate the total estimated print in doubles instead of floats. Because total print time is typically a big floating point number and the time of trapezoid is typically a small number, summing those numbers leads to a loss in precision. Switching to doubles reduces the loss of precision. (cherry picked from commit c5982f40196c178bd824c556ac11e8c6f67d5e7a) --- src/libslic3r/GCode/GCodeProcessor.cpp | 10 +++++----- src/libslic3r/GCode/GCodeProcessor.hpp | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 67d7e8c3a4..6302325f0d 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -417,7 +417,7 @@ void GCodeProcessor::TimeMachine::calculate_time(GCodeProcessorResult& result, P if (i == 0) block_time += additional_time; - time += block_time; + time += double(block_time); result.moves[block.move_id].time[static_cast(mode)] = block_time; gcode_time.cache += block_time; //BBS @@ -514,12 +514,12 @@ void GCodeProcessor::TimeMachine::calculate_time(GCodeProcessorResult& result, P std::nullopt }); } - g1_times_cache.push_back({ block.g1_line_id, block.remaining_internal_g1_lines, time }); + g1_times_cache.push_back({ block.g1_line_id, block.remaining_internal_g1_lines, float(time) }); // update times for remaining time to printer stop placeholders auto it_stop_time = std::lower_bound(stop_times.begin(), stop_times.end(), block.g1_line_id, [](const StopTime& t, unsigned int value) { return t.g1_line_id < value; }); if (it_stop_time != stop_times.end() && it_stop_time->g1_line_id == block.g1_line_id) - it_stop_time->elapsed_time = time; + it_stop_time->elapsed_time = float(time); } if (keep_last_n_blocks) { @@ -2561,7 +2561,7 @@ void GCodeProcessor::finalize(bool post_process) float GCodeProcessor::get_time(PrintEstimatedStatistics::ETimeMode mode) const { - return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? m_time_processor.machines[static_cast(mode)].time : 0.0f; + return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? float(m_time_processor.machines[static_cast(mode)].time) : 0.0f; } float GCodeProcessor::get_prepare_time(PrintEstimatedStatistics::ETimeMode mode) const @@ -2571,7 +2571,7 @@ float GCodeProcessor::get_prepare_time(PrintEstimatedStatistics::ETimeMode mode) std::string GCodeProcessor::get_time_dhm(PrintEstimatedStatistics::ETimeMode mode) const { - return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? short_time(get_time_dhms(m_time_processor.machines[static_cast(mode)].time)) : std::string("N/A"); + return (mode < PrintEstimatedStatistics::ETimeMode::Count) ? short_time(get_time_dhms(float(m_time_processor.machines[static_cast(mode)].time))) : std::string("N/A"); } std::vector>> GCodeProcessor::get_custom_gcode_times(PrintEstimatedStatistics::ETimeMode mode, bool include_remaining) const diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index f280bc97cb..f55d414514 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -459,7 +459,7 @@ class Print; AxisCoords axis_feedrate; // mm/s AxisCoords abs_axis_feedrate; // mm/s - //BBS: unit vector of enter speed and exit speed in x-y-z space. + //BBS: unit vector of enter speed and exit speed in x-y-z space. //For line move, there are same. For arc move, there are different. Vec3f enter_direction; Vec3f exit_direction; @@ -508,7 +508,9 @@ class Print; // hard limit for the travel acceleration, to which the firmware will clamp. float max_travel_acceleration; // mm/s^2 float extrude_factor_override_percentage; - float time; // s + // We accumulate total print time in doubles to reduce the loss of precision + // while adding big floating numbers with small float numbers. + double time; // s struct StopTime { unsigned int g1_line_id;