First failed step.
This commit is contained in:
parent
833c0a56eb
commit
5111cb9863
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
6
Cargo.lock
generated
Normal file
6
Cargo.lock
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "linearscale"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "linearscale"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
39
src/main.rs
39
src/main.rs
@ -1,4 +1,41 @@
|
|||||||
pub struct LinearScale {}
|
/// You configure it with an input range and an output range
|
||||||
|
/// then you pass it values within the input range and it returns where that value falls in the
|
||||||
|
/// output range
|
||||||
|
/// The trick is that input and output can be either integers or floats
|
||||||
|
/// and if it's all integers no floating point math is used. If either is a float then floating
|
||||||
|
/// point math is used
|
||||||
|
use std::ops::Add;
|
||||||
|
use std::ops::Div;
|
||||||
|
use std::ops::Mul;
|
||||||
|
use std::ops::RangeInclusive;
|
||||||
|
use std::ops::Sub;
|
||||||
|
|
||||||
|
pub struct LinearScale<InT, OutT>
|
||||||
|
where
|
||||||
|
InT: Sub<Output = InT> + Add + Mul + Div + From<OutT>,
|
||||||
|
OutT: Sub<Output = OutT> + Add + Mul + Div + From<InT>,
|
||||||
|
{
|
||||||
|
input: RangeInclusive<InT>,
|
||||||
|
output: RangeInclusive<OutT>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<InT, OutT> LinearScale<InT, OutT>
|
||||||
|
where
|
||||||
|
InT: Sub<Output = InT> + Add + Mul + Div + From<OutT>,
|
||||||
|
OutT: Sub<Output = OutT> + Add + Mul + Div + From<InT>,
|
||||||
|
{
|
||||||
|
fn new(input: RangeInclusive<InT>, output: RangeInclusive<OutT>) -> LinearScale<InT, OutT> {
|
||||||
|
LinearScale { input, output }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_for(&self, v: InT) -> OutT {
|
||||||
|
OutT::from(v)
|
||||||
|
//let in_alpha = (v - *self.input.start()) / (*self.input.end() - *self.input.start());
|
||||||
|
// (*self.output.start() + (in_alpha * (*self.output.end() - *self.output.start()))) / (*self.output.end() - *self.output.start())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user