aboutsummaryrefslogtreecommitdiff
path: root/src/math/vec2.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/vec2.rs')
-rw-r--r--src/math/vec2.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/math/vec2.rs b/src/math/vec2.rs
index 7834ffc..2b33f7b 100644
--- a/src/math/vec2.rs
+++ b/src/math/vec2.rs
@@ -8,7 +8,7 @@ use std::convert::{From, Into};
use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign};
use std::{fmt, mem};
-#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Serialize, Deserialize, Eq)]
+#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq)]
pub struct Vec2<T: Scalar + Copy> {
pub x: T,
pub y: T,
@@ -19,7 +19,7 @@ impl<T: Scalar + Copy> Vec2<T> {
Self { x, y }
}
- pub fn len(&self) -> T
+ pub fn length(&self) -> T
where
T: RealField,
{
@@ -202,6 +202,18 @@ impl<T: Scalar + Div<Output = T> + Copy> Div<T> for Vec2<T> {
// By default, the coordinates are first compared by their y-coordinates, then
// their x-coordinates
+impl<T: fmt::Debug> PartialOrd for Vec2<T>
+where
+ T: PartialOrd + Copy + 'static,
+{
+ fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+ match self.y.partial_cmp(&other.y) {
+ Some(Ordering::Equal) | None => self.x.partial_cmp(&other.x),
+ y_order => y_order,
+ }
+ }
+}
+
impl<T: fmt::Debug> Ord for Vec2<T>
where
T: Ord + Copy + 'static,