Tangentially affine foliations and leafwise affine functions on the torus