def convert_anchors(ori1, dest1, ori2, dest2):
    """
    Given a signal that we want to shift and stretch on the x axis, this affine
    operation can be defined by picking 2 points of the signal (ori1 and ori2,
    called here "anchors"), and mapping them to other 2 points (dest1 and
    dest2). For the given anchors, this function returns the corresponding
    stretching ratio and shifting amount (after stretching) needed to match the
    given anchors. This is given by solving the formula::

      ``[dest1, dest2] = shift + stretch * [ori1, ori2]``

    :param number ori1: any real-valued number. Same for ori2, dest1, dest2.
    :returns: a tuple (stretch, shift) with 2 real-valued numbers.
    """
    o1, d1, o2, d2 = float(ori1), float(dest1), float(ori2), float(dest2)
    stretch = (d1 - d2) / (o1 - o2)
    shift = d1 - stretch * o1
    return stretch, shift
