public int GetRoutes() { var blks = GetBlocks(); foreach (var b0 in blks) { if (b0 == null) { continue; } _branches.Clear(); _currentWay = ""; GetAllPath(b0); } foreach (var p in _paths) { Trace.WriteLine("P: " + p); } foreach (var p in _paths) { if (string.IsNullOrEmpty(p)) { continue; } WayPoints wps = new WayPoints(this, p); if (Routes == null) { Routes = new List <WayPoints>(); } Routes.Add(wps); } if (Routes == null) { return(0); } return(Routes.Count); }
private bool CheckSwitchAndTurn(MapItem currentItem, MapItem neighbour) { if (currentItem == null) { return(false); } if (!currentItem.IsSwitch) { return(false); } if (neighbour == null) { return(false); } var previousWay = new WayPoints(this, _currentWay); int lastIndex = previousWay.Count - 1; var fromWp = previousWay[lastIndex - 1]; var fromItem = Get(fromWp.X0, fromWp.Y1); var nb = neighbour; var xdelta = nb.X0 - fromItem.X0; var ydelta = nb.Y0 - fromItem.Y0; bool hasTurn = Math.Abs(xdelta) == 1 || Math.Abs(ydelta) == 1; if (hasTurn) { _currentWay = _currentWay.Trim(); int n = _currentWay.LastIndexOf("->", StringComparison.OrdinalIgnoreCase); _currentWay = _currentWay.Substring(0, n).Trim(); _currentWay += ">->"; } return(hasTurn); }