import math


def svd(mat):
    """
    Does a custom SVD decomposition of a affine matrix for matrix interpolation. The decomposition can be linearly
    interpolated.

    :param mat:
        The matrix to decompose.

    :return:
        The decomposition.
    :rtype: tuple(float)
    """
    a, b, c, d = mat.xx, mat.xy, mat.yx, mat.yy
    e, f, g, h = a + d, a - d, c + b, c - b
    a = math.sqrt(e * e + h * h)
    b = math.sqrt(f * f + g * g)
    c = math.atan2(h, e)
    d = math.atan2(g, f)
    return (a + b) / 2, (a - b) / 2, (c - d) / 2, (c + d) / 2, mat.x0, mat.y0