Index: polygon.c =================================================================== --- polygon.c (revision 15296) +++ polygon.c (revision 15297) @@ -51,6 +51,7 @@ #include "compat_nls.h" #include "obj_all.h" #include "obj_poly_draw.h" +#include "polygon_selfi.h" #define ROUND(x) ((long)(((x) >= 0 ? (x) + 0.5 : (x) - 0.5))) @@ -250,7 +251,27 @@ pcb_poly_contour_inv(contour); assert(contour->Flags.orient == (hole ? PCB_PLF_INV : PCB_PLF_DIR)); - pcb_polyarea_contour_include(np, contour); + /* attempt to auto-correct simple self intersecting cases */ + if (0 && pcb_pline_is_selfint(contour)) { + vtp0_t islands; + int n; + + /* most probably self intersecting polygon - attempt to fix it */ + vtp0_init(&islands); + pcb_pline_split_selfint(contour, &islands); + for(n = 0; n < vtp0_len(&islands); n++) { + pcb_pline_t *pl = *vtp0_get(&islands, n, 0); + pcb_poly_contour_pre(pl, pcb_true); + if (pl->Flags.orient != (hole ? PCB_PLF_INV : PCB_PLF_DIR)) + pcb_poly_contour_inv(pl); + assert(pl->Flags.orient == (hole ? PCB_PLF_INV : PCB_PLF_DIR)); + pcb_polyarea_contour_include(np, pl); + } + vtp0_uninit(&islands); + free(contour); + } + else + pcb_polyarea_contour_include(np, contour); contour = NULL; assert(pcb_poly_valid(np));