def relateObjectLocs(obj, entities, selectF):
    """calculate the minimum distance to reach any iterable of entities with a loc"""
    #if obj in entities: return 0 # is already one of the entities
    try:                    obj = obj.loc # get object's location, if it has one
    except AttributeError:  pass # assume obj is already a MapPoint
    try:                    func = obj.direct2dDistance # assume obj is a MapPoint
    except AttributeError:  raise ValueError("object %s (%s) does not possess and is not a %s"%(obj, type(obj), MapPoint))
    try:                    return selectF([(func(b.loc), b) for b in entities])
    except AttributeError:  return selectF([(func(b)    , b) for b in entities])
calculate the minimum distance to reach any iterable of entities with a loc