Example #1
0
void init_veronoi(SDL_Surface *s)
{
    kdtree_init(&tree, 2);

    int i;
    float pos[2];
    int *id = malloc(sizeof(int) * N_PLATES);
    for(i = 0; i < N_CELLS; i++){
        pos[0] = WIDTH * (abs(rand()) / (float) RAND_MAX);
        pos[1] = HEIGHT * (abs(rand()) / (float) RAND_MAX);
        if(i < N_PLATES)
        {
            id[i] = (i + 1);
            kdtree_insert(&tree, pos, &id[i]);
        } else 
        {
            int *closeid = kdtree_closest(&tree, pos, NULL);
            kdtree_insert(&tree, pos, closeid);
        }
    }
}
Example #2
0
//TODO: Maybe change this header to just have points and split to x and y here??
kdtree* kdtree_build(point2D *xpoints, point2D *ypoints, rect2D region, int n) {
  kdtree* tree = kdtree_init();
  tree->root = grow_tree(NULL, xpoints, ypoints, region, n);

  return tree;
}