I think you should use <= 0 here instead of < 1 because I'm not confident that positions.dx will always be an integer.  Same thing below.