A theory of neural integration in the head-direction system