mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
util: Add a rect_contains_point
utility method
This commit is contained in:
parent
dae4166eb3
commit
f8e3e50db5
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue