Grouping objects based on shape