From 88265bbb2176dc29e17717abeed5e6ff1180b3b7 Mon Sep 17 00:00:00 2001 From: Ty Overby Date: Sun, 31 Dec 2017 15:17:16 -0800 Subject: [PATCH] from_points can take an iterator instead of just a slice --- rls1514761716760.log | 0 src/rect.rs | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 rls1514761716760.log diff --git a/rls1514761716760.log b/rls1514761716760.log new file mode 100644 index 0000000..e69de29 diff --git a/src/rect.rs b/src/rect.rs index b9b491a..fc86480 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -229,16 +229,23 @@ where T: Copy + Clone + Zero + PartialOrd + PartialEq + Add + Sub]) -> Self { - // TODO: it would be less confusing if we inflated the size by the smallest - // possible value for the given scalar type to avoid the confusion described - // above. - if points.is_empty() { + pub fn from_points<'a, I>(points: I) -> Self + where + U: 'a, + T: 'a, + I: IntoIterator> + { + let mut points = points.into_iter(); + + let first = if let Some(first) = points.next() { + first + } else { return TypedRect::zero(); - } - let (mut min_x, mut min_y) = (points[0].x, points[0].y); + }; + + let (mut min_x, mut min_y) = (first.x, first.y); let (mut max_x, mut max_y) = (min_x, min_y); - for point in &points[1..] { + for point in points{ if point.x < min_x { min_x = point.x }