Extension to break apart paths into non-overlapping subpaths

Other sites and resources for Inkscape users.
spaelti
Posts: 12
Joined: Tue May 22, 2012 7:18 pm

Extension to break apart paths into non-overlapping subpaths

Postby spaelti » Wed May 23, 2012 4:53 pm

I have svgs consisting of complex paths that I would like to break into non-overlapping (sub)paths. Right now I break them apart by hand and then select and recombine the overlapping paths, but I have several hundred of these images and each consists of anywhere from 20 to 130 such overlapping groups. To get an idea of what I am trying to do, imagine a line of text as a complex path: break apart into constituent paths, then recombine each group of paths that form each letter, so that each letter is its own path object. Would it be possible to write an extension for this task?

User avatar
LiquidAsh
Posts: 71
Joined: Fri Apr 22, 2011 11:35 pm
Contact:

Re: Extension to break apart paths into non-overlapping subp

Postby LiquidAsh » Thu May 24, 2012 12:15 am

If I understand your problem correctly, I think the most difficult part will be determining which sub-paths are overlapping. Depending on how your data is laid out, this could be easy (comparing bounding boxes or circles), or it could be more difficult (finding slight overlaps within the curvature of paths). Either way, I think an extension should be possible.

spaelti
Posts: 12
Joined: Tue May 22, 2012 7:18 pm

Re: Extension to break apart paths into non-overlapping subp

Postby spaelti » Fri May 25, 2012 2:20 pm

You are of course correct that a true test of "non-overlapping" might be quite difficult. But for my purposes, a very simple idea of non-overlapping would be sufficient. As my example of the letters in a line of text indicates, checking the horizontal coordinates of the bounding box would actually be good enough. In fact I find that part of the problem perfectly straightforward. I was more wondering about how to combine paths. Am I correct that one would have to do this "by hand," that is modify the XML? Are there any modules for this kind of thing that are already written?

ofnuts
Posts: 15
Joined: Mon May 07, 2012 6:49 am
Location: Lost in my thoughts

Re: Extension to break apart paths into non-overlapping subp

Postby ofnuts » Fri May 25, 2012 5:08 pm

spaelti wrote:You are of course correct that a true test of "non-overlapping" might be quite difficult. But for my purposes, a very simple idea of non-overlapping would be sufficient. As my example of the letters in a line of text indicates, checking the horizontal coordinates of the bounding box would actually be good enough.
No, that won't work, due to kerning.A better method would be to check if any point of one of the paths (anchors and handles) is within the "envelope" (polygon that contains all anchors and handles) of the other. This isn't correct either but a lot less likely to fail with letters. But in all cases it will be very hard to handle diacritic marks and characters made of separate strokes (typical in the korean alphabet, but this will also happen in the latin alphabet with some font designs).

spaelti wrote:In fact I find that part of the problem perfectly straightforward. I was more wondering about how to combine paths. Am I correct that one would have to do this "by hand," that is modify the XML? Are there any modules for this kind of thing that are already written?
Combining the paths is the very easy part.

spaelti
Posts: 12
Joined: Tue May 22, 2012 7:18 pm

Re: Extension to break apart paths into non-overlapping subp

Postby spaelti » Fri May 25, 2012 7:50 pm

ofnuts wrote:
spaelti wrote:You are of course correct that a true test of "non-overlapping" might be quite difficult. But for my purposes, a very simple idea of non-overlapping would be sufficient. As my example of the letters in a line of text indicates, checking the horizontal coordinates of the bounding box would actually be good enough.
No, that won't work, due to kerning.A better method would be to check if any point of one of the paths (anchors and handles) is within the "envelope" (polygon that contains all anchors and handles) of the other.


It WILL work for me, because that is what I want. I want to separate the paths whenever there is a vertical strip of whitespace separating them. The bit about letters was only for illustration.

ofnuts wrote:
spaelti wrote:In fact I find that part of the problem perfectly straightforward. I was more wondering about how to combine paths. Am I correct that one would have to do this "by hand," that is modify the XML? Are there any modules for this kind of thing that are already written?
Combining the paths is the very easy part.


Well then, do you have a sample or bit of code that I could use to show me how to do this?

spaelti
Posts: 12
Joined: Tue May 22, 2012 7:18 pm

Re: Extension to break apart paths into non-overlapping subp

Postby spaelti » Wed May 30, 2012 4:18 pm

Well I have now succeeded in creating an extension to do more or less what I wanted. My particular thanks go to Nick -- author of this extension: close_curves, which proved helpful to creating this.

The way this extension works.
  1. Select a complex path
  2. Do "Break Apart" (shift-control-K)
  3. Run this extension

The result will be that all the subpaths which overlap, but are separated from other paths with a vertical strip of white-space, will be recombined separately.

Hope it's useful.
Attachments
combine_paths.zip
(3.65 KiB) Downloaded 354 times
Last edited by spaelti on Wed May 30, 2012 5:17 pm, edited 1 time in total.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Extension to break apart paths into non-overlapping subp

Postby ~suv » Wed May 30, 2012 5:00 pm

spaelti wrote:Well I have now succeeded in creating an extension to do more or less what I wanted.
(…)
Hope it's useful.

Thanks for sharing - could you add an INX file to the archive as well? This would make testing the extension a lot easier ;)

spaelti
Posts: 12
Joined: Tue May 22, 2012 7:18 pm

Re: Extension to break apart paths into non-overlapping subp

Postby spaelti » Wed May 30, 2012 5:20 pm

~suv wrote:Thanks for sharing - could you add an INX file to the archive as well? This would make testing the extension a lot easier ;)

Sorry. I thought I had included that. Has been fixed now.

spaelti
Posts: 12
Joined: Tue May 22, 2012 7:18 pm

Re: Extension to break apart paths into non-overlapping subp

Postby spaelti » Wed May 30, 2012 5:42 pm

Actually I have to say that the .inx file that I included is something that I just created by modifying some other .inx file(s) and I am really not sure that it is completely appropriate. (Presumably the <id> and the namespace can be anything you want??). What about the <dependency> nodes?
But it did work for me.


Return to “Inkscape Resources”