Root/
| 1 | /* |
| 2 | * p2d_contains_poly.c - Determine whether polygon contains other polygon |
| 3 | * |
| 4 | * Written 2012 by Werner Almesberger |
| 5 | * Copyright 2012 Werner Almesberger |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <assert.h> |
| 15 | |
| 16 | #include "poly2d.h" |
| 17 | |
| 18 | |
| 19 | int p2d_contains_poly(const struct p2d *a, const struct p2d *b) |
| 20 | { |
| 21 | const struct v2d *v; |
| 22 | int in = 0, out = 0; |
| 23 | |
| 24 | assert(p2d_is_closed(a)); |
| 25 | v = b->v; |
| 26 | while (v) { |
| 27 | if (p2d_contains_point(a, v)) |
| 28 | in++; |
| 29 | else |
| 30 | out++; |
| 31 | v = v->next; |
| 32 | if (v == b->v) |
| 33 | break; |
| 34 | } |
| 35 | if (in && out) |
| 36 | return -1; |
| 37 | return !out; |
| 38 | } |
| 39 |
Branches:
master
