[python] Turtle: use std::fabs std::copysign when possible

This commit is contained in:
Émilie Feral
2020-04-15 15:19:48 +02:00
committed by LeaNumworks
parent 675a0d3f4c
commit 61399d07eb

View File

@@ -73,7 +73,7 @@ void Turtle::left(mp_float_t angle) {
void Turtle::circle(mp_int_t radius, mp_float_t angle) {
mp_float_t oldHeading = heading();
mp_float_t length = (angle > 0 ? 1 : -1) * angle * k_headingScale * (radius > 0 ? 1 : -1) * radius;
mp_float_t length = std::fabs(angle * k_headingScale * radius);
if (length > 1) {
for (int i = 1; i < length; i++) {
mp_float_t progress = i / length;
@@ -82,7 +82,7 @@ void Turtle::circle(mp_int_t radius, mp_float_t angle) {
// Keyboard interruption. Return now to let MicroPython process it.
return;
}
setHeadingPrivate(oldHeading+angle*progress*((radius>0) ? 1 : -1));
setHeadingPrivate(oldHeading+std::copysign(angle*progress, radius));
}
forward(1);
setHeading(oldHeading+angle);