Esempio n. 1
0
        private static int GetLocalIntersectionSegmentIdx([NotNull] Linestring forSegments,
                                                          double virtualVertexIndex,
                                                          out double distanceAlongAsRatio)
        {
            Assert.ArgumentNotNull(forSegments, nameof(forSegments));
            Assert.ArgumentNotNaN(virtualVertexIndex, nameof(virtualVertexIndex));

            var localSegmentIdx = (int)Math.Truncate(virtualVertexIndex);

            distanceAlongAsRatio = virtualVertexIndex - localSegmentIdx;

            if (forSegments.IsLastPointInPart(localSegmentIdx) && distanceAlongAsRatio >= 0)
            {
                // out of segment bounds:
                if (forSegments.IsClosed)
                {
                    localSegmentIdx = 0;
                }
                else
                {
                    // last segment, end point:
                    localSegmentIdx      -= 1;
                    distanceAlongAsRatio += 1;
                }
            }

            return(localSegmentIdx);
        }
Esempio n. 2
0
        private static bool IsRingStartOrEnd([NotNull] Linestring linestring,
                                             double localVertexIndex)
        {
            Assert.False(double.IsNaN(localVertexIndex), "localVertexIndex is NaN");

            var vertexIndexIntegral = (int)localVertexIndex;

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            bool isVertex = localVertexIndex == vertexIndexIntegral;

            if (!isVertex)
            {
                return(false);
            }

            if (linestring.IsFirstPointInPart(vertexIndexIntegral) ||
                linestring.IsLastPointInPart(vertexIndexIntegral))
            {
                return(linestring.IsClosed);
            }

            return(false);
        }