mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-12 23:38:59 +08:00
Restrict speed setting to fixed-point output with 3 decimal places. Includes test.
Fixes #4769
This commit is contained in:
parent
05a2f9028a
commit
205cb02efa
@ -98,3 +98,30 @@ SCENARIO("lift() is not ignored after unlift() at normal values of Z") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SCENARIO("set_speed emits values with fixed-point output.") {
|
||||
|
||||
GIVEN("GCodeWriter instance") {
|
||||
GCodeWriter writer;
|
||||
WHEN("set_speed is called to set speed to 1.09321e+06") {
|
||||
THEN("Output string is G1 F1093210.000") {
|
||||
REQUIRE_THAT(writer.set_speed(1.09321e+06), Catch::Equals("G1 F1093210.000\n"));
|
||||
}
|
||||
}
|
||||
WHEN("set_speed is called to set speed to 1") {
|
||||
THEN("Output string is G1 F1.000") {
|
||||
REQUIRE_THAT(writer.set_speed(1.0), Catch::Equals("G1 F1.000\n"));
|
||||
}
|
||||
}
|
||||
WHEN("set_speed is called to set speed to 203.200022") {
|
||||
THEN("Output string is G1 F203.200") {
|
||||
REQUIRE_THAT(writer.set_speed(203.200022), Catch::Equals("G1 F203.200\n"));
|
||||
}
|
||||
}
|
||||
WHEN("set_speed is called to set speed to 203.200522") {
|
||||
THEN("Output string is G1 F203.200") {
|
||||
REQUIRE_THAT(writer.set_speed(203.200522), Catch::Equals("G1 F203.201\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +309,8 @@ GCodeWriter::set_speed(double F, const std::string &comment,
|
||||
const std::string &cooling_marker) const
|
||||
{
|
||||
std::ostringstream gcode;
|
||||
gcode << "G1 F" << F;
|
||||
gcode.precision(3);
|
||||
gcode << "G1 F" << std::fixed << F;
|
||||
COMMENT(comment);
|
||||
gcode << cooling_marker;
|
||||
gcode << "\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user