From a950c5b13cf485393499875c9af8b068eebfa5f2 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 7 May 2012 22:45:39 -0300 Subject: [PATCH] poly2d/: simplify semantics of first/next offset in area fill --- poly2d/README | 1 - poly2d/p2d_area.c | 4 ++-- poly2d/p2d_area_holes.cpp | 16 ++++++++-------- poly2d/poly2d.h | 6 +++--- poly2d/test/area | 6 +++--- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/poly2d/README b/poly2d/README index 406a9ed..9b0418d 100644 --- a/poly2d/README +++ b/poly2d/README @@ -43,7 +43,6 @@ Not yet specified: Other: - change the license from GPL to LGPL - 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 - try to generate dependencies also for *.cpp diff --git a/poly2d/p2d_area.c b/poly2d/p2d_area.c index 36695e8..bc45a66 100644 --- a/poly2d/p2d_area.c +++ b/poly2d/p2d_area.c @@ -32,13 +32,13 @@ static void recurse_area(struct p2d_hier *t, double offset, double overlap, } -struct p2d *p2d_area(const struct p2d *p, double offset, double overlap) +struct p2d *p2d_area(const struct p2d *p, double first, double next) { struct p2d_hier *t; struct p2d *res = NULL, **last = &res; t = p2d_hsort(p); - recurse_area(t, offset, overlap, &last); + recurse_area(t, first, next, &last); p2d_hier_free(t); return res; } diff --git a/poly2d/p2d_area_holes.cpp b/poly2d/p2d_area_holes.cpp index 414a2e0..7118766 100644 --- a/poly2d/p2d_area_holes.cpp +++ b/poly2d/p2d_area_holes.cpp @@ -52,17 +52,17 @@ static void append_poly(Polygon_2 poly, struct p2d ***last) } -static void recurse_area(Polygon_with_holes poly, double curr_off, - double next_off, struct p2d ***last) +static void recurse_area(Polygon_with_holes poly, double current, + double next, struct p2d ***last) { PolygonPtrVector tmp = CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2( - curr_off, poly); + current, poly); for (PolygonPtrVector::const_iterator pit = tmp.begin(); pit != tmp.end(); ++pit) { append_poly((*pit)->outer_boundary(), last); - recurse_area(**pit, next_off, next_off, last); + recurse_area(**pit, next, next, last); for (Polygon_with_holes::Hole_const_iterator hit = (*pit)->holes_begin(); @@ -74,7 +74,7 @@ static void recurse_area(Polygon_with_holes poly, double curr_off, extern "C" void p2d_area_holes_append(const struct p2d *p, - const struct p2d *holes, double offset, double overlap, + const struct p2d *holes, double first, double next, struct p2d ***last) { const struct p2d *h; @@ -87,15 +87,15 @@ extern "C" void p2d_area_holes_append(const struct p2d *p, poly.add_hole(p2d_to_P2(h, 0)); } - recurse_area(poly, offset, offset-overlap, last); + recurse_area(poly, first, next, last); } extern "C" struct p2d *p2d_area_holes(const struct p2d *p, - const struct p2d *holes, double offset, double overlap) + const struct p2d *holes, double first, double next) { struct p2d *res = NULL, **last = &res; - p2d_area_holes_append(p, holes, offset, overlap, &last); + p2d_area_holes_append(p, holes, first, next, &last); return res; } diff --git a/poly2d/poly2d.h b/poly2d/poly2d.h index 72281ff..fec85ff 100644 --- a/poly2d/poly2d.h +++ b/poly2d/poly2d.h @@ -127,11 +127,11 @@ struct p2d *p2d_offset_holes(const struct p2d *p, const struct p2d *holes, struct p2d *p2d_offset(const struct p2d *p, double off); void p2d_area_holes_append(const struct p2d *p, - const struct p2d *holes, double offset, double overlap, + const struct p2d *holes, double first, double next, struct p2d ***last); struct p2d *p2d_area_holes(const struct p2d *p, const struct p2d *holes, - double offset, double overlap); -struct p2d *p2d_area(const struct p2d *p, double offset, double overlap); + double first, double next); +struct p2d *p2d_area(const struct p2d *p, double first, double next); struct p2d *p2d_read_gnuplot(FILE *file); int p2d_write_gnuplot(FILE *file, const struct p2d *p); diff --git a/poly2d/test/area b/poly2d/test/area index 2517793..8485f91 100755 --- a/poly2d/test/area +++ b/poly2d/test/area @@ -12,7 +12,7 @@ p2d_append(p, v2d_new(5.5, 0)); p2d_append(p, v2d_new(5.5, 4.5)); p2d_append(p, v2d_new(0, 4.5)); p2d_close(p); -q = p2d_area(p, 1, 0); +q = p2d_area(p, 1, 1); p2d_write_gnuplot_all(stdout, q); EOF @@ -42,7 +42,7 @@ p2d_append(p, v2d_new(5.5, 0)); p2d_append(p, v2d_new(5.5, 4.5)); p2d_append(p, v2d_new(0, 4.5)); p2d_close(p); -q = p2d_area(p, 1, 0.3); +q = p2d_area(p, 1, 0.7); p2d_write_gnuplot_all(stdout, q); EOF @@ -81,7 +81,7 @@ p2d_append(p, v2d_new(18, 8)); p2d_append(p, v2d_new(18, 2)); p2d_close(p); -q = p2d_area(pl, 0.7, 0); +q = p2d_area(pl, 0.7, 0.7); p2d_write_gnuplot_all(stdout, q); EOF