public void EdgeDistanceMoreLessTolerance_NotOk() { // Line end 0.023 from edge is not ok // // S // | //|--E < 0.007 >| //| | //| | //|-------------| LineString line = new WKTReader().Read("LINESTRING(578257.898582255 6179230.84377762,578248.38610886 6179230.74258109,578248.487305386 6179238.43351703,578257.79738573 6179238.3323205,578256.811707854 6179230.83918227)") as LineString; // Assert that distance from end point to edge is 0.007 Coordinate[] linePointsMinusOne = new Coordinate[line.NumPoints - 1]; for (int i = 0; i < line.NumPoints - 1; i++) { linePointsMinusOne[i] = line.GetPointN(i).Coordinate; } LineString newLine = new LineString(linePointsMinusOne); var endPointToEdgeDistance = Math.Round(line.EndPoint.Distance(newLine), 3); Assert.Equal(0.007, endPointToEdgeDistance); // We should get false from our line validation logic Assert.False(LineIsValidRouteSegment(line)); }
public void LineIsValid_ShouldReturnFalse_OnEdgeDistanceMoreLessTolerance() { // Line end 0.023 from edge is not ok // // S // | //|--E < 0.007 >| //| | //| | //|-------------| var logger = A.Fake <ILogger <RouteSegmentValidator> >(); var applicationSettings = A.Fake <IOptions <ApplicationSetting> >(); A.CallTo(() => applicationSettings.Value).Returns(new ApplicationSetting { Tolerance = 0.01 }); var line = new WKTReader().Read("LINESTRING(578257.898582255 6179230.84377762,578248.38610886 6179230.74258109,578248.487305386 6179238.43351703,578257.79738573 6179238.3323205,578256.811707854 6179230.83918227)") as LineString; // Assert that distance from end point to edge is 0.007 Coordinate[] linePointsMinusOne = new Coordinate[line.NumPoints - 1]; for (int i = 0; i < line.NumPoints - 1; i++) { linePointsMinusOne[i] = line.GetPointN(i).Coordinate; } var newLine = new LineString(linePointsMinusOne); var endPointToEdgeDistance = Math.Round(line.EndPoint.Distance(newLine), 3); var routeSegmentValidator = new RouteSegmentValidator(logger, applicationSettings); var result = routeSegmentValidator.LineIsValid(line); // Assert that distance from end point to edge is 0.007 endPointToEdgeDistance.Should().Be(0.007); result.Should().BeFalse(); }