public ActionResult <List <Tuple <double, double> > > GetRoute(double distance, [FromQuery] double[] coordinates) { //coordinates: long, lat, start to end if (coordinates.Length < 4 || coordinates.Length % 2 != 0) { return(BadRequest()); } MapBox mapbox = new MapBox(distance, new Tuple <double, double>(coordinates[0], coordinates[1]), new Tuple <double, double>(coordinates[2], coordinates[3])); var wayPoints = RouteGeneration.generateOtherPoints(mapbox); var matrixResult = mapbox.generateMatrix(wayPoints).Result; var matrix = matrixResult.Item1; var realCoords = matrixResult.Item2; var distancesAndPoints = RouteGeneration.getDistancesAndPoints(matrix, mapbox.getDistance(), 0.5); var random = new Random(); var selectedRoute = distancesAndPoints[random.Next(distancesAndPoints.Count)]; var listOfPoints = selectedRoute.Item2; List <int> indices = new List <int>(); for (int i = 0; i < listOfPoints.Count; i++) { indices.Add(listOfPoints[i].Item1); } indices.Add(listOfPoints[listOfPoints.Count - 1].Item2); List <Tuple <double, double> > latsAndLongs = new List <Tuple <double, double> >(); for (int i = 0; i < indices.Count; i++) { latsAndLongs.Add(realCoords[indices[i]]); } return(latsAndLongs); }
static void Main(string[] args) { MapBox newBox = new MapBox(6, new Tuple <double, double> (-82.334380, 29.653420), new Tuple <double, double> (-82.323640, 29.650510)); //List<Tuple<double, double>> newList = new List<Tuple<double, double>>{newBox.startPoint, newBox.endPoint, // new Tuple<double, double>(-83,29.7), new Tuple<double, double>(-83.2,29.8)}; var newList = RouteGeneration.generateOtherPoints(newBox); var both = newBox.generateMatrix(newList).Result; var matrix = both.Item1; //RouteGeneration.routePath(newBox); var distances = RouteGeneration.getDistancesAndPoints(matrix, newBox.getDistance(), 0.5); int closeCounter = 0; foreach (var aids in distances) { var distance = aids.Item1; if (Math.Abs(6 - (distance * 0.000621371)) <= 0.5) { closeCounter++; Console.WriteLine($"Distance: {aids.Item1}, \nConnections:"); foreach (var point in aids.Item2) { Console.Write($"({point.Item1}, {point.Item2})"); } Console.WriteLine(); } } Console.WriteLine(closeCounter); }