Search in sources :

Example 41 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GraphHopperWebTest method testGetClientForRequest.

@ParameterizedTest(name = "POST={0}")
@ValueSource(booleans = { true, false })
public void testGetClientForRequest(boolean usePost) {
    GraphHopperWeb gh = new GraphHopperWeb(null).setPostRequest(usePost);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.509225, 1.534728)).addPoint(new GHPoint(42.512602, 1.551558)).putHint("vehicle", "car");
    req.putHint(GraphHopperWeb.TIMEOUT, 5);
    assertEquals(5, gh.getClientForRequest(req).connectTimeoutMillis());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GHMatrixAbstractRequester method putPoints.

private void putPoints(ObjectNode requestJson, String name, List<GHPoint> pList) {
    if (pList.isEmpty())
        return;
    ArrayNode outList = objectMapper.createArrayNode();
    for (GHPoint p : pList) {
        ArrayNode entry = objectMapper.createArrayNode();
        entry.add(p.lon);
        entry.add(p.lat);
        outList.add(entry);
    }
    requestJson.putArray(name).addAll(outList);
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 43 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GHMRequestTest method testCompact.

@Test
public void testCompact() {
    GHMRequest request = new GHMRequest();
    for (int i = 0; i < 3; i++) {
        request.addFromPoint(new GHPoint());
        request.addFromPointHint("");
    }
    request.addToPoint(new GHPoint());
    request.addToPointHint("");
    request.compactPointHints();
    assertTrue(request.getToPointHints().isEmpty());
    assertTrue(request.getFromPointHints().isEmpty());
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test)

Example 44 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GHRequestTest method testCorrectInit.

@Test
public void testCorrectInit() {
    double lat0 = 51, lon0 = 1, lat1 = 52, lon1 = 2, lat2 = 53, lon2 = 3;
    ArrayList<GHPoint> points = new ArrayList<>(3);
    points.add(new GHPoint(lat0, lon0));
    points.add(new GHPoint(lat1, lon1));
    points.add(new GHPoint(lat2, lon2));
    List<Double> favoredHeadings = Arrays.asList(3.14, 4.15, Double.NaN);
    GHRequest instance;
    instance = new GHRequest(points, favoredHeadings);
    compareFavoredHeadings(instance, favoredHeadings);
    comparePoints(instance, points);
    instance = new GHRequest(points.get(0), points.get(1), favoredHeadings.get(0), favoredHeadings.get(1));
    compareFavoredHeadings(instance, favoredHeadings.subList(0, 2));
    comparePoints(instance, points.subList(0, 2));
    instance = new GHRequest(lat0, lon0, lat1, lon1, favoredHeadings.get(0), favoredHeadings.get(1));
    compareFavoredHeadings(instance, favoredHeadings.subList(0, 2));
    comparePoints(instance, points.subList(0, 2));
    // check init without favoredHeadings
    instance = new GHRequest(points);
    comparePoints(instance, points);
    compareFavoredHeadings(instance, emptyList());
    instance = new GHRequest(points.get(0), points.get(1));
    comparePoints(instance, points.subList(0, 2));
    compareFavoredHeadings(instance, emptyList());
    instance = new GHRequest(lat0, lon0, lat1, lon1);
    comparePoints(instance, points.subList(0, 2));
    compareFavoredHeadings(instance, emptyList());
}
Also used : ArrayList(java.util.ArrayList) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test)

Example 45 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class HeadingRoutingTest method headingTest1.

@Test
public void headingTest1() {
    // Test enforce start direction
    GraphHopperStorage graph = createSquareGraph();
    Router router = createRouter(graph);
    // Start in middle of edge 4-5
    GHPoint start = new GHPoint(0.0015, 0.002);
    // End at middle of edge 2-3
    GHPoint end = new GHPoint(0.002, 0.0005);
    GHRequest req = new GHRequest().setPoints(Arrays.asList(start, end)).setHeadings(Arrays.asList(180., Double.NaN)).setProfile("profile").setPathDetails(Collections.singletonList("edge_key"));
    GHResponse response = router.route(req);
    assertFalse(response.hasErrors(), response.getErrors().toString());
    assertArrayEquals(new int[] { 4, 5, 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)

Aggregations

GHPoint (com.graphhopper.util.shapes.GHPoint)206 Test (org.junit.jupiter.api.Test)62 GHRequest (com.graphhopper.GHRequest)57 GHResponse (com.graphhopper.GHResponse)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 Test (org.junit.Test)45 LMProfile (com.graphhopper.config.LMProfile)27 Profile (com.graphhopper.config.Profile)27 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)27 CHProfile (com.graphhopper.config.CHProfile)26 Snap (com.graphhopper.storage.index.Snap)17 QueryResult (com.graphhopper.storage.index.QueryResult)15 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)13 ResponsePath (com.graphhopper.ResponsePath)11 ArrayList (java.util.ArrayList)11 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 PathWrapper (com.graphhopper.PathWrapper)8 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)8 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)8 IntArrayList (com.carrotsearch.hppc.IntArrayList)6