/* * 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 #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; }