| 55 | } |
| 56 | |
| 57 | int Contour::winding() const { |
| 58 | if (edges.empty()) |
| 59 | return 0; |
| 60 | double total = 0; |
| 61 | if (edges.size() == 1) { |
| 62 | Point2 a = edges[0]->point(0), b = edges[0]->point(1/3.), c = edges[0]->point(2/3.); |
| 63 | total += shoelace(a, b); |
| 64 | total += shoelace(b, c); |
| 65 | total += shoelace(c, a); |
| 66 | } else if (edges.size() == 2) { |
| 67 | Point2 a = edges[0]->point(0), b = edges[0]->point(.5), c = edges[1]->point(0), d = edges[1]->point(.5); |
| 68 | total += shoelace(a, b); |
| 69 | total += shoelace(b, c); |
| 70 | total += shoelace(c, d); |
| 71 | total += shoelace(d, a); |
| 72 | } else { |
| 73 | Point2 prev = edges.back()->point(0); |
| 74 | for (std::vector<EdgeHolder>::const_iterator edge = edges.begin(); edge != edges.end(); ++edge) { |
| 75 | Point2 cur = (*edge)->point(0); |
| 76 | total += shoelace(prev, cur); |
| 77 | prev = cur; |
| 78 | } |
| 79 | } |
| 80 | return sign(total); |
| 81 | } |
| 82 | |
| 83 | void Contour::reverse() { |
| 84 | for (int i = (int) edges.size()/2; i > 0; --i) |