JSPM

svg-path-contours

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 954
  • Score
    100M100P100Q107888F
  • License MIT

gets 2D contours from an SVG path

Package Exports

  • svg-path-contours

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (svg-path-contours) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

svg-path-contours

stable

Approximates an SVG path into a discrete list of 2D contours (polylines). This is useful for collision detection, intersection, triangulation & WebGL rendering, etc. It does not attempt to clean or optimize the discretized points.

img

Usage:

var parse = require('parse-svg-path')
var contours = require('svg-path-contours')

var path = 'm10,10C45.812,24.024,45.673,24,45.529,24H31.625
   c0.482-3.325,6.464-2.758,8.913-3.155z'

var result = contours(parse(path))

/* 
[ 
 [ [10,10], ...etc ]
 [ [x, y], ... ]
]
*/

Triangulation example:

var parse = require('parse-svg-path')
var simplify = require('simplify-path')
var contours = require('svg-path-contours')
var triangulate = require('triangulate-contours')

//get a list of polylines/contours from svg contents
var lines = contours(parse(path))

//simplify the contours before triangulation
lines = lines.map(function(path) {
    return simplify(path, threshold)
})

//turns into triangles, returns { positions, cells }
var shape = triangulate(lines)

//now draw the simplicial complex with Canvas/WebGL/etc

See demo/index.js for exmaple.

Usage

NPM

contours(svg)

Takes parsed SVG contents from parse-svg-path and produces a list of 2D polylines representing the contours of the shape.

License

MIT, see LICENSE.md for details.