} else if (j == max - 2 && !closed) { double distancePointLine = CGAlgorithms.distancePointLine(c4, c1, c2); if (distancePointLine < abs(offset) / 10) { c2.x = c4.x;
/** * 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 */ public static double distancePointLine(Coordinate p, Coordinate[] line) { if (line.length == 0) throw new IllegalArgumentException( "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 = distancePointLine(p, line[i], line[i + 1]); if (dist < minDistance) { minDistance = dist; } } return minDistance; }
return distancePointLine(A, C, D); if (C.equals(D)) return distancePointLine(D, A, B); distancePointLine(A, C, D), distancePointLine(B, C, D), distancePointLine(C, A, B), distancePointLine(D, A, B));