From f8e3e50db5041fd753d0cb83a7cb1464725cc976 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 28 Mar 2014 12:48:13 -0700 Subject: [PATCH] util: Add a `rect_contains_point` utility method --- src/components/util/geometry.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/util/geometry.rs b/src/components/util/geometry.rs index e02bb8a6bb9..248ce1ba01e 100644 --- a/src/components/util/geometry.rs +++ b/src/components/util/geometry.rs @@ -300,3 +300,11 @@ pub fn to_pt(au: Au) -> f64 { (a as f64) / 60f64 * 72f64 / 96f64 } +/// Returns true if the rect contains the given point. Points on the top or left sides of the rect +/// are considered inside the rectangle, while points on the right or bottom sides of the rect are +/// not considered inside the rectangle. +pub fn rect_contains_point>(rect: Rect, point: Point2D) -> bool { + point.x >= rect.origin.x && point.x < rect.origin.x + rect.size.width && + point.y >= rect.origin.y && point.y < rect.origin.y + rect.size.height +} +