Merge pull request #294 from fmOOmf/upsilon-dev

Correction CIRCLE avec angle négatif (correct circle with negative angle)
This commit is contained in:
Yaya-Cout
2025-11-05 14:58:05 +00:00
committed by GitHub

View File

@@ -76,19 +76,22 @@ void Turtle::left(mp_float_t angle) {
void Turtle::circle(mp_int_t radius, mp_float_t angle) { void Turtle::circle(mp_int_t radius, mp_float_t angle) {
mp_float_t oldHeading = heading(); mp_float_t oldHeading = heading();
mp_float_t length = std::fabs(angle * k_headingScale * radius); mp_float_t length = std::fabs(angle * k_headingScale * radius);
int direction = 1; // 1=forward, -1=backward
if (angle < 0) { direction =-1; }
if (length > 1) { if (length > 1) {
for (int i = 1; i < length; i++) { for (int i = 1; i < length; i++) {
mp_float_t progress = i / length; mp_float_t progress = i / length;
// Move the turtle forward // Move the turtle forward
if (forward(1)) { if (forward(direction)) {
// Keyboard interruption. Return now to let MicroPython process it. // Keyboard interruption. Return now to let MicroPython process it.
return; return;
} }
setHeadingPrivate(oldHeading+std::copysign(angle*progress, radius)); setHeadingPrivate(oldHeading+std::copysign(angle*progress, direction*radius));
} }
forward(1); forward(direction);
setHeading(oldHeading+angle); setHeading(oldHeading+std::copysign(angle, direction*radius));
} }
} }
bool Turtle::goTo(mp_float_t x, mp_float_t y) { bool Turtle::goTo(mp_float_t x, mp_float_t y) {