Root/poly2d/f2d_tri.c

1/*
2 * f2d_tri.c - Triangulate a set of nested polygons
3 *
4 * Written 2013 by Werner Almesberger
5 * Copyright 2013 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 <stdlib.h>
15
16#include "poly2d.h"
17#include "p2d_hsort.h"
18
19
20static void recurse_area(struct p2d_hier *t, struct f2d ***last)
21{
22    const struct p2d *p, *h;
23
24    for (p = &t->p; p; p = p->next) {
25        h = &p2d_to_hier(p)->holes->p;
26        f2d_tri_holes_append(p, h, last);
27        while (h) {
28            recurse_area(p2d_to_hier(h)->holes, last);
29            h = h->next;
30        }
31    }
32}
33
34
35struct f2d *f2d_tri(const struct p2d *p)
36{
37    struct p2d_hier *t;
38    struct f2d *res = NULL, **last = &res;
39
40    t = p2d_hsort(p);
41    recurse_area(t, &last);
42    p2d_hier_free(t);
43    return res;
44}
45
46
47void f2d_free_all(struct f2d *f)
48{
49    struct f2d *next;
50
51    while (f) {
52        next = f->next;
53        free(f);
54        f = next;
55    }
56}
57

Archive Download this file

Branches:
master



interactive