Example #1
0
        /// <summary>
        /// Only public to make the compiler happy about the "where TPoly : new" constraint.
        /// Will be populated by caller.
        /// </summary>
        public Obstacle(Shape shape, bool makeRect, double padding)
        {
            if (makeRect)
            {
                var paddedBox = shape.BoundingBox;
                paddedBox.Pad(padding);
                this.PaddedPolyline = Curve.PolyFromBox(paddedBox);
            }
            else
            {
                this.PaddedPolyline = InteractiveObstacleCalculator.PaddedPolylineBoundaryOfNode(shape.BoundaryCurve, padding);
#if TEST_MSAGL || VERIFY_MSAGL
                // This throws if the polyline is nonconvex.
                VisibilityGraph.CheckThatPolylineIsConvex(this.PaddedPolyline);
#endif // TEST || VERIFY
            }

            RoundVertices(this.PaddedPolyline);
            this.IsRectangle = this.IsPolylineRectangle();
            if (!this.IsRectangle)
            {
                this.ConvertToRectangleIfClose();
            }
            InputShape = shape;
            Ports      = new Set <Port>(InputShape.Ports);
        }
Example #2
0
        internal static Polyline CreateLoosePolyline(Polyline polyline)
        {
            var loosePolyline = InteractiveObstacleCalculator.CreatePaddedPolyline(polyline, ApproximateComparer.IntersectionEpsilon * 10);

            RoundVertices(loosePolyline);
            return(loosePolyline);
        }
        private static void CheckEdgesForOverlapWithNodes(double tightPadding, GeometryGraph graph)
        {
#if TEST_MSAGL
            if (!DontShowTheDebugViewer())
            {
                DisplayGeometryGraph.SetShowFunctions();
            }
#endif
            foreach (var e in graph.Edges.Where(e => !MultiEdge(e)))//avoid checking multi-edges since they routed as bundles and can slightly go over the nodes
            {
                Assert.IsNotNull(e.EdgeGeometry, "EdgeGeometry is null");
                Assert.IsNotNull(e.EdgeGeometry.Curve, "EdgeGeometry.Curve is null");
                foreach (var v in graph.Nodes)
                {
                    if (v == e.Source || v == e.Target)
                    {
                        continue;
                    }
                    var  box      = v.BoundingBox;
                    var  poly     = InteractiveObstacleCalculator.CreatePaddedPolyline(Curve.PolylineAroundClosedCurve(v.BoundaryCurve), tightPadding / 2);
                    bool overlaps = CurveOverlapsBox(e.EdgeGeometry.Curve, ref box, poly);
#if TEST_MSAGL
                    //uncomment to see the graph and the overlaps
                    if (overlaps && !DontShowTheDebugViewer())
                    {
                        LayoutAlgorithmSettings.ShowGraph(graph);
                        LayoutAlgorithmSettings.Show(poly, e.Curve);
                    }
#endif
                    Assert.IsFalse(overlaps);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Only public to make the compiler happy about the "where TPoly : new" constraint.
        /// Will be populated by caller.
        /// </summary>
        public Obstacle(Shape shape, bool makeRect, double padding)
        {
            if (makeRect)
            {
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=369 there are no structs in js
                var paddedBox = shape.BoundingBox.Clone();
#else
                var paddedBox = shape.BoundingBox;
#endif
                paddedBox.Pad(padding);
                this.PaddedPolyline = Curve.PolyFromBox(paddedBox);
            }
            else
            {
                this.PaddedPolyline = InteractiveObstacleCalculator.PaddedPolylineBoundaryOfNode(shape.BoundaryCurve, padding);
#if TEST_MSAGL || VERIFY_MSAGL
                // This throws if the polyline is nonconvex.
                VisibilityGraph.CheckThatPolylineIsConvex(this.PaddedPolyline);
#endif // TEST || VERIFY
            }

            RoundVertices(this.PaddedPolyline);
            this.IsRectangle = this.IsPolylineRectangle();
            if (!this.IsRectangle)
            {
                this.ConvertToRectangleIfClose();
            }

            InputShape = shape;
            Ports      = new Set <Port>(InputShape.Ports);
        }
        double GetLeftTipParam(double portParam, Point portPoint, Curve paddingCurve, Node node, double length)
        {
            bool  curveIsClockwise = InteractiveObstacleCalculator.CurveIsClockwise(node.BoundaryCurve, node.Center);
            Point tan = curveIsClockwise
                            ? node.BoundaryCurve.LeftDerivative(portParam)
                            : -node.BoundaryCurve.RightDerivative(portParam);

            tan = ((-tan.Normalize()) * length).Rotate(-EnteringAngle);
            IList <IntersectionInfo> xs = Curve.GetAllIntersections(paddingCurve,
                                                                    new LineSegment(portPoint, portPoint + tan), true);

            Debug.Assert(xs.Count == 1);
            return(xs[0].Par0);
        }
        void CreateLooseObstacles()
        {
            RootOfLooseHierarchy = RootOfTightHierararchy.Clone();

            TraverseHierarchy(RootOfLooseHierarchy, delegate(RectangleNode <Polyline> node) {
                if (node.UserData != null)
                {
                    Polyline tightPolyline = node.UserData;
                    double distance        =
                        FindMaxPaddingForTightPolyline(tightPolyline);
                    LooseObstacles.Add(
                        node.UserData =
                            LoosePolylineWithFewCorners(tightPolyline,
                                                        Math.Min(
                                                            router.LoosePadding,
                                                            distance * 0.3)));
                    node.Rectangle = node.UserData.BoundingBox;
                    InteractiveObstacleCalculator.UpdateRectsForParents(node);
                }
            });
        }
 /// <summary>
 /// Creates a padded polyline boundary of the node. The polyline offsets at least as the padding from the node boundary.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="padding"></param>
 /// <returns></returns>
 static Polyline PaddedPolylineBoundaryOfNode(Node node, double padding)
 {
     return(InteractiveObstacleCalculator.CreatePaddedPolyline(Curve.PolylineAroundClosedCurve(node.BoundaryCurve), padding));
 }
 ///<summary>
 ///</summary>
 ///<param name="closedCurve"></param>
 ///<param name="padding"></param>
 ///<returns></returns>
 static public Polyline GetPaddedPolyline(ICurve closedCurve, double padding)
 {
     return(InteractiveObstacleCalculator.CreatePaddedPolyline(Curve.PolylineAroundClosedCurve(closedCurve), padding));
 }
 void CalculateObstacles() {
     ObstacleCalculator = new InteractiveObstacleCalculator(Obstacles, TightPadding, LoosePadding,
                                                            IgnoreTightPadding);                                 
     ObstacleCalculator.Calculate();
 }
 /// <summary>
 /// An empty constructor for calling it from inside of MSAGL
 /// </summary>        
 internal InteractiveEdgeRouter() {
     ObstacleCalculator = new InteractiveObstacleCalculator(Obstacles, TightPadding, LoosePadding, false);
 }