From 4248624ecbd4c8fe83b104d548a6adb821520813 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 25 Apr 2022 01:01:20 +0100 Subject: [PATCH] hidden: Fix handling of unnotched (Distinct) pieces We need to un-occult them. But we were tracking what to recompute by looking in occ.notches. Un-notched pieces aren't there. Introduce a new HashSet for these. Signed-off-by: Ian Jackson --- src/hidden.rs | 20 +++++++++++++++++--- src/prelude.rs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/hidden.rs b/src/hidden.rs index e2b02ec1..1dcdf43c 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -53,6 +53,7 @@ pub struct Occultation { region: Region, // automatically affect pieces here occulter: PieceId, // kept in synch with PieceOccult::active notches: Notches, // kept in synch with PieceOccult::passive + unnotched: HashSet, // kept in synch with PieceOccult::passive ppiece_use_size: Pos, // taken from first piece #[serde(flatten)] views: OccultationViews, } @@ -145,7 +146,7 @@ impl PieceOccult { -> Option { self.active_occ(goccults)?.map(|occ| { let notches_len = usize::try_from(occ.notches.len()).unwrap(); - notches_len + notches_len + occ.unnotched.len() }) } @@ -159,6 +160,8 @@ impl PieceOccult { if let Some(notch) = permute_notch { occ.notches.remove(piece, notch) .unwrap_or_else(|e| error!("removing occulted piece {:?}", e)); + } else { + occ.unnotched.remove(&piece); } } } @@ -247,7 +250,10 @@ impl Occultation { } pub fn pieces(&self) -> impl Iterator + '_ { - self.notches.iter() + chain!( + self.notches.iter(), + self.unnotched.iter().cloned(), + ) } } @@ -715,6 +721,10 @@ fn recalculate_occultation_general< .notches .remove(piece, old_notch) .unwrap(); + } else { + occ + .unnotched + .remove(&piece); } }; let passive = if_chain!{ @@ -724,7 +734,10 @@ fn recalculate_occultation_general< if let Some(ilk) = wants!( ipc.occilk.as_ref() ); then { let permute_notch = match ilk { - IOI::Distinct(_) => None, + IOI::Distinct(_) => { + occ.unnotched.insert(piece); + None + }, IOI::Mix(ilk) => { if_chain!{ if occ.notches.is_empty(); @@ -983,6 +996,7 @@ pub fn create_occultation( views, ppiece_use_size: PosC::zero(), notches: default(), + unnotched: default(), }; debug!("creating occultation {:?}", &occultation); trace_dbg!("recalc", &recalc); diff --git a/src/prelude.rs b/src/prelude.rs index 5e700633..20c0f970 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -73,7 +73,7 @@ pub use flexi_logger::LogSpecification; pub use fs2::FileExt; pub use if_chain::if_chain; pub use index_vec::{define_index_type, index_vec, IndexSlice, IndexVec}; -pub use itertools::{iproduct, izip, zip_eq, EitherOrBoth, Itertools}; +pub use itertools::{chain, iproduct, izip, zip_eq, EitherOrBoth, Itertools}; pub use lazy_static::lazy_static; pub use log::{debug, error, info, trace, warn}; pub use log::{log, log_enabled}; -- 2.30.2