2013-10-14 02:33:05 +03:00
|
|
|
/*
|
|
|
|
* f2d_tri.c - Triangulate a set of nested polygons
|
|
|
|
*
|
|
|
|
* Written 2013 by Werner Almesberger
|
|
|
|
* Copyright 2013 Werner Almesberger
|
|
|
|
*
|
2015-01-19 01:43:08 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-10-14 02:33:05 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-10-14 04:09:49 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-10-14 02:33:05 +03:00
|
|
|
#include "poly2d.h"
|
|
|
|
#include "p2d_hsort.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void recurse_area(struct p2d_hier *t, struct f2d ***last)
|
|
|
|
{
|
|
|
|
const struct p2d *p, *h;
|
|
|
|
|
|
|
|
for (p = &t->p; p; p = p->next) {
|
|
|
|
h = &p2d_to_hier(p)->holes->p;
|
|
|
|
f2d_tri_holes_append(p, h, last);
|
|
|
|
while (h) {
|
|
|
|
recurse_area(p2d_to_hier(h)->holes, last);
|
|
|
|
h = h->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct f2d *f2d_tri(const struct p2d *p)
|
|
|
|
{
|
|
|
|
struct p2d_hier *t;
|
|
|
|
struct f2d *res = NULL, **last = &res;
|
|
|
|
|
|
|
|
t = p2d_hsort(p);
|
|
|
|
recurse_area(t, &last);
|
2013-10-14 17:13:22 +03:00
|
|
|
p2d_hier_free(t);
|
2013-10-14 02:33:05 +03:00
|
|
|
return res;
|
|
|
|
}
|
2013-10-14 04:09:49 +03:00
|
|
|
|
|
|
|
|
|
|
|
void f2d_free_all(struct f2d *f)
|
|
|
|
{
|
|
|
|
struct f2d *next;
|
|
|
|
|
|
|
|
while (f) {
|
|
|
|
next = f->next;
|
|
|
|
free(f);
|
|
|
|
f = next;
|
|
|
|
}
|
|
|
|
}
|