Example #1
0
        /// <summary>
        /// Gets the segment intersections between the specified path and multiline-string.
        /// </summary>
        /// <param name="segmentList1"></param>
        /// <param name="segmentList2"></param>
        /// <param name="tolerance"></param>
        /// <param name="optimizeLinearIntersections">If true, an optimiziation that improves the
        /// performance when linear intersections are present. If a segmentList1 segment is equal
        /// to a linestring2 segment it will directly be used. Other intersections will be missed.
        /// </param>
        /// <returns>The segment intersections with the index of the cut part of multiLinestring2</returns>
        public static IEnumerable <SegmentIntersection> GetSegmentIntersectionsXY(
            [NotNull] ISegmentList segmentList1,
            [NotNull] ISegmentList segmentList2,
            double tolerance,
            bool optimizeLinearIntersections = false)
        {
            if (GeomRelationUtils.AreBoundsDisjoint(segmentList1, segmentList2, tolerance))
            {
                yield break;
            }

            SegmentIntersection previousLinearIntersection = null;

            for (var lineIdx = 0; lineIdx < segmentList1.SegmentCount; lineIdx++)
            {
                Line3D line = segmentList1.GetSegment(lineIdx);

                foreach (SegmentIntersection result in GetSegmentIntersectionsXY(
                             lineIdx, line, segmentList2, tolerance,
                             previousLinearIntersection))
                {
                    if (optimizeLinearIntersections && result.SegmentsAreEqualInXy)
                    {
                        previousLinearIntersection = result;
                    }

                    yield return(result);
                }
            }
        }
Example #2
0
        private static SegmentIntersection TryGetContinuousLinearIntersection(
            int lineIdx,
            [NotNull] Line3D line1,
            [NotNull] ISegmentList segmentList2,
            [CanBeNull] SegmentIntersection previous,
            double tolerance)
        {
            if (previous == null ||
                previous.SourceIndex + 1 != lineIdx)
            {
                // We jumped over some source segments
                return(null);
            }

            int?targetIdx = previous.LinearIntersectionInOppositeDirection
                                                 ? segmentList2.PreviousSegmentIndex(previous.TargetIndex)
                                                 : segmentList2.NextSegmentIndex(previous.TargetIndex);

            if (targetIdx == null)
            {
                return(null);
            }

            Line3D targetSegment =
                segmentList2.GetSegment(targetIdx.Value);

            if (targetSegment.EqualsXY(line1, tolerance))
            {
                SegmentIntersection resultIntersection =
                    SegmentIntersection.CreateCoincidenceIntersectionXY(
                        lineIdx, targetIdx.Value,
                        previous.LinearIntersectionInOppositeDirection);

                return(resultIntersection);
            }

            return(null);
        }
Example #3
0
        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);
        }