fixed distance comparison (missing math.abs)