Пример #1
0
        public static IEnumerable <ILucidVertex> RemoveSelfIntersections(ILucidLine lineIn)
        {
            var segments = (from s in lineIn.Vertices.SlidingWindow(2)
                            select s).Where(w => w.Count() == 2).ToArray();

            var state = true;

            foreach (var segment in segments)
            {
                if (state == true)
                {
                    yield return(segment.First());
                }

                foreach (var otherSegment in from s in segments
                         where s != segment
                         select s)
                {
                    var intersect = GeometryHelper.LineIntersections(LucidLine.Create(segment), LucidLine.Create(otherSegment)).Any();
                    if (intersect)
                    {
                        state = !state;
                        break;
                    }
                }
            }

            yield return(lineIn.Vertices.Last());
        }
Пример #2
0
        public static ILucidLine FixDuplicateVertices(ILucidLine geometry, int precision = 2)
        {
            var vertexHash  = new HashSet <string>();
            var newVertices = new List <ILucidVertex>();

            var vertices = geometry.Vertices.ToArray();

            for (int i = 0; i < vertices.Length; i++)
            {
                var vertex = vertices[i];
                var id     = vertex.ToString(precision);
                if (!vertexHash.Contains(id))
                {
                    vertexHash.Add(id);
                    newVertices.Add(vertex);
                }
                else if (i == vertices.Length - 1)
                {
                    // We want to remove the interior duplicate not the last vertex
                    newVertices.Remove(newVertices.First(v => v.ToString(precision) == id));
                    newVertices.Add(vertex);
                }
            }

            var lineOut = LucidLine.Create(newVertices);

            return(lineOut);
        }
Пример #3
0
        public static LucidPolygon operator-(LucidPolygon first, LucidPolygon second)
        {
            throw new NotImplementedException();

            LucidPolygon intersection = null;

            if (!first.ExtentOverlaps(second))
            {
                return(null);
            }

            foreach (var segment in first.Vertices.SlidingWindow(2))
            {
                foreach (var secondSegment in second.Vertices.SlidingWindow(2))
                {
                    var point = GeometryHelper.LineIntersections(LucidLine.Create(segment), LucidLine.Create(secondSegment)).FirstOrDefault();
                    if (point != null)
                    {
                        if (intersection == null)
                        {
                            intersection = new LucidPolygon();
                        }

                        intersection += point;
                    }
                }
            }

            return(intersection);
        }
Пример #4
0
        /// <summary>
        /// Returns the nearest line segment from a line
        /// </summary>
        /// <param name="wholeLine"></param>
        /// <param name="referencePoint"></param>
        /// <returns></returns>
        public static ILucidLine NearestLineSegment(ILucidLine wholeLine, IPoint referencePoint)
        {
            if (wholeLine.Vertices.Count() == 2)
            {
                return(wholeLine);
            }

            var vertices = wholeLine.Vertices.SlidingWindow(2);
            var first    = LucidLine.Create(vertices.First());
            var last     = LucidLine.Create(vertices.Last());

            var nearest = NearestGeometry(referencePoint, first, last).First();

            return((ILucidLine)nearest);
        }
Пример #5
0
        public static bool Intersects(IPoint point, ILucidLine line, bool infinitLine = false, int precision = 1)
        {
            var coincidentPoint = line.Vertices.Where(v => v.IsCoincident(point)).FirstOrDefault();

            if (coincidentPoint == null)
            {
                var pointLine = LucidLine.Create(new IPoint[] {
                    new LucidPoint(0, 0),
                    point
                });

                var intersection = LineIntersections(pointLine, line, infinitLine).FirstOrDefault();
                if (intersection == null || !GeometryHelper.IsCoincident(intersection, point, precision))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #6
0
        public static ILucidGeometry Create(string geometryJson)
        {
            if (geometryJson.Contains("\"x\""))
            {
                return(LucidPoint.Create(geometryJson));
            }
            if (geometryJson.Contains("\"xmax\""))
            {
                return(LucidExtent.Create(geometryJson));
            }
            if (geometryJson.Contains("\"paths\""))
            {
                return(LucidLine.Create(geometryJson));
            }
            if (geometryJson.Contains("\"rings\""))
            {
                return(LucidPolygon.Create(geometryJson));
            }

            throw new Exception($"Unrecognized geometry type {geometryJson}");
        }
Пример #7
0
 public static LucidLine Create(Map geometry)
 {
     return(LucidLine.Create(geometry.ToString()));
 }
Пример #8
0
 public static LucidLine operator+(LucidLine first, LucidLine second)
 {
     return(LucidLine.Create(first.Vertices.Concat(second.Vertices)));
 }