voronoi
voronoi copied to clipboard
Access to the site by its index
Now, to get access to a separate site by its index, you need to either make a separate array sorted by site indexes, or use a chart search. Maybe there are other ways that I can't see?
I create an array where each entry is the index of the site with that site->index. A reverse lookup to "restore order".
uint32_t* restore_order = new uint32_t[my_diagram.numsites];
std::memset(restore_order, 0, my_diagram.numsites * sizeof(uint32_t));
{
const jcv_site* sites = jcv_diagram_get_sites(&my_diagram);
for (int i = 0; i < my_diagram.numsites; ++i)
{
const jcv_site* site = sites + i;
restore_order[site->index] = i;
}
}