Skip to content

Commit

Permalink
makeDetailsMask() roundDirInAscii (q27b)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 21, 2024
1 parent 587d32d commit c5b8d23
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,11 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre
double numDots = ceil(rem * 8.0);

uint8_t blanksAtEnd;
bool roundsUpInAscii = false;
bool roundsDownInAscii = false;
int roundDirInAscii = 0;
if (blanksAtTopCell >= 0) {
assert(blanksAtTopCell < 8);
blanksAtEnd = (uint8_t)blanksAtTopCell;
roundsUpInAscii = true;
roundDirInAscii = 1;
} else if (prev->nCellsPainted == 0 || prevTopPoint <= (double)(int)prev->nCellsPainted || rem <= 0.0) {
blanksAtEnd = (uint8_t)(8 - (uint8_t)numDots) % 8;
} else {
Expand All @@ -523,8 +522,11 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre
distance = distance + rem * 0.5;

// Tiebreaking direction that may be needed in the ASCII display mode.
roundsUpInAscii = distance > 0.5;
roundsDownInAscii = distance < 0.5;
if (distance > 0.5) {
roundDirInAscii = 1;
} else if (distance < 0.5) {
roundDirInAscii = -1;
}

distance *= 8.0;
if ((uint8_t)numDots % 2 == 0) {
Expand Down Expand Up @@ -559,23 +561,23 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre

if (new->nCellsPainted - prev->nCellsPainted == 1) {
assert(blanksAtStart + blanksAtEnd < 8);
if (roundsUpInAscii && needsTiebreak) {
if (roundDirInAscii > 0 && needsTiebreak) {
mask &= 0xF7FF;
}
mask >>= 8;
} else if (roundsUpInAscii) {
} else if (roundDirInAscii > 0) {
if (blanksAtStart < 4 && (uint8_t)(blanksAtStart + blanksAtEnd % 4) >= 4) {
mask &= 0xF7FF;
}
}

mask &= 0xFFFFU << blanksAtEnd;

if (roundsUpInAscii) {
if (roundDirInAscii > 0) {
if (needsTiebreak) {
mask |= 0x0004;
}
} else if (roundsDownInAscii) {
} else if (roundDirInAscii < 0) {
assert(blanksAtStart <= blanksAtEnd);
if (needsTiebreak) {
mask = (mask & 0xFFEF) | 0x0020;
Expand Down

0 comments on commit c5b8d23

Please sign in to comment.