Пример #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 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);
        }