Add Rect::distance_to_pos
This commit is contained in:
parent
038b3cf2e2
commit
d364dfac66
1 changed files with 11 additions and 0 deletions
|
@ -317,6 +317,17 @@ impl Rect {
|
||||||
self.width() * self.height()
|
self.width() * self.height()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The distance from the rect to the position.
|
||||||
|
///
|
||||||
|
/// The distance is zero when the position is in the interior of the rectangle.
|
||||||
|
#[inline]
|
||||||
|
pub fn distance_to_pos(&self, pos: Pos2) -> f32 {
|
||||||
|
self.distance_sq_to_pos(pos).sqrt()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The distance from the rect to the position, squared.
|
||||||
|
///
|
||||||
|
/// The distance is zero when the position is in the interior of the rectangle.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn distance_sq_to_pos(&self, pos: Pos2) -> f32 {
|
pub fn distance_sq_to_pos(&self, pos: Pos2) -> f32 {
|
||||||
let dx = if self.min.x > pos.x {
|
let dx = if self.min.x > pos.x {
|
||||||
|
|
Loading…
Reference in a new issue