That image was produced with @Riccardo’s unmodified code. I studied it very carefully and produced a variation (below) that uses the same idea (and much of his code) with a slightly different result. The great insight I got from @Riccardo is to identify “convex peninsulas” and chop them off, one at a time. His method of “weighting” and ranking them is delightfully elegant and simple, if obscure. Inspecting the results made me wonder why it didn’t always choose the smallest (or largest) “peninsula” to remove?
So my variant (below) identifies peninsulas as those edge segments where both ends extend outside the perimeter (Dispatch). Then it chooses the shorter of the segment’s two adjacent edges to compute the area and find the smallest peninsula. Instead of extruding one edge as @Riccardo did, I avoided the issue of extrude/move direction by using a PFrame and Mirror. The result is similar but slightly different, proving the point that there are many ways to do this without additional criteria to choose which is “best”. See the difference in the upper right corner? @Riccardo’s is pink/purple.
The difference below is at the bottom:
rectangles_V2_2019Jun17a.gh (26.3 KB)
As food for thought, here is a variation created with GIMP that looks reasonable if this were a building, but lopping off peninsulas won’t get there.
P.S. I added the ability to choose ‘Edge Length’ instead of ‘Area’ as the basis for choosing which peninsula to remove. For Crv5, the result now matches @Riccardo’s:
But with Crv1, we get something different:
By reversing the Sort ‘A’ output (see yellow arrow below), the largest instead of the smallest peninsula gets lopped off each time. This doesn’t work properly with ‘Edge Length’ though, as there is a flaw…
rectangles_V2_2019Jun18a.gh (42.6 KB)
P.P.S. The flaw I mentioned with largest ‘Edge Length’ also exists with largest ‘Area’ (instead of smallest), as it depends on the remaining perimeter shape. This example demonstrates the flawed assumption that the largest “peninsula” (by Area or Edge Link) doesn’t encompass a “gulf” on the opposite side, when in fact, it can: