chiark / gitweb /
hidden: Refactor a bit in preparation for unnotched pieces fix
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 24 Apr 2022 23:41:55 +0000 (00:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 25 Apr 2022 00:31:17 +0000 (01:31 +0100)
In both of these places, we're going to want to do something if there
is an occultation but notch is None.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/hidden.rs

index 26784e4e3fd799225d566149f835a6755bb9e8df..e2b02ec10f8344e1d437b0ce571da84657356a16 100644 (file)
@@ -154,11 +154,12 @@ impl PieceOccult {
                              piece: PieceId) {
     if_chain! {
       if let Some(Passive { occid, permute_notch }) = self.passive;
-      if let Some(notch) = permute_notch;
       if let Some(occ) = goccults.occults.get_mut(occid);
       then {
-        occ.notches.remove(piece, notch)
-          .unwrap_or_else(|e| error!("removing occulted piece {:?}", e));
+        if let Some(notch) = permute_notch {
+          occ.notches.remove(piece, notch)
+            .unwrap_or_else(|e| error!("removing occulted piece {:?}", e));
+        }
       }
     }
   }
@@ -707,11 +708,14 @@ fn recalculate_occultation_general<
       to_recalculate.mark_dirty(occid);
       goccults.occults.get_mut(occid).unwrap()
     };
-    if let Some((occid, Some(old_notch))) = occulteds.old {
-      occultation(goccults, occid)
-        .notches
-        .remove(piece, old_notch)
-        .unwrap()
+    if let Some((occid, old_notch)) = occulteds.old {
+      let occ = occultation(goccults, occid);
+      if let Some(old_notch) = old_notch {
+        occ
+          .notches
+          .remove(piece, old_notch)
+          .unwrap();
+      }
     };
     let passive = if_chain!{
       if let Some(occid) = occulteds.new;