rsvg_bbox_insert (RsvgBbox * dst, RsvgBbox * src)
{
    double affine[6];
    double xmin, ymin;
    double xmax, ymax;
    int i;

    if (src->virgin)
        return;

    if (!dst->virgin) {
        xmin = dst->x, ymin = dst->y;
        xmax = dst->x + dst->w, ymax = dst->y + dst->h;
    } else {
        xmin = ymin = xmax = ymax = 0;
    }

    _rsvg_affine_invert (affine, dst->affine);
    _rsvg_affine_multiply (affine, src->affine, affine);

    for (i = 0; i < 4; i++) {
        double rx, ry, x, y;
        rx = src->x + src->w * (double) (i % 2);
        ry = src->y + src->h * (double) (i / 2);
        x = affine[0] * rx + affine[2] * ry + affine[4];
        y = affine[1] * rx + affine[3] * ry + affine[5];
        if (dst->virgin) {
            xmin = xmax = x;
            ymin = ymax = y;
            dst->virgin = 0;
        } else {
            if (x < xmin)
                xmin = x;
            if (x > xmax)
                xmax = x;
            if (y < ymin)
                ymin = y;
            if (y > ymax)
                ymax = y;
        }
    }
    dst->x = xmin;
    dst->y = ymin;
    dst->w = xmax - xmin;
    dst->h = ymax - ymin;
}
rsvg_bbox_insert (RsvgBbox * dst, RsvgBbox * src)
{
    double affine[6];
    double xmin, ymin;
    double xmax, ymax;
    int i;

    if (src->virgin)
        return;

    if (!dst->virgin) {
        xmin = dst->x, ymin = dst->y;
        xmax = dst->x + dst->w, ymax = dst->y + dst->h;
    } else {
        xmin = ymin = xmax = ymax = 0;
    }

    _rsvg_affine_invert (affine, dst->affine);
    _rsvg_affine_multiply (affine, src->affine, affine);

    for (i = 0; i < 4; i++) {
        double rx, ry, x, y;
        rx = src->x + src->w * (double) (i % 2);
        ry = src->y + src->h * (double) (i / 2);
        x = affine[0] * rx + affine[2] * ry + affine[4];
        y = affine[1] * rx + affine[3] * ry + affine[5];
        if (dst->virgin) {
            xmin = xmax = x;
            ymin = ymax = y;
            dst->virgin = 0;
        } else {
            if (x < xmin)
                xmin = x;
            if (x > xmax)
                xmax = x;
            if (y < ymin)
                ymin = y;
            if (y > ymax)
                ymax = y;
        }
    }
    dst->x = xmin;
    dst->y = ymin;
    dst->w = xmax - xmin;
    dst->h = ymax - ymin;
}