mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
better astar WeightedNode::cmp
This commit is contained in:
parent
185ed84dbb
commit
6ccd44e28d
2 changed files with 7 additions and 10 deletions
|
@ -271,7 +271,7 @@ impl Vec3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The coordinates of a block in the world. For entities (if the coordinate
|
/// The coordinates of a block in the world. For entities (if the coordinate
|
||||||
/// with decimals), use [`Vec3`] instead.
|
/// have decimals), use [`Vec3`] instead.
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub struct BlockPos {
|
pub struct BlockPos {
|
||||||
|
|
|
@ -277,28 +277,25 @@ impl<P: Hash + Copy + Clone, M: Clone> Clone for Movement<P, M> {
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct WeightedNode {
|
pub struct WeightedNode {
|
||||||
index: usize,
|
index: usize,
|
||||||
|
/// The actual cost to get to this node
|
||||||
g_score: f32,
|
g_score: f32,
|
||||||
|
/// Sum of the g_score and heuristic
|
||||||
f_score: f32,
|
f_score: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for WeightedNode {
|
impl Ord for WeightedNode {
|
||||||
|
#[inline]
|
||||||
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||||
// intentionally inverted to make the BinaryHeap a min-heap
|
// intentionally inverted to make the BinaryHeap a min-heap
|
||||||
match other
|
match other.f_score.total_cmp(&self.f_score) {
|
||||||
.f_score
|
cmp::Ordering::Equal => self.g_score.total_cmp(&other.g_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),
|
|
||||||
s => s,
|
s => s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Eq for WeightedNode {}
|
impl Eq for WeightedNode {}
|
||||||
impl PartialOrd for WeightedNode {
|
impl PartialOrd for WeightedNode {
|
||||||
|
#[inline]
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||||
Some(self.cmp(other))
|
Some(self.cmp(other))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue