Region Union based on most common border with neighbors

Hi all
in short: How to merge smallest closed curve region with longest common border nearby region?
attached is a loop on a sorted by area which do union on smallest region with its “*Curve Nearest Object*” , this component is great but in my case has no tweaking parameter in case of equal distance and the selected neighbor mostly is not the one with most shared border.
the red circle show the wrong selected adjacent neighbor .
MergeCurve_001.gh (12.4 KB)

MergeCurve_001 Edited V0.gh (18.7 KB)

Not sure if this is right.
Honeycam 2023-09-25 19-38-31

3 Likes

Comparing center of regions will work on round-like shape but make bug in complicated shape mostly when that center point is out of curve area, for example in arc shape or spiked shape the center may be far away from another. Also this work on polygons.

Indeed centers is not the way to go (by any means).

I’ll give you some hints:

  1. At some “union” loop phase and given a collection of valid closed and planar Polylines (that may or may not be in contact) …

2 … try to get the so called contact connectivity Tree (or Matrix): i.e. what is in contact - or proximity - to what. Get an abstract hint on that matter (sadly for you it’s code but I think that you can get the general direction) :

  1. Then according your criteria find the Poly pair that has the longest contact length (or use some other criterion), do the Crv bool union, remove the 2 related Polys from the List, add the new one and repeat the loop (until there’s one Polyline left).

I could provide an entry level C# that does that … but it’s pure code (and thus a bit useless to you).

there is a network from geometry in heteroptera,and by using network of region (unfortunately base on surface not the region) solve the problem:
merge region

cell topology get longest neighbour.gh (52.5 KB)
Here is a way to get the neighbour

this was much better than using surface. also fast enough.
but rise issue on curves.