Compare commits
No commits in common. "1ca011f69c60903aff458d9862622536d5646b19" and "5e70a17a00a6a47e052e86cb8925dbd04167f4cb" have entirely different histories.
1ca011f69c
...
5e70a17a00
|
|
@ -297,12 +297,12 @@ impl TransferRegion {
|
||||||
let (s_ul, s_br) =
|
let (s_ul, s_br) =
|
||||||
standardize_rectangle(&source_corners.0, &source_corners.1);
|
standardize_rectangle(&source_corners.0, &source_corners.1);
|
||||||
let s_dims = (
|
let s_dims = (
|
||||||
s_br.row - s_ul.row + 1,
|
s_br.row.checked_sub(s_ul.row).unwrap() + 1,
|
||||||
s_br.col - s_ul.col + 1,
|
s_br.col.checked_sub(s_ul.col).unwrap() + 1,
|
||||||
);
|
);
|
||||||
let d_dims = (
|
let d_dims = (
|
||||||
d_br.row - d_ul.row + 1,
|
d_br.row.checked_sub(d_ul.row).unwrap() + 1,
|
||||||
d_br.col - d_ul.col + 1,
|
d_br.col.checked_sub(d_ul.col).unwrap() + 1,
|
||||||
);
|
);
|
||||||
let number_used_src_wells = (
|
let number_used_src_wells = (
|
||||||
// Number of used source wells
|
// Number of used source wells
|
||||||
|
|
@ -312,16 +312,31 @@ impl TransferRegion {
|
||||||
.div_euclid(il_source.1.unsigned_abs()),
|
.div_euclid(il_source.1.unsigned_abs()),
|
||||||
);
|
);
|
||||||
let count = (
|
let count = (
|
||||||
Self::calculate_replication_count(
|
// How many times can we replicate?
|
||||||
number_used_src_wells.0,
|
if il_dest.0.unsigned_abs() == 0 {
|
||||||
il_dest.0,
|
1
|
||||||
d_dims.0,
|
} else {
|
||||||
),
|
(1..)
|
||||||
Self::calculate_replication_count(
|
.position(|n| {
|
||||||
number_used_src_wells.1,
|
(n * number_used_src_wells.0 * il_dest.0.unsigned_abs())
|
||||||
il_dest.1,
|
.saturating_sub(il_dest.0.unsigned_abs())
|
||||||
d_dims.1,
|
+ 1
|
||||||
),
|
> d_dims.0
|
||||||
|
})
|
||||||
|
.unwrap() as u8
|
||||||
|
},
|
||||||
|
if il_dest.1.unsigned_abs() == 0 {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
(1..)
|
||||||
|
.position(|n| {
|
||||||
|
(n * number_used_src_wells.1 * il_dest.1.unsigned_abs())
|
||||||
|
.saturating_sub(il_dest.1.unsigned_abs())
|
||||||
|
+ 1
|
||||||
|
> d_dims.1
|
||||||
|
})
|
||||||
|
.unwrap() as u8
|
||||||
|
},
|
||||||
);
|
);
|
||||||
let i = i
|
let i = i
|
||||||
.saturating_sub(s_ul.row)
|
.saturating_sub(s_ul.row)
|
||||||
|
|
@ -339,25 +354,27 @@ impl TransferRegion {
|
||||||
Some(
|
Some(
|
||||||
possible_destination_wells
|
possible_destination_wells
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.filter(|Well { row: x, .. }| {
|
||||||
|
x.checked_sub(d_ul.row).unwrap()
|
||||||
|
% row_modulus // Counter along x
|
||||||
|
== (il_dest.0.unsigned_abs() *i)
|
||||||
|
% row_modulus
|
||||||
|
})
|
||||||
|
.filter(|Well { col: y, .. }| {
|
||||||
|
y.checked_sub(d_ul.col).unwrap()
|
||||||
|
% column_modulus // Counter along u
|
||||||
|
== (il_dest.1.unsigned_abs() *j)
|
||||||
|
% column_modulus
|
||||||
|
})
|
||||||
.filter(|Well { row: x, col: y }| {
|
.filter(|Well { row: x, col: y }| {
|
||||||
// Compute row and column offsets once
|
// How many times have we replicated? < How many are we allowed
|
||||||
let row_offset = x - d_ul.row;
|
// to replicate?
|
||||||
let col_offset = y - d_ul.col;
|
x.checked_sub(d_ul.row).unwrap().div_euclid(row_modulus)
|
||||||
|
|
||||||
// Row position check
|
|
||||||
let row_matches = row_offset % row_modulus
|
|
||||||
== (il_dest.0.unsigned_abs() * i) % row_modulus;
|
|
||||||
|
|
||||||
// Column position check
|
|
||||||
let col_matches = col_offset % column_modulus
|
|
||||||
== (il_dest.1.unsigned_abs() * j) % column_modulus;
|
|
||||||
|
|
||||||
// Replication limits check
|
|
||||||
let within_limits = row_offset.div_euclid(row_modulus)
|
|
||||||
< count.0
|
< count.0
|
||||||
&& col_offset.div_euclid(column_modulus) < count.1;
|
&& y.checked_sub(d_ul.col)
|
||||||
|
.unwrap()
|
||||||
row_matches && col_matches && within_limits
|
.div_euclid(column_modulus)
|
||||||
|
< count.1
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
|
|
@ -412,30 +429,6 @@ impl TransferRegion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calculate_replication_count(
|
|
||||||
number_of_source_wells: u8,
|
|
||||||
dest_interleave: i8,
|
|
||||||
dest_dimension: u8,
|
|
||||||
) -> u8 {
|
|
||||||
if dest_interleave == 0 {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the first position where the wells won't fit
|
|
||||||
// This tells us how many times we can replicate
|
|
||||||
(1..)
|
|
||||||
.position(|n| {
|
|
||||||
let wells_needed = {
|
|
||||||
// Calculate total wells needed for n replications
|
|
||||||
let total_wells = n * number_of_source_wells * dest_interleave.unsigned_abs();
|
|
||||||
// Adjust for interleaving offset and convert to actual position
|
|
||||||
total_wells.saturating_sub(dest_interleave.unsigned_abs()) + 1
|
|
||||||
};
|
|
||||||
wells_needed > dest_dimension
|
|
||||||
})
|
|
||||||
.unwrap() as u8
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn validate(&self) -> Result<(), &'static str> {
|
pub fn validate(&self) -> Result<(), &'static str> {
|
||||||
// Checks if the region does anything suspect
|
// Checks if the region does anything suspect
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue