Search in sources :

Example 76 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class HeadingRoutingTest method headingTest6.

@Test
public void headingTest6() {
    // Test if snaps at tower nodes are ignored
    GraphHopperStorage graph = createSquareGraph();
    Router router = createRouter(graph);
    // QueryPoints directly on TowerNodes
    GHPoint start = new GHPoint(0, 0);
    GHPoint via = new GHPoint(0.002, 0.000);
    GHPoint end = new GHPoint(0.002, 0.002);
    GHRequest req = new GHRequest().setPoints(Arrays.asList(start, via, end)).setHeadings(Arrays.asList(90., 270., 270.)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
    GHResponse response = router.route(req);
    assertFalse(response.hasErrors());
    assertArrayEquals(new int[] { 0, 1, 2, 3, 4 }, calcNodes(graph, response.getAll().get(0)));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 77 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class HeadingRoutingTest method headingTest3.

@Test
public void headingTest3() {
    GraphHopperStorage graph = createSquareGraph();
    Router router = createRouter(graph);
    // Start in middle of edge 4-5
    GHPoint start = new GHPoint(0.0015, 0.002);
    // Via Point between 8-7
    GHPoint via = new GHPoint(0.0005, 0.001);
    // End at middle of edge 2-3
    GHPoint end = new GHPoint(0.002, 0.0005);
    GHRequest req = new GHRequest().setPoints(Arrays.asList(start, via, end)).setHeadings(Arrays.asList(Double.NaN, 0., Double.NaN)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
    GHResponse response = router.route(req);
    assertFalse(response.hasErrors());
    assertArrayEquals(new int[] { 4, 5, 6, 7, 8, 3, 2 }, calcNodes(graph, response.getAll().get(0)));
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 78 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method doNotReadFinishInstruction.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void doNotReadFinishInstruction(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).putHint("vehicle", "car").putHint("turn_description", false);
    GHResponse res = gh.route(req);
    InstructionList instructions = res.getBest().getInstructions();
    String finishInstructionName = instructions.get(instructions.size() - 1).getName();
    assertEquals("", finishInstructionName);
}
Also used : InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 79 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method testOutOfBoundsException.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testOutOfBoundsException(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(-400.214943, -130.078125)).addPoint(new GHPoint(39.909736, -91.054687)).putHint("vehicle", "car");
    GHResponse res = gh.route(req);
    assertTrue(res.hasErrors(), "no errors found?");
    assertTrue(res.getErrors().get(0) instanceof PointOutOfBoundsException);
}
Also used : GHRequest(com.graphhopper.GHRequest) PointOutOfBoundsException(com.graphhopper.util.exceptions.PointOutOfBoundsException) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 80 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method testPathDetails.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testPathDetails(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).setProfile("my_car");
    req.getPathDetails().add("average_speed");
    GHResponse res = gh.route(req);
    assertFalse(res.hasErrors(), "errors:" + res.getErrors().toString());
    ResponsePath alt = res.getBest();
    assertEquals(1, alt.getPathDetails().size());
    List<PathDetail> details = alt.getPathDetails().get("average_speed");
    assertFalse(details.isEmpty());
    assertTrue((Double) details.get(0).getValue() > 20);
    assertTrue((Double) details.get(0).getValue() < 70);
}
Also used : ResponsePath(com.graphhopper.ResponsePath) PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GHResponse (com.graphhopper.GHResponse)100 GHRequest (com.graphhopper.GHRequest)86 GHPoint (com.graphhopper.util.shapes.GHPoint)52 Test (org.junit.Test)31 Test (org.junit.jupiter.api.Test)31 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ResponsePath (com.graphhopper.ResponsePath)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 PathWrapper (com.graphhopper.PathWrapper)9 GraphHopper (com.graphhopper.GraphHopper)7 InstructionList (com.graphhopper.util.InstructionList)7 PathDetail (com.graphhopper.util.details.PathDetail)7 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Profile (com.graphhopper.config.Profile)5 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)5