|
|
|
@ -464,24 +464,27 @@ where
|
|
|
|
|
self.ext_px |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn set_extension(&mut self, ext_px: u32) -> Option<Vec<Entity>> { |
|
|
|
|
pub fn set_extension(&mut self, mut ext_px: u32) -> Option<Vec<Entity>> { |
|
|
|
|
let entities = if ext_px < self.ext_px { |
|
|
|
|
let from = self.length_px - self.ext_px; |
|
|
|
|
let to = self.length_px - 1; |
|
|
|
|
self.probe(from, to, |_pos, _ent| ProbeAction::TakeRange) |
|
|
|
|
self.probe(0, self.ext_px - 1, |_pos, _ent| ProbeAction::TakeRange) |
|
|
|
|
} else { |
|
|
|
|
None |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
self.length_px -= self.ext_px; |
|
|
|
|
self.ext_px = ext_px; |
|
|
|
|
self.length_px += self.ext_px; |
|
|
|
|
if ext_px < self.ext_px { |
|
|
|
|
self.length_px -= self.ext_px; |
|
|
|
|
for (pos, _free, _ent) in self.contents.iter_mut() { |
|
|
|
|
assert!(*pos >= self.ext_px, "After the probe, this must not ever happen!"); |
|
|
|
|
*pos = (*pos).max(self.ext_px) - self.ext_px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if self.contents.len() > 0 { |
|
|
|
|
self.recalc_free_at(self.contents.len() - 1); |
|
|
|
|
self.ext_px = ext_px; |
|
|
|
|
self.prepend(ext_px); |
|
|
|
|
} else { |
|
|
|
|
self.prepend(ext_px - self.ext_px); |
|
|
|
|
self.ext_px = ext_px; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.clear_all_probes(); |
|
|
|
|
|
|
|
|
|
entities |
|
|
|
|
} |
|
|
|
@ -506,6 +509,7 @@ where
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
self.length_px += other.length_px; |
|
|
|
|
// TODO: Check!
|
|
|
|
|
self.ext_px += other.ext_px; |
|
|
|
|
|
|
|
|
|
if prev_len > 0 && (prev_len - 1) < self.contents.len() { |
|
|
|
@ -543,18 +547,6 @@ where
|
|
|
|
|
|
|
|
|
|
let split_len = (to - from) + 1; |
|
|
|
|
|
|
|
|
|
let to = if self.ext_px > 0 { |
|
|
|
|
// If we have an extension at the end, we need to extend the "to" range
|
|
|
|
|
// if it matches the actual end of the belt without the extension.
|
|
|
|
|
if to == ((self.length_px - 1) - self.ext_px) { |
|
|
|
|
to + self.ext_px |
|
|
|
|
} else { |
|
|
|
|
to |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
to |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let entities = self.probe(from, to, |_pos, _ent| ProbeAction::TakeRange); |
|
|
|
|
|
|
|
|
|
if from == 0 && to >= (self.length_px - 1) { |
|
|
|
@ -2770,22 +2762,170 @@ mod test {
|
|
|
|
|
fn check_transport_extension_merge_end_full() { |
|
|
|
|
let mut t1 = Transport::new(16); |
|
|
|
|
t1.append(16); |
|
|
|
|
t1.append_entity(941); |
|
|
|
|
assert!(t1.append_entity(941)); |
|
|
|
|
t1.set_extension(16); |
|
|
|
|
t1.append_entity(942); |
|
|
|
|
assert!(t1.insert_entity(0, 942)); |
|
|
|
|
let mut t2 = Transport::new(16); |
|
|
|
|
t2.append(16); |
|
|
|
|
t2.append_entity(841); |
|
|
|
|
t2.set_extension(16); |
|
|
|
|
t2.append_entity(842); |
|
|
|
|
t2.insert_entity(0, 842); |
|
|
|
|
|
|
|
|
|
assert_eq!(t1.dump_contents(), vec![(0, 0, 941), (16, 0, 942)]); |
|
|
|
|
assert_eq!(t1.dump_contents(), vec![(0, 0, 942), (16, 0, 941)]); |
|
|
|
|
t1.append_transport(&t2); |
|
|
|
|
assert_eq!( |
|
|
|
|
t1.dump_contents(), |
|
|
|
|
vec![(0, 0, 941), (16, 0, 942), (32, 0, 841), (48, 0, 842)] |
|
|
|
|
vec![(0, 0, 942), (16, 0, 941), (32, 0, 842), (48, 0, 841)] |
|
|
|
|
); |
|
|
|
|
assert_eq!(t1.length(), 64); |
|
|
|
|
assert_eq!(t1.extension_len(), 32); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_remove_items() { |
|
|
|
|
let mut t1 = Transport::new(16); |
|
|
|
|
t1.append(16); |
|
|
|
|
t1.append_entity(941); |
|
|
|
|
t1.set_extension(16); |
|
|
|
|
t1.insert_entity(0, 942); |
|
|
|
|
|
|
|
|
|
assert_eq!(t1.dump_contents(), vec![(0, 0, 942), (16, 0, 941)]); |
|
|
|
|
assert_eq!(t1.set_extension(0), Some(vec![942])); |
|
|
|
|
assert_eq!(t1.dump_contents(), vec![(0, 0, 941)]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_short_short() { |
|
|
|
|
let mut t1 = Transport::new(16); |
|
|
|
|
t1.append(16); |
|
|
|
|
t1.append_entity(941); |
|
|
|
|
t1.set_extension(16); |
|
|
|
|
t1.insert_entity(0, 942); |
|
|
|
|
|
|
|
|
|
assert_eq!(t1.set_extension(15), Some(vec![942])); |
|
|
|
|
assert_eq!(t1.dump_contents(), vec![(15, 0, 941)]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_short_longer() { |
|
|
|
|
let mut t1 = Transport::new(16); |
|
|
|
|
t1.append(16); |
|
|
|
|
t1.append_entity(941); |
|
|
|
|
t1.set_extension(16); |
|
|
|
|
t1.insert_entity(0, 942); |
|
|
|
|
|
|
|
|
|
assert_eq!(t1.dump_contents(), vec![(0, 0, 942), (16, 0, 941)]); |
|
|
|
|
assert_eq!(t1.set_extension(17), None); |
|
|
|
|
assert_eq!(t1.dump_contents(), vec![(1, 0, 942), (17, 0, 941)]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_split_mid_but_is_front() { |
|
|
|
|
let mut t = Transport::new(16); |
|
|
|
|
t.append(32); |
|
|
|
|
t.append_entity(941); |
|
|
|
|
t.append_entity(942); |
|
|
|
|
t.set_extension(16); |
|
|
|
|
t.insert_entity(0, 777); |
|
|
|
|
|
|
|
|
|
match t.split(16, 31) { |
|
|
|
|
SplitResult::CutMiddle(entities, r) => { |
|
|
|
|
assert_eq!(entities.expect("has some from split"), vec![941]); |
|
|
|
|
assert_eq!(t.dump_contents(), vec![(0, 0, 777)]); |
|
|
|
|
// TODO: Should the extension count or not? I think, the extension
|
|
|
|
|
// needs to be cropped too.
|
|
|
|
|
assert_eq!(t.length(), 16); |
|
|
|
|
assert_eq!(t.length_core(), 0); |
|
|
|
|
assert_eq!(r.dump_contents(), vec![(0, 0, 942)]); |
|
|
|
|
assert_eq!(r.length(), 0); |
|
|
|
|
assert_eq!(r.length_core(), 0); |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
assert!(false, "Expected CutMiddle") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_split_mid_real() { |
|
|
|
|
let mut t = Transport::new(16); |
|
|
|
|
t.append(48); |
|
|
|
|
t.append_entity(941); |
|
|
|
|
t.append_entity(942); |
|
|
|
|
t.append_entity(943); |
|
|
|
|
t.set_extension(16); |
|
|
|
|
t.insert_entity(0, 777); |
|
|
|
|
|
|
|
|
|
match t.split(32, 47) { |
|
|
|
|
SplitResult::CutMiddle(entities, r) => { |
|
|
|
|
assert_eq!(entities.expect("has some from split"), vec![942]); |
|
|
|
|
assert_eq!(t.dump_contents(), vec![(0, 0, 777), (16, 0, 941)]); |
|
|
|
|
assert_eq!(t.length(), 32); |
|
|
|
|
assert_eq!(t.length_core(), 16); |
|
|
|
|
assert_eq!(r.dump_contents(), vec![(0, 0, 943)]); |
|
|
|
|
assert_eq!(r.length(), 16); |
|
|
|
|
assert_eq!(r.length_core(), 16); |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
assert!(false, "Expected CutMiddle") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_split_front() { |
|
|
|
|
let mut t = Transport::new(16); |
|
|
|
|
t.append(32); |
|
|
|
|
t.append_entity(941); |
|
|
|
|
t.append_entity(942); |
|
|
|
|
t.set_extension(16); |
|
|
|
|
t.insert_entity(0, 777); |
|
|
|
|
|
|
|
|
|
match t.split(0, 15) { |
|
|
|
|
SplitResult::CropEnd(entities) => { |
|
|
|
|
assert_eq!(entities.expect("has some from split"), vec![454]); |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
assert!(false, "Expected CropEnd") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_split_back() { |
|
|
|
|
let mut t = Transport::new(16); |
|
|
|
|
t.append(32); |
|
|
|
|
t.append_entity(941); |
|
|
|
|
t.append_entity(942); |
|
|
|
|
t.set_extension(16); |
|
|
|
|
t.insert_entity(0, 777); |
|
|
|
|
|
|
|
|
|
match t.split(32, 47) { |
|
|
|
|
SplitResult::CropEnd(entities) => { |
|
|
|
|
assert_eq!(entities.expect("has some from split"), vec![454]); |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
assert!(false, "Expected CropEnd") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn check_transport_extension_split_all() { |
|
|
|
|
let mut t = Transport::new(16); |
|
|
|
|
t.append(32); |
|
|
|
|
t.append_entity(941); |
|
|
|
|
t.append_entity(942); |
|
|
|
|
t.set_extension(16); |
|
|
|
|
t.insert_entity(0, 777); |
|
|
|
|
|
|
|
|
|
match t.split(0, 47) { |
|
|
|
|
SplitResult::CropEnd(entities) => { |
|
|
|
|
assert_eq!(entities.expect("has some from split"), vec![454]); |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
assert!(false, "Expected CropEnd") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|