Apps Part of Threadsmith

Path Boolean Operations (SVG)

Union, intersect, subtract or exclude two SVG paths, or remove the overlaps of one path.

More options

Try an example: · ·

More about this tool

How it works

Paste two SVG paths (the d attribute) and combine them like a vector editor's Path menu: union, intersection, difference or exclusion. With an empty second path, union removes overlaps and self-intersections. Curves are flattened within your tolerance, combined exactly as polygons and refitted to Bézier curves; the result is checked against both inputs on a grid of test points. Threadsmith uses the same engine for Object → Combine shapes.

  • Both paths are parsed with the full SVG path grammar (arcs become cubic Béziers, about 2.7e-4 × radius off) and every curve is flattened adaptively so that the polygon stays within the curve tolerance. Open sub-paths are closed, as SVG filling does.
  • Vertices are snapped to a grid of 1e-9 × the drawing size; all segments are split at their crossings, T-junctions and collinear overlaps (sweep over x-sorted bounding boxes), and identical edges are merged with a signed count per path.
  • For every edge, an axis-parallel ray from its midpoint across all other edges gives the winding numbers of A and B on both sides. With each path's fill rule this decides whether each side is inside the result; edges with the result on one side only are kept, oriented and chained into rings (tightest turn first), and collinear points are removed. The result has winding ±1 inside, so it fills the same with nonzero and evenodd.
  • Curve refit: runs between corners (turns sharper than 35°) are fitted with least-squares cubic Béziers (chord-length parameters, Newton reparameterisation, split at the worst point). A curve is accepted only when every polygon point lies within the refit tolerance of the curve and 16 samples of the curve lie within it of the polygon; otherwise straight segments stay.
  • Check: on a 48 × 48 grid over the drawing, every point farther than twice the tolerances from any outline must be inside the re-read result exactly when the operation says so for its position in A and B.

The result is within the curve tolerance of the exact Boolean (plus the refit tolerance when curves are refitted) and rounded to the chosen decimals. Strokes, transforms, clip paths and text are not part of path data; convert them to paths first. Up to 200,000 characters per path and 40,000 segments after flattening.

Sources

Part of Threadsmith

Related tools

  • Threadsmith Digitizer – Turn shapes, SVG paths, text or a whole project into embroidery stitches with stats and preview.
  • Raster Artwork to SVG – Trace logos and flat artwork into real SVG paths with a limited color palette.
  • Vector Shape Generator – Make editable SVG polygons, stars and spirals from simple settings.

How to use Path Boolean Operations (SVG)

Combine two SVG paths by union, intersection, difference or exclusion, or remove the overlaps of one path, with curves refitted and a built-in point check.

What it is for

Vector editors have a Path or Pathfinder menu that merges, cuts and intersects shapes. This tool does the same for raw SVG path data: paste the d attribute of path A and path B, pick an operation and get one clean path back. Typical uses are building an icon from simple shapes, cutting a hole into a badge, getting the overlap of two outlines, or cleaning up a self-intersecting path from a font or a plotter file before cutting, engraving or embroidering it.

Leave path B empty and choose Union to remove the overlaps and self-intersections of path A alone. Threadsmith uses the same engine for Object → Combine shapes, so embroidery outlines can be combined in the app with undo.

Worked example

Path A is a 40 × 40 square (M0 0H40V40H0Z) and path B a circle with radius 12 in its middle, written with two SVG arcs. With Difference (A minus B), curve and refit tolerance 0.02 and 3 decimals:

  • Result area: 1147.6659 units², Outlines: 1, Holes: 1, Point check: Passed.
  • The exact area is 1600 − π · 12² = 1147.61; the small excess comes from flattening the circle inside the 0.02 tolerance.
  • Details shows 132 segments after flattening, 14 nodes in the result and 10 curve segments: the round hole came back as smooth Béziers instead of 128 tiny lines.
  • Test points checked: 2300 of 2300 agree, 4 near an outline skipped.

The union of two radius-10 circles 10 units apart gives 505.4375 units² (exact value 505.48) with 16 curve nodes. A self-intersecting five-pointed star drawn as one line (M50 0L79 91L2 35L98 35L21 91Z) with an empty path B becomes a single 10-node outline of 2828.9543 units².

How to read the result

  • Result path data (d) is ready to paste into an SVG <path>. It has winding ±1 inside, so it renders the same with fill-rule nonzero or evenodd.
  • Download path-….svg is a small standalone SVG file of the result.
  • The preview fills the result in blue and outlines path A (dashed red) and path B (dashed green).
  • Outlines and Holes count the rings; an exclusion of two overlapping shapes usually has two outlines.
  • Point check reads the result back and tests a 48 × 48 grid: every point not close to an outline must be inside the result exactly when the operation says so for its position in A and B.
  • Curve runs kept straight counts parts whose refitted curve did not stay within the refit tolerance; they stay as straight segments.

Tips and common mistakes

  • Coordinates are SVG user units; choose tolerances in the same units. 0.01–0.05 suits icons and millimetre drawings, larger drawings can use more.
  • Turn off Refit Bézier curves when you need the exact polygon (for example for a cutter that only takes lines).
  • Each path's Fill rule matters for overlapping or nested sub-paths: with evenodd the centre of a star drawn as one line is a hole, with nonzero it is filled.
  • Only path data is read. Transforms, strokes, clip paths and text in your SVG file are not applied; convert them to paths first.
  • Paths are limited to 200,000 characters each and 40,000 segments after flattening.

FAQ

How exact is the result?

Curves are flattened so that the polygon stays within the curve tolerance; the Boolean of the polygons is then exact up to a snap grid of a billionth of the drawing size. Refitting adds at most the refit tolerance, and the output is rounded to the chosen decimals.

Why did my result get more nodes than expected?

Nodes appear where outlines cross and where refitted curves had to be split to stay within the tolerance. A larger refit tolerance gives fewer nodes.

Can it combine more than two shapes?

The tool takes two paths, but path A may contain several sub-paths. For more shapes, run it again with the result as path A, or select all shapes in Threadsmith and use Combine shapes there.

Guide last updated:

For scripts and AI agents

  • JSON API: POST https://threadsmithpathboolean.usefulweb.app/api/v1/calculate (same calculation as this page)
  • Interface description: OpenAPI 3.1 · AI guide: llms.txt
  • MCP server (Streamable HTTP): https://threadsmithpathboolean.usefulweb.app/mcp · tool name threadsmith_path_boolean
Example request
curl -s -X POST https://threadsmithpathboolean.usefulweb.app/api/v1/calculate \
  -H 'content-type: application/json' \
  -d '{"pathA":"M-10 0A10 10 0 1 0 10 0A10 10 0 1 0 -10 0Z","pathB":"M0 0A10 10 0 1 0 20 0A10 10 0 1 0 0 0Z","op":"union","fillA":"nonzero","fillB":"nonzero","tolerance":0.01,"refit":true,"fitTolerance":0.01,"precision":3}'
Feedback · ideas & bug reports welcome