Paths - Cut/Intersect/Purge

Contour Scanner And Trimmer
Scanning
This tool helps you to find nasty contours which might bug you and prevent your work from being ready for production. It will find open contours, closed contours and self-intersecting contours and checks for a set of other attributes. Bentley-Ottmann algorithm is used to check for those intersections. The algorithm works with the accuracy of the selected paths (epsilons). Self-intersections usually happen if you just have large overlaps where the contour crosses itself like an 'eight' character for example. Using the highlighting it's easy to find contours with unproper path handles. While in a CAD system an area of of a surface can only be calculated if the contour is closed and clean, finding self intersections in Inkscape is not required to do so. SVG format allows to calculate areas on open contours and self-twisted curves. This "artwork behaviour" makes it harder for handling machinery-like drawings for laser cutting, vinyl cutting or whatever. That's why we need to have extra sanity checks but we also have the great freedom of InkScape.
Finding self-intersecting contours does only work for curves with straight line segments (polylines) because it just calculates with a set of given XY points. It does not respect bezier curve segments. Bezier curves have no regular points but special handles, which define the slope of the curve per handle side (left and right). To properly handle a bezier curve we need to split the bezier curve in a lot of small linear lines (acting like infinitessimal solution). We can use the tool Approximate Curves by Straight Lines (Flatten Beziers) to do this by hand or we use the built-in method if Contour Scanner and Trimmer (will make your curve looking edgy or ugly possible). If you want to leave the shape of the line clean (bezier type, no edgy approximation) we can also use Split Bezier (Subdivide Path) or Add Nodes instead. But remember that your calculated self-intersection points will only be an approximation then. The higher the subdivide count is the higher the precision of the calculated self-intersecting points coordinates will be.
After performing operations, which flatten or split the bezier curve, we we can or should use Chain Paths to put the pieces together again.
Trimming
By having a set of flattened straight line and finding global intersections we can also trim the paths using python library called "shapely". This allows to receive cut segments. Some basic tools to remove duplicates, are integrated.
The result
Using Contour Scanner correctly, we get a planar graph style drawing, like the definition gives: "In graph theory, a planar graph is a graph that can be embedded in the plane, i.e., it can be drawn on the plane in such a way that its edges intersect only at their endpoints. In other words, it can be drawn in such a way that no edges cross each other. Such a drawing is called a plane graph or planar embedding of the graph. A plane graph can be defined as a planar graph with a mapping from every node to a point on a plane, and from every edge to a plane curve on that plane, such that the extreme points of each curve are the points mapped from its end nodes, and all curves are disjoint except on their extreme points. " (https://en.wikipedia.org/wiki/Planar_graph)
Tips


If nothings is selected, the whole document will be processed, regardless of groups. In contrast, if you made a custom selection, check to handle or not to handle groups.


Works with paths which have Live Path Effects (LPE)

Convert your strokes and objects to paths before
Does not work for clones. You will need to unlink them before
Use extensions to filter short/unrequired paths
Use extensions to purge or repair invalid paths
Use 'Path → Simplify' or hit 'CTRL + L' to simplify the trimmed result. With a fine quantization setting the simplified paths will be nearly identical to the original path (except the position of control points)
Do not select too much paths at once if you have got a fine settings for quantization. This extension is slow and might calculate hours on ultra high configurations.

See also (similar extensions)

Incadiff
Occult Plugin (Hidden / Superimposed Line Removal)
Purge Duplicate Path Nodes
Purge Duplicate Path Segments
Purge Pointy Paths
Mutual Cut Line
Convert To Polylines
Deduplicate Plugin

The user interface
 
 
 
 

Quick example
Using Contour Scanner and Trimmer we can check the different contours and their behaviour. Usually a contour can be open or closed and it can intersect with itself or not. This will give us 4 different combinations and we can use this information to find out where the intersections are using Bentley-Ottmann algorithm. Short examples:



4 different basic line "types"
Marked paths by running the extension using colors and dot modifiers













Real example
Load sove graphic you want to fix
Depending on the steps you want to perform with the file maybe create some duplicate.

Run the extension
Configure the setting depending on what you want.

Fix the desired paths
Select the path to see the handles. The dot indicates that there might be something faulty. In the following example there are two handles at the same coordinate. We can pick one of them to drag it away from the other one. You can now delete the marking point
 

After rerunning the extension the dot will not appear again:

Overlapping lines
Contour Scanner is powerful. It can find and merge overlapping lines in the set of flattened sub split lines. We find those line intersections between lines where the same slope exists and which cover each other fully or partially (collinear overlapping lines). See the graphic to understand the problem.
At the moment Contour Scanner cannot remove those overlaps in original paths.

From left to right:

1st: path 1 is equal to path 2 (they share start point and end point and have the same direction)
2nd: path 1 and path 2 share direction, but not the start or end points
3rd: path 1 and path 2 share one point and direction
4rd: multiple overlapping lones

Issues
Trimming bezier curves
There is no algorithm done to split the original bezier curve after finding intersection points and t parameters yet.


green = a cutting line
black = original bezier curve
purple = approximated polyline
magenta = intersection point between cutting line and original path (the intersection between cutting line and approximated curve would be far away as you can see)

Create Links (Breakaway Connectors)
To create tabs in Inkscape, we cannot properly use the integrated eraser tool. It will clip only in a cosmetic fashion but we do not get the real paths we need. Creating links (also known as microtabs, tabs, bridges, breakaway connectors, links, perforations) is sometimes required for laser cutting or vinyl cutting. This extension allows to pinch paths to create according segments - no cosmetic one's, but real segments. It will split up open or closed contours with user defined rules. To get best output please try to close open paths before using. This extensions is ideal to cut cloth/textile stuff in the laser!
Also have a look at

Convert to Dashes
Lasercut bridges without using extensions
Ein- und Auslaufschnitte, Stege, Brücken, Laschen, Perforationen


Draw some contours

Run the extension and get result

Known issues
The path is not split up? Then please check if your path contains any connected Live Path Effect (LEP) which is associated with it. Like this:

You can remove it by using Apply Transformations extension for example.
Further development
See https://wiki.selfhtml.org/wiki/SVG/Farben/Kontur and https://svgwg.org/specs/strokes/#StrokeDashing
Create Links Extension does not support stroke-dashadjust SVG attribute yet. But if it is implemented in Inkscape, we can adjust the dash pattern

none: default value
stretch: if the pattern does not fully merge into the path length, strokes and gaps are stretched
compress: if the pattern does not fully merge into the path length, strokes and gaps are compressed
dashes: If the pattern does not fully merge into the path length, dashes are adjusted, gaps remain in the selected setting
gaps: if the pattern does not fully merge into the path length, gaps are adjusted, strokes remain in the selected setting

Destructive Clip
An Inkscape Extension which works like Object|Clip|Set except that the paths clipped are actually modified. Thus the clipping is included when exported, for example as a DXF file. Select two or more paths then choose Extensions|Modify path|Destructive clip. The topmost path will be used to clip the others.
Make some path and draw clipping border
Curves (including Arcs) in paths are not supported (use Extensions → Modify path → Flatten Beziers) and non-path objects in the selection will be ignored. Use Object → Ungroup.
Maybe you need to combine multiple contours with CTRL + K before running the extension

Run the extension and get the result
The order of selection defines what is clipped by which contour.

Filter By Length/Area
Paths with value smaller than the given threshold will be deleted. This extension might require to break up your object before.
Take some image
This is not a good example but shows the effect

Run the extension

Result

Incadiff
An Inkscape extension which applies successive difference operations on superimposed paths. Useful for plotter addicts as it removes hidden strokes. Incadiff works on paths and objects. It does not work for open paths. Incadiff does not operate like Contour Scanner And Trimmer and it does not remove duplicate lines if existing.
See also

PathOps
Mutual Cut Line
Contour Scanner And Trimmer
Purge Duplicate Path Segments

Source: https://github.com/incaya/incadiff

Mutual Cut Line
This extension cuts exactly 2 (ideally straight) path segments and will create intersected elements. Depending on the path direction (which can be reversed) the ends are going to be cut against each other
Draw some paths

Duplicate the paths (CTRL + D) and give some different color
This step is optional but helps to understand what's going on here

Check the result
We repeat the previous step and this step for all variants to show the possible outputs. You can reverse the path using "Path → Reverse"




Two regular paths
First and second path reversed
First path reversed
Second path reversed




Output with original as  overlap














Result only

Path Intersections
In case your resulting intersection markings are displaced please run Apply Transformations before running this.
Draw some example with intersecting paths

Run the extension

Check the intersections

Purge Duplicate Path Nodes
https://gitlab.com/EllenWasbo/inkscape-extension-removeduplicatenodes

Annotation belonging to the lines
This extension might turn straight lines into strange looking "d" content like the following
#using the extension will make
m 47.127583,101.78891 h 9.944022 z
 
#to
M 47.1276 101.789 C 47.1276 101.789 57.0716 101.789 57.0716 101.789 C 57.0716 101.789 47.1276 101.789 47.1276 101.789 Z
 
#selecting the line and moving it up/down/left/right will turn it into
m 47.1276,101.789 c 0,0 9.944,0 9.944,0 0,0 -9.944,0 -9.944,0 z
 

Purge Duplicate Path Segments
A common problem while laser cutting or vinyl cutting for example, is the problem with duplicating lines which are overlapping invisibly. Often you won't find them in your drawing. If you use graphics without filtered duplications you might run into issues like burnt edges, rough-cut edges, long running cutting processes, etc.
This plugin removes duplicates from paths with respect to their type (bezier or straight line segments). Please note that maybe you need to combine all lines/paths to one common path to make this work. So this plugin is ideal to remove common edges like professional nesting software is doing too.
Key phrases: remove overlapping lines, remove duplicated lines, purge redundant lines, purge doubled lines, remove common edges, remove occulted lines, hidden line removal, retrace edges, chain paths, clean paths
Annotation belonging to the lines
This extension also helps removing straight line duplications where start or end point is duplicated by using "z" or "Z" in "d" descriptor, which invokes a closing contour, like the following
#turns
m 47.127583,101.78891 h 9.944022 z
 
#into
M 47.1276 101.789 L 57.0716 101.789
Example on how to remove duplicates
Draw a line and copy/paste it


for each line a path 'd' is defined:

Make the paths overlapping  visually (to enforce having some example of duplicated, invisible path)


Combine the lines (Ctrl + K)

The path is now duplicated. See entry 'd' - this is repeated
Run the extension
Now check the XML element tree to see the cleaned up path

Real example and known limitation(s)
Get some parts you want to optimize by rearranging and removing common edges

Check the node count
Calculate the total number of nodes by clicking through XML tree and noting down the nodes count. We use this information to check how good we can reduce the duplicates in the drawing.


For this example we have 13 paths witha total of 38 * 5 + 21 *8 = 358 nodes
Check the total line length
We can also get a goodcomparison by measuring the total length of all paths before and after purging duplicate lines.

Rearrange and combine all paths
CTRL + K to combine the things. You might need to ungroup all items before.

Run the extension and get the result

Check the line length again

Known Limitation: We reduced the set by 8 nodes (only). The limitation can be found in detail: Duplicated paths are only removed if start and end point of the line segment are equal. It will not work if one line segment is shorter or longer because the X1Y1 or X2Y2 coordinate will be different. A more complicated algorithm is required to get optimal results. The following screenshots just shows one line segments moved to reveal the remaining underlying common edge. To avoid this problem we would need to intersect all lines with each other to receive the whole set of intersecting points. Then we proceed to remove duplicate segments.

 

Check the total line length again
We reduced the line length from 2893.74 mm to 2882.45 mm. Not a great saving for this example, but still a reduction.

Purge Pointy Paths
This filter deletes paths which render as point only, like:


m 45.250809,91.692739 - this path contains onyl one command - a single point

m 45.250809,91.692739 z - this path contains two commands, but only one coordinate. It's a single point, the path is closed by a Z command


m 45.250809,91.692739 l 45.250809,91.692739 - this path contains two commands, but the first and second coordinate are the same. It will render als point

m 45.250809,91.692739 l 45.250809,91.692739 z - this path contains three commands, but the first and second coordinate are the same. It will render als point, the path is closed by a Z command

Remove Duplicate Line Segments
An Inkscape extension to remove duplicate line segments with an option to add a tolerance for regarding the segments as a match. See http://cutlings.wasbo.net/inkscape-extension-removeduplicatelines

See also

Purge Duplicate Path Segments
Contour Scanner And Trimmer
Purge Duplicate Path Nodes
Deduplicate Plugin

Split And Break Bezier At t
Splits a path at value t=0..1 (t=0.5 means 50%)
Applies independently for each sub path in selection.

Allows better control over splitting than Add Nodes or Split Bezier (Subdivide Path).
Draw some path

Run the extension

Splitted path

Split Bezier (Subdivide Path)
Function is like Modify Path → Add Nodes but it provides additional features like

splitting path into disconnected sub paths (break apart)
choose units

Please note that the plugin will sub-divide each path segment (from path handle to path handle). So it does not split the whole curve into given amount of piece like acting "as one item". Each bezier segment is it's own element.
Draw some example

Run the extension

Note that "Live preview" will only work if "Break apart" is not selected

Tip: Breaking apart the curve can also be done by ...
Selecting the path and show handles

Select all handles and break
 

Break apart the path
SHIFT + CTRL + K

Tip: Splitted paths can be combined again nearly the same look like before by ...
Example for bezier path
Draw some curve and split it up running the extension

Duplicate the path
CTRL + D to duplicate. We use this to check the quality of simplification
Run Path → Simplify
As you can see the result has other handles than before. The right image shows a black curve (curve before simplification), the green shows the simplified curve. You can see that the curve is not exactly the same. So we can say that simplification for bezier curves is not the best in all use cases, but it will work absolutely fine for straight line segments:

As you can see the result has other handles than before. The right image shows a black curve (curve before simplification), the green shows the simplified curve. You can see that the curve is not exactly the same. So we can say that simplification for bezier curves is not the best in all use cases, but it will work absolutely fine for straight line segments:

Example for path with straight line segments only
Draw some curve and split it up running the extension


Run Path → Simplify