From 856a3252f693421df519cbc4d9bc03cfc0f0c212 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 17 Sep 2023 21:44:17 -0500 Subject: heightmaps --- azalea-core/src/math.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'azalea-core/src/math.rs') diff --git a/azalea-core/src/math.rs b/azalea-core/src/math.rs index 6683dd10..01695a0a 100644 --- a/azalea-core/src/math.rs +++ b/azalea-core/src/math.rs @@ -9,17 +9,17 @@ pub static SIN: LazyLock<[f32; 65536]> = LazyLock::new(|| { }); /// A sine function that uses a lookup table. -pub fn sin(var0: f32) -> f32 { - let var0 = var0 * 10430.378; - let var0 = var0 as usize; - SIN[var0 & 65535] +pub fn sin(x: f32) -> f32 { + let x = x * 10430.378; + let x = x as usize; + SIN[x & 65535] } /// A cosine function that uses a lookup table. -pub fn cos(var0: f32) -> f32 { - let var0 = var0 * 10430.378 + 16384.0; - let var0 = var0 as usize; - SIN[var0 & 65535] +pub fn cos(x: f32) -> f32 { + let x = x * 10430.378 + 16384.0; + let x = x as usize; + SIN[x & 65535] } // TODO: make this generic @@ -56,6 +56,10 @@ pub fn lerp(amount: T, a: T, b: T) -> T { a + amount * (b - a) } +pub fn ceil_log2(x: u32) -> u32 { + u32::BITS - x.leading_zeros() +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3