Index: trunk/src/obj_poly.h =================================================================== --- trunk/src/obj_poly.h (revision 10050) +++ trunk/src/obj_poly.h (revision 10051) @@ -94,7 +94,81 @@ /* call cb for each point of each island and cutout */ void pcb_poly_map_contours(pcb_polygon_t *p, void *ctx, pcb_poly_map_cb_t *cb); +typedef struct pcb_poly_it_s { + pcb_polygon_t *p; + pcb_polyarea_t *pa; + pcb_pline_t *cntr; + pcb_vnode_t *v; +} pcb_poly_it_t; +/* Set the iterator to the first island of the polygon; returns NULL if no contour available */ +static inline PCB_FUNC_UNUSED pcb_polyarea_t *pcb_poly_island_first(pcb_polygon_t *p, pcb_poly_it_t *it) +{ + it->p = p; + it->pa = p->Clipped; + it->cntr = NULL; + it->v = NULL; + return it->pa; +} + +/* Set the iterator to the next island of the polygon; returns NULL if no more */ +static inline PCB_FUNC_UNUSED pcb_polyarea_t *pcb_poly_island_next(pcb_poly_it_t *it) +{ + if (it->pa->f == it->p->Clipped) + return NULL; + it->pa = it->pa->f; + it->cntr = NULL; + it->v = NULL; + return it->pa; +} + +/* Set the iterator to trace the outer contour of the current island */ +static inline PCB_FUNC_UNUSED pcb_pline_t *pcb_poly_contour(pcb_poly_it_t *it) +{ + it->v = NULL; + return it->cntr = it->pa->contours; +} + +/* Set the iterator to trace the first hole of the current island; returns NULL if there are no holes */ +static inline PCB_FUNC_UNUSED pcb_pline_t *pcb_poly_hole_first(pcb_poly_it_t *it) +{ + it->v = NULL; + return it->cntr = it->pa->contours->next; +} + +/* Set the iterator to trace the next hole of the current island; returns NULL if there are were more holes */ +static inline PCB_FUNC_UNUSED pcb_pline_t *pcb_poly_hole_next(pcb_poly_it_t *it) +{ + it->v = NULL; + return it->cntr = it->cntr->next; +} + +/* Set the iterator to the first point of the last selected contour or hole; + read the coords into x,y; returns 1 on success, 0 if there are no points */ +static inline PCB_FUNC_UNUSED int pcb_poly_vect_first(pcb_poly_it_t *it, pcb_coord_t *x, pcb_coord_t *y) +{ + it->v = it->cntr->head.next; + if (it->v == NULL) + return 0; + *x = it->v->point[0]; + *y = it->v->point[1]; + return 1; +} + + +/* Set the iterator to the next point of the last selected contour or hole; + read the coords into x,y; returns 1 on success, 0 if there are were more points */ +static inline PCB_FUNC_UNUSED int pcb_poly_vect_next(pcb_poly_it_t *it, pcb_coord_t *x, pcb_coord_t *y) +{ + it->v = it->v->next; + if (it->v == it->cntr->head.next) + return 0; + *x = it->v->point[0]; + *y = it->v->point[1]; + return 1; +} + + /*** loops ***/ #define PCB_POLY_LOOP(layer) do { \