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(
|
let nearest = bounds
|
||||||
(None, iced_native::Point::ORIGIN),
|
.map(|(index, bounds)| (index, bounds.center()))
|
||||||
|best, (idx, bounds)| {
|
.min_by(|(_, center_a), (_, center_b)| {
|
||||||
let center = bounds.center();
|
center_a
|
||||||
|
.distance(point)
|
||||||
|
.partial_cmp(¢er_b.distance(point))
|
||||||
|
.unwrap_or(std::cmp::Ordering::Greater)
|
||||||
|
});
|
||||||
|
|
||||||
if center.distance(point) < best.1.distance(point) {
|
nearest.map(|(idx, center)| {
|
||||||
(Some(idx), center)
|
Hit::NearestCharOffset(char_index(idx), point - center)
|
||||||
} else {
|
})
|
||||||
best
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
idx.map(|idx| Hit::NearestCharOffset(char_index(idx), point - nearest))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trim_measurement_cache(&mut self) {
|
pub fn trim_measurement_cache(&mut self) {
|
||||||
|
|
|
||||||
|
|
@ -195,20 +195,18 @@ impl Pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (idx, nearest) = bounds.fold(
|
let nearest = bounds
|
||||||
(None, iced_native::Point::ORIGIN),
|
.map(|(index, bounds)| (index, bounds.center()))
|
||||||
|best, (idx, bounds)| {
|
.min_by(|(_, center_a), (_, center_b)| {
|
||||||
let center = bounds.center();
|
center_a
|
||||||
|
.distance(point)
|
||||||
|
.partial_cmp(¢er_b.distance(point))
|
||||||
|
.unwrap_or(std::cmp::Ordering::Greater)
|
||||||
|
});
|
||||||
|
|
||||||
if center.distance(point) < best.1.distance(point) {
|
nearest.map(|(idx, center)| {
|
||||||
(Some(idx), center)
|
Hit::NearestCharOffset(char_index(idx), point - center)
|
||||||
} else {
|
})
|
||||||
best
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
idx.map(|idx| Hit::NearestCharOffset(char_index(idx), point - nearest))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trim_measurement_cache(&mut self) {
|
pub fn trim_measurement_cache(&mut self) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue