veloren_world/util/
math.rs

1use std::ops::Range;
2use vek::*;
3
4/// Return a value between 0 and 1 corresponding to how close to the centre of
5/// `range` `x` is. The exact function used is left unspecified, but it shall
6/// have the shape of a bell-like curve. This function is required to return `0`
7/// (or a value extremely close to `0`) when `x` is outside of `range`.
8pub fn close(x: f32, range: Range<f32>) -> f32 {
9    let mean = (range.start + range.end) / 2.0;
10    let width = (range.end - range.start) / 2.0;
11    (1.0 - ((x - mean) / width).clamped(-1.0, 1.0).powi(2)).powi(2)
12}