Beispiel #1
0
        /*
         * internal static bool DebugClose(Point target, Point source)
         * {
         *  var a = new Point(307, 7);
         *  var b = new Point(540.6, 15);
         *
         *  return (target - a).Length < 2 && (source - b).Length < 5 ||
         *      (source - a).Length < 2 && (target - b).Length<5;
         * }
         */

        internal VisibilityEdge AddEdge(Point source, Point target, Func <VisibilityVertex, VisibilityVertex, VisibilityEdge> edgeCreator)
        {
            VisibilityEdge   edge;
            var              sourceV = FindVertex(source);
            VisibilityVertex targetV = null;

            if (sourceV != null)
            {
                targetV = FindVertex(target);
                if (targetV != null && sourceV.TryGetEdge(targetV, out edge))
                {
                    return(edge);
                }
            }

            if (sourceV == null) //then targetV is also null
            {
                sourceV = AddVertex(source);
                targetV = AddVertex(target);
            }
            else if (targetV == null)
            {
                targetV = AddVertex(target);
            }

            edge = edgeCreator(sourceV, targetV);
            sourceV.OutEdges.Insert(edge);
            targetV.AddInEdge(edge);
            return(edge);
        }
Beispiel #2
0
        static internal VisibilityEdge AddEdge(VisibilityVertex source, VisibilityVertex target)
        {
            VisibilityEdge visEdge;

            if (source.TryGetEdge(target, out visEdge))
            {
                return(visEdge);
            }
            if (source == target)
            {
                Debug.Assert(false, "Self-edges are not allowed");
                throw new InvalidOperationException("Self-edges are not allowed");
            }

            var edge = new VisibilityEdge(source, target);

            source.OutEdges.Insert(edge);
            target.AddInEdge(edge);
            return(edge);
        }