Calculate the best position of the camera

I present you a script which tries to calculate the best position of the camera for a given rotation (the angle of the camera is fixed) which enables to see all the scene.

For example:
http://www.ubuntu-pics.de/bild/61180/screenshot_205_Z2jfex.png
http://www.ubuntu-pics.de/bild/61181/screenshot_206_fFX8MU.png

However, this script isn’t perfect.
Since the rightmost, leftmost, highest, lowest points (on the camera screen) change when you move it, you may need sometimes to run the script several times until the position of the camera converges to the “best solution”.
In some rare case, there is no convergence and the script fails.

The script (for Blender 2.49):
http://www.yspilots.com/shadowhunters/python/best_camera_position.zip
Note: once installed, you can launch the script for the Python_menu/misc

By the way, do you know others scripts which can do that job?