Skip to content

Commit

Permalink
findTopCellItem() handle underflow (f4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 7, 2024
1 parent daef50d commit 30f1565
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ static uint8_t GraphMeterMode_findTopCellItem(const Meter* this, double scaledTo
// Find the item that occupies the largest area of the top cell.
// Favor item with higher index in case of a tie.

double area = (value / scaledTotal) * (double)(int)graphHeight;

// if (maxValue <= 0.0)
// if (topCellItem >= i)
if (topCellItem > i) {
Expand All @@ -422,7 +424,6 @@ static uint8_t GraphMeterMode_findTopCellItem(const Meter* this, double scaledTo
// If (topCell == 0), permit the cases where the division underflows
// (topPoint == 0.0).

double area = (value / scaledTotal) * (double)(int)graphHeight;
if (area > topPoint - (double)(int)topCell) {
hasArea = true;
maxValue = topPoint - (double)(int)topCell;
Expand All @@ -432,7 +433,6 @@ static uint8_t GraphMeterMode_findTopCellItem(const Meter* this, double scaledTo
topCellItem = i;
} else {
if (hasArea) {
double area = (value / scaledTotal) * (double)(int)graphHeight;
if (area >= maxValue) {
hasArea = false;
maxValue = value;
Expand Down

0 comments on commit 30f1565

Please sign in to comment.