Example #1
0
 /// <summary>
 /// This method returns a double representing the length of time (in seconds) that it would
 /// take to get to from a PseudoNode to a Node along the same Path. If the given Node is
 /// not on the same Path, this returns Double.MAX_VALUE as this method contains no support
 /// for routing.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="pseudoNode"></param>
 /// <returns></returns>
 public double GetTimeToNodeFrom(Node node, PseudoNode pseudoNode)
 {
     if (pseudoNode.GetPath() == this)
     {
         return(GetTimeToNodeFrom(node, pseudoNode.GetDistanceAlongPath()));
     }
     else
     {
         Debug.WriteLine("The PseudoNode does not lie on this Path.");
         return(Double.MaxValue);
     }
 }
Example #2
0
        /// <summary>
        /// This sets the directions of travel for each of the Paths in the path_route array. The result is stored
        /// in the path_directions array.
        /// </summary>
        void DetermineDirections()
        {
            // Initialise the size of the new Path directions to be the same as the size as the
            // path_route
            path_directions = new List <Direction>(path_route.Count);

            // If the route only contains one path
            if (path_route.Count == 1)
            {
                if (source_node.GetDistanceAlongPath() < end_node.GetDistanceAlongPath())
                {
                    path_directions.Add(Direction.FORWARDS);
                }
                else
                {
                    path_directions.Add(Direction.BACKWARDS);
                }
                // Do not allow processing of the rest of this function
                return;
            }

            // Loop through each Path (except the last) and find the correct direction
            for (int i = 0; i < path_route.Count - 1; i++)
            {
                // Get nodes that exist on the current Path
                Node [] current_nodes = path_route[i].GetNodes();

                // Get nodes that exist on the next Path
                Node [] next_nodes = path_route[i + 1].GetNodes();

                if (current_nodes[0] == next_nodes[0] || current_nodes[0] == next_nodes[1])
                {
                    path_directions.Add(Direction.BACKWARDS);
                }
                else
                {
                    path_directions.Add(Direction.FORWARDS);
                }
            }

            // Find the direction of the last Path
            Node [] last_path_nodes       = path_route[path_route.Count - 1].GetNodes();
            Node [] penultimate_path_node = path_route[path_route.Count - 2].GetNodes();

            if (last_path_nodes[0] == penultimate_path_node[0] || last_path_nodes[0] == penultimate_path_node[1])
            {
                path_directions.Add(Direction.FORWARDS);
            }
            else
            {
                path_directions.Add(Direction.BACKWARDS);
            }
        }
Example #3
0
        /// <summary>
        /// This method returns a double that represents the length of time (in seconds) that it
        /// would take to get from one PseudoNode on the Path to another on the Path. If one of
        /// the nodes is not on this Path, this method will return Double.MaxValue.
        /// </summary>
        /// <param name="destination_node"></param>
        /// <param name="source_node"></param>
        /// <returns></returns>
        public double GetTimeToPseudoNodeFrom(PseudoNode destination_node, PseudoNode source_node)
        {
            // Check both PseudoNodes are on the Path
            if (destination_node.GetPath() != this || source_node.GetPath() != this)
            {
                return(Double.MaxValue);
            }

            // Calculate length of time
            double destination_distance = destination_node.GetDistanceAlongPath();
            double source_distance      = source_node.GetDistanceAlongPath();
            double time = (destination_distance - source_distance) / speed_limit;

            time = (time > 0) ? time : -time;
            return(time);
        }
Example #4
0
 /// <summary>
 /// Sets up a PseudoNode at the same point as the given PseudoNode.
 /// </summary>
 /// <param name="node"></param>
 public PseudoNode(PseudoNode node)
 {
     path = node.GetPath();
     distance_along_path = node.GetDistanceAlongPath();
 }
Example #5
0
 /// <summary>
 /// Returns a double representing the distance along the path from the first node
 /// in the path array to the second (note that it's not in the direction of travel).
 /// </summary>
 /// <returns></returns>
 public double GetDistanceAlongPath()
 {
     return(position.GetDistanceAlongPath());
 }