-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Closed
Description
@sgomes already doing some work on this.
Notes
Step values need to be able to be quantized to decimal places, e.g. min = 0, max = 5, step = .2. Possible algorithm: Take the raw value, divide it by step, round that number, and then multiply the original step value by the rounded number. E.g.
function quantize(val, min, max, step) {
const numSteps = Math.round(val / step);
const quantizedVal = numSteps * step;
return Math.max(min, Math.min(max, quantizedVal));
}
const min = 0, max = 5, step = .2;
quantize(3.56, min, max, step); // 3.6
quantize(2.148692, min, max, step) // 2.2
quantize(1.061733, min, max, step) // 1Reactions are currently unavailable