コード例 #1
0
        public void TiledBarrierGraph_RemoveEdge_2Edges_RemoveFirst_ShouldLeave1()
        {
            var graphs = new TiledBarrierGraph();
            var v1     = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);
            var v2     = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341431);
            var v3     = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341432);
            var e1     = graphs.AddEdge(v1, v2, Enumerable.Empty <(double longitude, double latitude)>(),
                                        new TagsCollection());;
            var e2 = graphs.AddEdge(v1, v3, Enumerable.Empty <(double longitude, double latitude)>(),
                                    new TagsCollection());

            graphs.DeleteEdge(e1);

            var enumerator = graphs.GetEnumerator();

            Assert.True(enumerator.MoveTo(v1));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(v1, enumerator.Vertex1);
            Assert.Equal(v3, enumerator.Vertex2);
            Assert.Equal(e2, enumerator.Edge);
            Assert.False(enumerator.MoveNext());

            Assert.True(enumerator.MoveTo(v2));
            Assert.False(enumerator.MoveNext());

            Assert.True(enumerator.MoveTo(v3));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(v1, enumerator.Vertex2);
            Assert.Equal(v3, enumerator.Vertex1);
            Assert.Equal(e2, enumerator.Edge);
            Assert.False(enumerator.MoveNext());
        }
コード例 #2
0
        public void TiledBarrierGraphExtensions_NextClockwise_TwoOtherEdges_ShouldBeClockWise()
        {
            var graphs = new TiledBarrierGraph();
            var v1     = graphs.AddVertex(
                4.801325798034667,
                51.268153126307524);
            var v2 = graphs.AddVertex(
                4.801331162452698,
                51.267829233580834);
            var v3 = graphs.AddVertex(
                4.801816642284393,
                51.26783426820025);
            var v4 = graphs.AddVertex(
                4.801317751407623,
                51.26754225936128);
            var e1 = graphs.AddEdge(v1, v2);
            var e2 = graphs.AddEdge(v2, v3);
            var e3 = graphs.AddEdge(v2, v4);

            var enumerator = graphs.GetEnumerator();

            enumerator.MoveTo(v1);
            enumerator.MoveNext();

            using var clockwise = enumerator.NextClockwise().GetEnumerator();
            Assert.True(clockwise.MoveNext());
            Assert.Equal(v4, clockwise.Current.Vertex2);
            Assert.True(clockwise.MoveNext());
            Assert.Equal(v3, clockwise.Current.Vertex2);
            Assert.False(clockwise.MoveNext());
        }
コード例 #3
0
        public void Faces_AssignFaces_OneLoop2_ShouldAssign2()
        {
            var graphs = new TiledBarrierGraph();

            //    0
            //   / \
            //  1---2

            var v1 = graphs.AddVertex(
                4.788075685501099,
                51.26676188180721, 564341430);
            var v2 = graphs.AddVertex(
                4.786123037338257,
                51.26496276736555, 564341431);
            var v3 = graphs.AddVertex(
                4.790832996368408,
                51.265137311403734, 564341432);

            var e1 = graphs.AddEdge(v1, v2);
            var e2 = graphs.AddEdge(v3, v2);
            var e3 = graphs.AddEdge(v3, v1);

            graphs.SetTileLoaded(Tiles.TileStatic.WorldTileLocalId(graphs.GetVertex(v1), 14));
            graphs.SetTileLoaded(Tiles.TileStatic.WorldTileLocalId(graphs.GetVertex(v2), 14));
            graphs.SetTileLoaded(Tiles.TileStatic.WorldTileLocalId(graphs.GetVertex(v3), 14));

            graphs.AssignFaces(Tiles.TileStatic.WorldTileLocalId(graphs.GetVertex(v1), 14));

            Assert.Equal(3, graphs.FaceCount);
            var enumerator = graphs.GetEnumerator();

            enumerator.MoveTo(v1);
            enumerator.MoveNextUntil(e1);

            Assert.NotEqual(int.MaxValue, enumerator.FaceLeft);
            var left = enumerator.FaceLeft;

            Assert.NotEqual(int.MaxValue, enumerator.FaceRight);
            var right = enumerator.FaceRight;

            enumerator.MoveTo(v2);
            enumerator.MoveNextUntil(e2);
            Assert.False(enumerator.Forward);
            Assert.Equal(left, enumerator.FaceRight);
            Assert.Equal(right, enumerator.FaceLeft);
            enumerator.MoveTo(v3);
            enumerator.MoveNextUntil(e3);
            Assert.Equal(left, enumerator.FaceLeft);
            Assert.Equal(right, enumerator.FaceRight);
        }
コード例 #4
0
        public void Faces_RightTurnLoop_3EdgeLoop_Backward_ShouldReturnCounterClockwiseLoop()
        {
            var graphs = new TiledBarrierGraph();

            //    0
            //   / \
            //  1---2

            var v1 = graphs.AddVertex(
                4.788075685501099,
                51.26676188180721, 564341430);
            var v2 = graphs.AddVertex(
                4.786123037338257,
                51.26496276736555, 564341431);
            var v3 = graphs.AddVertex(
                4.790832996368408,
                51.265137311403734, 564341432);

            var e1 = graphs.AddEdge(v1, v2);
            var e2 = graphs.AddEdge(v2, v3);
            var e3 = graphs.AddEdge(v3, v1);

            graphs.SetTileLoaded(Tiles.TileStatic.WorldTileLocalId(graphs.GetVertex(v1), 14));
            graphs.SetTileLoaded(Tiles.TileStatic.WorldTileLocalId(graphs.GetVertex(v2), 14));
            graphs.SetTileLoaded(Tiles.TileStatic.WorldTileLocalId(graphs.GetVertex(v3), 14));

            // calculate right turn loop starting at e1.
            var enumerator = graphs.GetEnumerator();

            enumerator.MoveTo(v2);
            enumerator.MoveNextUntil(e1);
            var(loop, _) = enumerator.RightTurnLoop();

            Assert.NotNull(loop);
            Assert.Equal(3, loop.Count);
            Assert.Equal((v2, e1, false, v1), loop[0]);
            Assert.Equal((v1, e3, false, v3), loop[1]);
            Assert.Equal((v3, e2, false, v2), loop[2]);
        }
コード例 #5
0
        public void Faces_AssignFaces_OneEdge_ShouldAssign1()
        {
            var graphs = new TiledBarrierGraph();

            var v1   = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);
            var v2   = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341431);
            var e    = graphs.AddEdge(v1, v2);
            var tile = Tiles.TileStatic.WorldTileLocalId(4.7522735595703125, 50.97918242660188, 14);

            graphs.SetTileLoaded(tile);

            graphs.AssignFaces(tile);

            Assert.Equal(1, graphs.FaceCount);
        }
コード例 #6
0
        public void TiledBarrierGraphExtensions_NextClockwise_OneOtherEdge_ShouldBeSingle()
        {
            var graphs = new TiledBarrierGraph();
            var v1     = graphs.AddVertex(
                4.801331162452698,
                51.267829233580834);
            var v2 = graphs.AddVertex(
                4.801325798034667,
                51.268153126307524);
            var v3 = graphs.AddVertex(
                4.801816642284393,
                51.26783426820025);
            var e1 = graphs.AddEdge(v2, v1);
            var e2 = graphs.AddEdge(v1, v3);

            var enumerator = graphs.GetEnumerator();

            enumerator.MoveTo(v2);
            enumerator.MoveNext();

            var clockwise = enumerator.NextClockwise();

            Assert.Single(clockwise);
        }
コード例 #7
0
        public void TiledBarrierGraph_RemoveEdge_2Edges_Add4_Remove2_ShouldLeave2()
        {
            var graphs = new TiledBarrierGraph();

            var v1 = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);
            var v2 = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341431);
            var v3 = graphs.AddVertex(4.752981662750244, 50.978996666362015, 564341432);
            var v4 = graphs.AddVertex(4.7518390417099, 50.97881090537897, 564341433);
            var e1 = graphs.AddEdge(v1, v2);
            var e2 = graphs.AddEdge(v3, v4);

            var v5 = graphs.AddVertex(4.752375483512878, 50.97889534228157);
            var e3 = graphs.AddEdge(v1, v5);
            var e4 = graphs.AddEdge(v5, v2);
            var e5 = graphs.AddEdge(v3, v5);
            var e6 = graphs.AddEdge(v5, v4);

            graphs.DeleteEdge(e1);
            graphs.DeleteEdge(e2);

            var enumerator = graphs.GetEnumerator();

            Assert.True(enumerator.MoveTo(v1));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(e3, enumerator.Edge);
            Assert.False(enumerator.MoveNext());

            Assert.True(enumerator.MoveTo(v2));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(e4, enumerator.Edge);
            Assert.False(enumerator.MoveNext());

            Assert.True(enumerator.MoveTo(v3));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(e5, enumerator.Edge);
            Assert.False(enumerator.MoveNext());

            Assert.True(enumerator.MoveTo(v4));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(e6, enumerator.Edge);
            Assert.False(enumerator.MoveNext());

            var expected = new HashSet <int>(new [] { e3, e4, e5, e6 });

            Assert.True(enumerator.MoveTo(v5));
            Assert.True(enumerator.MoveNext());
            Assert.True(expected.Remove(enumerator.Edge));
            Assert.True(enumerator.MoveNext());
            Assert.True(expected.Remove(enumerator.Edge));
            Assert.True(enumerator.MoveNext());
            Assert.True(expected.Remove(enumerator.Edge));
            Assert.True(enumerator.MoveNext());
            Assert.True(expected.Remove(enumerator.Edge));
            Assert.False(enumerator.MoveNext());
            Assert.Empty(expected);
        }
コード例 #8
0
        public void TiledBarrierGraphExtensions_NextClockwise_NoOtherEdge_ShouldBeEmpty()
        {
            var graphs = new TiledBarrierGraph();
            var v1     = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);
            var v2     = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341431);
            var e      = graphs.AddEdge(v1, v2);

            var enumerator = graphs.GetEnumerator();

            enumerator.MoveTo(v1);
            enumerator.MoveNext();

            var clockwise = enumerator.NextClockwise();

            Assert.Empty(clockwise);
        }
コード例 #9
0
        public void TiledBarrierGraph_SetFace_Right_1Edge_ShouldSetFaceRight()
        {
            var graphs = new TiledBarrierGraph();
            var v1     = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);
            var v2     = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341431);
            var e      = graphs.AddEdge(v1, v2);

            var f = graphs.AddFace();

            graphs.SetFace(e, false, f);

            var enumerator = graphs.GetEnumerator();

            enumerator.MoveTo(v1);
            enumerator.MoveNext();
            Assert.Equal(int.MaxValue, enumerator.FaceLeft);
            Assert.Equal(f, enumerator.FaceRight);
        }
コード例 #10
0
        public void TiledBarrierGraph_FaceEnumerator_1Edge_Left_ShouldEnumerateEdge()
        {
            var graphs = new TiledBarrierGraph();
            var v1     = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);
            var v2     = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341431);
            var e      = graphs.AddEdge(v1, v2);

            var f = graphs.AddFace();

            graphs.SetFace(e, true, f);

            var enumerator = graphs.GetFaceEnumerator();

            Assert.True(enumerator.MoveTo(f));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(e, enumerator.Edge);
            Assert.True(enumerator.IsLeft);
            Assert.False(enumerator.MoveNext());
        }
コード例 #11
0
        public void TiledBarrierGraph_AddEdge_1Edge_ShouldAddEdge0()
        {
            var graphs = new TiledBarrierGraph();
            var v1     = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);
            var v2     = graphs.AddVertex(4.7525310516357420, 50.97851368626033, 564341431);
            var e      = graphs.AddEdge(v1, v2);

            Assert.Equal(2, graphs.VertexCount);
            Assert.Equal(0, e);

            var enumerator = graphs.GetEnumerator();

            Assert.True(enumerator.MoveTo(v1));
            Assert.True(enumerator.MoveNext());
            Assert.Equal(v1, enumerator.Vertex1);
            Assert.Equal(v2, enumerator.Vertex2);
            Assert.Equal(0, enumerator.Edge);
            Assert.NotNull(enumerator.Shape);
            Assert.Empty(enumerator.Shape);
            Assert.Equal(0, enumerator.Tags.Count);
            Assert.False(enumerator.MoveNext());
        }