1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pub use ;
pub use Mat2;
pub use Bounds;
use f32;
/// The mathematical constant Pi.
pub const PI: f32 = f32PI;
/// Infinity; a value that is larger than all other possible values.
pub const INFINITY: f32 = f32INFINITY;
/// Clamps (limits) the value of `x` in the inclusive range from `min` to `max`.
///
/// If `x < min`, `min` is returned. If `x > max`, `max` is returned.
///
/// # Examples
///
/// ```
/// # use physics2d::math::clamp;
///
/// assert_eq!(clamp(-10.0, -3.0, 5.0), -3.0);
/// assert_eq!(clamp(1.0, -3.0, 5.0), 1.0);
/// assert_eq!(clamp(999999.0, -3.0, 5.0), 5.0);
/// ```
/// Clamps (limits) the value of `x` in the inclusive range from `0.0` to `1.0`.
///
/// If `x < 0.0`, `0.0` is returned. If `x > 1.0`, `1.0` is returned.
///
/// # Examples
///
/// ```
/// # use physics2d::math::clamp01;
///
/// assert_eq!(clamp01(-10.0), 0.0);
/// assert_eq!(clamp01(0.12345678), 0.12345678);
/// assert_eq!(clamp01(999.8989), 1.0);
/// ```