intersectionSafe method
Computes a segment intersection using homogeneous coordinates. Round-off error can cause the raw computation to fail, (usually due to the segments being approximately parallel). If this happens, a reasonable approximation is computed instead.
@param p1 a segment endpoint @param p2 a segment endpoint @param q1 a segment endpoint @param q2 a segment endpoint @return the computed intersection point
Implementation
Coordinate intersectionSafe(
Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) {
Coordinate? intPt = Intersection.intersection(p1, p2, q1, q2);
if (intPt == null) intPt = nearestEndpoint(p1, p2, q1, q2);
// System.out.println("Snapped to " + intPt);
return intPt;
}