def edge_distances(peak, feature):
    """
    Return distances between peak and feature edges

    Arguments:
      peak (Peak): peak instance
      feature (Feature): feature instance

    Returns:
      tuple: a pair of distances, the first being the
        smallest distance between an edge of the peak
        region and an edge of the feature region and
        the second being the distance from the same peak
        edge to the opposite feature edge.
        Both distances are zero if the peak is entirely
        contained within the feature (or vice versa).
        If there is partial overlap then the smallest
        distance is returned as zero, the second is
        the amount of the peak that lies outside the
        feature.

    """
    if (peak.start >= feature.start and peak.end <= feature.end or feature.
        start >= peak.start and feature.end <= peak.end):
        return 0, 0
    ds_fs = abs(peak.start - feature.start)
    ds_fe = abs(peak.start - feature.end)
    de_fs = abs(peak.end - feature.start)
    de_fe = abs(peak.end - feature.end)
    if peak.start >= feature.start and peak.start <= feature.end:
        return 0, de_fe
    if peak.end >= feature.start and peak.end <= feature.end:
        return 0, ds_fs
    if ds_fe < de_fs:
        return ds_fe, ds_fs
    else:
        return de_fs, de_fe
