diff options
Diffstat (limited to 'glow/src')
| -rw-r--r-- | glow/src/text.rs | 24 | 
1 files changed, 11 insertions, 13 deletions
| diff --git a/glow/src/text.rs b/glow/src/text.rs index 4ebd7087..3b6f3bf5 100644 --- a/glow/src/text.rs +++ b/glow/src/text.rs @@ -187,20 +187,18 @@ impl Pipeline {              }          } -        let (idx, nearest) = bounds.fold( -            (None, iced_native::Point::ORIGIN), -            |best, (idx, bounds)| { -                let center = bounds.center(); - -                if center.distance(point) < best.1.distance(point) { -                    (Some(idx), center) -                } else { -                    best -                } -            }, -        ); +        let nearest = bounds +            .map(|(index, bounds)| (index, bounds.center())) +            .min_by(|(_, center_a), (_, center_b)| { +                center_a +                    .distance(point) +                    .partial_cmp(¢er_b.distance(point)) +                    .unwrap_or(std::cmp::Ordering::Greater) +            }); -        idx.map(|idx| Hit::NearestCharOffset(char_index(idx), point - nearest)) +        nearest.map(|(idx, center)| { +            Hit::NearestCharOffset(char_index(idx), point - center) +        })      }      pub fn trim_measurement_cache(&mut self) { | 
