mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-20 03:35:41 +02:00
particle/ramp: don't use floating point arithmetic
This commit is contained in:
parent
1929099ca4
commit
052513c736
1 changed files with 10 additions and 2 deletions
|
@ -33,13 +33,21 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
||||||
const struct tag *tag = tag_for_name(tags, ramp->tag);
|
const struct tag *tag = tag_for_name(tags, ramp->tag);
|
||||||
assert(tag != NULL);
|
assert(tag != NULL);
|
||||||
|
|
||||||
|
assert(ramp->count > 0);
|
||||||
|
|
||||||
long value = tag->as_int(tag);
|
long value = tag->as_int(tag);
|
||||||
long min = tag->min(tag);
|
long min = tag->min(tag);
|
||||||
long max = tag->max(tag);
|
long max = tag->max(tag);
|
||||||
|
|
||||||
double progress = (double)value / (max - min);
|
assert(value >= min && value <= max);
|
||||||
|
assert(max >= min);
|
||||||
|
|
||||||
size_t idx = progress * ramp->count;
|
size_t idx = 0;
|
||||||
|
if (max - min > 0)
|
||||||
|
idx = ramp->count * value / (max - min);
|
||||||
|
|
||||||
|
if (idx == ramp->count)
|
||||||
|
idx--;
|
||||||
/*
|
/*
|
||||||
* printf("ramp: value: %lu, min: %lu, max: %lu, progress: %f, idx: %zu\n",
|
* printf("ramp: value: %lu, min: %lu, max: %lu, progress: %f, idx: %zu\n",
|
||||||
* value, min, max, progress, idx);
|
* value, min, max, progress, idx);
|
||||||
|
|
Loading…
Add table
Reference in a new issue