Root/poly2d/p2d_area.c

1/*
2 * p2d_area.c - Fill a set of nested polygons
3 *
4 * Written 2012 by Werner Almesberger
5 * Copyright 2012 Werner Almesberger
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 */
12
13
14#include "poly2d.h"
15#include "p2d_hsort.h"
16
17
18static void recurse_area(struct p2d_hier *t, double offset, double overlap,
19    struct p2d ***last)
20{
21    const struct p2d *p, *h;
22
23    for (p = &t->p; p; p = p->next) {
24        h = &p2d_to_hier(p)->holes->p;
25        p2d_area_holes_append(p, h, offset, overlap, last);
26        while (h) {
27            recurse_area(p2d_to_hier(h)->holes, offset, overlap,
28                last);
29            h = h->next;
30        }
31    }
32}
33
34
35struct p2d *p2d_area(const struct p2d *p, double first, double next)
36{
37    struct p2d_hier *t;
38    struct p2d *res = NULL, **last = &res;
39
40    t = p2d_hsort(p);
41    recurse_area(t, first, next, &last);
42    p2d_hier_free(t);
43    return res;
44}
45

Archive Download this file

Branches:
master



interactive