1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#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);
void free_tree(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
|