Crates.io | scales |
lib.rs | scales |
version | 0.1.3 |
source | src |
created_at | 2020-10-29 14:51:47.002491 |
updated_at | 2020-11-26 16:37:52.70296 |
description | A utility library for converting values between scales. |
homepage | |
repository | https://github.com/bbmsoft/scales.git |
max_upload_size | |
id | 306661 |
size | 50,995 |
A utility library for converting values between scales.
It provides reusable converters that make translating ranged values from one scale to another easy. Imagine you have a slider in your UI that has a linear internal value but it controls a logarithmic parameter. Normally you would be doing something like this:
let relative = (slider.value() - slider.min()) / (slider.max() - slider.min());
let log_range = parameter.max().log10() - parameter.min().log10();
let exp = parameter.min().log10() + relative * log_range;
let new_value = 10f64.powf(exp);
parameter.set(new_value);
Using scales you can reduce that to:
let new_value = (&slider_scale, ¶meter_scale).convert(slider.value());
parameter.set(new_value);
where slider_scale
and parameter_scale
are reusable components that look like this:
let slider_scale = LinearScale::new(slider.min(), slider.max());
let parameter_scale = LogarithmicScale::new(parameter.min(), parameter.max());
Expect breaking changes anytime!