public static LucidPolygon Create(IEnumerable <IPoint> initialRing, LucidSpatialReference spatialReference = null)
        {
            if (initialRing.Count() < 2)
            {
                throw new Exception($"Invalid polygon ring. {initialRing} Too few vertices.");
            }

            var ring = GeometryHelper.Intersects(initialRing.First(), initialRing.Last())
                ? initialRing : initialRing.Concat(initialRing.Take(1));

            return(new LucidPolygon()
            {
                Rings = new List <List <ILucidVertex> >()
                {
                    new List <ILucidVertex>(ring.Select(p => p.AsVertex()))
                },
                SpatialReference = spatialReference
            });
        }
Exemple #2
0
        public static IEnumerable <IPoint> LineIntersections(ILucidLine first, ILucidLine second, bool infinitLines = false)
        {
            var firstExtent  = CalculateExtent(first);
            var secondExtent = CalculateExtent(second);

            if (infinitLines || GeometryHelper.Intersects(first, second))
            {
                foreach (var firstLine in from p in first.Vertices.TumblingWindow(2)
                         select new AlgebraicLine(p.First(), p.Last()))
                {
                    foreach (var secondLine in from p in second.Vertices.TumblingWindow(2)
                             select new AlgebraicLine(p.First(), p.Last()))
                    {
                        var intersection = Intersection(firstLine, secondLine);

                        if (intersection != null && (infinitLines || (GeometryHelper.Intersects(intersection, firstExtent) && GeometryHelper.Intersects(intersection, secondExtent))))
                        {
                            yield return(intersection);
                        }
                    }
                }
            }
        }
 public bool ExtentOverlaps(LucidPolygon other)
 {
     return(GeometryHelper.Intersects(this.AsExtent(), other.AsExtent()));
 }