Remove duplicate lines

I recentIy published an Inkscape extension to remove duplicate nodes that is useful when preparing designs for my cutting machine. Sometimes there might be duplicate line segments. This might be problematic as the cutter will trace that path twize and might mess up the product or, if used as a plotter, spill the ink. Others have provided Inkscape extensions to remove duplicate lines, but so far I’ve not found any that accept a user defined tolerance for the matching of segments allowing for inaccuracies f.x. with snapping. So I wanted to give it a try and write that extension.

(Scroll down to bottom of this post to find the download links).

What the extension does

The extension compare all line segments (between nodes). All four control points of the cubic bezier curves are compared after converting the paths to cubic super path. Identical line segments will always be removed, that is when all four control points are the exact same independent of direction (a reversed match is also a match). There are three additional options to select:

  • Include searching for matching segments where one continuous path is overlapping itself.
  • Adding a tolerance to allow for some discrepancies and still regard it a match. What looks like a exact match will often be slightly different when regarding all decimals. Using snapping will most often cause some discrepancy.
  • Optionally interpolate the remaining line segment with the removed line segment.

NB: If the tolerance is larger than the length of the some line segments and the option to include matches where a path is overlapping itself might cause finding a match between neighboring small segments.

NB2: Interpolation might cause a rough or slight deformation compared to the original paths. This is because the average of each pair of controlpoints replace the original controlpoints i.e. a simple approximation.

NB3: The extension ignores grouped paths. Ungroup first (you will get a warning).

NB4: All shape elements have to be converted to path, else they will be ignored (you will get a warning).

The dialog box for the extension and the options available to remove duplicate line segements.

Examples

Hexagon pattern

A hexagon pattern can easily be created in Inkscape drawing hexagons and then snapping these shapes together. Cutting or plotting this paths will cause all but the outer edges to cut or plot twize. For better visualize how the extension operates I will let the hexagons have some distance and I will leave the original path in pink with a duplicate in black on top to show the original and the result for comparison.

Here a tolerance have been applied. The resulting black paths is lacking where the pink original is visible. The first path is the hexacon where all sides remain, removing a segment of the two hexagons above it. The next path is the upper right hexagon, finding and removing a match in the next and central hexagon. And finally the central hexagon find another match to remove from the last path, the upeer left hexagon.

The next example is the same as above with an interpolation between the matches before removing the match.

Interpolating control points of the removed and remaining line segment. I’m not ure if this will be useful, but I just could not resist trying to make the option available.

From stickfont to single line font

I’ve been working quite a lot with single line fonts. TTF and OTF fonts can only contain closed paths. A stickfont have closed paths and zero with and might look like a single line font. The problem with the stickfonts is that each glyph have a duplication.

I tried the remove duplicate lines extension with my own stickfonts and the Cambam stickfonts to remove the duplication. For my own stickfonts I had to explored different methods for creating them and have now found that OTF font type is optimal for this. The OTF font format keep the cubic Bèzier splines better than the TTF font (conversion to quadratic splines). The Cambam stickfonts are TTF, but have a lot of nodes so the conversion is simple (little curvature pr line segment) and do not change. So the remove duplicate lines extension will work also for the Cambam stickfonts (though be a bit slow due to the excessive number of nodes).

How to convert from stickfont to single line font in Inkscape:

  • create your text using a stickfont (one with good match between the line segments, like my OTF stickfonts)
  • use text on path if you like
  • Object to path (Shift + Ctrl + C)
  • Ungroup (Shift + Ctrl + G)
  • Extensions – Cutlings – Remove Duplicate Lines … – Apply
  • Validate the results (use Preferences setting Tools->Node->Show path direction to see small red half-arrows visualizing the direction in edit node mode)

Text to path and ungroup

Here I have written a text with the Cambam Stick8 font, object to path and ungroup.

Now look at the paths in edit node mode. I have the Preferences setting Tools-Node-Show path direction so the small red arrows show in the image below that we have path in both directions. Also the gray diamond node indicators lack the black frame indicating that there are nodes on top of each other.

The Cambam stickfont converted to path, ungrouped and shown in edit node mode. All line segments are duplicated and reversed.

Appøy remove duplicate lines to convert the stickfont to single line font

Now apply the remove duplicate lines extension selecting the option to compare each path against itself and with a small tolarance as there is slight differences due to precision from the ttF font or the convert text to path conversion.

Here after applying the removeDuplicateLines-extension the paths have only one direction. The reversed path is removed and the stickfont is converted to single line paths. Remember to use the option to compare each path against itself and add a small tolerance. I used 0,1 but it will depend on the font size and your unit setting.

Jigsaw from outlines to cutlines

I downloaded this jigsaw svg file from Wikipedia. Each puzzle piece is a closed path. If you want to cut that jigsaw with a cutter, each path will be traced twize. This is either unnecessary or might destroy the edges. I’ve used removeDuplicateLines to remove the overlapping line segments, just to show an example of what this extension can do.

Before and after removing duplicate lines for a part of the jigsaw. The dark lines showing an overlap disappear.

Then I havecombined the paths (Ctrl+K) and used the removeDuplicateNodes extension to join the splitted paths – just for fun and to show some options:

How to download the extension

  • Go to my Inkscape Resources and download the zip file (arrow down button)
    • or if you have an GitLab account you could download from here.
  • The zip file containing the files removeDuplicateLines .inx and .py
  • Unzip and place the files in your User extensions folder. (Check Inkscape Preferences (Shift+Ctrl+P) and find your local User extensions folder specified in the System tab).
  • Restart Inkscape to update with the new extensions. You will find these in menu Extensions > Cutlings > Remove duplicate lines…

How to use the extension

Select the paths for which you want to clean up duplicate lines. Select Extensions > Cutlings > Remove duplicate lines… Set your selections and tolerance. Apply (or Live preview to watch what will happen while playing with the settings).

2 thoughts on “Remove duplicate lines

Leave a Reply

Your email address will not be published. Required fields are marked *