def _point_within_bounds(bounds, p):
    """Check if point is within bounds, end points inclusive"""
    A, B = bounds
    # we have to add epsilon since test against horizontal or vertical
    #  lines may fail if the point is off by numerical precision
    eps = 1e-10
    (Ax,Ay), (Bx,By), (px,py)=A,B,p
    return (
        (min((Ax,Bx))-eps<=px<=max((Ax,Bx))+eps) and
        (min((Ay,By))-eps<=py<=max((Ay,By))+eps)
        )