1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 18:58:58 +02:00
cae-tools/poly2d/p2d_make.c

74 lines
1.1 KiB
C
Raw Normal View History

/*
* p2d_make.c - Polygon creation
*
* Written 2012 by Werner Almesberger
* Copyright 2012 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <assert.h>
#include "util.h"
#include "poly2d.h"
struct p2d *p2d_new(void)
{
struct p2d *np;
np = alloc_type(struct p2d);
np->v = NULL;
np->last = NULL;
np->next = NULL;
return np;
}
struct v2d *v2d_new(double x, double y)
{
struct v2d *nv;
nv = alloc_type(struct v2d);
nv->x = x;
nv->y = y;
nv->next = NULL;
return nv;
}
void p2d_append(struct p2d *p, struct v2d *v)
{
if (p->last && p->last->next)
v->next = p->v;
if (p->last)
p->last->next = v;
else
p->v = v;
p->last = v;
}
void p2d_prepend(struct p2d *p, struct v2d *v)
{
v->next = p->v;
p->v = v;
if (p->last) {
if (p->last->next)
p->last->next = v;
} else {
p->last = v;
}
}
void p2d_close(struct p2d *p)
{
assert(!p->v || !p->last->next);
p->last->next = p->v;
}