JSPM

normalize-path-scale

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 167
  • Score
    100M100P100Q79609F
  • License MIT

normalizes a 2d path to its bounding box

Package Exports

  • normalize-path-scale

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 (normalize-path-scale) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

normalize-path-scale

stable

Normalizes a 2D path to its bounding box. This is useful to take a series of paths (e.g. SVG) and normalize them all into the -1.0 .. 1.0 range, for easier rendering. It also makes it more suitable for rendering SVG paths in 3D space with WebGL.

Also corrects aspect ratio.

var discretize = require('discretize-svg-path')
var parse = require('parse-svg-path')
var normalize = require('normalize-path-scale')

//parse into usable array
var path = parse(svgContents)

//approximate into discrete points
var points = discretize(path)

//normalize to -1.0 .. 1.0
points = normalize(points)

//render with webgl / canvas / etc
//...

Usage

NPM

normalize(path)

Produces a new path (with new points) from the original 2D path, but scaled based on its bounding box so that all points are within the range of -1.0 to 1.0. This also maintains the original aspect ratio of the path.

var path = normalize([ [20,20], [10,10], [40,-50] ])

License

MIT, see LICENSE.md for details.