point-in-svg-path
v1.0.2
Published
Checks if a point is in an svg path
Downloads
25,821
Readme
point-in-svg-path
Determines if a point is in a SVG path - code cribbed from Snap.svg - path.js
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: [] } ]
*/