/// <summary> /// Disconnects the given StreetEndpoint from this StreetConnector. /// </summary> /// <param name="ep">The StreetEndpoint that should be disconnected</param> /// <returns>The result of the disconnection try</returns> public DisconnectResult Disconnect(StreetEndpoint ep) { if (ep1 == ep) { ep1 = null; } else if (ep2 == ep) { ep2 = null; } else { return(DisconnectResult.NotConnected); } return(DisconnectResult.Disconnected); }
/// <summary> /// Creates a new StreetSegment between two StreetConnectors. /// </summary> /// <param name="c1">The first StreetConnector</param> /// <param name="c2">The second StreetConnector</param> public StreetSegment(StreetConnector c1, StreetConnector c2) { id = NextID; ep1 = new StreetEndpoint(this); ep2 = new StreetEndpoint(this); if (!ep1.Connect(c1) || !ep2.Connect(c2)) { throw new StreetMapException("Could not connect this StreetSegment with all StreetConnectors"); } length = CalcLength(); speedLimit = DEFAULT_SPEED_LIMIT; UpdateMinDriveTime(); lanes = DEFAULT_LANES_COUNT; UpdateSpace(); }
/// <summary> /// Disconnects from the connected StreetConnector. /// </summary> /// <returns>True if the connection could be broken, false otherwise</returns> public bool Disconnect(StreetConnector connector) { StreetEndpoint ep = FindEndpoint(connector); if (ep == null) { return(true); } if (!ep.Disconnect()) { throw new StreetMapException("Could not disconnect this StreetHub from the StreetConnector"); } connections.Remove(ep); isGreenList.Remove(connector.ID); return(true); }
/// <summary> /// Returns all StreetConnectors that are connected to the assoziated StreetType, except the one connected to the given StreetEndpoint. /// </summary> /// <param name="ep">The StreetEndpoint for which the connected StreetConnectors should be searched</param> /// <returns>A list of all connected StreetConnectors</returns> public override List <StreetConnector> FindNeighbours(StreetEndpoint ep) { List <StreetConnector> neighbours = new List <StreetConnector>(); if (ep1 == ep) { neighbours.Add(ep2.Connector); } else if (ep2 == ep) { neighbours.Add(ep1.Connector); } else { throw new ArgumentException("The given StreetEndpoint isn't connected to this StreetSegment"); } return(neighbours); }
/// <summary> /// Connects to the given StreetConnector. /// </summary> /// <param name="connector">The StreetConnector to connect to</param> /// <returns>True if a connection could be established, false otherwise</returns> public bool Connect(StreetConnector connector) { if (FindEndpoint(connector) != null) { return(true); } StreetEndpoint ep = new StreetEndpoint(this); if (!ep.Connect(connector)) { throw new StreetMapException("Could not connect this StreetHub to the StreetConnector"); } connections.Add(ep); isGreenList.Add(connector.ID, true); UpdateSpace(); return(true); }
private void UpdateSpace() { if (connections.Count <= 1) { space = 0; return; } StreetEndpoint root = connections.First(); space = 0; foreach (StreetEndpoint ep in connections) { if (ep == root) { continue; } space += Coordinate.GetDistance(root.Connector.Coordinate, ep.Connector.Coordinate); } space *= USABLE_SPACE; }
/// <summary> /// Connects the given StreetEndpoint to this StreetConnector. /// </summary> /// <param name="ep">The StreetEndpoint that should be connected</param> /// <returns>The result of the connection try</returns> public ConnectResult Connect(StreetEndpoint ep) { if (ep == ep1 || ep == ep2) { return(ConnectResult.AlreadyConnected); } if (ep1 == null) { ep1 = ep; } else if (ep2 == null) { ep2 = ep; } else { return(ConnectResult.NoFreeSlot); } return(ConnectResult.Connected); }
/// <summary> /// Returns all StreetConnectors that are connected to the assoziated StreetType, except the one connected to the given StreetEndpoint. /// </summary> /// <param name="ep">The StreetEndpoint for which the connected StreetConnectors should be searched</param> /// <returns>A list of all connected StreetConnectors</returns> public override List <StreetConnector> FindNeighbours(StreetEndpoint ep) { List <StreetConnector> neighbours = new List <StreetConnector>(); bool isConnected = false; foreach (StreetEndpoint endpoint in connections) { if (endpoint == ep) { isConnected = true; } else { neighbours.Add(endpoint.Connector); } } if (!isConnected) { throw new ArgumentException("The given StreetEndpoint isn't connected to this StreetHub"); } return(neighbours); }
/// <summary> /// Returns all StreetConnectors that are connected to the assoziated StreetType, except the one connected to the given StreetEndpoint. /// </summary> /// <param name="ep">The StreetEndpoint for which the connected StreetConnectors should be searched</param> /// <returns>A list of all connected StreetConnectors</returns> public abstract List <StreetConnector> FindNeighbours(StreetEndpoint ep);