private async Task <List <RouteWaypoint> > ParseWaypoints(List <SyncromaticsWaypoint> syncWaypoints) { List <RouteWaypoint> waypoints = new List <RouteWaypoint>(); double distance = 0; for (int i = 0; i < syncWaypoints.Count; i++) { SyncromaticsWaypoint waypoint = syncWaypoints[i]; if (i != 0) { distance += new Coordinate(syncWaypoints[i - 1].Latitude, syncWaypoints[i - 1].Longitude).DistanceTo(new Coordinate(waypoint.Latitude, waypoint.Longitude)); } waypoints.Add(new RouteWaypoint(waypoint.Latitude, waypoint.Longitude, distance)); } return(waypoints); }
private List <Stop> ParseStops(List <SyncromaticsWaypoint> waypoints, List <SyncromaticsStop> syncromaticsStops) { List <Stop> stops = new List <Stop>(); for (int i = 0; i < syncromaticsStops.Count; i++) { SyncromaticsStop stop = syncromaticsStops[i]; //calculate stop paths int firstWaypointIndex = waypoints.FindIndex(x => x.Latitude == stop.Latitude && x.Longitude == stop.Longitude); if (firstWaypointIndex != -1) { SyncromaticsWaypoint waypoint = waypoints[firstWaypointIndex]; if (firstWaypointIndex != waypoints.Count - 1) { SyncromaticsWaypoint nextWaypoint = waypoints[firstWaypointIndex + 1]; Coordinate firstCoord = new Coordinate(waypoint.Latitude, waypoint.Longitude); Coordinate secondCoord = new Coordinate(nextWaypoint.Latitude, nextWaypoint.Longitude); double bearing = firstCoord.GetBearingTo(secondCoord); stops.Add(new Stop(firstCoord, stop, Coordinate.DegreesToCardinal(bearing))); } else { Console.WriteLine($"error: stop {stop.Name} does not have a valid NEXT waypoint!"); } } } /* * we are going to re-order these stops based on where the MSC and Lib is, since, combined, they are hubs * for every route. * * if a route has both the MSC and the Library as a stop point, they generally placed at opposite ends of the route. * for the purposes of this interim organization, if both are present, the msc will be first. * * msc ID: 401 * library ID: 102 */ List <Stop> tempStopsList = new List <Stop>(); int LIBIndex = stops.FindIndex(x => x.RTPI == 102); int MSCIndex = stops.FindIndex(x => x.RTPI == 401); if (MSCIndex != -1) { //route goes to msc at all (it's always first) for (int i = MSCIndex; i < stops.Count; i++) { tempStopsList.Add(stops[i]); } for (int i = 0; i < MSCIndex; i++) { tempStopsList.Add(stops[i]); } } else if (LIBIndex != -1) { //goes to lib only for (int i = LIBIndex; i < stops.Count; i++) { tempStopsList.Add(stops[i]); } for (int i = 0; i < LIBIndex; i++) { tempStopsList.Add(stops[i]); } } return(tempStopsList); }