Skip to content

Commit

Permalink
makeDetailsMask() prevTopPoint arg (q22b)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 19, 2024
1 parent 721e591 commit af0ddff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
25 changes: 9 additions & 16 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ static void GraphMeterMode_addItemAdjStack(GraphColorAdjStack* stack, double sca
stack->nItems++;
}

static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* prev, const GraphColorComputeState* new, double rem, int blanksAtTopCell) {
static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* prev, const GraphColorComputeState* new, double prevTopPoint, double rem, int blanksAtTopCell) {
assert(new->nCellsPainted > prev->nCellsPainted);
assert(rem >= 0.0);
assert(rem < 1.0);
Expand All @@ -513,18 +513,15 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre
assert(blanksAtTopCell < 8);
blanksAtEnd = (uint8_t)blanksAtTopCell;
roundsUpInAscii = true;
} else if (prev->nCellsPainted == 0 || prev->topPoint <= (double)(int)prev->nCellsPainted) {
} else if (prev->nCellsPainted == 0 || prevTopPoint <= (double)(int)prev->nCellsPainted || rem <= 0.0) {
blanksAtEnd = (uint8_t)maxBlanks % 8;
} else if ((double)(int)new->nCellsPainted > new->topPoint) {
assert(new->nCellsPainted - new->topPoint < 1.0);
assert(rem > 0.0);
} else {
// 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 distance = new->topPoint - (double)(int)(new->nCellsPainted - 1);
assert(distance > rem);
distance = distance - rem * 0.5;
double distance = prevTopPoint - (double)(int)prev->nCellsPainted;
distance = distance + rem * 0.5;

// Tiebreaking direction that may be needed in the ASCII display mode.
roundsUpInAscii = distance > 0.5;
Expand All @@ -539,11 +536,8 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre
assert(distance < INT_MAX);

unsigned int maxBlanks2 = 8 - (unsigned int)(int)numDots / 2;
assert(maxBlanks2 >= distance);
maxBlanks2 -= (unsigned int)(int)distance;
maxBlanks2 -= MINIMUM(maxBlanks2, (unsigned int)(int)distance);
blanksAtEnd = (uint8_t)maxBlanks2;
} else {
blanksAtEnd = 0;
}
assert(blanksAtEnd < 8);

Expand Down Expand Up @@ -656,7 +650,6 @@ static void GraphMeterMode_computeColors(Meter* this, const GraphDrawContext* co

GraphColorComputeState restart = {
.valueSum = 0.0,
.topPoint = 0.0,
.nCellsPainted = 0,
.nItemsPainted = 0
};
Expand Down Expand Up @@ -711,7 +704,6 @@ static void GraphMeterMode_computeColors(Meter* this, const GraphDrawContext* co
assert(new.valueSum < DBL_MAX || prev.valueSum + value >= DBL_MAX);
}

new.topPoint = (new.valueSum / scaledTotal) * (double)(int)graphHeight;
double area = (value / scaledTotal) * (double)(int)graphHeight;
assert(area >= 0.0); // "area" can be 0.0 when the division underflows
double rem = area;
Expand Down Expand Up @@ -754,7 +746,7 @@ static void GraphMeterMode_computeColors(Meter* this, const GraphDrawContext* co
assert(restart.nItemsPainted == prev.nItemsPainted);

if (!rItemIsDetermined) {
stack.startPoint = new.topPoint;
stack.startPoint = (new.valueSum / scaledTotal) * (double)(int)graphHeight;
rItemMinCells = nCells;
rem = 0.0;
} else if (rItemHasExtraCell) {
Expand Down Expand Up @@ -836,8 +828,9 @@ static void GraphMeterMode_computeColors(Meter* this, const GraphDrawContext* co
rem = (0.125 * dotAlignment);

if (nCells > 0 && new.nCellsPainted <= nCellsToPaint) {
double prevTopPoint = (prev.valueSum / scaledTotal) * (double)(int)graphHeight;
int blanksAtTopCellArg = (new.nCellsPainted == nCellsToPaint) ? (int)blanksAtTopCell : -1;
uint16_t mask = GraphMeterMode_makeDetailsMask(&prev, &new, rem, blanksAtTopCellArg);
uint16_t mask = GraphMeterMode_makeDetailsMask(&prev, &new, prevTopPoint, rem, blanksAtTopCellArg);

GraphColorCell* cellsStart = &valueStart[firstCellIndex + (size_t)increment * prev.nCellsPainted];
GraphMeterMode_paintCellsForItem(cellsStart, increment, prev.nItemsPainted, nCells, mask);
Expand Down
1 change: 0 additions & 1 deletion Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ typedef struct GraphDrawContext_ {
/* Used in GraphMeterMode_computeColors() subroutines only */
typedef struct GraphColorComputeState_ {
double valueSum;
double topPoint;
unsigned int nCellsPainted;
uint8_t nItemsPainted;
} GraphColorComputeState;
Expand Down

0 comments on commit af0ddff

Please sign in to comment.