Skip to content

Commit

Permalink
clippy and add things that i accidentally didn't commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Dec 15, 2023
1 parent 2c9d4f8 commit a94d795
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
6 changes: 3 additions & 3 deletions azalea-client/src/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn update_hit_result_component(
};
let instance = instance_lock.read();

let hit_result = pick(look_direction, &eye_position, &instance, pick_range);
let hit_result = pick(look_direction, &eye_position, &instance.chunks, pick_range);
if let Some(mut hit_result_ref) = hit_result_ref {
**hit_result_ref = hit_result;
} else {
Expand All @@ -212,13 +212,13 @@ pub fn update_hit_result_component(
pub fn pick(
look_direction: &LookDirection,
eye_position: &Vec3,
instance: &Instance,
chunks: &azalea_world::ChunkStorage,
pick_range: f64,
) -> BlockHitResult {
let view_vector = view_vector(look_direction);
let end_position = eye_position + &(view_vector * pick_range);
azalea_physics::clip::clip(
&instance.chunks,
chunks,
ClipContext {
from: *eye_position,
to: end_position,
Expand Down
28 changes: 24 additions & 4 deletions azalea-core/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub static SIN: LazyLock<[f32; 65536]> = LazyLock::new(|| {
/// A sine function that uses a lookup table.
pub fn sin(x: f32) -> f32 {
let x = x * 10430.378;
let x = x as usize;
SIN[x & 65535]
let x = x as i32 as usize & 65535;
SIN[x]
}

/// A cosine function that uses a lookup table.
pub fn cos(x: f32) -> f32 {
let x = x * 10430.378 + 16384.0;
let x = x as usize;
SIN[x & 65535]
let x = x as i32 as usize & 65535;
SIN[x]
}

// TODO: make this generic
Expand Down Expand Up @@ -83,4 +83,24 @@ mod tests {
assert_eq!(gcd(12, 7), 1);
assert_eq!(gcd(7, 12), 1);
}

#[test]
fn test_sin() {
const PI: f32 = std::f32::consts::PI;
// check that they're close enough
fn assert_sin_eq_enough(number: f32) {
let a = sin(number);
let b = f32::sin(number);
assert!((a - b).abs() < 0.01, "sin({number}) failed, {a} != {b}");
}
assert_sin_eq_enough(0.0);
assert_sin_eq_enough(PI / 2.0);
assert_sin_eq_enough(PI);
assert_sin_eq_enough(PI * 2.0);
assert_sin_eq_enough(PI * 3.0 / 2.0);
assert_sin_eq_enough(-PI / 2.0);
assert_sin_eq_enough(-PI);
assert_sin_eq_enough(-PI * 2.0);
assert_sin_eq_enough(-PI * 3.0 / 2.0);
}
}
1 change: 0 additions & 1 deletion azalea/src/pathfinder/goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::f32::consts::SQRT_2;

use azalea_core::position::{BlockPos, Vec3};
use azalea_entity::LookDirection;
use azalea_world::ChunkStorage;

use super::costs::{COST_HEURISTIC, FALL_N_BLOCKS_COST, JUMP_ONE_BLOCK_COST};
Expand Down

0 comments on commit a94d795

Please sign in to comment.