mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-03 07:15:29 -04:00
grid: swap_row: drop requirement that row indices be positive
This commit is contained in:
parent
4ffd93ca4c
commit
379f7cf646
1 changed files with 3 additions and 2 deletions
5
grid.c
5
grid.c
|
|
@ -12,12 +12,13 @@ grid_swap_row(struct grid *grid, int row_a, int row_b)
|
||||||
{
|
{
|
||||||
assert(grid->offset >= 0);
|
assert(grid->offset >= 0);
|
||||||
assert(row_a != row_b);
|
assert(row_a != row_b);
|
||||||
assert(row_a >= 0);
|
|
||||||
assert(row_b >= 0);
|
|
||||||
|
|
||||||
int real_a = (grid->offset + row_a + grid->num_rows) % grid->num_rows;
|
int real_a = (grid->offset + row_a + grid->num_rows) % grid->num_rows;
|
||||||
int real_b = (grid->offset + row_b + grid->num_rows) % grid->num_rows;
|
int real_b = (grid->offset + row_b + grid->num_rows) % grid->num_rows;
|
||||||
|
|
||||||
|
assert(real_a >= 0);
|
||||||
|
assert(real_b >= 0);
|
||||||
|
|
||||||
struct row *tmp = grid->rows[real_a];
|
struct row *tmp = grid->rows[real_a];
|
||||||
grid->rows[real_a] = grid->rows[real_b];
|
grid->rows[real_a] = grid->rows[real_b];
|
||||||
grid->rows[real_b] = tmp;
|
grid->rows[real_b] = tmp;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue