예제 #1
0
        private static void CollectIntersection(
            [NotNull] SegmentIntersection intersection,
            [NotNull] ISegmentList source,
            [NotNull] IDictionary <int, HashSet <double> > allLinearIntersectionFactors,
            [NotNull] ICollection <SegmentIntersection> intersectionsForCurrentSourceSegment)
        {
            // Collect segments for current index in list, unless they are clearly not needed
            // (and would need to be filtered by a later linear intersection if added)

            bool isLinear = intersection.HasLinearIntersection;

            if (isLinear)
            {
                int partIndex;
                int localSegmentIndex =
                    source.GetLocalSegmentIndex(intersection.SourceIndex, out partIndex);

                double linearIntersectionStartFactor =
                    localSegmentIndex +
                    intersection.GetLinearIntersectionStartFactor(true);

                double linearIntersectionEndFactor =
                    localSegmentIndex +
                    intersection.GetLinearIntersectionEndFactor(true);

                if (intersection.IsSourceZeroLength2D &&
                    ContainsIntersection(allLinearIntersectionFactors,
                                         partIndex, linearIntersectionEndFactor))
                {
                    // avoid double linear segments if the source segment is vertical
                    return;
                }

                AddIntersectionFactor(linearIntersectionStartFactor, partIndex,
                                      allLinearIntersectionFactors, source);

                AddIntersectionFactor(linearIntersectionEndFactor, partIndex,
                                      allLinearIntersectionFactors, source);
            }

            if (!isLinear && intersection.SourceStartIntersects &&
                source.IsFirstSegmentInPart(intersection.SourceIndex) && source.IsClosed)
            {
                // will be reported again at the end
                return;
            }

            if (!isLinear && intersection.SourceEndIntersects &&
                !source.IsLastSegmentInPart(intersection.SourceIndex))
            {
                // will be reported again at next segment
                return;
            }

            intersectionsForCurrentSourceSegment.Add(intersection);
        }
예제 #2
0
        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));
        }