Modified from the Diva sources to fix a bug when flipping shapes.