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

39 lines
769 B
C
Raw Normal View History

/*
* p2d_contains_poly.c - Determine whether polygon contains other polygon
*
* 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 "poly2d.h"
int p2d_contains_poly(const struct p2d *a, const struct p2d *b)
{
const struct v2d *v;
int in = 0, out = 0;
assert(p2d_is_closed(a));
v = b->v;
while (v) {
if (p2d_contains_point(a, v))
in++;
else
out++;
v = v->next;
if (v == b->v)
break;
}
if (in && out)
return -1;
return !out;
}