build_distance_mesh uses local vars in loop.