Restitution e = 1 (perfectly elastic, no loss). Every wall hit applies an impulse split by inverse mass, so the ball and square swap their normal velocity. Tangential motion is untouched → no friction.
Momentum and kinetic energy stay exactly constant (compare now vs init); the pink COM marker drifts in a straight line, proving momentum is conserved across the torus.
Wrap is handled with a wrap-aware relative coordinate, so collisions stay correct when the square crosses the 1024 seam.