mc_core/
math.rs

1
2#[allow(clippy::approx_constant)]
3pub const JAVA_PI: f64 = 3.14159265358979323846;
4
5
6#[inline]
7pub fn lerp(factor: f64, from: f64, to: f64) -> f64 {
8    from + factor * (to - from)
9}
10
11
12#[inline(always)]
13fn mc_sin_table(i: u16) -> f32 {
14    (i as f64 * JAVA_PI * 2.0 / 65536.0).sin() as f32
15}
16
17
18/// Emulate the Minecraft sinus lookup table.
19pub fn mc_sin(x: f32) -> f32 {
20    mc_sin_table(((x * 10430.38) as i32 & 0xffff) as u16)
21}
22
23
24/// Emulate the Minecraft cosinus lookup table.
25pub fn mc_cos(x: f32) -> f32 {
26    mc_sin_table(((x * 10430.38 + 16384.0) as i32 & 0xffff) as u16)
27}