fraction
Parameters
- self:*Axis
- *Axis
- val:f64
- f64
Source
Implementation
pub fn fraction(self: *Axis, val: f64) f32 {
if (self.min == null or self.max == null) return 0;
const min = self.min.?;
const max = self.max.?;
switch (self.scale) {
.linear => {
return @floatCast((val - min) / (max - min));
},
.log => |log_data| {
const val_exp = std.math.log(f64, log_data.base, val);
const min_exp = std.math.log(f64, log_data.base, min);
const max_exp = std.math.log(f64, log_data.base, max);
return @floatCast((val_exp - min_exp) / (max_exp - min_exp));
},
}
}