mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 04:50:49 +02:00
39 lines
778 B
C
39 lines
778 B
C
/*
|
|
* p2d_contains_poly.c - Determine whether polygon contains other polygon
|
|
*
|
|
* Written 2012 by Werner Almesberger
|
|
* Copyright 2012 Werner Almesberger
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
|
|
#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;
|
|
}
|