Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        internal static void AddTileFor(this TiledBarrierGraph graph, int vertex, Func <uint, IEnumerable <OsmGeo> > getTile,
                                        Func <TagsCollectionBase, bool> isBarrier)
        {
            var vLocation = graph.GetVertex(vertex);
            var t         = TileStatic.WorldTileLocalId(vLocation.longitude, vLocation.latitude, graph.Zoom);

            graph.AddTiles(new[] { t }, getTile, isBarrier);
        }
        /// <summary>
        /// Builds a guid for the given vertex.
        /// </summary>
        /// <param name="graph">The graph.</param>
        /// <param name="vertex">The vertex.</param>
        public static Guid GetVertexGuid(this TiledBarrierGraph graph, int vertex)
        {
            // we have a planar graph so location <-> guid.
            // we generate an id based on the vertex location relative in a tile.

            var location     = graph.GetVertex(vertex);
            var tileLocation = TileStatic.ToLocalTileCoordinates(graph.Zoom, location, 16384);

            return(GuidUtility.Create(Namespace, tileLocation.GetBytes()));
        }
Exemplo n.º 4
0
        public void TiledBarrierGraph_AddVertex_1Vertex_ShouldAddVertex0()
        {
            var graphs = new TiledBarrierGraph();
            var v      = graphs.AddVertex(4.7522735595703125, 50.97918242660188, 564341430);

            Assert.Equal(1, graphs.VertexCount);
            Assert.Equal(0, v);

            var vLocation = graphs.GetVertex(v);

            Assert.Equal((4.7522735595703125, 50.97918242660188), vLocation);
        }
Exemplo n.º 5
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]);
        }
Exemplo n.º 6
0
 private static byte[] GetVertexLocationBytes(this TiledBarrierGraph graph, int v)
 {
     return(TileStatic.ToLocalTileCoordinates(graph.Zoom, graph.GetVertex(v), 16384).GetBytes());
 }