From 39e9728b0e82dfff05f7c9381eeeca030f9dcb39 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 13:48:39 +0000 Subject: [PATCH] Badger2040: Fix text rotation aliasing for #290 Fix text rendering at 90, 180 and 270 degree rotations by avoiding float -> int truncation. --- libraries/badger2040/badger2040.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/badger2040/badger2040.cpp b/libraries/badger2040/badger2040.cpp index 0b65395b..451fb097 100644 --- a/libraries/badger2040/badger2040.cpp +++ b/libraries/badger2040/badger2040.cpp @@ -264,11 +264,11 @@ namespace pimoroni { int8_t nx = (*pv++) * s; int8_t ny = (*pv++) * s; - int rcx = cx * ac - cy * as; - int rcy = cx * as + cy * ac; + int rcx = (cx * ac - cy * as) + 0.5f; + int rcy = (cx * as + cy * ac) + 0.5f; - int rnx = nx * ac - ny * as; - int rny = nx * as + ny * ac; + int rnx = (nx * ac - ny * as) + 0.5f; + int rny = (nx * as + ny * ac) + 0.5f; if(pen_down) { line(rcx + x, rcy + y, rnx + x, rny + y); @@ -293,8 +293,8 @@ namespace pimoroni { float ac = cos(deg2rad(a)); for(auto &c : message) { - int rcx = ox * ac; - int rcy = ox * as; + int rcx = (ox * ac) + 0.5f; + int rcy = (ox * as) + 0.5f; ox += glyph(c, cx + rcx, cy + rcy, s, a); }