From c8f9a8e4445e116acea42c3b9f29135bbf2920d6 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 10 Feb 2024 18:31:29 +0800 Subject: [PATCH] makeDetailsMask() use ceil() (k2) --- Meter.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Meter.c b/Meter.c index cc11b7b08..f59f9baa6 100644 --- a/Meter.c +++ b/Meter.c @@ -503,7 +503,8 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre assert(rem >= 0.0); assert(rem < 1.0); - double maxBlanks = (1.0 - rem) * 8.0; + double numDots = ceil(rem * 8.0); + double maxBlanks = 8.0 - numDots; uint8_t blanksAtEnd; bool roundsUpInAscii = false; @@ -519,8 +520,17 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre // Unlike other conditions, this one rounds to nearest for visual reason. // In case of a tie, display the dot at lower position of the graph, // i.e. MSB of the "details" data. - double fraction = maxBlanks - (int)maxBlanks; - double distance = (new->nCellsPainted - new->topPoint) * 8.0 + (1.0 - fraction) * 0.5; + + double fraction = (rem * 8.0) - (numDots - 1.0); + assert(fraction > 0.0); + assert(fraction <= 1.0); + + double distance; + if (new->nCellsPainted > 1) { + distance = (new->nCellsPainted - new->topPoint) * 8.0 + fraction * 0.5; + } else { + distance = new->nCellsPainted * 8.0 + (fraction * 0.5 - new->topPoint * 8.0); + } blanksAtEnd = (uint8_t)distance; // Tiebreaking direction that may be needed in the ASCII display mode.