https://github.com/luncheon/simplify-svg-path
Extracts `Path#simplify()` from Paper.js.
https://github.com/luncheon/simplify-svg-path
paper paperjs path svg
Last synced: 3 months ago
JSON representation
Extracts `Path#simplify()` from Paper.js.
- Host: GitHub
- URL: https://github.com/luncheon/simplify-svg-path
- Owner: luncheon
- License: mit
- Created: 2020-09-04T06:30:10.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-09-27T05:49:30.000Z (over 2 years ago)
- Last Synced: 2024-05-30T16:51:23.700Z (about 2 years ago)
- Topics: paper, paperjs, path, svg
- Language: JavaScript
- Homepage: https://luncheon.github.io/simplify-svg-path/index.html
- Size: 169 KB
- Stars: 32
- Watchers: 2
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simplify-svg-path
Extracts `Path#simplify()` from Paper.js.
http://paperjs.org/reference/path/#simplify
## Installation & Usage
### [npm](https://www.npmjs.com/package/@luncheon/simplify-svg-path)
```bash
$ npm i @luncheon/simplify-svg-path
```
```javascript
import simplifySvgPath from '@luncheon/simplify-svg-path'
const points = [[10, 10], [10, 20], [20, 20]];
const path = simplifySvgPath(points);
// "M10,10c0,3.33333 -2.35702,7.64298 0,10c2.35702,2.35702 6.66667,0 10,0"
```
### CDN ([jsDelivr](https://www.jsdelivr.com/package/npm/@luncheon/simplify-svg-path))
```html
const path = simplifySvgPath([[10, 10], [10, 20], [20, 20]]);
```
## API
```ts
simplifySvgPath(
points: [x: number, y: number][], // `{ x: number, y: number }[]` is also acceptable
{
closed: boolean = false,
tolerance: number = 2.5,
precision: number = 5,
} = {}
): string
// SVG path command string such as
// "M10,10c0,3.33333 -2.35702,7.64298 0,10c2.35702,2.35702 6.66667,0 10,0"
```
## Note
The logic is a copy of Paper.js v0.12.11.
If you like this, please send your thanks and the star to [Paper.js](https://github.com/paperjs/paper.js).