chiark / gitweb /
ilks: Refactoring of passive computation
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 Apr 2022 17:41:09 +0000 (18:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 Apr 2022 18:00:24 +0000 (19:00 +0100)
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 <ijackson@chiark.greenend.org.uk>
src/hidden.rs

index 993c98e3401ec5f23416afa48695a1ce82cc1aa8..8dd0f8c6cd63172fac2c5361ab52c76184cbe668 100644 (file)
@@ -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