# HG changeset patch # User alfadur # Date 1553722416 -10800 # Node ID 069291842d5263055a33936e8e4f430f51c80424 # Parent 2cc36cb1c25827847a69a1a183a8d4c05aff12dc fix atlas.insert_set diff -r 2cc36cb1c258 -r 069291842d52 rust/lib-hedgewars-engine/src/render/atlas.rs --- a/rust/lib-hedgewars-engine/src/render/atlas.rs Thu Mar 28 00:13:13 2019 +0300 +++ b/rust/lib-hedgewars-engine/src/render/atlas.rs Thu Mar 28 00:33:36 2019 +0300 @@ -127,8 +127,7 @@ .collect(); } - pub fn insert(&mut self, size: Size) -> Option { - let (rect, _) = self.find_position(size)?; + fn split_insert(&mut self, rect: Rect) { let mut splits = vec![]; for i in (0..self.free_rects.len()).rev() { @@ -136,10 +135,15 @@ self.free_rects.swap_remove(i as usize); } } + self.free_rects.extend(splits); self.prune(); + self.used_rects.push(rect); + } - self.used_rects.push(rect); + pub fn insert(&mut self, size: Size) -> Option { + let (rect, _) = self.find_position(size)?; + self.split_insert(rect); Some(rect) } @@ -156,15 +160,12 @@ .filter_map(|(i, s)| self.find_position(*s).map(|res| (i, res))) .min_by_key(|(_, (_, fit))| fit.clone()) { + self.split_insert(rect); + result.push(rect); sizes.swap_remove(index); } - if sizes.is_empty() { - self.used_rects.extend_from_slice(&result); - result - } else { - vec![] - } + result } pub fn reset(&mut self) {