/// <summary>
 /// Constructor which sets properties.
 /// </summary>
 /// <param name="tdi">The train drawing info to which this vertex belongs.</param>
 /// <param name="time">The time of day that the vertex represents.</param>
 /// <param name="arrivalDeparture">Whether the vertex represents an arrival time, a departure time, or both.</param>
 /// <param name="x">The X-coordinate of the vertex.</param>
 /// <param name="y">The Y-coordinate of the vertex.</param>
 public VertexInformation(TrainDrawingInfo tdi, TimeOfDay time, ArrivalDepartureOptions arrivalDeparture, double x, double y)
 {
     TrainDrawingInfo = tdi;
     Time             = time;
     ArrivalDeparture = arrivalDeparture;
     X = x;
     Y = y;
 }
        /// <summary>
        /// Generate train drawing information.
        /// </summary>
        /// <returns>A series of train drawing information objects containing drawing instructions.</returns>
        public IEnumerable <TrainDrawingInfo> GetTrainDrawingInformation()
        {
            RecomputeTimeBase();
            RecomputeLocationCoordinates();

            foreach (Train train in TrainList.Where(t => t.TrainTimes?.Count > 0))
            {
                TrainDrawingInfo tdi = new TrainDrawingInfo {
                    Properties = train.GraphProperties, Headcode = train.Headcode, Train = train
                };
                for (int i = 0; i < train.TrainTimes.Count; ++i)
                {
                    if (train.TrainTimes[i]?.ArrivalTime?.Time != null && train.TrainTimes[i]?.DepartureTime?.Time != null)
                    {
                        double locationCoordinate = _locationCoordinates[train.TrainTimes[i].Location.Id];
                        tdi.Lines.Add(new LineCoordinates(
                                          new VertexInformation(tdi, train.TrainTimes[i].ArrivalTime.Time, ArrivalDepartureOptions.Arrival, GetXPositionFromTime(train.TrainTimes[i].ArrivalTime.Time),
                                                                locationCoordinate),
                                          new VertexInformation(tdi, train.TrainTimes[i].DepartureTime.Time, ArrivalDepartureOptions.Departure, GetXPositionFromTime(train.TrainTimes[i].DepartureTime.Time),
                                                                locationCoordinate)));
                    }
                    if (i > 0 && train.TrainTimes[i - 1]?.DepartureTime?.Time != null)
                    {
                        VertexInformation startVertex =
                            new VertexInformation(tdi, train.TrainTimes[i - 1].DepartureTime.Time, ArrivalDepartureOptions.Departure,
                                                  GetXPositionFromTime(train.TrainTimes[i - 1].DepartureTime.Time), _locationCoordinates[train.TrainTimes[i - 1].Location.Id]);
                        double endY = _locationCoordinates[train.TrainTimes[i].Location.Id];
                        if (train.TrainTimes[i]?.ArrivalTime?.Time != null)
                        {
                            tdi.Lines.Add(new LineCoordinates(startVertex, new VertexInformation(tdi, train.TrainTimes[i].ArrivalTime.Time, ArrivalDepartureOptions.Arrival,
                                                                                                 GetXPositionFromTime(train.TrainTimes[i].ArrivalTime.Time), endY)));
                        }
                        else if (train.TrainTimes[i]?.DepartureTime?.Time != null)
                        {
                            tdi.Lines.Add(new LineCoordinates(startVertex, new VertexInformation(tdi, train.TrainTimes[i].DepartureTime.Time, ArrivalDepartureOptions.Departure,
                                                                                                 GetXPositionFromTime(train.TrainTimes[i].DepartureTime.Time), endY)));
                        }
                    }
                }

                yield return(tdi);
            }
        }