From: Ian Jackson Date: Sun, 17 Apr 2022 17:41:09 +0000 (+0100) Subject: ilks: Refactoring of passive computation X-Git-Tag: otter-1.1.0~510 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=6b4d4230f3ef6991e0a8de82644d0cadb1f3c32d;p=otter.git ilks: Refactoring of passive computation Use if_chain instead of the outer if let. This is good because we're going to want to add another condition. Signed-off-by: Ian Jackson --- diff --git a/src/hidden.rs b/src/hidden.rs index 993c98e3..8dd0f8c6 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -692,22 +692,26 @@ fn recalculate_occultation_general< .remove(piece, old_notch) .unwrap() }; - let passive = if let Some(occid) = occulteds.new { + let passive = if_chain!{ + if let Some(occid) = occulteds.new; let zg = gen.next(); let occ = occultation(goccults, occid); - if_chain!{ - if occ.notches.is_empty(); - if let Some(ilk) = wants!( ipc.occilk.as_ref() ); - if let Some(ilk) = wants!( ioccults.ilks.get(ilk) ); - if let Some(bbox) = want!( Ok = ilk.p_occ.bbox_approx() ); - if let Some(size) = want!( Ok = bbox.br() - bbox.tl(), ?(bbox) ); - then { occ.ppiece_use_size = size; } - }; - let notch = occ.notches - .insert(zg, piece); - Some(Passive { occid, notch }) - } else { - None + then { + if_chain!{ + if occ.notches.is_empty(); + if let Some(ilk) = wants!( ipc.occilk.as_ref() ); + if let Some(ilk) = wants!( ioccults.ilks.get(ilk) ); + if let Some(bbox) = want!( Ok = ilk.p_occ.bbox_approx() ); + if let Some(size) = want!( Ok = bbox.br() - bbox.tl(), ?(bbox) ); + then { occ.ppiece_use_size = size; } + }; + let notch = occ.notches + .insert(zg, piece); + Some(Passive { occid, notch }) + } + else { + None + } }; gpieces.byid_mut(piece).unwrap().occult.passive = passive; })(); // <- no ?, infallible commitment