#ifndef GEOM_H #define GEOM_H #include #include #include // The maximum number of Tris in a Plate. #define NTRI 4 // A two dimensional vector. typedef struct { int x; int y; } Vec2; typedef struct { int x, y; } Pt; typedef struct { Pt* a; Pt* b; } Edge; typedef struct { Pt a; Pt b; Pt c; } Tri; extern Tri* alltris[512]; extern size_t allsize; Tri* tri_init(Pt a, Pt b, Pt c); void tri_destroy(Tri* tri); // Check if a point is within the triangle. Uses barycentric coordinate system. bool tri_within(Pt pt, Tri* tri); // Get the center point of a Tri. Pt tri_center(Tri* tri); // Compare two points. int pt_cmp(const void* a, const void* b); // Get the convex hull around the area. Given the points in the area and their // number. Pt* cvx_hull(Pt* area, size_t n, size_t* out_n); typedef struct { Color col; size_t ntris; Tri* tris; } Plate; #endif