point-in-svg-path

1.0.2 • Public • Published

point-in-svg-path

Determines if a point is in a SVG path - code cribbed from Snap.svg - path.js

travis npm

Examples

Check if a single point is inside a single closed path:

const { pointInSvgPath } = require('point-in-svg-path')

pointInSvgPath('M80 80A 45 45, 0, 0, 0, 125 125L 125 80 Z', 100, 100) // true
pointInSvgPath('M80 230A 45 45, 0, 0, 1, 125 275L 125 230 Z', 115, 200) // false

Check which points intersect which paths:

const { getPointsAndIntersectingPaths } = require('point-in-svg-path')

const results = getPointsAndIntersectingPaths(
  [{ id: 'test-path', data: 'M80 80A 45 45, 0, 0, 0, 125 125L 125 80 Z' }], 
  [{ id: 'test-point', x: 100, y: 100 }, { id: 'test-point', x:750, y: 500 }]
)

console.log(results)
/*
[ { pointId: 'test-point',
    x: 100,
    y: 100,
    intersectingPathIds: [ 'test-path' ] },
  { pointId: 'test-point', x: 750, y: 500, intersectingPathIds: [] } ]
*/

Readme

Keywords

none

Package Sidebar

Install

npm i point-in-svg-path

Weekly Downloads

6,311

Version

1.0.2

License

ISC

Unpacked Size

30 kB

Total Files

3

Last publish

Collaborators

  • max.nachlinger