#include #include #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; in_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); } }