Fixed error in automatic bounding box algorithm.

The patch fixes a corner-case error in the automatic bounding box finding algorithm. The issue was first reported here: https://github.com/enigma-dev/enigma-dev/issues/44.