Point inside a polygon algorithm
The first action performed is an acceleration test. If the point is not inside the maximum limits of the polygon then it is not considered to be inside the polygon.
If point is inside the maximum bounds of the polygon then there is a possibility of being inside the polygon. Thus, it is drawn a semi-line on the X axis to the right of the point. If the semi-line intersects the polygon an odd number of times then the point is inside the polygon. The intersection test is performed for every segment of the polygon.
If the point belongs to a vertix of the polygon or belongs to one of the segments which define the polygon then it is considered to be inside the polygon.
There are a few cases in which special care needs to be taken, regarding the intersection counting. If the intersection point coincides with one of the vertices then one intersection is counted, but only if it is the vertice with the higher Y value. This way only one intersection is counted, as one polygon vertice belongs to two segments and otherwise it would be tested twice. Another case is when the segment belongs to the semi-line and no intersection is counted.