public void ProlongEnd_NoPoints_ShouldReturnOriginalLine() { var lineToProlong = new LineString(new[] { new Coordinate(0, 0), new Coordinate(1, 1) }); var results = _executor.ProlongLineEnd(lineToProlong, new Coordinate[0], new List <LineString>(), 5, 200); Assert.AreEqual(lineToProlong.Coordinates.Length, results.Coordinates.Length); }
/// <summary> /// This method is try to prolong all lines according to original GPS trace. /// for each line it prolongs the end of the line. /// </summary> /// <param name="linesToProlong"></param> /// <param name="gpxItmLines"></param> /// <returns></returns> private async Task <List <ILineString> > ProlongLinesEndAccordingToOriginalGpx(List <ILineString> linesToProlong, List <ILineString> gpxItmLines) { var prolongedLines = new List <ILineString>(); var currentLineIndex = gpxItmLines.Count - 1; var currentPositionIndex = gpxItmLines[currentLineIndex].Coordinates.Length - 1; for (int lineIndex = linesToProlong.Count - 1; lineIndex >= 0; lineIndex--) { var prolongedLine = linesToProlong[lineIndex]; var currentCoordinate = prolongedLine.Coordinates.Last(); // can we improve this by keeping reference to the position in the orignal line? UpdateIndexes(currentCoordinate, gpxItmLines, ref currentLineIndex, ref currentPositionIndex); var originalCoordinates = gpxItmLines[currentLineIndex].Coordinates.Skip(currentPositionIndex).ToArray(); var lineStringInArea = await GetLineStringsInArea(new LineString(new[] { currentCoordinate, currentCoordinate }), _options.MaximalProlongLineLength); prolongedLine = _gpxProlongerExecutor.ProlongLineEnd(prolongedLine, originalCoordinates, lineStringInArea.Concat(prolongedLines).Concat(linesToProlong.Take(lineIndex)).ToArray(), _options.DistanceToExisitngLineMergeThreshold, _options.MaximalProlongLineLength); prolongedLines.Add(prolongedLine); } prolongedLines.Reverse(); // reverse back to keep the original order of the lines return(prolongedLines); }