util: Add a rect_contains_point utility method

This commit is contained in:
Patrick Walton 2014-03-28 12:48:13 -07:00
parent dae4166eb3
commit f8e3e50db5

View file

@ -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<T:Ord + Add<T,T>>(rect: Rect<T>, point: Point2D<T>) -> 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
}