mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python] Turtle: use std::fabs std::copysign when possible
This commit is contained in:
committed by
LeaNumworks
parent
675a0d3f4c
commit
61399d07eb
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user