feat(math/polygon_tangents): Add unit tests for triangle case

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-05-30 21:32:00 +02:00
parent eff197d410
commit d1bcf22e96
1 changed files with 38 additions and 8 deletions

View File

@ -160,10 +160,10 @@ mod tests {
#[test] #[test]
fn petp00() { fn petp00() {
let poly_ext = &[ let poly_ext = &[
(point! { x: 0.0, y: 0.0 }, FixedDotIndex::new(0.into())), (point! { x: 0., y: 0. }, FixedDotIndex::new(0.into())),
(point! { x: 1.0, y: 0.0 }, FixedDotIndex::new(1.into())), (point! { x: 1., y: 0. }, FixedDotIndex::new(1.into())),
(point! { x: 1.0, y: 1.0 }, FixedDotIndex::new(2.into())), (point! { x: 1., y: 1. }, FixedDotIndex::new(2.into())),
(point! { x: 0.0, y: 1.0 }, FixedDotIndex::new(3.into())), (point! { x: 0., y: 1. }, FixedDotIndex::new(3.into())),
]; ];
let origin = point! { x: 0.5, y: -1.0 }; let origin = point! { x: 0.5, y: -1.0 };
assert_eq!( assert_eq!(
@ -175,10 +175,10 @@ mod tests {
#[test] #[test]
fn petp00cw() { fn petp00cw() {
let poly_ext = &[ let poly_ext = &[
(point! { x: 0.0, y: 0.0 }, FixedDotIndex::new(0.into())), (point! { x: 0., y: 0. }, FixedDotIndex::new(0.into())),
(point! { x: 0.0, y: 1.0 }, FixedDotIndex::new(3.into())), (point! { x: 0., y: 1. }, FixedDotIndex::new(3.into())),
(point! { x: 1.0, y: 1.0 }, FixedDotIndex::new(2.into())), (point! { x: 1., y: 1. }, FixedDotIndex::new(2.into())),
(point! { x: 1.0, y: 0.0 }, FixedDotIndex::new(1.into())), (point! { x: 1., y: 0. }, FixedDotIndex::new(1.into())),
]; ];
let origin = point! { x: 0.5, y: -1.0 }; let origin = point! { x: 0.5, y: -1.0 };
assert_eq!( assert_eq!(
@ -186,4 +186,34 @@ mod tests {
Ok((FixedDotIndex::new(1.into()), FixedDotIndex::new(0.into()))) 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())))
);
}
} }