backported a bug that could leed to an infinite loop when finding the best map extend due to double precision problems