diff options
author | sanine <sanine.not@pm.me> | 2022-01-25 22:59:44 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-01-25 22:59:44 -0600 |
commit | 008cf63a05d7be6ed165747ec5e735e002de3b2d (patch) | |
tree | 024d04980a4f0cd6faa426939cfb60e9a3d7b6a3 /experimental/tectonics/tectonics.h | |
parent | ec20b587362d76d6c48ecc1a5c1e65f1bb9293da (diff) |
add quadtree and basic world model
Diffstat (limited to 'experimental/tectonics/tectonics.h')
-rw-r--r-- | experimental/tectonics/tectonics.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/experimental/tectonics/tectonics.h b/experimental/tectonics/tectonics.h new file mode 100644 index 0000000..5f39ff7 --- /dev/null +++ b/experimental/tectonics/tectonics.h @@ -0,0 +1,76 @@ +#ifndef TECTONICS_H +#define TECTONICS_H + +#include <stdlib.h> +#include <stdbool.h> +#include <cairo.h> + +struct point_t { + double x, y; + void *data; +}; + + +struct quad_region_t { + struct point_t center; + double half_dim; +}; + + +struct quadtree_node_t { + struct quad_region_t region; + + int id; + + /* children */ + struct quadtree_node_t *nw, *ne, *sw, *se; +}; + + +struct world_t { + struct point_t *points; + struct quadtree_node_t tree; + int n_points; +}; + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * quadtree + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +bool contains_point(struct quad_region_t region, struct point_t pt); +struct quadtree_node_t new_node(struct point_t center, double half_dim); +void subdivide(struct quadtree_node_t *node, struct point_t *points); +bool insert(struct quadtree_node_t *node, + struct point_t *points, int id); +int get_closest(struct quadtree_node_t *root, + struct point_t pt); +void draw_quadtree(cairo_t *cr, struct quadtree_node_t *root); + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * util + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +void get_cairo_size(cairo_t *cr, int *width, int *height); +double rand01(); +double distance(double x0, double y0, double x1, double y1); + + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * + * worlds + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +void create_world(struct world_t *world, int n_points); +void free_world(struct world_t *world); +void render_world(cairo_t *cr, struct world_t *world); +void run_world_step(struct world_t *world); + +#endif |