'Make complex isolating intervals disjoint and sort roots.'

@classmethod
def _complexes_sorted(cls, complexes):

    if (not complexes):
        return []
    cache = {}
    (imag, complexes) = cls._separate_imaginary_from_complex(complexes)
    complexes = cls._refine_complexes(complexes)
    def key(c):
        'return,    for    ax**n+b,    +/-root(abs(b/a),    b)    according    to    the\n                                                apparent    sign    of    the    imaginary    interval,    e.g.    if    the    interval\n                                                were    (0,    3)    the    positive    root    would    be    returned.\n                                                '
        (u, f, k) = c
        r = _root(abs((f.TC() / f.LC())), f.degree())
        if ((u.ay < 0) or (u.by < 0)):
            return (- r)
        return r
    imag = sorted(imag, key=(lambda c: key(c)))
    if complexes:
        complexes = sorted(complexes, key=(lambda c: c[0].a))
        for (i, c) in enumerate(reversed(complexes)):
            if (c[0].bx <= 0):
                break
        i = ((len(complexes) - i) - 1)
        if i:
            i += 1
        complexes = ((complexes[:i] + imag) + complexes[i:])
    else:
        complexes = imag
    for (root, factor, _) in complexes:
        if (factor in cache):
            cache[factor].append(root)
        else:
            cache[factor] = [root]
    for (factor, roots) in cache.items():
        _complexes_cache[factor] = roots
    return complexes
