From d1bcf22e96cc2d37fe9db6c30b1d80532741d523 Mon Sep 17 00:00:00 2001 From: Ellen Emilia Anna Zscheile Date: Fri, 30 May 2025 21:32:00 +0200 Subject: [PATCH] feat(math/polygon_tangents): Add unit tests for triangle case --- src/math/polygon_tangents.rs | 46 +++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/math/polygon_tangents.rs b/src/math/polygon_tangents.rs index 7d449e5..2ab1064 100644 --- a/src/math/polygon_tangents.rs +++ b/src/math/polygon_tangents.rs @@ -160,10 +160,10 @@ mod tests { #[test] fn petp00() { let poly_ext = &[ - (point! { x: 0.0, y: 0.0 }, FixedDotIndex::new(0.into())), - (point! { x: 1.0, y: 0.0 }, FixedDotIndex::new(1.into())), - (point! { x: 1.0, y: 1.0 }, FixedDotIndex::new(2.into())), - (point! { x: 0.0, y: 1.0 }, FixedDotIndex::new(3.into())), + (point! { x: 0., y: 0. }, FixedDotIndex::new(0.into())), + (point! { x: 1., y: 0. }, FixedDotIndex::new(1.into())), + (point! { x: 1., y: 1. }, FixedDotIndex::new(2.into())), + (point! { x: 0., y: 1. }, FixedDotIndex::new(3.into())), ]; let origin = point! { x: 0.5, y: -1.0 }; assert_eq!( @@ -175,10 +175,10 @@ mod tests { #[test] fn petp00cw() { let poly_ext = &[ - (point! { x: 0.0, y: 0.0 }, FixedDotIndex::new(0.into())), - (point! { x: 0.0, y: 1.0 }, FixedDotIndex::new(3.into())), - (point! { x: 1.0, y: 1.0 }, FixedDotIndex::new(2.into())), - (point! { x: 1.0, y: 0.0 }, FixedDotIndex::new(1.into())), + (point! { x: 0., y: 0. }, FixedDotIndex::new(0.into())), + (point! { x: 0., y: 1. }, FixedDotIndex::new(3.into())), + (point! { x: 1., y: 1. }, FixedDotIndex::new(2.into())), + (point! { x: 1., y: 0. }, FixedDotIndex::new(1.into())), ]; let origin = point! { x: 0.5, y: -1.0 }; assert_eq!( @@ -186,4 +186,34 @@ mod tests { Ok((FixedDotIndex::new(1.into()), FixedDotIndex::new(0.into()))) ); } + + #[test] + #[ignore = "https://codeberg.org/topola/topola/issues/238"] + fn triangle() { + let poly_ext = &[ + (point! { x: 0., y: 0. }, FixedDotIndex::new(0.into())), + (point! { x: 1., y: 1. }, FixedDotIndex::new(1.into())), + (point! { x: 0., y: 2. }, FixedDotIndex::new(2.into())), + ]; + let origin = point! { x: 2., y: 1. }; + assert_eq!( + petp(poly_ext, false, origin), + Ok((FixedDotIndex::new(2.into()), FixedDotIndex::new(0.into()))) + ); + } + + #[test] + #[ignore = "https://codeberg.org/topola/topola/issues/238"] + fn triangle_cw() { + let poly_ext = &[ + (point! { x: 0., y: 0. }, FixedDotIndex::new(0.into())), + (point! { x: 0., y: 2. }, FixedDotIndex::new(2.into())), + (point! { x: 1., y: 1. }, FixedDotIndex::new(1.into())), + ]; + let origin = point! { x: 2., y: 1. }; + assert_eq!( + petp(poly_ext, true, origin), + Ok((FixedDotIndex::new(2.into()), FixedDotIndex::new(0.into()))) + ); + } }