Skip to content

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

Notifications You must be signed in to change notification settings

maxnachlinger/point-in-svg-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: [] } ]
*/

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published