From be3a6444ec548d8764e51659008327b8dec78b35 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Fri, 23 May 2025 13:07:27 -0700 Subject: [PATCH] addressed review Signed-off-by: Ashwin Naren --- components/script/dom/htmlareaelement.rs | 1 + tests/unit/script/htmlareaelement.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index a342e0ab2dd..535d296a29f 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -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); diff --git a/tests/unit/script/htmlareaelement.rs b/tests/unit/script/htmlareaelement.rs index faa33c25940..becfd17b88a 100644 --- a/tests/unit/script/htmlareaelement.rs +++ b/tests/unit/script/htmlareaelement.rs @@ -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))); }