/* Tests the hexpaint routines. */ /* Last edited on 2005-02-04 07:44:09 by stolfi */ #include #include #include #include #include #include #include #include /* INTERNAL PROTOTYPES */ int main(int argc, char **argv); int test_paint_polygon(void); int main(int argc, char **argv) { test_paint_polygon(); return 0; } int test_paint_polygon(void) { /* Canvas lower and upper corners: */ r2_t org = (r2_t){{1,2}}; r2_t lim = (r2_t){{11,14}}; /* Canvas dimensions (user units): */ double sx = lim.c[0] - org.c[0]; double sy = lim.c[1] - org.c[1]; /* Desired spacings: */ double dx = 0.2; double dy = 0.1; /* Canvas size: */ int nx = (int)(sx/dx + 0.5); int ny = (int)(sy/dy + 0.5); /* Create a canvas: */ hxp_canvas_t s = hxp_canvas_new(org, (r2_t){{dx,dy}}, (i2_t){{nx,ny}}, 0); /* Create some polygon with holes: */ r2_vec_t R = r2_vec_new(10); R.el[0] = (r2_t){{3,3}}; R.el[1] = (r2_t){{3,9}}; R.el[2] = (r2_t){{9,9}}; R.el[3] = (r2_t){{9,3}}; R.el[4] = (r2_t){{6,8}}; R.el[5] = (r2_t){{8,6}}; R.el[6] = (r2_t){{6,4}}; R.el[7] = (r2_t){{4,6}}; R.el[8] = (r2_t){{6,8}}; R.el[9] = (r2_t){{9,3}}; /* Paint it on a canvas: */ hxp_paint_polygon(R, &s, 1); /* Extract painted pixels: */ i2_vec_t K = hxp_list_pixels(&s, 1); /* print their positions */ int i; for (i = 0; i < K.nel; i++) { i2_t Ki = K.el[i]; r2_t Vi = hxp_pixel_pos(&s, Ki); i2_gen_print(stderr, &Ki, "%3d", "(", ",", ")"); fprintf(stderr, " = "); r2_gen_print(stderr, &Vi, "%.3f", "(", ",", ")"); fprintf(stderr, "\n"); } fprintf(stderr, "OK so far...\n"); return(0); }