diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-12-15 11:26:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-15 11:26:40 -0600 |
| commit | a707e2eb82b74994a16083b31fa4576332cf1995 (patch) | |
| tree | db6c2ac94dd73590befd68a9b1b0ef960410b0df /azalea-core/src/math.rs | |
| parent | 59e140ddd655c7dc6e35109b91286118c51bcc06 (diff) | |
| download | azalea-drasl-a707e2eb82b74994a16083b31fa4576332cf1995.tar.xz | |
Add mining to the pathfinder (#122)
* basic pathfinder mining poc
* mining descending and autotool
* pathfinder mining descending
* pathfinder fixes
* allow disabling pathfinder miner and other fixes
* small optimization to avoid chunk vec iter lookup sometimes
* seeded rng in pathfinder bench
* consistently use f32::INFINITY
this brings performance much closer to how it was before
* astar heuristic optimization from baritone
* add downward_move
* fix downward move execute
* avoid liquids and falling blocks when mining
* fix COST_HEURISTIC
* fix to not path through flowing liquids
* only reset pathfinder timeout while mining if the block is close enough
* cache mining costs of block positions
* fix mine_while_at_start and move PathfinderDebugParticles to its own module
* add ReachBlockPosGoal
in other news: azalea's sin/cos functions were broken this whole time and i never noticed
* clippy and add things that i accidentally didn't commit
* improve wording on doc for azalea::pathfinder
Diffstat (limited to 'azalea-core/src/math.rs')
| -rw-r--r-- | azalea-core/src/math.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/azalea-core/src/math.rs b/azalea-core/src/math.rs index 83e6020e..aa9d88c8 100644 --- a/azalea-core/src/math.rs +++ b/azalea-core/src/math.rs @@ -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 @@ -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); + } } |
