diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-22 20:58:28 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-22 20:58:28 +0300 |
| commit | 092fbe195d22dfecb768c98f91b6ab733f1bb72f (patch) | |
| tree | 067b3d2f4b332a9b9b0456777cf9b9f3dccc8eb8 /path.c | |
| parent | 55b10d144a6855791f3918f37ccdf36fd8109e58 (diff) | |
| download | astar-092fbe195d22dfecb768c98f91b6ab733f1bb72f.tar.xz | |
Clean up path_reverse()
Diffstat (limited to 'path.c')
| -rw-r--r-- | path.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -332,6 +332,7 @@ void path_free(Path path, size_t height) { void path_reverse(Path *path, size_t width, size_t height, Position *start, Position *end) { Path new_path = path_new(width, height); + if (new_path == NULL) error("Failed to allocate path\n"); Position cur = *end; while (cur.x != start->x || cur.y != start->y) { @@ -341,16 +342,18 @@ void path_reverse(Path *path, size_t width, size_t height, Position *start, Posi } /* Switch start and end around */ - start->x = start->x ^ end->x; - end->x = start->x ^ end->x; - start->x = start->x ^ end->x; + start->x ^= end->x; + end->x ^= start->x; + start->x ^= end->x; - start->y = start->y ^ end->y; - end->y = start->y ^ end->y; - start->y = start->y ^ end->y; + start->y ^= end->y; + end->y ^= start->y; + start->y ^= end->y; path_free(*path, height); *path = new_path; + + return; } char **visited_new(size_t width, size_t height) { |
