def intersection(i0, j0, i1, j1):
    """
    Intersection inside a polygon.

    In case of equality we consider that i0 < i1 < j1 < j0

    INPUT:

    - ``i0``, ``j0`` -- start and end of the first curve

    - ``i1``, ``j1`` -- start and end of the second curve

    TESTS::

        sage: from flatsurf.geometry.fundamental_group import intersection
        sage: intersection(3,0,3,2)
        1
        sage: intersection(0,1,1,2)
        1
        sage: intersection(0,2,3,1)
        -1
        sage: intersection(0,3,3,2)
        0
        sage: intersection(1,1,1,1)
        0
        sage: intersection(3,2,3,2)
        0
        sage: intersection(3,2,0,3)
        0
        sage: intersection(0,3,0,3)
        0
        sage: intersection(0,2,0,2)
        0
    """
    if i0 <= j0:
        return (i0 <= i1 <= j0) - (i0 <= j1 <= j0)
    else:
        return (j0 < j1 < i0) - (j0 < i1 < i0)
