parry3d_f64/utils/weighted_value.rs
1use crate::math::Real;
2use core::cmp::Ordering;
3
4#[derive(Copy, Clone)]
5pub struct WeightedValue<T> {
6 pub value: T,
7 pub cost: Real,
8}
9
10impl<T> WeightedValue<T> {
11 /// Creates a new reference packed with a cost value.
12 #[inline]
13 pub fn new(value: T, cost: Real) -> WeightedValue<T> {
14 WeightedValue { value, cost }
15 }
16}
17
18impl<T> PartialEq for WeightedValue<T> {
19 #[inline]
20 fn eq(&self, other: &WeightedValue<T>) -> bool {
21 self.cost.eq(&other.cost)
22 }
23}
24
25impl<T> Eq for WeightedValue<T> {}
26
27impl<T> PartialOrd for WeightedValue<T> {
28 #[inline]
29 fn partial_cmp(&self, other: &WeightedValue<T>) -> Option<Ordering> {
30 Some(self.cmp(other))
31 }
32}
33
34impl<T> Ord for WeightedValue<T> {
35 #[inline]
36 fn cmp(&self, other: &WeightedValue<T>) -> Ordering {
37 if self.cost < other.cost {
38 Ordering::Less
39 } else if self.cost > other.cost {
40 Ordering::Greater
41 } else {
42 Ordering::Equal
43 }
44 }
45}