public void DrawDecoration()
        {
            foreach (var element in Visuals)
            {
                if (element is CryptoLineView)
                {
                    CryptoLineView result = element as CryptoLineView;

                    if (result.Line.Equals(this))
                    {
                        continue;
                    }

                    foreach (FromTo fromTo in PointList)
                    {
                        foreach (FromTo resultFromTo in result.Line.PointList)
                        {
                            if (LineUtil.FindIntersection(fromTo.From, fromTo.To, resultFromTo.From, resultFromTo.To, out intersectPoint))
                            {
                                fromTo.Intersection.Add(intersectPoint);
                                //resultFromTo.Intersection.Add(intersectPoint);
                            }
                        }
                    }
                }
            }
        }
        public static bool PerformOrthogonalPointConnection(Node n1, Point p2, Node n3, List <Node> nodeList, QuadTreeLib.QuadTree <WorkspaceManager.View.VisualComponents.CryptoLineView.FakeNode> quadTreePlugins)
        {
            if (LineUtil.IsConnectionPossible(n1.Point, p2, quadTreePlugins) && LineUtil.IsConnectionPossible(n3.Point, p2, quadTreePlugins))
            {
                Node n2 = new Node()
                {
                    Point = p2
                };
                n1.Vertices.Add(n2);

                n2.Vertices.Add(n1);
                n2.Vertices.Add(n3);

                n3.Vertices.Add(n2);

                nodeList.Add(n2);
                return(true);
            }

            return(false);
        }
        private void makeOrthogonalPoints()
        {
            bool failed = false;

            if (!IsEditingPoint)
            {
                if (!isSubstituteLine && !IsDragged && !HasComputed && !loaded)
                {
                    List <Node>      nodeList = new List <Node>();
                    FrameworkElement parent   = Model.WorkspaceModel.MyEditor.Presentation;

                    // add start and end. Index will be 0 and 1
                    Node startNode = new Node()
                    {
                        Point = LineUtil.Cheat42(StartPoint, StartPointSource, 1)
                    },
                         endNode = new Node()
                    {
                        Point = LineUtil.Cheat42(EndPoint, EndPointSource, -1)
                    };
                    nodeList.Add(startNode);
                    nodeList.Add(endNode);

                    QuadTreeLib.QuadTree <FakeNode> quadTreePlugins = helper.PluginTree;

                    for (int routPoint = 0; routPoint < 4; ++routPoint)
                    {
                        foreach (var element in Visuals)
                        {
                            if (element is ComponentVisual)
                            {
                                IRouting p1 = element as IRouting;
                                nodeList.Add(new Node()
                                {
                                    Point = p1.GetRoutingPoint(routPoint)
                                });
                            }
                        }
                    }

                    // connect points
                    int       loopCount             = nodeList.Count;
                    const int performanceTradeoffAt = 2;

                    LinkedList <Node> path = null;

                    for (int i = 0; i < loopCount; ++i)
                    {
                        StackFrameDijkstra.Dijkstra <Node> dijkstra = new StackFrameDijkstra.Dijkstra <Node>();
                        path = dijkstra.findPath(nodeList, startNode, endNode);
                        if (path != null)
                        {
                            break;
                        }

                        var p1 = nodeList[i];
                        // TODO: inner loop restriction! n²-n!
                        // is k=i instead of k=0 correct?
                        for (int k = i; k < loopCount; ++k)
                        {
                            var p2 = nodeList[k];
                            if (p1 == p2)
                            {
                                continue;
                            }
                            if (p1.Vertices.Contains(p2))
                            {
                                continue;
                            }

                            // no helping point required?
                            if (p1.Point.X == p2.Point.X ||
                                p1.Point.Y == p2.Point.Y)
                            {
                                LineUtil.PerformOrthogonalPointConnection(p1, p2, quadTreePlugins);
                            }
                            else
                            {
                                Point help = new Point(p1.Point.X, p2.Point.Y);

                                if (!LineUtil.PerformOrthogonalPointConnection(p1, help, p2, nodeList, quadTreePlugins))
                                {
                                    help = new Point(p2.Point.X, p1.Point.Y);
                                    if (!LineUtil.PerformOrthogonalPointConnection(p1, help, p2, nodeList, quadTreePlugins))
                                    {
                                        // optional todo: double edge helping routes
                                    }
                                }
                            }
                        }
                    }

                    if (path == null)
                    {
                        StackFrameDijkstra.Dijkstra <Node> dijkstra = new StackFrameDijkstra.Dijkstra <Node>();
                        path = dijkstra.findPath(nodeList, startNode, endNode);
                    }

                    if (path != null)
                    {
                        var list = path.ToList();
                        PointList.Clear();
                        Point startPoint = StartPoint, curPoint, prevPoint = startPoint;
                        bool  isStart = true;
                        for (int c = 0; c < list.Count; ++c)
                        {
                            var i = list[c];
                            curPoint = i.Point;
                            //this.PointList.Add(new FromTo(prevPoint, curPoint));
                            if ((startPoint.X != curPoint.X && startPoint.Y != curPoint.Y))
                            {
                                if (isStart)
                                {
                                    this.PointList.Add(new FromTo(startPoint, prevPoint, FromToMeta.HasStartPoint));
                                    isStart = false;
                                }
                                else
                                {
                                    this.PointList.Add(new FromTo(startPoint, prevPoint));
                                }

                                startPoint = prevPoint;
                            }
                            if (c == list.Count - 1)
                            {
                                if ((startPoint.X != EndPoint.X && startPoint.Y != EndPoint.Y))
                                {
                                    this.PointList.Add(new FromTo(startPoint, curPoint));
                                    startPoint = curPoint;
                                }
                            }

                            prevPoint = curPoint;
                        }
                        this.PointList.Add(new FromTo(startPoint, EndPoint, FromToMeta.HasEndpoint));
                        HasComputed = true;
                        raiseComputationDone(true);
                        return;
                    }
                    failed = true;
                }
                //Failsafe
                if (IsDragged || failed || isSubstituteLine)
                {
                    if (StartPoint.X < EndPoint.X)
                    {
                        PointList.Clear();
                        PointList.Add(new FromTo(StartPoint, new Point((EndPoint.X + StartPoint.X) / 2, StartPoint.Y)));
                        PointList.Add(new FromTo(new Point((EndPoint.X + StartPoint.X) / 2, StartPoint.Y), new Point((EndPoint.X + StartPoint.X) / 2, EndPoint.Y)));
                        PointList.Add(new FromTo(new Point((EndPoint.X + StartPoint.X) / 2, EndPoint.Y), EndPoint));
                    }
                    else
                    {
                        if (StartPoint.X > EndPoint.X)
                        {
                            PointList.Clear();
                            PointList.Add(new FromTo(StartPoint, new Point((StartPoint.X + EndPoint.X) / 2, StartPoint.Y)));
                            PointList.Add(new FromTo(new Point((StartPoint.X + EndPoint.X) / 2, StartPoint.Y), new Point((StartPoint.X + EndPoint.X) / 2, EndPoint.Y)));
                            PointList.Add(new FromTo(new Point((StartPoint.X + EndPoint.X) / 2, EndPoint.Y), EndPoint));
                        }
                    }
                }
                raiseComputationDone(false);
            }
            raiseComputationDone(true);
        }