A low-level library for performing boolean operations on SVG paths. The project is still in early stages of development; please, help me test it and provide reduced examples of failure cases.
- Comment the code thoroughly.
- Support shape builder use-case.
npm install path-boolnpm run build
# or with asserts:
npm run build-dev# build first (benchmark imports dist/path-bool.js)
npm run build
# run all benchmark fixtures from bench/fixtures
npm run bench
# run a subset of cases by name
npm run bench -- --cases nesting-03,nesting-04
# run wildcard subset and custom folder
npm run bench -- --root ./my-bench-fixtures --cases "stress-*"Benchmark input format:
- each case contains an SVG file named
original.svg(override with--file) - that SVG has two path elements with IDs
aandb(override with--id-aand--id-b) - benchmark runs all boolean ops:
union,difference,intersection,exclusion,division,fracture
See the docs directory or visit https://r-flash.github.io/PathBool.js/.
A snippet of possible usage:
import * as PathBool from "path-bool";
// initialize path from SVG path data...
const pathA = PathBool.pathFromPathData("M0,0 C...");
// ...or from an array of SVG path commands...
const pathA = PathBool.pathFromCommands([["M", [0, 0]], ["C", [/*...*/], /*...*/]/*...*/]);
// ...or directly from path segments (L, C, Q, or A with the start point prepended)
const pathA = [["C", [0, 0], [/*...*/], /*...*/], /*...*/];
const fillRuleA = PathBool.FillRule.EvenOdd;
const pathB = PathBool.pathFromPathData("M0,0 C...");
const fillRuleB = PathBool.FillRule.NonZero;
const op = PathBool.PathBooleanOperation.Union;
const result = PathBool.pathBoolean(pathA, fillRuleA, pathB, fillRuleB, op);
console.log(result.map(PathBool.pathToPathData));
console.log(result.map(PathBool.pathToCommands));MIT License
Copyright © 2024 Adam Platkevič