| 137 | } |
| 138 | |
| 139 | int AnnotationToMask::wn_PnPoly(const Point& P, const std::vector<Point>& V) const { |
| 140 | int wn = 0; // the winding number counter |
| 141 | |
| 142 | // loop through all edges of the polygon |
| 143 | for (int i = 0; i<V.size() - 1; i++) { // edge from V[i] to V[i+1] |
| 144 | if (V[i].getY() <= P.getY()) { // start y <= P.y |
| 145 | if (V[i + 1].getY() > P.getY()) // an upward crossing |
| 146 | if (isLeft(V[i], V[i + 1], P) > 0) // P left of edge |
| 147 | ++wn; // have a valid up intersect |
| 148 | } |
| 149 | else { // start y > P.y (no test needed) |
| 150 | if (V[i + 1].getY() <= P.getY()) // a downward crossing |
| 151 | if (isLeft(V[i], V[i + 1], P) < 0) // P right of edge |
| 152 | --wn; // have a valid down intersect |
| 153 | } |
| 154 | } |
| 155 | return wn; |
| 156 | } |