public WSVehicleUpdateMsg(VehicleState state, StopPath path, Route route) : this(state) { if (path == null) { this.DepartingStopID = 0; this.ArrivingStopID = 0; } else { this.DepartingStopID = path.OriginStopID; this.ArrivingStopID = path.DestinationStopID; } Route = route; }
private List <StopPath> ParseStopPaths(List <SyncromaticsWaypoint> waypoints, List <SyncromaticsStop> stops) { //this is REALLY messy but at least it works for now //TODO: Refactor List <StopPath> paths = new List <StopPath>(); for (int i = 0; i < stops.Count; i++) { SyncromaticsStop stop = stops[i]; //calculate stop paths int firstWaypointIndex = waypoints.FindIndex(x => x.Latitude == stop.Latitude && x.Longitude == stop.Longitude); if (i != stops.Count - 1) { int lastWayPointIndex = waypoints.FindIndex(x => x.Latitude == stops[i + 1].Latitude && x.Longitude == stops[i + 1].Longitude); List <Coordinate> coordinates = new List <Coordinate>(); for (int j = firstWaypointIndex; j < lastWayPointIndex + 1; j++) { coordinates.Add(new Coordinate(waypoints[j].Latitude, waypoints[j].Longitude)); } double totalDistance = 0.0; for (int j = 0; j < coordinates.Count; j++) { if (j != coordinates.Count - 1) { totalDistance += coordinates[j].DistanceTo(coordinates[j + 1]); } } StopPath path = new StopPath() { OriginStopID = stop.ID, DestinationStopID = stops[i + 1].ID, Path = coordinates, TotalPathDistance = totalDistance }; paths.Add(path); } else if (i == stops.Count - 1) { int lastWayPointIndex = waypoints.FindIndex(x => x.Latitude == stops[0].Latitude && x.Longitude == stops[0].Longitude); List <Coordinate> coordinates = new List <Coordinate>(); for (int j = firstWaypointIndex; j < waypoints.Count; j++) { coordinates.Add(new Coordinate(waypoints[j].Latitude, waypoints[j].Longitude)); } for (int j = 0; j <= lastWayPointIndex; j++) { coordinates.Add(new Coordinate(waypoints[j].Latitude, waypoints[j].Longitude)); } double totalDistance = 0.0; for (int j = 0; j < coordinates.Count; j++) { if (j != coordinates.Count - 1) { totalDistance += coordinates[j].DistanceTo(coordinates[j + 1]); } } StopPath path = new StopPath() { OriginStopID = stop.ID, DestinationStopID = stops[0].ID, Path = coordinates, TotalPathDistance = totalDistance }; paths.Add(path); } } return(paths); }