Exemple #1
0
        public bool IsOnTheRightSide([NotNull] ISegmentList source,
                                     [NotNull] Pnt3D testPoint,
                                     bool disregardOrientation = false)
        {
            Assert.True(source.IsClosed, "Source must be closed ring(s)");

            Linestring sourceRing = source.GetPart(SourcePartIndex);

            double sourceRatio;
            int    sourceSegmentIdx =
                GetLocalSourceIntersectionSegmentIdx(sourceRing, out sourceRatio);

            Line3D sourceSegment = sourceRing[sourceSegmentIdx];

            if (sourceRatio > 0 && sourceRatio < 1)
            {
                // The intersection is on the source segment's interior
                return(sourceSegment.IsLeftXY(testPoint) < 0);
            }

            Line3D previousSegment, nextSegment;

            // Intersection at source vertex 0 or 1 -> get the 2 adjacent segments
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (sourceRatio == 0)
            {
                previousSegment =
                    sourceRing.PreviousSegmentInRing(sourceSegmentIdx, true);

                nextSegment = SegmentIntersection.IsSourceZeroLength2D
                                                      ? sourceRing.NextSegmentInRing(sourceSegmentIdx, true)
                                                      : sourceSegment;
            }
            else             // sourceRatio == 1
            {
                previousSegment = SegmentIntersection.IsSourceZeroLength2D
                                                          ? sourceRing.PreviousSegmentInRing(
                    sourceSegmentIdx, true)
                                                          : sourceSegment;
                nextSegment = sourceRing.NextSegmentInRing(sourceSegmentIdx, true);
            }

            bool result = GeomTopoOpUtils.IsOnTheRightSide(previousSegment.StartPoint, Point,
                                                           nextSegment.EndPoint, testPoint);

            if (!disregardOrientation && sourceRing.ClockwiseOriented == false)
            {
                result = !result;
            }

            return(result);
        }
        private static IEnumerable <Linestring> GetUnused(ISegmentList linestrings,
                                                          HashSet <int> usedIndexes)
        {
            for (int i = 0; i < linestrings.PartCount; i++)
            {
                if (usedIndexes.Contains(i))
                {
                    continue;
                }

                Linestring cutLine = linestrings.GetPart(i);

                yield return(cutLine);
            }
        }
Exemple #3
0
        private static void AddIntersectionFactor(
            double localIntersectionFactor,
            int partIndex,
            [NotNull] IDictionary <int, HashSet <double> > usedIntersectionFactorsByPart,
            [NotNull] ISegmentList source)
        {
            Linestring part = source.GetPart(partIndex);

            if (IsRingStartOrEnd(part, localIntersectionFactor))
            {
                // add both start and end point
                AddIntersectionFactor(0, partIndex, usedIntersectionFactorsByPart);
                AddIntersectionFactor(part.SegmentCount, partIndex, usedIntersectionFactorsByPart);
            }
            else
            {
                AddIntersectionFactor(localIntersectionFactor, partIndex,
                                      usedIntersectionFactorsByPart);
            }
        }