diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2014-12-21 13:49:25 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2014-12-21 13:56:04 +0000 |
commit | 7f9d14aa516527f6abf77b4df294acfa832d0dc6 (patch) | |
tree | 2323c2832f4a37e0a5c7593484885ab9a50bb02d /overlay | |
parent | c537cdb08eb7a862b50fab2d66aa40f8efaaf933 (diff) |
overlay: Negative modulus
Don't use a negative index into the array if the desired element is
negative, just wrap around properly into the ring for the chart.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'overlay')
-rw-r--r-- | overlay/chart.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/overlay/chart.c b/overlay/chart.c index 2a33d612..734e911f 100644 --- a/overlay/chart.c +++ b/overlay/chart.c @@ -143,7 +143,11 @@ static double value_at(struct chart *chart, int n) else if (n >= chart->current_sample) n = chart->current_sample - 1; - return chart->samples[n % chart->num_samples]; + n %= chart->num_samples; + if (n < 0) + n += chart->num_samples; + + return chart->samples[n]; } static double gradient_at(struct chart *chart, int n) |