summaryrefslogtreecommitdiffstats
path: root/glow
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-09-15 15:08:35 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2021-09-15 15:08:35 +0700
commitc914b2a05be2c33ec936f63efd25daaf2b4c4739 (patch)
treeadd25c986ba0582628d921e45c2eae4006e19ee4 /glow
parent643500bbdf1a169db1bcdcb8e971334037274d38 (diff)
downloadiced-c914b2a05be2c33ec936f63efd25daaf2b4c4739.tar.gz
iced-c914b2a05be2c33ec936f63efd25daaf2b4c4739.tar.bz2
iced-c914b2a05be2c33ec936f63efd25daaf2b4c4739.zip
Use `Iterator::min_by` instead of `fold` in `hit_test`
Diffstat (limited to 'glow')
-rw-r--r--glow/src/text.rs24
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(&center_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) {