MCPcopy Create free account
hub / github.com/emilk/egui_plot / find_closest_rect

Function find_closest_rect

egui_plot/src/math.rs:32–50  ·  view source on GitHub ↗
(
    rects: impl IntoIterator<Item = &'a T>,
    point: Pos2,
    transform: &PlotTransform,
)

Source from the content-addressed store, hash-verified

30}
31
32pub fn find_closest_rect<'a, T>(
33 rects: impl IntoIterator<Item = &'a T>,
34 point: Pos2,
35 transform: &PlotTransform,
36) -> Option<ClosestElem>
37where
38 T: 'a + RectElement,
39{
40 rects
41 .into_iter()
42 .enumerate()
43 .map(|(index, bar)| {
44 let bar_rect = transform.rect_from_values(&bar.bounds_min(), &bar.bounds_max());
45 let dist_sq = bar_rect.distance_sq_to_pos(point);
46
47 ClosestElem { index, dist_sq }
48 })
49 .min_by_key(|e| e.dist_sq.ord())
50}

Callers 2

find_closestMethod · 0.85
find_closestMethod · 0.85

Calls 3

rect_from_valuesMethod · 0.80
bounds_minMethod · 0.45
bounds_maxMethod · 0.45

Tested by

no test coverage detected