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
|
#include <stddef.h>
#include <math.h>
#include "tectonics.h"
#include "geometry.h"
#include "drawing.h"
void get_cairo_size(cairo_t *cr, int *width, int *height)
{
cairo_surface_t *surface = cairo_get_target(cr);
*width = cairo_image_surface_get_width(surface);
*height = cairo_image_surface_get_height(surface);
}
void draw_world(cairo_t *cr, struct world_t *world)
{
int width, height;
get_cairo_size(cr, &width, &height);
double r = ((double)width) / (100*sqrt(world->n_points));
cairo_set_source_rgba(cr, 1, 0, 0, 1);
for (int i=0; i<world->n_points; i++) {
struct point_t *pt = world->points + i;
double xc = pt->x * width;
double yc = pt->y * height;
cairo_arc(cr, xc, yc, r, 0, 2*M_PI);
cairo_stroke(cr);
}
//draw_quadtree(cr, &(world->tree));
}
void draw_quadtree(cairo_t *cr, struct quadtree_node_t *node)
{
int width, height;
get_cairo_size(cr, &width, &height);
cairo_set_source_rgba(cr, 0, 0, 1, 1);
struct point_t center = node->region.center;
double half_dim = node->region.half_dim;
double x = (center.x - half_dim) * width;
double y = (center.y - half_dim) * height;
cairo_rectangle(cr, x, y, 2*half_dim * width, 2*half_dim * height);
cairo_stroke(cr);
if (node->nw != NULL) {
draw_quadtree(cr, node->nw);
draw_quadtree(cr, node->ne);
draw_quadtree(cr, node->sw);
draw_quadtree(cr, node->se);
}
}
|