use crate::{air::VectorGridAir, VectorGrid}; impl VectorGrid { fn trim_left(&mut self) -> usize { let mut column_cut = 0; 'column: while column_cut + 1 < self.width.get() { let mut i = column_cut; while i < self.items.len() { if !self.items[i].is_air() { break 'column; } i += self.width.get() } column_cut += 1 } self.cut_columns(0..column_cut); column_cut } fn trim_right(&mut self) { let mut column_cut = self.width.get(); 'column: while column_cut > 1 { let mut i = column_cut - 1; while i < self.items.len() { if !self.items[i].is_air() { break 'column; } i += self.width.get(); } column_cut -= 1; } self.cut_columns(column_cut..self.width.get()); } fn trim_end(&mut self) { let mut i = self.items.len(); while i > 0 { i -= 1; if !self.items[i].is_air() { self.items.splice(i + 1..self.items.len(), []); return; } } } fn trim_start(&mut self) -> usize { let mut row_cut = 0; for tile in self.items.iter() { if !tile.is_air() { break; } row_cut += 1; } row_cut /= self.width.get(); self.items.splice(0..row_cut * self.width.get(), []); row_cut } pub fn trim(&mut self, transform: &mut Transform) { transform.translation += Vec3::new(self.trim_left() as f32, 0.0, 0.0); self.trim_right(); self.trim_end(); transform.translation += Vec3::new(0.0, self.trim_start() as f32, 0.0,); } }