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); }
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()); }
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>()); }