private GridCell FindGridCell(double[] requestStart) { foreach (var g in _grid) { if (DistanceHelpers.IsInside(requestStart, g.Border.Select(x => x.ToDoubleArray()).ToArray())) { return(g); } } throw new Exception(); }
private void CheckIfAllPoinsInsidePolygon(RouteSearchRequestDTO request) { var polygon = request.PolygonPoints.Select(x => x.ToDoubleArray()).ToArray(); foreach (var p in request.Points) { if (!DistanceHelpers.IsInside(p.ToDoubleArray(), polygon)) { throw new Exception("Ne visi tarpiniai taškai patenka į apibrėžtą poligoną"); } } if (!DistanceHelpers.IsInside(request.Start.ToDoubleArray(), polygon)) { throw new Exception("Pradžia nepatenka į apibrėžtą poligoną"); } if (!DistanceHelpers.IsInside(request.End.ToDoubleArray(), polygon)) { throw new Exception("Pabaiga nepatenka į apibrėžtą poligoną"); } }
public LoadedData2 LoadDataBetweenTwoPoints(double[] start, double[] end, double[][] polygonPoints) { var cellSequence = new List <GridCell>(); var startGridCell = FindGridCell(start); var endGridCell = FindGridCell(end); cellSequence.Add(startGridCell); if (startGridCell.Index != endGridCell.Index) { cellSequence.Add(endGridCell); } if (!cellToFeatures.ContainsKey(startGridCell.Index)) { cellToFeatures[startGridCell.Index] = ReadCellData(startGridCell.Index); UpdateNeighbours(cellToFeatures, startGridCell); } if (!cellToFeatures.ContainsKey(endGridCell.Index)) { cellToFeatures[endGridCell.Index] = ReadCellData(endGridCell.Index); UpdateNeighbours(cellToFeatures, endGridCell); } var tempGridCells = GetTempGridCells(cellSequence.ToArray()); foreach (var c in tempGridCells) { if (!cellToFeatures.ContainsKey(c.Index)) { cellToFeatures[c.Index] = ReadCellData(c.Index); UpdateNeighbours(cellToFeatures, c); } cellSequence.Add(c); } var result = new List <RouteFeature>(); //double diff = 6000; //var count = 0; //DistanceHelpers.DistanceBetweenCoordinates(); foreach (var c in cellSequence) { //count += cellToFeatures[c.Index].Features.Length; //how much we will save result.AddRange(cellToFeatures[c.Index].Features); //foreach (var f in cellToFeatures[c.Index].Features) //{ // var cord = f.Data.Coordinates.Skip(f.Data.Coordinates.Length / 2).FirstOrDefault().ToDoubleArray(); // var projection = DistanceHelpers.GetProjectionOnLine(new Tuple<double[], double[]>(start, end), cord); // if (DistanceHelpers.DistanceBetweenCoordinates(projection, cord) < diff) // { // result.Add(f); // } //} } return(new LoadedData2() { StartFeature = FindClosetFeature(start, cellToFeatures[startGridCell.Index].Features), EndFeature = FindClosetFeature(end, cellToFeatures[endGridCell.Index].Features), AllFeatures = polygonPoints.Length == 0 ? result.ToArray() : result.Where(x => DistanceHelpers.IsInside(x.Data.Coordinates.First().ToDoubleArray(), polygonPoints) || DistanceHelpers.IsInside(x.Data.Coordinates.Last().ToDoubleArray(), polygonPoints)).ToArray() }); }