/// <summary> /// Computes the intersection point of the lines defined by two segments, if there is one. /// </summary> /// <remarks> /// There may be 0, 1 or an infinite number of intersection points between two lines. /// If there is a unique intersection point, it is returned. /// Otherwise, <c>null</c> is returned. /// If more information is required about the details of the intersection, /// the <see cref="RobustLineIntersector"/> class should be used. /// </remarks> /// <param name="line">A line segment defining a straight line</param> /// <returns>An intersection point, or <c>null</c> if there is none or an infinite number</returns> /// <seealso cref="RobustLineIntersector"/> public Coordinate LineIntersection(LineSegment line) { try { var intPt = HCoordinate.Intersection(_p0, _p1, line._p0, line._p1); return(intPt); } catch (NotRepresentableException ex) { // eat this exception, and return null; } return(null); }
/// <summary> /// Adds a mitre join connecting the two reflex offset segments. /// The mitre will be beveled if it exceeds the mitre ratio limit. /// </summary> /// <param name="p"></param> /// <param name="offset0">The first offset segment</param> /// <param name="offset1">The second offset segment</param> /// <param name="distance">The offset distance</param> private void AddMitreJoin(Coordinate p, LineSegment offset0, LineSegment offset1, double distance) { bool isMitreWithinLimit = true; Coordinate intPt; /** * This computation is unstable if the offset segments are nearly collinear. * However, this situation should have been eliminated earlier by the check for * whether the offset segment endpoints are almost coincident */ try { intPt = HCoordinate.Intersection(offset0.P0, offset0.P1, offset1.P0, offset1.P1); double mitreRatio = distance <= 0.0 ? 1.0 : intPt.Distance(p) / Math.Abs(distance); if (mitreRatio > _bufParams.MitreLimit) { isMitreWithinLimit = false; } } catch (NotRepresentableException ex) { intPt = new Coordinate(0, 0); isMitreWithinLimit = false; } if (isMitreWithinLimit) { _segList.AddPt(intPt); } else { AddLimitedMitreJoin(offset0, offset1, distance, _bufParams.MitreLimit); // addBevelJoin(offset0, offset1); } }