#include #include #include #include #include #include #include #include #define NSITES 1000 #define NORMAL 1 void srandom(int); int random(void); float frandom(void); void makesites(void); void plot_delaunay (edge_ref e); void draw_delaunay_edge (edge_ref e, void *closure); int main(void); site_struct sites[NSITES]; void makesites() { int i, j; float s, t; srandom(4615); if (NORMAL) { /* central limit approx to normal distribuition: */ for (i=0; i < NSITES; i++) { s = t = 0.0; for (j=0; j<9; j++) { s += frandom() - 0.5; t += frandom() - 0.5; } sites[i].x = s; sites[i].y = t; } } else { /* uniform distribution: */ for (i=0; ix, op->y, dp->x, dp->y); } void plot_delaunay (edge_ref e) { float xmin = -6.0; float xmax = +6.0; float ymin = -6.0; float ymax = +6.0; float wx = xmax - xmin; float wy = ymax - ymin; float wm = (wx > wy ? wx : wy); double scale = 6.0 * 72.0 / wm; double hc = 4.25 * 72.0; double hmin = hc - scale * wx / 2.0; double hmax = hc + scale * wx / 2.0; double vc = 6.50 *72.0; double vmin = vc - scale * wy / 2.0; double vmax = vc + scale * wy / 2.0; FILE *f = fopen("deltest.ps", "w"); if (f == NULL) { error ("plot_delaunay: can't open output file"); } ps_begin_document(f); ps_begin_page(f, 1, xmin, xmax, ymin, ymax, hmin, hmax, vmin, vmax, 1, 1); ps_add_caption(f, "Delaunay triangulation"); quad_enum(e, draw_delaunay_edge, (void *)f); ps_draw_frame(f); ps_end_page(f); ps_end_document(f, 1); fclose(f); } int main(void) { edge_ref e; makesites(); e = delaunay_build (sites, NSITES); printf("Delaunay returned %x:%d \n", (e & 0xfffffffcu), (e&3)); plot_delaunay(e); return(0); }