mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Add Rect::distance_to_pos
This commit is contained in:
@@ -317,6 +317,17 @@ impl Rect {
|
||||
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]
|
||||
pub fn distance_sq_to_pos(&self, pos: Pos2) -> f32 {
|
||||
let dx = if self.min.x > pos.x {
|
||||
|
||||
Reference in New Issue
Block a user