1
0

rename point to vec2

This commit is contained in:
Rokas Puzonas 2023-06-11 16:40:16 +03:00
parent 861826d3ff
commit aff6457ce0
5 changed files with 26 additions and 29 deletions

View File

@ -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

View File

@ -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)

14
day9.c
View File

@ -4,7 +4,7 @@
#include <sys/param.h>
#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;
}
}

18
point.h
View File

@ -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_

15
vec2.h Normal file
View File

@ -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_