From e8b3db76b2a01d2eb9b65cf6323377de90b165c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 8 Apr 2019 14:53:36 +0200 Subject: [PATCH] [python/turtle] Fix rounding errors Some horizontal/vertical lines were not properly drawn Example script: from math import * from turtle import * def a(): def carre(n): fd(n) right(90) fd(n) right(90) fd(n) right(90) fd(n) right(90) penup() goto(-158,109) pendown() carre(100) for j in range(10): for i in range(26): penup() fd(2) pendown() carre(10) penup() fd(10) pendown() penup() goto(-158,109-10*(j+1)) pendown() --- python/port/mod/turtle/turtle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/port/mod/turtle/turtle.cpp b/python/port/mod/turtle/turtle.cpp index 0b7dcad89..7a66d4240 100644 --- a/python/port/mod/turtle/turtle.cpp +++ b/python/port/mod/turtle/turtle.cpp @@ -118,8 +118,8 @@ bool Turtle::goTo(mp_float_t x, mp_float_t y) { * the computation of the position on the principal coordinate is done * using a barycenter, roundings might skip some pixels, which results in * a dotted line. */ - mp_float_t currentX = principalDirection == PrincipalDirection::Y ? x * progress + oldx * (1 - progress) : oldx + (x > oldx ? i : -i); - mp_float_t currentY = principalDirection == PrincipalDirection::X ? y * progress + oldy * (1 - progress) : oldy + (y > oldy ? i : -i); + mp_float_t currentX = xLength == 0 ? x : (principalDirection == PrincipalDirection::Y ? x * progress + oldx * (1 - progress) : oldx + (x > oldx ? i : -i)); + mp_float_t currentY = yLength == 0 ? y : (principalDirection == PrincipalDirection::X ? y * progress + oldy * (1 - progress) : oldy + (y > oldy ? i : -i)); if (dot(currentX, currentY) || draw(false)) { // Keyboard interruption. Return now to let MicroPython process it. return true;