clean up part1 helper fn
This commit is contained in:
parent
92b6b86197
commit
ca854d2cd3
1 changed files with 4 additions and 11 deletions
|
@ -49,16 +49,9 @@ fn new_tail(head: &Position, tail: &Position) -> Position {
|
||||||
let dy = head.1 - tail.1;
|
let dy = head.1 - tail.1;
|
||||||
let dx = head.0 - tail.0;
|
let dx = head.0 - tail.0;
|
||||||
match (dx, dy) {
|
match (dx, dy) {
|
||||||
(0, 0) => *tail,
|
(m, n) if m.abs() < 2 && n.abs() < 2 => *tail,
|
||||||
(n, m) if (n.abs() == 1) && (m.abs() == 1) => *tail,
|
(m, _) if m.abs() == 2 => (tail.0 + m / 2, tail.1 + dy),
|
||||||
(n, 0) | (0, n) if n.abs() == 1 => *tail,
|
(_, m) if m.abs() == 2 => (tail.0 + dx, tail.1 + m / 2),
|
||||||
(_, 2) | (_, -2) if dx.abs() == 1 => (tail.0 + dx, tail.1 + (dy / 2)),
|
_ => unreachable!(),
|
||||||
(2, y) | (-2, y) if y.abs() == 1 => {
|
|
||||||
let sign = dx / dx.abs();
|
|
||||||
(tail.0 + sign * (dx.abs() - 1), tail.1 + dy)
|
|
||||||
}
|
|
||||||
(n, _) if n.abs() == 2 => (tail.0 + n / 2, tail.1),
|
|
||||||
(_, n) if n.abs() == 2 => (tail.0, tail.1 + n / 2),
|
|
||||||
_ => unreachable!("got {:?}", (dx, dy)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue