Beispiel #1
0
        public void TestBlockPathsLattice()
        {
            var result = Rectify.MakeRectangles(GridLatticeTestData.KeyholeApertureLattice());

            Assert.AreEqual(2, result.Count, "Did not get 2 initial rectangles as expected");

            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            var resultPath = pathfinder.CalculatePath(new Position(2, 3), new Position(2, 1));

            Assert.AreEqual(3, resultPath.Count, "Did not find a path where expected");

            pathfinder.ReplaceCellEdgeAt(new Position(2, 2), Direction.North, EdgeType.Wall);

            Assert.AreEqual(5, pathfinder.NodeCount, "Did not get the 5 total rectangles expected");


            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 3));
            Assert.AreEqual(0, resultPath.Count, "did not find a path when expected");

            resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 1));
            Assert.AreEqual(2, resultPath.Count, "found a path when none expected");


            resultPath = pathfinder.CalculatePath(new Position(1, 2), new Position(2, 2));
            Assert.AreEqual(2, resultPath.Count, "Did not find a path where expected");
        }
Beispiel #2
0
        public void BiggerSequentialEdgeAdditionTest()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10));
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            //add edges to the same cell one after another

            pathfinder.ReplaceCellEdgeAt(new Position(6, 4), Direction.West, EdgeType.Wall);

            pathfinder.ReplaceCellEdgeAt(new Position(6, 4), Direction.South, EdgeType.Wall);

            pathfinder.ReplaceCellEdgeAt(new Position(7, 4), Direction.West, EdgeType.Wall);

            var resultPath = pathfinder.CalculatePath(new Position(3, 3), new Position(8, 2));

            Assert.AreNotEqual(0, resultPath.Count, "Did not find expected path");
        }
Beispiel #3
0
        public void TestPathAfterNewEdges()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10, 10));
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            for (int i = 0; i < 10; i++)
            {
                pathfinder.ReplaceCellEdgeAt(new Position(7, i), Direction.West, EdgeType.Wall);
            }

            var resultPath = pathfinder.CalculatePath(new Position(0, 6), new Position(9, 5));

            Assert.AreEqual(0, resultPath.Count, "Did not generate a zero path as expected");

            pathfinder.ReplaceCellEdgeAt(new Position(5, 2), Direction.North, EdgeType.Wall);

            resultPath = pathfinder.CalculatePath(new Position(0, 6), new Position(9, 5));
            Assert.AreEqual(0, resultPath.Count, "Did not generate a zero path as expected");
        }
Beispiel #4
0
        public void SequentialEdgeAdditionTest()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice());
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            //add edges to the same cell one after another

            pathfinder.ReplaceCellEdgeAt(new Position(1, 1), Direction.West, EdgeType.Wall);
            var resultPath = pathfinder.CalculatePath(new Position(0, 1), new Position(1, 1));

            Assert.AreNotEqual(2, resultPath.Count, "Did not path around wall edge as expected");

            pathfinder.ReplaceCellEdgeAt(new Position(1, 1), Direction.South, EdgeType.Wall);
            resultPath = pathfinder.CalculatePath(new Position(0, 1), new Position(1, 1));
            Assert.AreNotEqual(2, resultPath.Count, "Did not path around wall edge as expected");

            pathfinder.ReplaceCellEdgeAt(new Position(1, 1), Direction.East, EdgeType.Wall);
            resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(2, 0));
            Assert.AreEqual(3, resultPath.Count, "Did not path around wall edge as expected");
        }
Beispiel #5
0
        public void TestNoPathNecessary()
        {
            var result     = Rectify.MakeRectangles(GridLatticeTestData.HorizBisectedLattice());
            var pathfinder = new RectifyPathfinder(result, StandardLatticeParams);

            var resultPath = pathfinder.CalculatePath(new Position(2, 0), new Position(2, 4));

            Assert.AreEqual(0, resultPath.Count, "Did not generate a zero path as expected");

            pathfinder.ReplaceCellEdgeAt(new Position(2, 2), Direction.North, EdgeType.None);

            resultPath = pathfinder.CalculatePath(new Position(2, 0), new Position(2, 4));
            Assert.AreNotEqual(0, resultPath.Count, "Did not generate a non-zero path as expected");
        }