public static void DoTest() { var graph = new DirectedGraph <Employee>(); var employeeA = new Employee("a", "", 10); var employeeB = new Employee("b", "a", 10); var employeeC = new Employee("c", "a", 10); var employeeD = new Employee("d", "a", 10); var employeeE = new Employee("e", "b", 10); var verticesSet1 = new Employee[] { employeeA, employeeB, employeeC, employeeD, employeeE }; graph.AddVertices(verticesSet1); graph.AddEdge(employeeA, employeeB); graph.AddEdge(employeeA, employeeC); graph.AddEdge(employeeA, employeeD); graph.AddEdge(employeeB, employeeE); var allEdges = graph.Edges.ToList(); Assert.True(graph.VerticesCount == 5, "Wrong vertices count."); Assert.True(graph.EdgesCount == 4, "Wrong edges count."); Assert.True(graph.EdgesCount == allEdges.Count, "Wrong edges count."); Assert.True(graph.OutgoingEdges(employeeA).ToList().Count == 3, "Wrong outgoing edges from 'a'."); Assert.True(graph.OutgoingEdges(employeeB).ToList().Count == 1, "Wrong outgoing edges from 'b'."); Assert.True(graph.OutgoingEdges(employeeC).ToList().Count == 0, "Wrong outgoing edges from 'c'."); Assert.True(graph.OutgoingEdges(employeeD).ToList().Count == 0, "Wrong outgoing edges from 'd'."); Assert.True(graph.OutgoingEdges(employeeE).ToList().Count == 0, "Wrong outgoing edges from 'e'."); Assert.True(graph.IncomingEdges(employeeA).ToList().Count == 0, "Wrong incoming edges from 'a'."); Assert.True(graph.IncomingEdges(employeeB).ToList().Count == 1, "Wrong incoming edges from 'b'."); Assert.True(graph.IncomingEdges(employeeC).ToList().Count == 1, "Wrong incoming edges from 'c'."); Assert.True(graph.IncomingEdges(employeeD).ToList().Count == 1, "Wrong incoming edges from 'd'."); Assert.True(graph.IncomingEdges(employeeE).ToList().Count == 1, "Wrong incoming edges from 'e'."); // DFS from A // Walk the graph using DFS from A: var dfsWalk = graph.DepthFirstWalk(employeeA); // output: (s) (a) (x) (z) (d) (c) (f) (v) // DFS from F // Walk the graph using DFS from F: //dfsWalk = graph.DepthFirstWalk(employeeB); // output: (s) (a) (x) (z) (d) (c) (f) (v) foreach (var node in dfsWalk) { Console.Write(string.Format("({0})", node.Id)); } graph.Clear(); }
public void Clear_RemovesAllPoints() { var toValue = "to"; var fromValue = "from"; _directedGraph.Add(toValue); _directedGraph.Add(fromValue); _directedGraph.Clear(); _directedGraph.Count.Should().Be(0); }
public void Clear() { var myGraph = new DirectedGraph <int, EdgeData>(); myGraph.AddNodes(1, 2, 3, 4); myGraph.AddEdges( (1, 2, dummyEdgeData), (2, 3, dummyEdgeData), (3, 4, dummyEdgeData) ); myGraph.Clear(); myGraph.Nodes.Should().BeEmpty(); }
public void BuildGraphFromInstances() { Verify(); splineGraph.Clear(); // 1) Append all graphs into single graph. for (int i = 0, iCount = SplineGraphComponent.instances.Count; i < iCount; ++i) { SplineGraphComponent instance = SplineGraphComponent.instances[i]; instance.Verify(); if (instance.type != type) { continue; } Int16 vertexStart = (Int16)splineGraph.vertices.count; splineGraph.PushDirectedGraph(ref instance.splineGraph, Allocator.Persistent); Int16 vertexEnd = (Int16)splineGraph.vertices.count; // Transform vertices into splineGraphManager's coordinate system: Transform instanceTransform = instance.GetComponent <Transform>(); for (Int16 v = vertexStart; v < vertexEnd; ++v) { float3 position = splineGraph.payload.positions.data[v]; quaternion rotation = splineGraph.payload.rotations.data[v]; float2 scale = splineGraph.payload.scales.data[v]; float2 leash = splineGraph.payload.leashes.data[v]; float3 forwardOS = math.mul(rotation, new float3(0.0f, 0.0f, 1.0f)); float3 tangentOS = math.mul(rotation, new float3(1.0f, 0.0f, 0.0f)); float3 bitangentOS = math.mul(rotation, new float3(0.0f, 1.0f, 0.0f)); float3 forwardWS = instanceTransform.TransformVector(forwardOS); float3 tangentWS = instanceTransform.TransformVector(tangentOS); float3 bitangentWS = instanceTransform.TransformVector(bitangentOS); float3 forwardMOS = transform.InverseTransformVector(forwardWS); float3 tangentMOS = transform.InverseTransformVector(tangentWS); float3 bitangentMOS = transform.InverseTransformVector(bitangentWS); float mosFromInstanceOSScale = math.length(forwardMOS); float2 mosFromInstanceOSLeashScale = new float2( math.length(tangentMOS), math.length(bitangentMOS) ); // Construct manager-object-space rotation from transformed frame, so that scale can be accounted for in final rotation. // In particular, we care about this for using -1 scale to perform mirroring of graph in X, Y, or Z. forwardMOS = math.normalize(forwardMOS); bitangentMOS = math.normalize(bitangentMOS); quaternion rotationMOS = Quaternion.LookRotation(forwardMOS, bitangentMOS); // Manager-Object-space from world-space * World-space from Instance-Object-space position = instanceTransform.TransformPoint(position); position = transform.InverseTransformPoint(position); rotation = rotationMOS; scale = scale * mosFromInstanceOSScale; leash = leash * mosFromInstanceOSLeashScale; splineGraph.payload.positions.data[v] = position; splineGraph.payload.rotations.data[v] = rotation; splineGraph.payload.scales.data[v] = scale; splineGraph.payload.leashes.data[v] = leash; } for (Int16 v = vertexStart; v < vertexEnd; ++v) { splineGraph.payload.VertexComputePayloads(ref splineGraph, v); } } // 2) Weld vertices. VertexWeldAllWithinThreshold(); // 3) VertexWeldAllRedundant(); // 4) Compact. BuildCompactGraph(); // Need to set the dirty flag here because the call to Verify() above cleared any dirty flags that were possibly set by UndoRecord() // and we have just changed our runtime data representation. isDirty = true; }