fix rule rotation

This commit is contained in:
Crispy 2024-05-16 23:27:37 +02:00
parent 438efffaf3
commit 219c6521b3

View file

@ -252,30 +252,30 @@ impl Rule {
} }
if self.flip_x { if self.flip_x {
transform_variants(&mut self.variants, |b| { transform_variants(&mut self.variants, |base| {
let mut new = b.clone(); let mut new = base.clone();
for y in 0..new.height { for y in 0..new.height {
for x in 0..new.width { for x in 0..new.width {
let mut old = b.get(new.width - x - 1, y); let mut cell = base.get(new.width - x - 1, y);
if let (_, RuleCellTo::Copy(cx, _cy)) = &mut old { if let (_, RuleCellTo::Copy(cx, _cy)) = &mut cell {
*cx = new.width - *cx - 1; *cx = new.width - *cx - 1;
} }
new.set_both(x, y, old); new.set_both(x, y, cell);
} }
} }
new new
}); });
} }
if self.flip_y { if self.flip_y {
transform_variants(&mut self.variants, |b| { transform_variants(&mut self.variants, |base| {
let mut new = b.clone(); let mut new = base.clone();
for y in 0..new.height { for y in 0..new.height {
for x in 0..new.width { for x in 0..new.width {
let mut old = b.get(x, new.height - y - 1); let mut cell = base.get(x, new.height - y - 1);
if let (_, RuleCellTo::Copy(_cx, cy)) = &mut old { if let (_, RuleCellTo::Copy(_cx, cy)) = &mut cell {
*cy = new.height - *cy - 1; *cy = new.height - *cy - 1;
} }
new.set_both(x, y, old); new.set_both(x, y, cell);
} }
} }
new new
@ -283,32 +283,35 @@ impl Rule {
} }
if self.rotate { if self.rotate {
// 180° rotations (same as flipping x and y) // 180° rotations (same as flipping x and y)
transform_variants(&mut self.variants, |b| { transform_variants(&mut self.variants, |base| {
let mut new = b.clone(); let mut new = base.clone();
for y in 0..new.height { for y in 0..new.height {
for x in 0..new.width { for x in 0..new.width {
let mut old = b.get(new.width - x - 1, new.height - y - 1); let mut cell = base.get(new.width - x - 1, new.height - y - 1);
if let (_, RuleCellTo::Copy(cx, cy)) = &mut old { if let (_, RuleCellTo::Copy(cx, cy)) = &mut cell {
*cx = new.width - *cx - 1; let new_x = new.width - *cx - 1;
*cy = new.height - *cy - 1; let new_y = new.height - *cy - 1;
(*cx, *cy) = (new_x, new_y);
} }
new.set_both(x, y, old); new.set_both(x, y, cell);
} }
} }
new new
}); });
// 90° rotations // 90° rotations
transform_variants(&mut self.variants, |b| { transform_variants(&mut self.variants, |base| {
let mut new = b.clone(); let mut new = base.clone();
new.height = b.width; new.height = base.width;
new.width = b.height; new.width = base.height;
for y in 0..new.height { for y in 0..new.height {
for x in 0..new.width { for x in 0..new.width {
let mut old = b.get(y, x); let mut cell = base.get(y, new.width - x - 1);
if let (_, RuleCellTo::Copy(cx, cy)) = &mut old { if let (_, RuleCellTo::Copy(cx, cy)) = &mut cell {
(*cx, *cy) = (*cy, *cx); let new_x = new.height - *cy - 1;
let new_y = *cx;
(*cx, *cy) = (new_x, new_y);
} }
new.set_both(x, y, old); new.set_both(x, y, cell);
} }
} }
new new