void InsertOverlappingSet(Set <Polyline> overlappingSet)
        {
            foreach (Polyline p in overlappingSet)
            {
                tightObstacles.Remove(p);
            }

            var hull = new Polyline();

            foreach (Point p in ConvexHull.CalculateConvexHull(EnumerateOverSetOfPolylines(overlappingSet)))
            {
                hull.AddPoint(p);
            }
            hull.Closed = true;

            //debug
            //List<ICurve> ls=new List<ICurve>();
            //foreach(Polyline p in overlappingSet)
            //    ls.Add(p);

            //ls.Add(hull);
            //SugiyamaLayoutSettings.Show(ls.ToArray());
            //end of debug

            tightObstacles.Insert(hull);
        }
Example #2
0
 static Polyline CreateLoosePolylineOnBisectors(Polyline tightPolyline, double offset)
 {
     return(new Polyline(ConvexHull.CalculateConvexHull(BisectorPoints(tightPolyline, offset)))
     {
         Closed = true
     });
 }
        Polyline InitialTightPolyline(Shape shape)
        {
            var poly = InteractiveObstacleCalculator.PaddedPolylineBoundaryOfNode(shape.BoundaryCurve, TightPadding);
            var stickingPointsArray = LoosePolylinesUnderShape(shape).SelectMany(l => l).Where(
                p => Curve.PointRelativeToCurveLocation(p, poly) == PointLocation.Outside).ToArray();

            if (stickingPointsArray.Length <= 0)
            {
                return(poly);
            }
            return(new Polyline(
                       ConvexHull.CalculateConvexHull(poly.Concat(stickingPointsArray)))
            {
                Closed = true
            });
        }
Example #4
0
        public void CalculateConvexHullTest()
        {
            IEnumerable <Point> expected = new[] { new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10) };
            var points = new List <Point>();

            for (int i = 0; i < 20; ++i)
            {
                points.AddRange(expected);
            }

            IEnumerable <Point> actual = ConvexHull.CalculateConvexHull(points);

            Assert.AreEqual(4, actual.Count(), "Expected only 4 points in convex hull");
            foreach (var point in expected)
            {
                Assert.IsTrue(actual.Contains(point), "expected point not found in convex hull " + point);
            }
        }
Example #5
0
        private static void VerifyAndDisplayConvexHull(Point[] points)
        {
            var hull = new Polyline(ConvexHull.CalculateConvexHull(points))
            {
                Closed = true
            };

            VerifyPointsAreInOrOnHull(points, hull);

#if TEST_MSAGL
            MsaglTestBase.EnableDebugViewer();
            if (LayoutAlgorithmSettings.ShowDebugCurvesEnumeration == null)
            {
                return;
            }
            var poly = new Polyline(points);
            LayoutAlgorithmSettings.ShowDebugCurves(new DebugCurve(100, 0.01, "magenta", hull), new DebugCurve(100, 0.001, "green", poly));
#endif
        }
Example #6
0
        static internal Polyline CreatePaddedPolyline(Polyline poly, double padding)
        {
            Debug.Assert(Point.GetTriangleOrientation(poly[0], poly[1], poly[2]) == TriangleOrientation.Clockwise
                         , "Unpadded polyline is not clockwise");

            var ret = new Polyline();

            if (!PadCorner(ret, poly.EndPoint.Prev, poly.EndPoint, poly.StartPoint, padding))
            {
                return(CreatePaddedPolyline(new Polyline(ConvexHull.CalculateConvexHull(poly))
                {
                    Closed = true
                }, padding));
            }

            if (!PadCorner(ret, poly.EndPoint, poly.StartPoint, poly.StartPoint.Next, padding))
            {
                return(CreatePaddedPolyline(new Polyline(ConvexHull.CalculateConvexHull(poly))
                {
                    Closed = true
                }, padding));
            }


            for (var pp = poly.StartPoint; pp.Next.Next != null; pp = pp.Next)
            {
                if (!PadCorner(ret, pp, pp.Next, pp.Next.Next, padding))
                {
                    return(CreatePaddedPolyline(new Polyline(ConvexHull.CalculateConvexHull(poly))
                    {
                        Closed = true
                    },
                                                padding));
                }
            }

            Debug.Assert(Point.GetTriangleOrientation(ret[0], ret[1], ret[2]) != TriangleOrientation.Counterclockwise
                         , "Padded polyline is counterclockwise");

            ret.Closed = true;
            return(ret);
        }
        /// <summary>
        /// The convex hull of all the points of all the nodes in the cluster
        /// </summary>
        private Polyline ComputeConvexHull()
        {
            var points = new List <Point>();

            foreach (Node v in cluster.Nodes)
            {
                CvxHull r = new RCHull(null, v, 0);
                foreach (PolylinePoint p in r.TranslatedBoundary().PolylinePoints)
                {
                    points.Add(p.Point);
                }
            }

            foreach (Cluster c in cluster.Clusters)
            {
                points.AddRange(new ClusterConvexHull(c, this).TranslatedBoundary());
            }

            return(new Polyline(ConvexHull.CalculateConvexHull(points))
            {
                Closed = true
            });
        }