def scale_segment(x1, y1, x2, y2, trim_frac=0.2):
    """Scale segment and leave center point of segment constant"""
    dx = min(1.0, abs(x2 - x1)) * trim_frac
    dy = min(1.0, abs(y2 - y1)) * trim_frac
    if y2 > y1:
        Y2 = y2 - dy
        Y1 = y1 + dy
    else:
        Y2 = y2 + dy
        Y1 = y1 - dy
    if x2 > x1:
        X2 = x2 - dx
        X1 = x1 + dx
    else:
        X2 = x2 + dx
        X1 = x1 - dx
    return X1, Y1, X2, Y2
