From 6ccd44e28d29a33abb32a0d0bed466dce8d61676 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 27 Dec 2024 06:56:58 +0000 Subject: better astar WeightedNode::cmp --- azalea/src/pathfinder/astar.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'azalea/src/pathfinder') diff --git a/azalea/src/pathfinder/astar.rs b/azalea/src/pathfinder/astar.rs index cd3ee119..c36ea790 100644 --- a/azalea/src/pathfinder/astar.rs +++ b/azalea/src/pathfinder/astar.rs @@ -277,28 +277,25 @@ impl Clone for Movement { #[derive(PartialEq)] pub struct WeightedNode { index: usize, + /// The actual cost to get to this node g_score: f32, + /// Sum of the g_score and heuristic f_score: f32, } impl Ord for WeightedNode { + #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { // intentionally inverted to make the BinaryHeap a min-heap - match other - .f_score - .partial_cmp(&self.f_score) - .unwrap_or(cmp::Ordering::Equal) - { - cmp::Ordering::Equal => self - .g_score - .partial_cmp(&other.g_score) - .unwrap_or(cmp::Ordering::Equal), + match other.f_score.total_cmp(&self.f_score) { + cmp::Ordering::Equal => self.g_score.total_cmp(&other.g_score), s => s, } } } impl Eq for WeightedNode {} impl PartialOrd for WeightedNode { + #[inline] fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } -- cgit v1.2.3