Transformation-Invariant Learning and Theoretical Guarantees for OOD Generalization