add point functions
This commit is contained in:
parent
bc8e01fd6f
commit
bb3d890ad6
@ -13,6 +13,7 @@ set(SOURCES
|
||||
src/input.c
|
||||
src/math.c
|
||||
src/vector.c
|
||||
src/utility.c
|
||||
)
|
||||
|
||||
add_library(flint ${SOURCES})
|
||||
|
@ -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
|
||||
|
35
src/utility.c
Normal file
35
src/utility.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user