public Pnt3D GetNonIntersectingSourcePoint([NotNull] Linestring sourceRing, double distanceFromIntersectionAsRatio) { Assert.NotNull(SegmentIntersection); double factor; var searchForward = true; if (Type == IntersectionPointType.LinearIntersectionStart) { searchForward = false; factor = SegmentIntersection.GetLinearIntersectionStartFactor(true); } else if (Type == IntersectionPointType.LinearIntersectionEnd) { factor = SegmentIntersection.GetLinearIntersectionEndFactor(true); } else { factor = SegmentIntersection.GetIntersectionPointFactorAlongSource(); } Line3D segment = sourceRing[SegmentIntersection.SourceIndex]; if (searchForward) { factor += distanceFromIntersectionAsRatio; } else { factor -= distanceFromIntersectionAsRatio; } if (factor >= 1) { segment = sourceRing[ sourceRing.NextIndexInRing(SegmentIntersection.SourceIndex)]; factor -= 1; } else if (factor < 0) { segment = sourceRing[ sourceRing.PreviousIndexInRing(SegmentIntersection.SourceIndex)]; factor += 1; } return(segment.GetPointAlong(factor, true)); }
public static IntersectionPoint3D CreateSingleIntersectionPoint( [NotNull] SegmentIntersection intersection, [NotNull] ISegmentList sourceSegments, [NotNull] ISegmentList targetSegments, double tolerance) { Line3D sourceSegment = sourceSegments.GetSegment(intersection.SourceIndex); double?targetIntersectionFactorOnSource = intersection.GetIntersectionPointFactorAlongSource(); int sourcePartIdx; int sourceSegmentIndex = sourceSegments.GetLocalSegmentIndex( intersection.SourceIndex, out sourcePartIdx); Pnt3D point; double sourceIndex; // ReSharper disable once CompareOfFloatsByEqualityOperator if (targetIntersectionFactorOnSource == 0) { point = sourceSegment.StartPoint; sourceIndex = sourceSegmentIndex; } // ReSharper disable once CompareOfFloatsByEqualityOperator else if (targetIntersectionFactorOnSource == 1) { point = sourceSegment.EndPoint; sourceIndex = sourceSegmentIndex + 1; } else { point = sourceSegment.GetPointAlong( targetIntersectionFactorOnSource.Value, true); sourceIndex = sourceSegmentIndex + targetIntersectionFactorOnSource.Value; } IntersectionPoint3D result = new IntersectionPoint3D(point, sourceIndex, intersection) { SourcePartIndex = sourcePartIdx }; bool?targetDeviatesToLeft; result.Type = intersection.IsCrossingInPoint( sourceSegments, targetSegments, tolerance, out targetDeviatesToLeft) ? IntersectionPointType.Crossing : IntersectionPointType.TouchingInPoint; result.TargetDeviatesToLeftOfSource = targetDeviatesToLeft; int targetPartIdx; result.VirtualTargetVertex = CalculateVirtualTargetVertex( targetSegments, result.Type, intersection, out targetPartIdx); result.TargetPartIndex = targetPartIdx; return(result); }