Exemplo n.º 1
0
        public static (bool success, IEnumerable <uint> missingTiles) AssignFaces(this TiledBarrierGraph graph,
                                                                                  uint tile)
        {
            if (!graph.HasTile(tile))
            {
                return(false, new[] { tile });
            }
            var tileBox = TileStatic.Box(graph.Zoom, tile);

            var tilesMissing = new HashSet <uint>();

            graph.ResetFaces();

            // the default face for the case where a loop cannot be found.
            var unAssignableFace = graph.AddFace();

            // check each edges for faces and if missing assign them.
            var enumerator = graph.GetEnumerator();

            for (var v = 0; v < graph.VertexCount; v++)
            {
                if (!enumerator.MoveTo(v))
                {
                    continue;
                }
                if (!enumerator.MoveNext())
                {
                    continue;
                }

                var vBox = graph.GetVertexBox(v);
                if (vBox == null || !vBox.Value.Overlaps(tileBox))
                {
                    continue;
                }
                // var vTile = TileStatic.WorldTileLocalId(vLocation.longitude, vLocation.latitude, graph.Zoom);
                // if (vTile != tile) continue;

                enumerator.MoveTo(v);
                while (enumerator.MoveNext())
                {
                    if (enumerator.Forward && enumerator.FaceRight != int.MaxValue)
                    {
                        continue;
                    }
                    if (!enumerator.Forward && enumerator.FaceLeft != int.MaxValue)
                    {
                        continue;
                    }

                    // check if the edge bbox overlaps the tiles.
                    var eBox = enumerator.Box;
                    if (!eBox.Overlaps(tileBox))
                    {
                        continue;
                    }

                    // ok this edge has an undetermined face.
                    var result = enumerator.AssignFace(unAssignableFace);
                    if (!result.success)
                    {
                        tilesMissing.UnionWith(result.missingTiles);
                    }
                }
            }

            if (tilesMissing.Count > 0)
            {
                return(false, tilesMissing);
            }

            return(true, Enumerable.Empty <uint>());
        }