Example #1
0
 public bool HasPathByEdge(TEdge sourceEdge, TEdge targetEdge)
 {
     if (IsSameEdge(sourceEdge, targetEdge))
     {
         throw new InvalidOperationException();
     }
     else if (IsNeighbor(sourceEdge, targetEdge))
     {
         return(true);
     }
     else
     {
         return(this.HasPathByVertex(sourceEdge.Target, targetEdge.Source));
     }
 }
            public DeviationPath(
                [NotNull, ItemNotNull] TEdge[] parentPath,
                int deviationIndex,
                [NotNull] TEdge deviationEdge,
                double weight)
            {
                Debug.Assert(parentPath != null);
                Debug.Assert(0 <= deviationIndex && deviationIndex < parentPath.Length);
                Debug.Assert(deviationEdge != null);
                Debug.Assert(weight >= 0);

                ParentPath     = parentPath;
                DeviationIndex = deviationIndex;
                DeviationEdge  = deviationEdge;
                Weight         = weight;
            }
            public DeviationPath(
                TEdge[] parentPath,
                int deviationIndex,
                TEdge deviationEdge,
                double weight)
            {
                Contract.Requires(parentPath != null);
                Contract.Requires(0 <= deviationIndex && deviationIndex < parentPath.Length);
                Contract.Requires(deviationEdge != null);
                Contract.Requires(weight >= 0);

                this.ParentPath     = parentPath;
                this.DeviationIndex = deviationIndex;
                this.DeviationEdge  = deviationEdge;
                this.Weight         = weight;
            }
            private void ReadEdge([NotNull] IDictionary <string, TVertex> vertices)
            {
                Debug.Assert(vertices != null);
                Debug.Assert(
                    _reader.NodeType == XmlNodeType.Element &&
                    _reader.Name == EdgeTag &&
                    _reader.NamespaceURI == _graphMLNamespace);

                // Get subtree
                using (XmlReader subReader = _reader.ReadSubtree())
                {
                    // Read id
                    string id       = ReadAttributeValue(_reader, IdAttribute);
                    string sourceId = ReadAttributeValue(_reader, SourceAttribute);
                    if (!vertices.TryGetValue(sourceId, out TVertex source))
                    {
                        throw new ArgumentException($"Could not find vertex {sourceId}.");
                    }
                    string targetId = ReadAttributeValue(_reader, TargetAttribute);
                    if (!vertices.TryGetValue(targetId, out TVertex target))
                    {
                        throw new ArgumentException($"Could not find vertex {targetId}.");
                    }

                    TEdge edge = _edgeFactory(source, target, id);
                    ReadDelegateCompiler.SetEdgeDefault(edge);

                    // Read data
                    while (subReader.Read())
                    {
                        if (_reader.NodeType == XmlNodeType.Element &&
                            _reader.Name == DataTag &&
                            _reader.NamespaceURI == _graphMLNamespace)
                        {
                            ReadDelegateCompiler.EdgeAttributesReader(subReader, _graphMLNamespace, edge);
                        }
                    }

                    _graph.AddEdge(edge);
                }
            }
 public bool TryGetEdge(out TEdge edge)
 {
     edge = _edge;
     return(_edgeStored);
 }
Example #6
0
 public SugiEdge(TEdge original, SugiVertex source, SugiVertex target, EdgeTypes type)
     : base(source, target, type)
 {
     Original = original;
 }
 public Event(int root, TEdge edge, bool isStart)
 {
     this.root    = root;
     this.edge    = edge;
     this.isStart = isStart;
 }
Example #8
0
 public bool TryGetEdge(out TEdge _edge)
 {
     _edge = this._edge;
     return(this.edgeStored);
 }
Example #9
0
 public RemovedTreeNodeData(TVertex vertex, TEdge edge)
 {
     Vertex = vertex;
     Edge   = edge;
 }
        internal static bool AddPath(this Clipper clipper, List <Vector2d> pg, PolyType polyType, float scale,
                                     bool closed)
        {
            if (!closed)
            {
                throw new ClipperException("AddPath: Open paths have been disabled.");
            }

            int highI = pg.Count() - 1;

            if (closed)
            {
                while (highI > 0 && (pg[highI] == pg[0]))
                {
                    --highI;
                }
            }
            while (highI > 0 && (pg[highI] == pg[highI - 1]))
            {
                --highI;
            }
            if ((closed && highI < 2) || (!closed && highI < 1))
            {
                return(false);
            }

            //create a new edge array ...
            List <TEdge> edges = new List <TEdge>(highI + 1);

            for (int i = 0; i <= highI; i++)
            {
                edges.Add(ClipperPool.AllocEdge());
            }

            bool IsFlat = true;

            //1. Basic (first) edge initialization ...
            var pg0     = new IntPoint(pg[0].X * scale, pg[0].Y * scale);
            var pgHighI = new IntPoint(pg[highI].X * scale, pg[highI].Y * scale);

            edges[1].Curr = new IntPoint(pg[1].X * scale, pg[1].Y * scale);
            clipper.RangeTest(pg0, ref clipper.m_UseFullRange);
            clipper.RangeTest(pgHighI, ref clipper.m_UseFullRange);
            clipper.InitEdge(edges[0], edges[1], edges[highI], pg0);
            clipper.InitEdge(edges[highI], edges[0], edges[highI - 1], pgHighI);
            for (int i = highI - 1; i >= 1; --i)
            {
                var pgI = new IntPoint(pg[i].X * scale, pg[i].Y * scale);
                clipper.RangeTest(pgI, ref clipper.m_UseFullRange);
                clipper.InitEdge(edges[i], edges[i + 1], edges[i - 1], pgI);
            }
            TEdge eStart = edges[0];

            //2. Remove duplicate vertices, and (when closed) collinear edges ...
            TEdge E = eStart, eLoopStop = eStart;

            for (;;)
            {
                //nb: allows matching start and end points when not Closed ...
                if (E.Curr == E.Next.Curr && (closed || E.Next != eStart))
                {
                    if (E == E.Next)
                    {
                        break;
                    }
                    if (E == eStart)
                    {
                        eStart = E.Next;
                    }
                    E         = clipper.RemoveEdge(E);
                    eLoopStop = E;
                    continue;
                }
                if (E.Prev == E.Next)
                {
                    break; //only two vertices
                }
                if (closed &&
                    ClipperBase.SlopesEqual(E.Prev.Curr, E.Curr, E.Next.Curr, clipper.m_UseFullRange) &&
                    (!clipper.PreserveCollinear ||
                     !clipper.Pt2IsBetweenPt1AndPt3(E.Prev.Curr, E.Curr, E.Next.Curr)))
                {
                    //Collinear edges are allowed for open paths but in closed paths
                    //the default is to merge adjacent collinear edges into a single edge.
                    //However, if the PreserveCollinear property is enabled, only overlapping
                    //collinear edges (ie spikes) will be removed from closed paths.
                    if (E == eStart)
                    {
                        eStart = E.Next;
                    }
                    E         = clipper.RemoveEdge(E);
                    E         = E.Prev;
                    eLoopStop = E;
                    continue;
                }
                E = E.Next;
                if ((E == eLoopStop) || (!closed && E.Next == eStart))
                {
                    break;
                }
            }

            if ((!closed && (E == E.Next)) || (closed && (E.Prev == E.Next)))
            {
                return(false);
            }

            //3. Do second stage of edge initialization ...
            E = eStart;
            do
            {
                clipper.InitEdge2(E, polyType);
                E = E.Next;
                if (IsFlat && E.Curr.Y != eStart.Curr.Y)
                {
                    IsFlat = false;
                }
            } while (E != eStart);

            //4. Finally, add edge bounds to LocalMinima list ...

            //Totally flat paths must be handled differently when adding them
            //to LocalMinima list to avoid endless loops etc ...
            if (IsFlat)
            {
                if (closed)
                {
                    return(false);
                }
            }

            clipper.m_edges.Add(edges);
            bool  leftBoundIsForward;
            TEdge EMin = null;

            //workaround to avoid an endless loop in the while loop below when
            //open paths have matching start and end points ...
            if (E.Prev.Bot == E.Prev.Top)
            {
                E = E.Next;
            }

            for (;;)
            {
                E = clipper.FindNextLocMin(E);
                if (E == EMin)
                {
                    break;
                }
                if (EMin == null)
                {
                    EMin = E;
                }

                //E and E.Prev now share a local minima (left aligned if horizontal).
                //Compare their slopes to find which starts which bound ...
                LocalMinima locMin = new LocalMinima();
                locMin.Next = null;
                locMin.Y    = E.Bot.Y;
                if (E.Dx < E.Prev.Dx)
                {
                    locMin.LeftBound   = E.Prev;
                    locMin.RightBound  = E;
                    leftBoundIsForward = false; //Q.nextInLML = Q.prev
                }
                else
                {
                    locMin.LeftBound   = E;
                    locMin.RightBound  = E.Prev;
                    leftBoundIsForward = true; //Q.nextInLML = Q.next
                }
                locMin.LeftBound.Side  = EdgeSide.esLeft;
                locMin.RightBound.Side = EdgeSide.esRight;

                if (locMin.LeftBound.Next == locMin.RightBound)
                {
                    locMin.LeftBound.WindDelta = -1;
                }
                else
                {
                    locMin.LeftBound.WindDelta = 1;
                }
                locMin.RightBound.WindDelta = -locMin.LeftBound.WindDelta;

                E = clipper.ProcessBound(locMin.LeftBound, leftBoundIsForward);
                if (E.OutIdx == ClipperBase.Skip)
                {
                    E = clipper.ProcessBound(E, leftBoundIsForward);
                }

                TEdge E2 = clipper.ProcessBound(locMin.RightBound, !leftBoundIsForward);
                if (E2.OutIdx == ClipperBase.Skip)
                {
                    E2 = clipper.ProcessBound(E2, !leftBoundIsForward);
                }

                if (locMin.LeftBound.OutIdx == ClipperBase.Skip)
                {
                    locMin.LeftBound = null;
                }
                else if (locMin.RightBound.OutIdx == ClipperBase.Skip)
                {
                    locMin.RightBound = null;
                }
                clipper.InsertLocalMinima(locMin);
                if (!leftBoundIsForward)
                {
                    E = E2;
                }
            }
            return(true);
        }
Example #11
0
 void AddEdge(int from, int to)
 {
     TEdge edge = new TEdge(from, to);
     edges.Add(edge);
 }
Example #12
0
 public void Add(TEdge edge)
 {
     heap.Add(edge);
     Lift(heap.Count - 1);
 }
 public HeapEntry(TVertex vertex, TEdge edge)
 {
     Vertex = vertex;
     Edge   = edge;
 }
Example #14
0
 public EdgeWithWeight(TEdge original, double weight)
 {
     Original = original;
     Weight   = weight;
 }
Example #15
0
 public static void FreeEdge(TEdge edge)
 {
     edge.Reset();
     EdgeStack.Push(edge);
 }
Example #16
0
 public RemovedTreeNodeData([NotNull] TVertex vertex, [NotNull] TEdge edge)
 {
     Vertex = vertex;
     Edge   = edge;
 }