pointToSegmentString static method
Computes the distance from a point to a sequence of line segments.
@param p a point @param line a sequence of contiguous line segments defined by their vertices @return the minimum distance between the point and the line segments
Implementation
static double pointToSegmentString(Coordinate p, List<Coordinate> line) {
if (line.length == 0)
throw new ArgumentError("Line array must contain at least one vertex");
// this handles the case of length = 1
double minDistance = p.distance(line[0]);
for (int i = 0; i < line.length - 1; i++) {
double dist = Distance.pointToSegment(p, line[i], line[i + 1]);
if (dist < minDistance) {
minDistance = dist;
}
}
return minDistance;
}