Sorting 2d shapes