From aff6457ce0803ab96b74d254e69c5e7a7924e33e Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sun, 11 Jun 2023 16:40:16 +0300 Subject: [PATCH] rename point to vec2 --- Makefile | 2 +- day12.c | 6 +++--- day9.c | 14 +++++++------- point.h | 18 ------------------ vec2.h | 15 +++++++++++++++ 5 files changed, 26 insertions(+), 29 deletions(-) delete mode 100644 point.h create mode 100644 vec2.h diff --git a/Makefile b/Makefile index 8c384d4..65e37ac 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -main: main.c day*.c vec.h aoc.h point.h +main: main.c day*.c vec.h aoc.h vec2.h types.h gcc -o main main.c -lcurl run: main diff --git a/day12.c b/day12.c index 743e9e7..34d4f25 100644 --- a/day12.c +++ b/day12.c @@ -5,14 +5,14 @@ #include "aoc.h" #include "types.h" -#include "point.h" +#include "vec2.h" typedef struct { u8 *map; u32 width; u32 height; - Point_u32 start; - Point_u32 end; + vec2_u32 start; + vec2_u32 end; } day12_map; static void print_day12_map(day12_map *map) diff --git a/day9.c b/day9.c index 7397d0a..370d185 100644 --- a/day9.c +++ b/day9.c @@ -4,7 +4,7 @@ #include #include "aoc.h" -#include "point.h" +#include "vec2.h" typedef enum { MOVE_DIR_UP, @@ -106,7 +106,7 @@ static void get_move_direction(MOVE_DIR dir, int *dx, int *dy) } } -static void follow_point(Point *tail, Point *head) +static void follow_point(vec2 *tail, vec2 *head) { int diffx = abs(head->x - tail->x); int diffy = abs(head->y - tail->y); @@ -137,8 +137,8 @@ static void day9_part1(void *p) } map[ox][oy] = true; - Point head = { 0, 0 }; - Point tail = { 0, 0 }; + vec2 head = { 0, 0 }; + vec2 tail = { 0, 0 }; for (int i = 0; i < moves->count; i++) { RopeMove *move = &moves->moves[i]; int dx = 0, dy = 0; @@ -177,7 +177,7 @@ static void day9_part2(void *p) map[ox][oy] = true; int rope_size = 10; - Point rope[rope_size]; + vec2 rope[rope_size]; for (int i = 0; i < rope_size; i++) { rope[i].x = 0; rope[i].y = 0; @@ -188,7 +188,7 @@ static void day9_part2(void *p) int dx = 0, dy = 0; get_move_direction(move->dir, &dx, &dy); for (int _ = 0; _ < move->count; _++) { - Point *head = &rope[0]; + vec2 *head = &rope[0]; head->x += dx; head->y += dy; @@ -196,7 +196,7 @@ static void day9_part2(void *p) follow_point(&rope[j], &rope[j-1]); } - Point *tail = &rope[rope_size-1]; + vec2 *tail = &rope[rope_size-1]; map[tail->x+ox][tail->y+oy] = true; } } diff --git a/point.h b/point.h deleted file mode 100644 index 4623b9f..0000000 --- a/point.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef POINT_H_ -#define POINT_H_ - -#include "types.h" - -typedef struct { - int x, y; -} Point; - -typedef struct { - u8 x, y; -} Point_u8; - -typedef struct { - u32 x, y; -} Point_u32; - -#endif //POINT_H_ diff --git a/vec2.h b/vec2.h new file mode 100644 index 0000000..6ff7f71 --- /dev/null +++ b/vec2.h @@ -0,0 +1,15 @@ +#ifndef VEC2_H_ +#define VEC2_H_ + +#include "types.h" + +typedef struct { + int x, y; +} vec2; + +#define TYPEDEF_VEC2(type) typedef struct { type x, y; } vec2_##type + +TYPEDEF_VEC2(u8); +TYPEDEF_VEC2(u32); + +#endif //VEC2_H_