How can I get an accurate bounding rect for an AnimationCurve

Hi guys

I’m currently using the following to get my curve bounding rect:

public static Rect GetBounds(this AnimationCurve extends)
{
    if (extends.length == 0)
       return new Rect();

    float xMin = extends.keys.First().time;
    float xMax = extends.keys.Last().time;

    float yMin = extends.keys.First().value;
    float yMax = yMin;

    foreach (Keyframe frame in extends.keys)
    {
        if (frame.value < yMin)
            yMin = frame.value;

        if (frame.value > yMax)
            yMax = frame.value;
    }

    return Rect.MinMaxRect(xMin, yMax, xMax, yMin);
}

The problem is that this method doesn’t consider the tangents of each KeyFrame.

I presume Unity already has some hidden method for getting the bounding Rect since it is able to focus curves in the curve editor.

Does anyone know how I can get an accurate bounding Rect for my AnimationCurves?

Thanks,
Ves

I’ve ended up using reflection to get at the NormalCurveRenderer class and call GetBounds.