Nearest Segment
Given a point like [0.5, 1]
and a line in the form of an array of coordinates like [[0,0], [1, 1], [2, 2]]
this module finds the nearest segment to the point within the array.
A segment is 2 adjacent points within the given coordinates.
This returns 2 indicies into the original coordinates array.
npm install nearest-segment
Example usage
var getNearest = var coordinates = 00 1 1 2 2 var segmentIndices = // = [0, 1] var closestPoint1 = coordinatessegmentIndices0// = [0,0] var closestPoint2 = coordinatessegmentIndices1// = [1, 1]