Added logic for joining invalid polygons to meet constraints.