Exemplo n.º 1
0
        public void Draw(Transformer transformer, Vector2[] path, ColorRgba startColor, ColorRgba endColor, ColorRgba nodeColor, ColorRgba lineColor)
        {
            var waypointPathVisualization = new WaypointPathVisualization();

            waypointPathVisualization.StartColor    = startColor;
            waypointPathVisualization.TargetColor   = endColor;
            waypointPathVisualization.WaypointColor = nodeColor;
            waypointPathVisualization.LineColor     = lineColor;
            waypointPathVisualization.SetPath(path, transformer);
            var renderer = new MockupRenderer();

            waypointPathVisualization.Draw(renderer);

            Assert.Equal(path.Length, renderer.FillCircleCalls.Count);
            AssertFillCircleCall(renderer, transformer, startColor, path, 0);
            for (var i = 1; i < path.Length - 1; i++)
            {
                AssertFillCircleCall(renderer, transformer, nodeColor, path, i);
            }
            AssertFillCircleCall(renderer, transformer, endColor, path, path.Length - 1);

            for (var i = 0; i < path.Length - 1; i++)
            {
                var from = transformer.ToWorld(path[i]);
                var to   = transformer.ToWorld(path[i + 1]);

                Assert.Equal(from, renderer.DrawLineCalls[i].from);
                Assert.Equal(to, renderer.DrawLineCalls[i].to);
                Assert.Equal(lineColor, renderer.DrawLineCalls[i].color);
            }
        }
Exemplo n.º 2
0
        public void Draw(DefinitionNode[] definitionNodes, Transformer transform)
        {
            var nodeConnectionVisualization = new NodeConnectionVisualization(definitionNodes, transform);
            var color = new ColorRgba(new Random(definitionNodes.Length).Next());

            nodeConnectionVisualization.Color = color;
            var renderer = new MockupRenderer();

            nodeConnectionVisualization.Draw(renderer);

            Assert.Equal(definitionNodes.Select(x => x.Connections.Length).Sum(), renderer.DrawLineCalls.Count);
            for (int i = 0; i < renderer.DrawLineCalls.Count; i++)
            {
                Assert.Equal(color, renderer.DrawLineCalls[i].color);
            }
        }
        public void Draw(Array2D <Vector2> vectors, Transformer transformer, ColorRgba color)
        {
            var vectorFieldVisualization = new VectorFieldVisualization();

            vectorFieldVisualization.Vectors     = vectors;
            vectorFieldVisualization.Transformer = transformer;
            vectorFieldVisualization.Color       = color;

            var renderer = new MockupRenderer();

            vectorFieldVisualization.Draw(renderer);

            Assert.Equal(vectors.Length, renderer.DrawLineCalls.Count);
            for (var i = 0; i < vectors.Length; i++)
            {
                var drawnVector    = renderer.DrawLineCalls[i].to - renderer.DrawLineCalls[i].from;
                var expectedVector = vectors.Array[i] * 0.5f * transformer.Scale.X;
                Assert.Equal(expectedVector, drawnVector);
            }
        }
        public void Draw(DefinitionNode[] definitionNodes, Transformer transform)
        {
            var nodeTextVisualization = new NodeTextVisualization(definitionNodes, transform);
            var random = new Random(definitionNodes.Length);
            var color  = new ColorRgba(random.Next());

            nodeTextVisualization.Color = color;

            var texts = new string[definitionNodes.Length];

            for (int i = 0; i < definitionNodes.Length; i++)
            {
                if (i % 2 == 0)
                {
                    continue;
                }
                string text;
                if (i % 3 == 0)
                {
                    text = random.Next().ToString();
                }
                else
                {
                    text = "";
                }
                texts[i] = text;
                nodeTextVisualization.Texts[i] = text;
            }
            var renderer = new MockupRenderer();

            nodeTextVisualization.Draw(renderer);

            Assert.Equal(texts.Count(x => !string.IsNullOrEmpty(x)), renderer.DrawTextCalls.Count);
            for (int i = 0; i < renderer.DrawLineCalls.Count; i++)
            {
                Assert.Equal(color, renderer.DrawTextCalls[i].color);
                Assert.Equal(texts[i], renderer.DrawTextCalls[i].text);
            }
        }
        public void Draw(DefinitionNode[] definitionNodes, Transformer transform)
        {
            var nodeVisualization = new NodeVisualization(definitionNodes, transform)
            {
                Nodes = definitionNodes.Select((node, i) => i)
            };
            var random = new Random(definitionNodes.Length);
            var color  = new ColorRgba(random.Next());

            nodeVisualization.Color = color;
            var renderer = new MockupRenderer();

            nodeVisualization.Draw(renderer);

            Assert.Equal(definitionNodes.Length, renderer.FillCircleCalls.Count);
            for (int i = 0; i < definitionNodes.Length; i++)
            {
                Assert.Equal(definitionNodes[i].Position, transform.ToLocal(renderer.FillCircleCalls[i].position));
                Assert.Equal(transform.Scale.X * 0.25f, renderer.FillCircleCalls[i].radius);
                Assert.Equal(color, renderer.FillCircleCalls[i].color);
            }
        }
        public void Draw(IDefinitionNodeNetwork definitionNodeNetwork, Vector2 startPosition, Vector2 targetPosition)
        {
            var renderer = new MockupRenderer();
            var astarAlgorithmVisualization = new AstarAlgorithmVisualization(definitionNodeNetwork);

            astarAlgorithmVisualization.SetStart(startPosition);
            renderer.ClearCalls();
            astarAlgorithmVisualization.Draw(renderer);
            Assert.Equal(1, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.StartColor));
            Assert.Equal(0, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.TargetColor));
            Assert.Equal(0, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.ClosedSetColor || x.color == astarAlgorithmVisualization.OpenSetColor));

            astarAlgorithmVisualization.SetTarget(targetPosition);
            renderer.ClearCalls();
            astarAlgorithmVisualization.Draw(renderer);
            Assert.Equal(1, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.StartColor));
            Assert.Equal(1, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.TargetColor));
            Assert.Equal(0, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.ClosedSetColor || x.color == astarAlgorithmVisualization.OpenSetColor));

            astarAlgorithmVisualization.Start(0f, PathfindaxCollisionCategory.None);

            while (!astarAlgorithmVisualization.Step())
            {
                renderer.ClearCalls();
                astarAlgorithmVisualization.Draw(renderer);
                Assert.True(renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.ClosedSetColor || x.color == astarAlgorithmVisualization.OpenSetColor) > 0);
                Assert.Equal(1, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.StartColor));
                Assert.Equal(1, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.TargetColor));
            }

            renderer.ClearCalls();
            astarAlgorithmVisualization.Draw(renderer);
            Assert.True(renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.ClosedSetColor || x.color == astarAlgorithmVisualization.OpenSetColor) > 0);
            Assert.True(renderer.DrawLineCalls.Count > 0);
            Assert.Equal(1, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.StartColor));
            Assert.Equal(1, renderer.FillCircleCalls.Count(x => x.color == astarAlgorithmVisualization.TargetColor));
        }
Exemplo n.º 7
0
 private void AssertFillCircleCall(MockupRenderer renderer, Transformer transformer, ColorRgba color, Vector2[] path, int i)
 {
     Assert.Equal(path[i], transformer.ToLocal(renderer.FillCircleCalls[i].position));
     Assert.Equal(transformer.Scale.X * 0.25f, renderer.FillCircleCalls[i].radius);
     Assert.Equal(color, renderer.FillCircleCalls[i].color);
 }