From e1e0f2b17519c5b65be7ca0855fcff2179e5b997 Mon Sep 17 00:00:00 2001 From: Phil Ellison Date: Sun, 19 May 2024 19:32:29 +0100 Subject: [PATCH] Add test for drawing line segment with zero length and remove dead code from intersection_points --- src/drawing/line.rs | 15 +++++++++++++++ src/hough.rs | 3 --- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/drawing/line.rs b/src/drawing/line.rs index d4fdc8a2..2d38b1d6 100644 --- a/src/drawing/line.rs +++ b/src/drawing/line.rs @@ -353,6 +353,21 @@ mod tests { // 3 / | \ 0 // / 2 | 1 \ + #[test] + fn test_draw_line_segment_zero_length() { + let image = GrayImage::from_pixel(5, 5, Luma([1u8])); + + let expected = gray_image!( + 1, 1, 1, 1, 1; + 4, 1, 1, 1, 1; + 1, 1, 1, 1, 1; + 1, 1, 1, 1, 1; + 1, 1, 1, 1, 1); + + let actual = draw_line_segment(&image, (0f32, 1f32), (0f32, 1f32), Luma([4u8])); + assert_pixels_eq!(actual, expected); + } + #[test] fn test_draw_line_segment_horizontal() { let image = GrayImage::from_pixel(5, 5, Luma([1u8])); diff --git a/src/hough.rs b/src/hough.rs index 87746aca..b6af7f8e 100644 --- a/src/hough.rs +++ b/src/hough.rs @@ -170,9 +170,6 @@ pub fn intersection_points( if right_y >= 0.0 && right_y <= h { let right_intersect = (w, right_y); - if let Some(s) = start { - return Some((s, right_intersect)); - } start = Some(right_intersect); }