diff --git a/petri/src/lib.rs b/petri/src/lib.rs index 52cd21a..4076dc3 100644 --- a/petri/src/lib.rs +++ b/petri/src/lib.rs @@ -24,7 +24,7 @@ pub struct Rule { // probability: u8 pub flip_h: bool, pub flip_v: bool, - // rotate: + pub rotate: bool, } #[derive(Debug, Clone, PartialEq)] @@ -93,6 +93,7 @@ impl Rule { variants: Vec::new(), flip_h: false, flip_v: false, + rotate: false, } } @@ -171,7 +172,7 @@ impl Rule { } } new - }) + }); } if self.flip_v { transform_variants(&mut self.variants, |b| { @@ -183,6 +184,32 @@ impl Rule { } } new + }); + } + if self.rotate { + // 180° rotations (same as flipping x and y) + transform_variants(&mut self.variants, |b| { + let mut new = b.clone(); + for y in 0..new.height { + for x in 0..new.width { + let old = b.get(new.width - x - 1, new.height - y - 1); + new.set_both(x, y, old); + } + } + new + }); + // 90° rotations + transform_variants(&mut self.variants, |b| { + let mut new = b.clone(); + new.height = b.width; + new.width = b.height; + for y in 0..new.height { + for x in 0..new.width { + let old = b.get(y, x); + new.set_both(x, y, old); + } + } + new }) } } diff --git a/uscope/src/main.rs b/uscope/src/main.rs index e8adc28..0e5f614 100644 --- a/uscope/src/main.rs +++ b/uscope/src/main.rs @@ -131,6 +131,9 @@ fn rule_editor(ui: &mut Ui, rule: &mut Rule, cells: &[CellData]) { if ui.checkbox(&mut rule.flip_v, "flip V").changed() { rule.generate_variants(); } + if ui.checkbox(&mut rule.rotate, "rotate").changed() { + rule.generate_variants(); + } let cells_y = rule.height(); let cells_x = rule.width();