1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Update MSRV to Rust 1.70.0 (#3310)

* Update to Rust 1.70

* Fix renamed clippy lint

* Use let-else more

* Code cleanup

* Remove derelict Safety comments

* Enable more clippy lints
This commit is contained in:
Emil Ernerfeldt
2023-09-06 07:59:24 +02:00
committed by GitHub
parent 707ca04c08
commit 82704bebbf
52 changed files with 102 additions and 87 deletions

View File

@@ -360,9 +360,17 @@ impl Rect {
/// Signed distance to the edge of the box.
///
/// Negative inside the box.
///
/// ```
/// # use emath::{pos2, Rect};
/// let rect = Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0));
/// assert_eq!(rect.signed_distance_to_pos(pos2(0.50, 0.50)), -0.50);
/// assert_eq!(rect.signed_distance_to_pos(pos2(0.75, 0.50)), -0.25);
/// assert_eq!(rect.signed_distance_to_pos(pos2(1.50, 0.50)), 0.50);
/// ```
pub fn signed_distance_to_pos(&self, pos: Pos2) -> f32 {
let edge_distances = (pos - self.center()).abs() - self.size() * 0.5;
let inside_dist = edge_distances.x.max(edge_distances.y).min(0.0);
let inside_dist = edge_distances.max_elem().min(0.0);
let outside_dist = edge_distances.max(Vec2::ZERO).length();
inside_dist + outside_dist
}