EdgeToVertices() public static method

public static EdgeToVertices ( IEdge edge, String className, String methodOrPropertyName, IVertex &vertex1, IVertex &vertex2 ) : void
edge IEdge
className String
methodOrPropertyName String
vertex1 IVertex
vertex2 IVertex
return void
Esempio n. 1
0
        IsIncidentEdge
        (
            IEdge edge
        )
        {
            AssertValid();

            const String MethodName   = "IsIncidentEdge";
            const String ArgumentName = "edge";

            this.ArgumentChecker.CheckArgumentNotNull(
                MethodName, ArgumentName, edge);

            IVertex oVertex1, oVertex2;

            EdgeUtil.EdgeToVertices(edge, this.ClassName, MethodName,
                                    out oVertex1, out oVertex2);

            return(oVertex1 == this || oVertex2 == this);
        }
Esempio n. 2
0
        IsParallelTo
        (
            IEdge otherEdge
        )
        {
            AssertValid();

            const String MethodName   = "IsParallelTo";
            const String ArgumentName = "otherEdge";

            this.ArgumentChecker.CheckArgumentNotNull(
                MethodName, ArgumentName, otherEdge);

            IVertex oOtherVertex1, oOtherVertex2;

            // Get the other edge's vertices.

            EdgeUtil.EdgeToVertices(otherEdge, this.ClassName, MethodName,
                                    out oOtherVertex1, out oOtherVertex2);

            // The following code implements the table in the documentation for
            // IEdge.IsParallelTo().

            if (
                !(
                    (m_oVertex1 == oOtherVertex1 && m_oVertex2 == oOtherVertex2)
                    ||
                    (m_oVertex1 == oOtherVertex2 && m_oVertex2 == oOtherVertex1)
                    )
                )
            {
                // The two edges do not connect the same two vertices.

                return(false);
            }

            switch (this.ParentGraph.Directedness)
            {
            case GraphDirectedness.Directed:

                Debug.Assert(this.IsDirected && otherEdge.IsDirected);

                return(m_oVertex1 == oOtherVertex1);

            case GraphDirectedness.Undirected:

                Debug.Assert(!this.IsDirected && !otherEdge.IsDirected);

                return(true);

            case GraphDirectedness.Mixed:

                if (!this.IsDirected || !otherEdge.IsDirected)
                {
                    return(true);
                }

                return(m_oVertex1 == oOtherVertex1);

            default:

                Debug.Assert(false);

                return(false);
            }
        }
Esempio n. 3
0
        Clone
        (
            Boolean copyMetadataValues,
            Boolean copyTag
        )
        {
            AssertValid();

            const String MethodName = "Clone";

            IGraph oNewGraph = new Graph(m_eDirectedness);

            // Copy the base-class fields to the new edge.

            this.CopyTo(oNewGraph, copyMetadataValues, copyTag);

            // The vertices need to be copied to the new graph.  Loop through the
            // vertices in this original graph.

            IVertexCollection oNewVertices = oNewGraph.Vertices;

            foreach (IVertex oOriginalVertex in m_oVertexCollection)
            {
                IVertex oNewVertex = oOriginalVertex.Clone(
                    copyMetadataValues, copyTag);

                // To make it easier to copy the edges in this original graph,
                // temporarily store the ID of the new vertex in the Tag of the
                // original vertex.  Save the Tag so it can be restored later.

                oOriginalVertex.Tag =
                    new VertexMapper(oOriginalVertex.Tag, oNewVertex);

                oNewVertices.Add(oNewVertex);
            }

            // The edges need to be copied to the new graph.  Loop through the
            // edges in this original graph.

            IEdgeCollection oNewEdges = oNewGraph.Edges;

            foreach (IEdge oOriginalEdge in m_oEdgeCollection)
            {
                // Get the original edge's vertices.

                IVertex oOriginalVertex1, oOriginalVertex2;

                EdgeUtil.EdgeToVertices(oOriginalEdge, this.ClassName, MethodName,
                                        out oOriginalVertex1, out oOriginalVertex2);

                // Retrieve the VertexMapper objects that were temporarily stored
                // in the vertices' Tags.

                Debug.Assert(oOriginalVertex1.Tag is VertexMapper);
                Debug.Assert(oOriginalVertex2.Tag is VertexMapper);

                VertexMapper oVertexMapper1 = (VertexMapper)oOriginalVertex1.Tag;
                VertexMapper oVertexMapper2 = (VertexMapper)oOriginalVertex2.Tag;

                // Get the new vertices that correspond to the original edge's
                // vertices.

                IVertex oNewVertex1 = oVertexMapper1.NewVertex;
                IVertex oNewVertex2 = oVertexMapper2.NewVertex;

                // Copy the original edge, connecting the new vertices in the
                // process.

                IEdge oNewEdge = oOriginalEdge.Clone(copyMetadataValues, copyTag,
                                                     oNewVertex1, oNewVertex2,
                                                     oOriginalEdge.IsDirected);

                oNewEdges.Add(oNewEdge);
            }

            // Restore the original vertices' Tags.

            foreach (IVertex oOriginalVertex in m_oVertexCollection)
            {
                Debug.Assert(oOriginalVertex.Tag is VertexMapper);

                VertexMapper oVertexMapper = (VertexMapper)oOriginalVertex.Tag;

                oOriginalVertex.Tag = oVertexMapper.OriginalVertexTag;
            }

            return(oNewGraph);
        }