diff --git a/poly2d/README b/poly2d/README index a6bf8dc..406a9ed 100644 --- a/poly2d/README +++ b/poly2d/README @@ -16,23 +16,22 @@ operation in cameo. Later, poly2d could replace more parts of cameo. poly2d puts more emphasis on simplicity than on performance. Some -functions expect clockwise closed polygons that don't self-intersect. +functions expect closed polygons that don't self-intersect. For now, +it doesn't matter whether polygons are clockwise or counter-clockwise. The table below shows the capabilities -Open Counter-clockwise -| Concave Min. vertices +Open Min. vertices +| Concave | | Self-intersect -| | | | | -Y Y Y Y 0 p2d_contains_poly(b), p2d_free, p2d_free_all, - p2d_is_closed, p2d_copy, p2d_reverse, p2d_vertices, - p2d_write_gnuplog, p2d_write_gnuplot_all -Y Y Y Y 1 p2d_read_gnuplot -- Y Y Y 0 p2d_simplify -- Y - Y 3 p2d_is_cw -- Y - - 3 p2d_contains_point, p2d_contains_poly (a), -- Y - # 3 p2d_area*, p2d_offset* - -# CGAL uses ccw, poly2d uses cw. Need to switch. +| | | | +Y Y Y 0 p2d_contains_poly(b), p2d_copy, p2d_free, p2d_free_all, + p2d_is_closed, p2d_no_intersect, p2d_reverse, + p2d_vertices, p2d_write_gnuplot, p2d_write_gnuplot_all +Y Y Y 1 p2d_read_gnuplot +- Y Y 0 p2d_simplify +- Y - 3 p2d_is_cw +- Y - 3 p2d_contains_point, p2d_contains_poly (a), +- Y - 3 p2d_area*, p2d_offset* Not yet implemented: - p2d_simplify (low priority - the offsetting from CGAL already covers @@ -43,8 +42,6 @@ Not yet specified: Other: - change the license from GPL to LGPL -- change ccw to cw -- make sure CGAL is only fed ccw ploygons and cw holes - transform CGAL's idea of outer polygons into something we can use - use more meaningful offset/overlap model for area fill - check for memory leaks diff --git a/poly2d/cgal_helper.h b/poly2d/cgal_helper.h index dff6a5f..8e6886f 100644 --- a/poly2d/cgal_helper.h +++ b/poly2d/cgal_helper.h @@ -35,7 +35,7 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Polygon_2 Polygon_2; -static inline Polygon_2 p2d_to_P2(const struct p2d *p) +static inline Polygon_2 p2d_to_P2(const struct p2d *p, int ccw) { const struct v2d *v; Polygon_2 np; @@ -46,6 +46,8 @@ static inline Polygon_2 p2d_to_P2(const struct p2d *p) v = v->next; } while (v != p->v); + if (p2d_is_cw(p) == ccw) + np.reverse_orientation(); return np; } diff --git a/poly2d/p2d_area_holes.cpp b/poly2d/p2d_area_holes.cpp index 8153db7..414a2e0 100644 --- a/poly2d/p2d_area_holes.cpp +++ b/poly2d/p2d_area_holes.cpp @@ -80,11 +80,11 @@ extern "C" void p2d_area_holes_append(const struct p2d *p, const struct p2d *h; assert(p2d_is_closed(p)); - Polygon_with_holes poly(p2d_to_P2(p)); + Polygon_with_holes poly(p2d_to_P2(p, 1)); for (h = holes; h; h = h->next) { assert(p2d_is_closed(h)); - poly.add_hole(p2d_to_P2(h)); + poly.add_hole(p2d_to_P2(h, 0)); } recurse_area(poly, offset, offset-overlap, last); diff --git a/poly2d/p2d_offset.cpp b/poly2d/p2d_offset.cpp index 349b0a8..daa24e9 100644 --- a/poly2d/p2d_offset.cpp +++ b/poly2d/p2d_offset.cpp @@ -50,11 +50,11 @@ extern "C" struct p2d *p2d_offset_holes(const struct p2d *p, struct p2d *res = NULL, **last = &res; assert(p2d_is_closed(p)); - Polygon_with_holes poly(p2d_to_P2(p)); + Polygon_with_holes poly(p2d_to_P2(p, 1)); for (h = holes; h; h = h->next) { assert(p2d_is_closed(h)); - poly.add_hole(p2d_to_P2(h)); + poly.add_hole(p2d_to_P2(h, 0)); } PolygonPtrVector tmp = off > 0 ? diff --git a/poly2d/test/offset b/poly2d/test/offset index 5ccbee5..4cf3728 100755 --- a/poly2d/test/offset +++ b/poly2d/test/offset @@ -49,4 +49,28 @@ expect <