I would merge those two if's and use std::swap for swapping width with height