Add general range-detection code. Avoid unnecessarily computing 3D entity positions. This was SVN commit r7817.