From bb3d890ad645f0bae14a3232c4abd04d4deef74a Mon Sep 17 00:00:00 2001 From: Evan Burkey Date: Wed, 29 Nov 2023 14:01:41 -0800 Subject: [PATCH] add point functions --- CMakeLists.txt | 1 + include/lfutility.h | 6 ++++++ src/utility.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/utility.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f66843..77fecb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(SOURCES src/input.c src/math.c src/vector.c + src/utility.c ) add_library(flint ${SOURCES}) diff --git a/include/lfutility.h b/include/lfutility.h index 41d9b3e..9cf55b9 100644 --- a/include/lfutility.h +++ b/include/lfutility.h @@ -6,4 +6,10 @@ typedef struct Point { int y; } Point; +Point Point_new(int x, int y); +Point *Point_new_p(int x, int y); +int Point_cmp(Point a, Point b); +int Point_cmp_p(const Point *a, const Point *b); +int Point_cmp_v(const void *a, const void *b); + #endif // LIBFLINT_H_UTILITY diff --git a/src/utility.c b/src/utility.c new file mode 100644 index 0000000..9330ab2 --- /dev/null +++ b/src/utility.c @@ -0,0 +1,35 @@ +#include + +#include "lfutility.h" + +Point Point_new(int x, int y) { + Point p; + p.x = x; + p.y = y; + return p; +} + +Point *Point_new_p(int x, int y) { + Point *p = malloc(sizeof(struct Point)); + p->x = x; + p->y = y; + return p; +} +int Point_cmp(const Point a, const Point b) { + if (a.x == b.x && a.y == b.y) { + return 1; + } + return 0; +} + +int Point_cmp_p(const Point *a, const Point *b) { + if (a->x == b->x && a->y == b->y) { + return 1; + } + return 0; +} + +int Point_cmp_v(const void *a, const void *b) { + return Point_cmp_p(a, b); +} +