How to automatically place a label on visual center of nested shapes?
Hi, I’ve written a JavaScript for Adobe Illustrator to automatically add text labels to shapes. The problem is that the shapes have sometimes odd forms (like U f.e.) it’s therefore hard to find the visual center of the shapes lying inside the shape to place the text label. I found the following algorithm: A new algorithm for finding a visual center of a polygon | by Mapbox | maps for developers which does the job to some extend (N.B.: some “porting” of the code has been required to use it in Illustrator, see Solved: Re: ‘require’ keyword to import modules in Illustr... - Adobe Support Community - 11708866 )
The result of using this algo is still not satisfying especially in case of “nested” shapes like for example:

This is NOT because the mentioned algo is not good enough but rather because my script does a ‘for loop’ over each shape but there is currently no detection mechanism to check if there is another (the outermost) shape lying inside the current shape. Such a inner shape would determine the ‘hole’ inside the current shape which shall be added to the overall coordinated of the current shapes (in GeoJSON-like format ) to get better results with the mentioned algorithm. I wonder if somebody has overcome this problem? I would be grateful if you could share the (JavaScript) code you've been using to solve this problem!