Ejemplo n.º 1
0
        private static IPoly InjectEdge(EdgePoly poly, IEdge newEdge)
        {
            //get indes of new edge
            int index = 0;

            for (; index < poly.Resolution; index++)
            {
                var edge = poly.GetEdge(index);
                if (IsParallel(newEdge, edge))
                {
                    if (edge.ContainsEdge(newEdge))
                    {
                        break;
                    }
                }
            }

            if (index == poly.Resolution)
            {
                return(poly);
            }

            List <IEdge> output = new List <IEdge>();

            for (int i = 0; i < poly.Resolution; i++)
            {
                if (i == index)
                {
                    IEdge orig = poly.GetEdge(i);
                    IEdge left, right;

                    left = orig.Clone(orig.A, newEdge.A);
                    if (left.Length() > 0.0001f)
                    {
                        output.Add(left);
                    }
                    output.Add(newEdge.Clone());

                    right = orig.Clone(newEdge.B, orig.B);
                    if (right.Length() > 0.0001f)
                    {
                        output.Add(right);
                    }
                }
                else
                {
                    output.Add(poly.GetEdge(i));
                }
            }

            return(new EdgePoly(output.ToArray()));
        }
Ejemplo n.º 2
0
        TestCloneBad4()
        {
            // Vertices not in same graph.

            try
            {
                IVertex oVertex1 = m_aoVertices[0];
                IVertex oVertex2 = m_aoVertices[1];

                IEdge oEdge = CreateEdge(oVertex1, oVertex2, true);

                IGraph oGraph2 = new Graph();

                IVertex [] aoVertices2 = TestGraphUtil.AddVertices(oGraph2, 2);

                oEdge.Clone(true, true, oVertex1, aoVertices2[0], true);
            }
            catch (ArgumentException oArgumentException)
            {
                Assert.AreEqual(

                    "Smrf.NodeXL.Core."
                    + "Edge.Constructor: vertex1 and vertex2 have been added to"
                    + " different graphs.  An edge can't connect vertices from"
                    + " different graphs.\r\n"
                    + "Parameter name: vertex2"
                    ,
                    oArgumentException.Message
                    );

                throw oArgumentException;
            }
        }
Ejemplo n.º 3
0
        TestCloneBad3()
        {
            // null vertex 2.

            try
            {
                IVertex oVertex1 = m_aoVertices[0];
                IVertex oVertex2 = m_aoVertices[1];

                IEdge oEdge = CreateEdge(oVertex1, oVertex2, true);

                oEdge.Clone(true, true, oVertex1, null, true);
            }
            catch (ArgumentNullException oArgumentNullException)
            {
                Assert.AreEqual(

                    "Smrf.NodeXL.Core."
                    + "Edge.Clone: vertex2 argument can't be null.\r\n"
                    + "Parameter name: vertex2"
                    ,
                    oArgumentNullException.Message
                    );

                throw oArgumentNullException;
            }
        }
Ejemplo n.º 4
0
 private static IEdge CreateRemappedEdge(
     IEdge edge,
     Dictionary<INode, INode> remap)
 {
     IEdge newEdge = edge.Clone();
     newEdge.Source = remap[edge.Source];
     newEdge.Target = remap[edge.Target];
     return newEdge;
 }
Ejemplo n.º 5
0
        public static IEdge[] RemoveIntersecting(this IEdge a, IEdge b)
        {
            IEdge[] output    = new IEdge[2];
            Vector3 direction = a.Direction();

            Vector3[] points = new Vector3[] { a.A, a.B, b.A, b.B };
            float[]   keys   = new float[] { 0f, Vector3.Dot(a.A - a.B, direction), Vector3.Dot(a.A - b.A, direction), Vector3.Dot(a.A - b.B, direction) };
            System.Array.Sort(keys, points);
            if ((points[1] - points[0]).sqrMagnitude > 0.0001f * 0.0001f)
            {
                output[0] = a.Clone(points[0], points[1]);
            }
            if ((points[3] - points[2]).sqrMagnitude > 0.0001f * 0.0001f)
            {
                output[1] = a.Clone(points[3], points[2]);
            }
            return(output);
        }
Ejemplo n.º 6
0
        private static void Clone(IEdge sut)
        {
            // Arrange

            // Act
            var result = (IEdge)sut.Clone();

            // Assert
            Assert.True(result != sut);
            Assert.Equal(sut, result);
        }
Ejemplo n.º 7
0
        TestClone
        (
            Boolean bCopyMetadataValues,
            Boolean bCopyTag,
            CloneOverload eCloneOverload
        )
        {
            // Create N objects, set random metadata and Tag on each object, clone
            // each object, check new object.

            const Int32 Vertices = 1000;

            CreateGraph(GraphDirectedness.Directed, Vertices);

            // Connect the first vertex to each of the other vertices.

            IEdge [] aoEdges = new Edge[Vertices - 1];

            for (Int32 i = 0; i < Vertices - 1; i++)
            {
                IEdge oEdge = aoEdges[i] =
                    CreateEdge(m_aoVertices[0], m_aoVertices[i + 1], true);

                MetadataUtil.SetRandomMetadata(oEdge, true, true, i);

                oEdge.Name = oEdge.ID.ToString();
            }

            // Create a second graph with 2 vertices for the
            // CloneOverload.SpecifiedVertices case.

            IGraph oGraph2 = new Graph();

            IVertex [] aoVertices2 = TestGraphUtil.AddVertices(oGraph2, 2);

            for (Int32 i = 0; i < Vertices - 1; i++)
            {
                // Clone the object.

                IEdge oEdge = aoEdges[i];

                IEdge oNewEdge = null;

                switch (eCloneOverload)
                {
                case CloneOverload.SameType:

                    oNewEdge = oEdge.Clone(bCopyMetadataValues, bCopyTag);

                    break;

                case CloneOverload.SpecifiedVertices:

                    oNewEdge = oEdge.Clone(
                        bCopyMetadataValues, bCopyTag, aoVertices2[0],
                        aoVertices2[1], true);

                    break;

                default:

                    Debug.Assert(false);
                    break;
                }

                // Check the metadata on the new object.

                MetadataUtil.CheckRandomMetadata(
                    oNewEdge, bCopyMetadataValues, bCopyTag, i);

                // Check the name and ID on the new object.

                Assert.AreEqual(oEdge.Name, oNewEdge.Name);

                Assert.AreNotEqual(oEdge.ID, oNewEdge.ID);

                // Check the vertices on the new object.

                Assert.IsNotNull(oNewEdge.Vertices);
                Assert.AreEqual(2, oNewEdge.Vertices.Length);

                if (eCloneOverload == CloneOverload.SpecifiedVertices)
                {
                    Assert.AreEqual(aoVertices2[0], oNewEdge.Vertices[0]);
                    Assert.AreEqual(aoVertices2[1], oNewEdge.Vertices[1]);

                    // Make sure the cloned edge can be added to the second graph.

                    oGraph2.Edges.Add(oNewEdge);
                }
                else
                {
                    Assert.AreEqual(oEdge.Vertices[0], oNewEdge.Vertices[0]);
                    Assert.AreEqual(oEdge.Vertices[1], oNewEdge.Vertices[1]);
                }
            }
        }