From 6b687b91e788b4e91a6ed30640a2477b9596b954 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 26 Jan 2022 02:32:06 -0600 Subject: refactor: move drawing functions into drawing.h/drawing.c --- experimental/tectonics/drawing.c | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 experimental/tectonics/drawing.c (limited to 'experimental/tectonics/drawing.c') diff --git a/experimental/tectonics/drawing.c b/experimental/tectonics/drawing.c new file mode 100644 index 0000000..91f873b --- /dev/null +++ b/experimental/tectonics/drawing.c @@ -0,0 +1,56 @@ +#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); + } +} -- cgit v1.2.1