Files
terrin/src/include/geom.h
2026-01-03 11:05:21 -05:00

58 lines
944 B
C

#ifndef GEOM_H
#define GEOM_H
#include <raylib.h>
#include <stdbool.h>
#include <stdlib.h>
// 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