scales

Crates.ioscales
lib.rsscales
version0.1.3
sourcesrc
created_at2020-10-29 14:51:47.002491
updated_at2020-11-26 16:37:52.70296
descriptionA utility library for converting values between scales.
homepage
repositoryhttps://github.com/bbmsoft/scales.git
max_upload_size
id306661
size50,995
Michael Bachmann (babymotte)

documentation

README

Scales

Build Status Current Crates.io Version

A utility library for converting values between scales.

What does it do?

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, &parameter_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());

Early development status!

Expect breaking changes anytime!

Commit count: 59

cargo fmt