From ad171e44eee88ac47d0d457cdc0db37d825176d6 Mon Sep 17 00:00:00 2001 From: ferris Date: Tue, 18 Nov 2025 16:39:51 +0100 Subject: [PATCH] Relax constraints for min_area/convex_hull to support f32/f64 --- src/geometry.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/geometry.rs b/src/geometry.rs index c904efdc..eef3811e 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -100,7 +100,7 @@ where /// The returned points are the [top left, top right, bottom right, bottom left] points of this rectangle. pub fn min_area_rect(points: &[Point]) -> [Point; 4] where - T: NumCast + Copy + Ord, + T: NumCast + Copy + PartialOrd, { let hull = convex_hull(points); match hull.len() { @@ -187,7 +187,7 @@ where /// [Graham scan algorithm]: https://en.wikipedia.org/wiki/Graham_scan pub fn convex_hull(points: impl Into>>) -> Vec> where - T: NumCast + Copy + Ord, + T: NumCast + Copy + PartialOrd, { let mut points = points.into(); if points.is_empty() { @@ -385,6 +385,25 @@ mod tests { ) } + #[test] + fn test_min_area_f32() { + assert_eq!( + min_area_rect(&[ + Point::new(100., 20.), + Point::new(140., 30.), + Point::new(130., 60.), + Point::new(80., 55.), + Point::new(60., 25.) + ]), + [ + Point::new(60., 16.), + Point::new(141., 24.), + Point::new(137., 61.), + Point::new(57., 53.) + ] + ) + } + #[test] fn test_contour_area() { let points = [