added pruning restriction into range search.

optimized the distance calculation.