def point_in_polygon(S, q):
    """determine if a point is within a polygon

    The code below is from Wm. Randolph Franklin <wrf@ecse.rpi.edu>
    (see URL below) with some minor modifications for integer. It returns
    true for strictly interior points, false for strictly exterior, and ub
    for points on the boundary.  The boundary behavior is complex but
    determined; in particular, for a partition of a region into polygons,
    each point is "in" exactly one polygon.
    (See p.243 of [O'Rourke (C)] for a discussion of boundary behavior.)

    See http://www.faqs.org/faqs/graphics/algorithms-faq/ Subject 2.03

    Args:
        S ([type]): [description]
        q ([type]): [description]

    Returns:
        [type]: [description]
    """
    c = False
    p0 = S[-1]
    for p1 in S:
        if (p1.y <= q.y < p0.y) or (p0.y <= q.y < p1.y):
            d = (q - p0).cross(p1 - p0)
            if p1.y > p0.y:
                if d < 0:
                    c = not c
            else:  # v1.y < v0.y
                if d > 0:
                    c = not c
        p0 = p1
    return c