Hi,
Is there any way to allow joining multiple selected regions (not intersected) to generate only one region representing them as shown below?
Input regions:
Required output as one region:
I tried to use the following boolean operation code which is inspired by @_gile 's post, but it only returns the outlining boundary because the inner regions are fully contained inside the outlining region.
public static Region JoinRegions(List<Region> selectedRegions)
{
var boundaryRegion = selectedRegions.First();
foreach (var region in selectedRegions.Skip(1))
{
boundaryRegion.BooleanOperation(BooleanOperationType.BoolUnite, region);
}
foreach (var region in selectedRegions.Skip(1))
{
//TODO:Join region inside the boundary region
//boundaryRegion.BooleanOperation(BooleanOperationType.BoolSubtract, region);
}
return boundaryRegion;
}
Thanks in advance.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
You have to substract the inner regions to the boundary one.
public static Region JoinRegions(List<Region> selectedRegions)
{
var boundaryRegion = selectedRegions.Aggregate((r1, r2) => r1.Area < r2.Area ? r2 : r1);
foreach (var region in selectedRegions)
{
if (region != boundaryRegion)
{
boundaryRegion.BooleanOperation(BooleanOperationType.BoolSubtract, region);
}
}
return boundaryRegion;
}
Can't find what you're looking for? Ask the community or share your knowledge.