final double offset = new Line(p1, p2, tolerance).getOffset(point);
if (FastMath.abs(offset) < tolerance) {
// the point is collinear to the line (p1, p2)
final double distanceToCurrent = p1.distance(point);
if (distanceToCurrent < tolerance || p2.distance(point) < tolerance) {
// the point is assumed to be identical to either p1 or p2
return;
}
final double distanceToLast = p1.distance(p2);