From 2d4e1bfc951745e82c7fe670dceda18fc94e86a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Fri, 9 Jan 2015 22:34:57 +0100 Subject: [PATCH] Fix warnings related to the POrd implementation. --- src/structs/pnt.rs | 2 +- src/structs/vec.rs | 2 +- src/structs/vec_macros.rs | 59 +++++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/structs/pnt.rs b/src/structs/pnt.rs index 49bcf7a1..528e4737 100644 --- a/src/structs/pnt.rs +++ b/src/structs/pnt.rs @@ -41,7 +41,7 @@ pub struct Pnt1 { new_impl!(Pnt1, x); orig_impl!(Pnt1, x); -ord_impl!(Pnt1, x); +ord_impl!(Pnt1, x,); scalar_mul_impl!(Pnt1, x); scalar_div_impl!(Pnt1, x); scalar_add_impl!(Pnt1, x); diff --git a/src/structs/vec.rs b/src/structs/vec.rs index 927799da..92181472 100644 --- a/src/structs/vec.rs +++ b/src/structs/vec.rs @@ -41,7 +41,7 @@ pub struct Vec1 { } new_impl!(Vec1, x); -ord_impl!(Vec1, x); +ord_impl!(Vec1, x,); vec_axis_impl!(Vec1, x); vec_cast_impl!(Vec1, x); as_array_impl!(Vec1, 1); diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 58b59f80..013e831b 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -78,74 +78,73 @@ macro_rules! at_fast_impl( // FIXME: N should be bounded by Ord instead of BaseFloat… // However, f32/f64 does not implement Ord… macro_rules! ord_impl( - ($t: ident, $($compN: ident),+) => ( + ($t: ident, $comp0: ident, $($compN: ident),*) => ( impl POrd for $t { #[inline] fn inf(&self, other: &$t) -> $t { - $t::new($(self.$compN.min(other.$compN)),+) + $t::new(self.$comp0.min(other.$comp0) + $(, self.$compN.min(other.$compN))*) } #[inline] fn sup(&self, other: &$t) -> $t { - $t::new($(self.$compN.max(other.$compN)),+) + $t::new(self.$comp0.max(other.$comp0) + $(, self.$compN.max(other.$compN))*) } #[inline] #[allow(unused_mut)] // otherwise there will be a warning for is_eq or Vec1. - fn partial_cmp(&self, other: &$t) -> POrdering { - let mut first = true; - let mut is_lt = false; - let mut is_eq = false; - $( - if first { - is_lt = self.$compN < other.$compN; - is_eq = self.$compN == other.$compN; - first = false; - } - else if is_lt { // < + fn partial_cmp(&self, other: &$t) -> POrdering { + let is_lt = self.$comp0 < other.$comp0; + let mut is_eq = self.$comp0 == other.$comp0; + + if is_lt { // < + $( if self.$compN > other.$compN { return POrdering::NotComparable } - } - else { // >= + )* + + POrdering::PartialLess + } + else { // >= + $( if self.$compN < other.$compN { return POrdering::NotComparable } else if self.$compN > other.$compN { is_eq = false; } + + )* + + if is_eq { + POrdering::PartialEqual + } + else { + POrdering::PartialGreater } - )+ - - if is_lt { - POrdering::PartialLess - } - else if is_eq { - POrdering::PartialEqual - } - else { - POrdering::PartialGreater } } #[inline] fn partial_lt(&self, other: &$t) -> bool { - $(self.$compN < other.$compN)&&+ + self.$comp0 < other.$comp0 $(&& self.$compN < other.$compN)* } #[inline] fn partial_le(&self, other: &$t) -> bool { - $(self.$compN <= other.$compN)&&+ + self.$comp0 <= other.$comp0 $(&& self.$compN <= other.$compN)* } #[inline] fn partial_gt(&self, other: &$t) -> bool { - $(self.$compN > other.$compN)&&+ + self.$comp0 > other.$comp0 $(&& self.$compN > other.$compN)* } #[inline] fn partial_ge(&self, other: &$t) -> bool { - $(self.$compN >= other.$compN)&&+ + self.$comp0 >= other.$comp0 $(&& self.$compN >= other.$compN)* } } )