mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10:03 -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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user