From 32dd3814af03a85d15fc403f7615c14a63a97194 Mon Sep 17 00:00:00 2001 From: Emilia Date: Thu, 25 May 2023 12:29:17 -0400 Subject: [PATCH] Allow changing source interleave ... and of course a fix to the replicate math with a source interleave. --- src/components/transfer_menu.rs | 45 +++++++++++++++++++++++++++++++-- src/data/transfer_region.rs | 15 ++++++----- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/components/transfer_menu.rs b/src/components/transfer_menu.rs index a1f1110..5fb6f50 100644 --- a/src/components/transfer_menu.rs +++ b/src/components/transfer_menu.rs @@ -53,6 +53,36 @@ pub fn TransferMenu() -> Html { }) }; + let on_source_interleave_x_change = { + let ct_dispatch = ct_dispatch.clone(); + + Callback::from(move |e: Event| { + let target: Option = e.target(); + let input = target.and_then(|t| t.dyn_into::().ok()); + if let Some(input) = input { + if let Ok(num) = input.value().parse::() { + ct_dispatch.reduce_mut(|state| { + state.transfer.interleave_source = (num, state.transfer.interleave_source.1); + }); + } + } + }) + }; + let on_source_interleave_y_change = { + let ct_dispatch = ct_dispatch.clone(); + + Callback::from(move |e: Event| { + let target: Option = e.target(); + let input = target.and_then(|t| t.dyn_into::().ok()); + if let Some(input) = input { + if let Ok(num) = input.value().parse::() { + ct_dispatch.reduce_mut(|state| { + state.transfer.interleave_source = (state.transfer.interleave_source.0, num); + }); + } + } + }) + }; let on_dest_interleave_x_change = { let ct_dispatch = ct_dispatch.clone(); @@ -100,11 +130,22 @@ pub fn TransferMenu() -> Html { value={RegionDisplay::from(&ct_state.transfer.dest_region).text}/>
+ {"Source Interleave "} + + + + +
+
{"Destination Interleave "} - + - +
diff --git a/src/data/transfer_region.rs b/src/data/transfer_region.rs index 6ada926..fae8f9e 100644 --- a/src/data/transfer_region.rs +++ b/src/data/transfer_region.rs @@ -157,20 +157,23 @@ impl TransferRegion { d_br.1.checked_sub(d_ul.1).unwrap() + 1, ); let N_s = ( // Number of used source wells - s_dims.0.div_euclid(il_source.0.abs() as u8), - s_dims.1.div_euclid(il_source.1.abs() as u8), + (s_dims.0 + il_source.0.abs() as u8 - 1).div_euclid(il_source.0.abs() as u8), + (s_dims.1 + il_source.1.abs() as u8 - 1).div_euclid(il_source.1.abs() as u8), ); let D_per_replicate = ( // How many wells are used per replicate? - (s_dims.0 * (il_dest.0.abs() as u8)) + (N_s.0 * (il_dest.0.abs() as u8)) // Conditionally subtract one to ignore the trailing interleave well .saturating_sub(if il_dest.0.abs() > 1 {1} else {0}), - (s_dims.1 * (il_dest.1.abs() as u8)) + (N_s.1 * (il_dest.1.abs() as u8)) .saturating_sub(if il_dest.1.abs() > 1 {1} else {0}), ); let count = ( // How many times can we replicate? d_dims.0.div_euclid(D_per_replicate.0), d_dims.1.div_euclid(D_per_replicate.1), ); + let i = i.saturating_sub(s_ul.0).saturating_div(il_source.0.abs() as u8); + let j = j.saturating_sub(s_ul.1).saturating_div(il_source.1.abs() as u8); + log::debug!("s_dims: {:?}, N_s: {:?}", s_dims, N_s); Some( possible_destination_wells @@ -178,13 +181,13 @@ impl TransferRegion { .filter(|(x, _)| { x.checked_sub(d_ul.0).unwrap() % (N_s.0 * il_dest.0.abs() as u8) // Counter along x - == ((il_dest.0.abs() as u8 *(i).checked_sub(1u8).unwrap())) + == ((il_dest.0.abs() as u8 *i)) % (N_s.0 * il_dest.0.abs() as u8) }) .filter(|(_, y)| { y.checked_sub(d_ul.1).unwrap() % (N_s.1 * il_dest.1.abs() as u8) // Counter along u - == ((il_dest.1.abs() as u8 *(j).checked_sub(1u8).unwrap())) + == ((il_dest.1.abs() as u8 *j)) % (N_s.1 * il_dest.1.abs() as u8) }) .filter(|(x,y)| {