rename point to vec2
This commit is contained in:
parent
861826d3ff
commit
aff6457ce0
2
Makefile
2
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
|
gcc -o main main.c -lcurl
|
||||||
|
|
||||||
run: main
|
run: main
|
||||||
|
6
day12.c
6
day12.c
@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
#include "aoc.h"
|
#include "aoc.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "point.h"
|
#include "vec2.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 *map;
|
u8 *map;
|
||||||
u32 width;
|
u32 width;
|
||||||
u32 height;
|
u32 height;
|
||||||
Point_u32 start;
|
vec2_u32 start;
|
||||||
Point_u32 end;
|
vec2_u32 end;
|
||||||
} day12_map;
|
} day12_map;
|
||||||
|
|
||||||
static void print_day12_map(day12_map *map)
|
static void print_day12_map(day12_map *map)
|
||||||
|
14
day9.c
14
day9.c
@ -4,7 +4,7 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include "aoc.h"
|
#include "aoc.h"
|
||||||
#include "point.h"
|
#include "vec2.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MOVE_DIR_UP,
|
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 diffx = abs(head->x - tail->x);
|
||||||
int diffy = abs(head->y - tail->y);
|
int diffy = abs(head->y - tail->y);
|
||||||
@ -137,8 +137,8 @@ static void day9_part1(void *p)
|
|||||||
}
|
}
|
||||||
map[ox][oy] = true;
|
map[ox][oy] = true;
|
||||||
|
|
||||||
Point head = { 0, 0 };
|
vec2 head = { 0, 0 };
|
||||||
Point tail = { 0, 0 };
|
vec2 tail = { 0, 0 };
|
||||||
for (int i = 0; i < moves->count; i++) {
|
for (int i = 0; i < moves->count; i++) {
|
||||||
RopeMove *move = &moves->moves[i];
|
RopeMove *move = &moves->moves[i];
|
||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0;
|
||||||
@ -177,7 +177,7 @@ static void day9_part2(void *p)
|
|||||||
map[ox][oy] = true;
|
map[ox][oy] = true;
|
||||||
|
|
||||||
int rope_size = 10;
|
int rope_size = 10;
|
||||||
Point rope[rope_size];
|
vec2 rope[rope_size];
|
||||||
for (int i = 0; i < rope_size; i++) {
|
for (int i = 0; i < rope_size; i++) {
|
||||||
rope[i].x = 0;
|
rope[i].x = 0;
|
||||||
rope[i].y = 0;
|
rope[i].y = 0;
|
||||||
@ -188,7 +188,7 @@ static void day9_part2(void *p)
|
|||||||
int dx = 0, dy = 0;
|
int dx = 0, dy = 0;
|
||||||
get_move_direction(move->dir, &dx, &dy);
|
get_move_direction(move->dir, &dx, &dy);
|
||||||
for (int _ = 0; _ < move->count; _++) {
|
for (int _ = 0; _ < move->count; _++) {
|
||||||
Point *head = &rope[0];
|
vec2 *head = &rope[0];
|
||||||
head->x += dx;
|
head->x += dx;
|
||||||
head->y += dy;
|
head->y += dy;
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ static void day9_part2(void *p)
|
|||||||
follow_point(&rope[j], &rope[j-1]);
|
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;
|
map[tail->x+ox][tail->y+oy] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
point.h
18
point.h
@ -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_
|
|
Loading…
Reference in New Issue
Block a user