Explain runtime invariants and avoid redundant unwraps
This commit is contained in:
1 parent
34f2f07301
commit
1b51ba83b4
116 files changed
+1643
-515
No files matched your search
@@ -49,9 +49,9 @@ impl Geometry {
|
||||
fn from_values(values: [f64; COUNT]) -> Self {
|
||||
Self {
|
||||
bounds: Rect::new(values[0], values[1], values[2], values[3]),
|
||||
radii: values[4..8].try_into().unwrap(),
|
||||
margin: values[8..12].try_into().unwrap(),
|
||||
thickness: values[12..16].try_into().unwrap(),
|
||||
radii: [values[4], values[5], values[6], values[7]],
|
||||
margin: [values[8], values[9], values[10], values[11]],
|
||||
thickness: [values[12], values[13], values[14], values[15]],
|
||||
gap: values[16],
|
||||
fusion: values[17],
|
||||
}
|
||||
|
||||
@@ -211,10 +211,14 @@ pub fn notch_border(
|
||||
let mut paths = Vec::new();
|
||||
while let Some((a, b)) = segments.pop() {
|
||||
let mut path = vec![a, b];
|
||||
while let Some(index) = segments
|
||||
.iter()
|
||||
.position(|&(a, _)| close(a, *path.last().unwrap()))
|
||||
{
|
||||
while let Some(index) = segments.iter().position(|&(a, _)| {
|
||||
close(
|
||||
a,
|
||||
*path
|
||||
.last()
|
||||
.expect("an outline path starts with two points and only grows"),
|
||||
)
|
||||
}) {
|
||||
path.push(segments.swap_remove(index).1);
|
||||
}
|
||||
while let Some(index) = segments.iter().position(|&(_, b)| close(b, path[0])) {
|
||||
|
||||
@@ -183,10 +183,10 @@ pub fn resolve_with_gap(
|
||||
result.minimum_width = minimum.required_width();
|
||||
// Flexible content yields space without changing the stored item preference.
|
||||
for (_, item) in &candidates {
|
||||
let Some(measured) = measurements
|
||||
.get(&item.id)
|
||||
.filter(|measured| measured.minimum.is_some())
|
||||
else {
|
||||
let Some(measured) = measurements.get(&item.id) else {
|
||||
continue;
|
||||
};
|
||||
let Some(minimum) = measured.minimum else {
|
||||
continue;
|
||||
};
|
||||
if fits(&result) {
|
||||
@@ -199,7 +199,7 @@ pub fn resolve_with_gap(
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let minimum = measured.minimum.unwrap().min(width);
|
||||
let minimum = minimum.min(width);
|
||||
result.items.insert(
|
||||
measured.id.clone(),
|
||||
Placement::Visible {
|
||||
@@ -352,10 +352,14 @@ pub fn resolve_with_gap(
|
||||
let mut high = maximum;
|
||||
for _ in 0..20 {
|
||||
let width = (low + high) * 0.5;
|
||||
*result.items.get_mut(&measured.id).unwrap() = Placement::Visible {
|
||||
representation,
|
||||
width,
|
||||
};
|
||||
*result
|
||||
.items
|
||||
.get_mut(&measured.id)
|
||||
.expect("visible items retain their allocation during width refinement") =
|
||||
Placement::Visible {
|
||||
representation,
|
||||
width,
|
||||
};
|
||||
result.update_widths(panel, overflow_width);
|
||||
if fits(&result) {
|
||||
low = width
|
||||
@@ -363,14 +367,21 @@ pub fn resolve_with_gap(
|
||||
high = width
|
||||
}
|
||||
}
|
||||
*result.items.get_mut(&measured.id).unwrap() = Placement::Visible {
|
||||
representation,
|
||||
width: low,
|
||||
};
|
||||
*result
|
||||
.items
|
||||
.get_mut(&measured.id)
|
||||
.expect("visible items retain their allocation during width refinement") =
|
||||
Placement::Visible {
|
||||
representation,
|
||||
width: low,
|
||||
};
|
||||
}
|
||||
result
|
||||
.overflow
|
||||
.sort_by_key(|id| ordered.iter().position(|item| &item.id == id).unwrap());
|
||||
result.overflow.sort_by_key(|id| {
|
||||
ordered
|
||||
.iter()
|
||||
.position(|item| &item.id == id)
|
||||
.expect("overflow contains only authored item IDs")
|
||||
});
|
||||
result.update_widths(panel, overflow_width);
|
||||
result
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user