use super::funejson::Value; use super::charts_scale_linear_scale::{floats, interpolate, normalise, pair, round6}; /// The domain value at a position in the range: linear_scale read backwards. /// Never clamped; a position past the end of the axis is a value past the end /// of the data. /// /// # Panics /// Panics if the domain or range does not have exactly two values, or the /// range's ends are equal. pub fn invert_linear(domain: &[f64], range: &[f64], value: f64) -> f64 { let (d0, d1) = pair(domain, "domain"); let (r0, r1) = pair(range, "range"); round6(interpolate(d0, d1, normalise(r0, r1, value, "range"))) } pub fn fune_vector(args: &[Value]) -> Value { Value::Float(invert_linear(&floats(&args[0]), &floats(&args[1]), args[2].as_f64())) }