Use Iterator::min_by instead of fold in hit_test
This commit is contained in:
parent
643500bbdf
commit
c914b2a05b
2 changed files with 22 additions and 26 deletions
|
|
@ -187,20 +187,18 @@ impl Pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
let (idx, nearest) = bounds.fold(
|
||||
(None, iced_native::Point::ORIGIN),
|
||||
|best, (idx, bounds)| {
|
||||
let center = bounds.center();
|
||||
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)
|
||||
});
|
||||
|
||||
if center.distance(point) < best.1.distance(point) {
|
||||
(Some(idx), center)
|
||||
} else {
|
||||
best
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -195,20 +195,18 @@ impl Pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
let (idx, nearest) = bounds.fold(
|
||||
(None, iced_native::Point::ORIGIN),
|
||||
|best, (idx, bounds)| {
|
||||
let center = bounds.center();
|
||||
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)
|
||||
});
|
||||
|
||||
if center.distance(point) < best.1.distance(point) {
|
||||
(Some(idx), center)
|
||||
} else {
|
||||
best
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue