From d758359791fb5a8a6c083b96161170f512a7fdb9 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 13 Oct 2013 21:29:48 -0300 Subject: [PATCH] poly2d/p2d_hsort.c (p2d_hier_free): make freeing of polygons optional --- poly2d/f2d_tri.c | 2 +- poly2d/p2d_area.c | 6 +++--- poly2d/p2d_hsort.c | 11 ++++++----- poly2d/p2d_hsort.h | 8 +++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/poly2d/f2d_tri.c b/poly2d/f2d_tri.c index bab50f3..418ce88 100644 --- a/poly2d/f2d_tri.c +++ b/poly2d/f2d_tri.c @@ -37,6 +37,6 @@ struct f2d *f2d_tri(const struct p2d *p) t = p2d_hsort(p); recurse_area(t, &last); - p2d_hier_free(t); + p2d_hier_free(t, 0); return res; } diff --git a/poly2d/p2d_area.c b/poly2d/p2d_area.c index bc45a66..b0ef6b1 100644 --- a/poly2d/p2d_area.c +++ b/poly2d/p2d_area.c @@ -1,8 +1,8 @@ /* * p2d_area.c - Fill a set of nested polygons * - * Written 2012 by Werner Almesberger - * Copyright 2012 Werner Almesberger + * Written 2012, 2013 by Werner Almesberger + * Copyright 2012, 2013 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,6 +39,6 @@ struct p2d *p2d_area(const struct p2d *p, double first, double next) t = p2d_hsort(p); recurse_area(t, first, next, &last); - p2d_hier_free(t); + p2d_hier_free(t, 1); return res; } diff --git a/poly2d/p2d_hsort.c b/poly2d/p2d_hsort.c index 07aa958..2570211 100644 --- a/poly2d/p2d_hsort.c +++ b/poly2d/p2d_hsort.c @@ -1,8 +1,8 @@ /* * p2d_hsort.c - Hierarchical polygon sort * - * Written 2012 by Werner Almesberger - * Copyright 2012 Werner Almesberger + * Written 2012, 2013 by Werner Almesberger + * Copyright 2012, 2013 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -92,16 +92,17 @@ struct p2d_hier *p2d_hsort(const struct p2d *p) } -void p2d_hier_free(struct p2d_hier *t) +void p2d_hier_free(struct p2d_hier *t, bool free_poly) { struct p2d_hier *next; struct p2d *p; while (t) { - p2d_hier_free(t->holes); + p2d_hier_free(t->holes, free_poly); p = &t->p; next = p2d_to_hier(p->next); - p2d_free(p); + if (free_poly) + p2d_free(p); t = next; } } diff --git a/poly2d/p2d_hsort.h b/poly2d/p2d_hsort.h index e789656..8f9b37c 100644 --- a/poly2d/p2d_hsort.h +++ b/poly2d/p2d_hsort.h @@ -1,8 +1,8 @@ /* * p2d_hsort.h - Hierarchical polygon sort * - * Written 2012 by Werner Almesberger - * Copyright 2012 Werner Almesberger + * Written 2012, 2013 by Werner Almesberger + * Copyright 2012, 2013 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,6 +14,8 @@ #ifndef P2D_HSORT_H #define P2D_HSORT_H +#include + #include "poly2d.h" @@ -27,6 +29,6 @@ struct p2d_hier { struct p2d_hier *p2d_hsort(const struct p2d *p); -void p2d_hier_free(struct p2d_hier *t); +void p2d_hier_free(struct p2d_hier *t, bool free_poly); #endif /* !P2D_HSORT_H */