mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-01 22:07:28 -06:00
Never crash: algo pyramids and ui-egui parity without expect (#40)
Three remaining expect() sites in files no open PR touches: algo::inpaint::complete and algo::pyramid::gaussian loop with while-let instead of levels.last().expect(), and ui-egui parity::compute indexes the menu it just pushed instead of last_mut().expect(). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1d832d3e84
commit
91ef877f2f
@@ -358,8 +358,7 @@ pub fn complete(w: usize, h: usize, ch: usize, img: &[f32], hole: &[bool], p: &C
|
||||
let mut levels = vec![Level { w, h, img: img.to_vec(), hole: hole.to_vec() }];
|
||||
let mut ext = (bx1 - bx0).max(by1 - by0);
|
||||
let mut exts = vec![ext];
|
||||
loop {
|
||||
let l = levels.last().expect("non-empty");
|
||||
while let Some(l) = levels.last() {
|
||||
if ext <= 2 * psz || l.w / 2 < 3 * psz || l.h / 2 < 3 * psz {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ pub fn expand(l: &Level, ch: usize, w: usize, h: usize) -> Vec<f32> {
|
||||
pub fn gaussian(w: usize, h: usize, ch: usize, px: &[f32], levels: usize) -> Vec<Level> {
|
||||
let mut out = vec![Level { w, h, px: px.to_vec() }];
|
||||
while out.len() < levels.max(1) {
|
||||
let last = out.last().expect("non-empty");
|
||||
let Some(last) = out.last() else { break };
|
||||
if last.w <= 1 && last.h <= 1 {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -62,13 +62,14 @@ pub fn compute() -> Parity {
|
||||
continue;
|
||||
}
|
||||
let top = path.first().copied().unwrap_or("?");
|
||||
let m = match menus.iter().position(|m| m.menu == top) {
|
||||
Some(i) => &mut menus[i],
|
||||
let i = match menus.iter().position(|m| m.menu == top) {
|
||||
Some(i) => i,
|
||||
None => {
|
||||
menus.push(MenuParity { menu: top.to_string(), live: 0, total: 0, missing: Vec::new() });
|
||||
menus.last_mut().expect("just pushed")
|
||||
menus.len() - 1
|
||||
}
|
||||
};
|
||||
let Some(m) = menus.get_mut(i) else { continue };
|
||||
m.total += 1;
|
||||
if is_live(id) {
|
||||
m.live += 1;
|
||||
|
||||
Reference in New Issue
Block a user