There are two primary problems with this code: 1. There's a lot of duplicated code, differing only in the axes used. These could somehow derive from a common base class, with appropriate virtuals. 2. Only the `xz_rect` class has `pdf_value()` and `random()` member functions.