Skip to content

Commit

Permalink
makeDetailsMask() roundDirInAscii (p23a)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 19, 2024
1 parent 13c6f1a commit b68c97d
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 @@ -507,12 +507,11 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre
double maxBlanks = 8.0 - numDots;

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 || prev->topPoint <= (double)(int)prev->nCellsPainted) {
blanksAtEnd = (uint8_t)maxBlanks % 8;
} else if ((double)(int)new->nCellsPainted > new->topPoint) {
Expand All @@ -527,8 +526,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 @@ -566,23 +568,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 &= 0xFFFF << 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 b68c97d

Please sign in to comment.