Skip to content

Latest commit

 

History

History
52 lines (37 loc) · 2.61 KB

README.md

File metadata and controls

52 lines (37 loc) · 2.61 KB

svg.pathmod.js

A plugin for the svgdotjs.github.io library to modify SVG paths. The core of this plugin is based on simplify-js (c) 2017, Vladimir Agafonkin

Get Started

npm install svg.pathmod.js

Usage

If you don't see image below look at this page on https://janmisker.github.io/svg.pathmod.js/, because inline SVG might be disabled.

Quickest to just show it. First image is a path with 133 points, for example drawn by user. Second image is the simplified version of that path.

var svg = SVG().addTo('#drawing').size(100,100)
var path = svg.path(....) // create a path
path.simplify(1, true)

The simplified version has only 16 points, making it much more lightweight, and it also looks better. There are of course parameters, for example using a tolerance of 5 and not employing the radial distance algorithm this is the result:

path.simplify(5, false)
This results in a path consisting of just 6 points. Of course it depends on your use case what is an acceptable simplification.

Destructive modification

Do note that the path is modified in place, if you need to keep hold of the existing path make sure to clone it first.

Licence

svg.pathmod.js is licensed under the terms of the MIT License.

Dependencies

This module requires svg.js >= v3.0.12