detect collisions with borders