Skip to content

Commit 5b8c06e

Browse files
committed
Remove PartialOrd for Coordinate
Revert back to not deriving `PartialOrd`.
1 parent 9f1af54 commit 5b8c06e

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

geo-types/src/coordinate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use approx::{AbsDiffEq, RelativeEq, UlpsEq};
99
/// as an envelope, a precision model, and spatial reference system
1010
/// information), a `Coordinate` only contains ordinate values and accessor
1111
/// methods.
12-
#[derive(Eq, PartialEq, PartialOrd, Clone, Copy, Debug, Hash)]
12+
#[derive(Eq, PartialEq, Clone, Copy, Debug, Hash)]
1313
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1414
pub struct Coordinate<T>
1515
where

geo/src/utils.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Internal utility functions, types, and data structures.
22
33
use crate::contains::Contains;
4+
use geo_types::{CoordinateType, Coordinate};
45

56
/// Partition a mutable slice in-place so that it contains all elements for
67
/// which `predicate(e)` is `true`, followed by all elements for which
@@ -131,21 +132,14 @@ where
131132
/// other words, point with minimum `x` coord, and breaking
132133
/// ties with minimum `y` coord. Should only be called on a
133134
/// non-empty slice with no `nan` coordinates.
134-
pub fn lexicographically_least_index<T: Copy + PartialOrd>(pts: &[T]) -> usize {
135-
assert!(pts.len() > 0);
136-
137-
let mut min: Option<(usize, T)> = None;
138-
for (i, pt) in pts.iter().enumerate() {
139-
if let Some((_, min_pt)) = min {
140-
if pt < &min_pt {
141-
min = Some( (i, *pt) )
142-
}
143-
} else {
144-
min = Some( (i, *pt) )
145-
}
146-
}
135+
pub fn lexicographically_least_index<T: CoordinateType>(pts: &[Coordinate<T>]) -> usize {
136+
137+
pts.iter().enumerate().min_by(
138+
|(_, p), (_, q)| p.x.partial_cmp(&q.x).unwrap().then(
139+
p.y.partial_cmp(&q.y).unwrap()
140+
)
141+
).unwrap().0
147142

148-
min.unwrap().0
149143
}
150144

151145
#[cfg(test)]

0 commit comments

Comments
 (0)