(
rects: impl IntoIterator<Item = &'a T>,
point: Pos2,
transform: &PlotTransform,
)
| 30 | } |
| 31 | |
| 32 | pub fn find_closest_rect<'a, T>( |
| 33 | rects: impl IntoIterator<Item = &'a T>, |
| 34 | point: Pos2, |
| 35 | transform: &PlotTransform, |
| 36 | ) -> Option<ClosestElem> |
| 37 | where |
| 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 | } |
no test coverage detected