Skip to content

Commit

Permalink
makeDetailsMask() use ceil() (k2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 10, 2024
1 parent 363edd3 commit c8f9a8e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit c8f9a8e

Please sign in to comment.