addressed review

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This commit is contained in:
Ashwin Naren 2025-05-23 13:07:27 -07:00
parent e8577efb56
commit be3a6444ec
No known key found for this signature in database
GPG key ID: D96D7DE56FBCB6B6
2 changed files with 7 additions and 0 deletions

View file

@ -207,6 +207,7 @@ impl Area {
Area::Polygon { ref points } => {
// Ray-casting algorithm to determine if point is inside polygon
// https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm
let mut inside = false;
debug_assert!(points.len() % 2 == 0);

View file

@ -196,4 +196,10 @@ fn test_hit_test_polygon() {
assert!(!poly3.hit_test(&Point2D::new(6.0, 0.0)));
assert!(!poly3.hit_test(&Point2D::new(0.0, 6.0)));
assert!(!poly3.hit_test(&Point2D::new(6.0, 6.0)));
// Concave polygon test
let poly4 = Area::Polygon {
points: vec![0.0, 0.0, 1.0, 1.0, 2.0, 0.0, 2.0, 2.0, 0.0, 2.0],
};
assert!(poly4.hit_test(&Point2D::new(1.5, 1.5)));
assert!(!poly4.hit_test(&Point2D::new(1.0, 0.0)));
}