use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testGetPathsDirectionEnforcement4.
@Test
public void testGetPathsDirectionEnforcement4() {
// Test straight via routing
instance = createSquareGraphInstance(false);
// 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);
// Via Point betweeen 8-3
GHPoint via = new GHPoint(0.0015, 0.001);
GHRequest req = new GHRequest().addPoint(start).addPoint(via).addPoint(end);
req.getHints().put(Routing.PASS_THROUGH, true);
GHResponse response = new GHResponse();
List<Path> paths = instance.calcPaths(req, response);
assertFalse(response.hasErrors());
assertEquals(1, response.getAll().size());
assertEquals(IntArrayList.from(9, 4, 3, 10), paths.get(0).calcNodes());
assertEquals(IntArrayList.from(10, 8, 1, 2, 11), paths.get(1).calcNodes());
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testGetPathsDirectionEnforcement6.
@Test
public void testGetPathsDirectionEnforcement6() {
// Test if query results at tower nodes are ignored
instance = createSquareGraphInstance(false);
// 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().addPoint(start, 90.).addPoint(via, 270.).addPoint(end, 270.);
GHResponse response = new GHResponse();
List<Path> paths = instance.calcPaths(req, response);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 0, 1, 2 }, paths.get(0).calcNodes().toArray());
assertArrayEquals(new int[] { 2, 3, 4 }, paths.get(1).calcNodes().toArray());
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperIT method testMonacoStraightVia.
@Test
public void testMonacoStraightVia() {
GHRequest rq = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854)).addPoint(new GHPoint(43.740371, 7.426946)).addPoint(new GHPoint(43.740794, 7.427294)).setVehicle(vehicle).setWeighting("fastest");
rq.getHints().put(Routing.PASS_THROUGH, true);
GHResponse rsp = hopper.route(rq);
PathWrapper arsp = rsp.getBest();
assertEquals(297, arsp.getDistance(), 5.);
assertEquals(27, arsp.getPoints().getSize());
// test if start and first point are identical leading to an empty path, #788
rq = new GHRequest().addPoint(new GHPoint(43.741069, 7.426854)).addPoint(new GHPoint(43.741069, 7.426854)).addPoint(new GHPoint(43.740371, 7.426946)).setVehicle(vehicle).setWeighting("fastest");
rq.getHints().put(Routing.PASS_THROUGH, true);
rsp = hopper.route(rq);
assertEquals(91, rsp.getBest().getDistance(), 5.);
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperIT method testMonacoVia.
@Test
public void testMonacoVia() {
GHResponse rsp = hopper.route(new GHRequest().addPoint(new GHPoint(43.727687, 7.418737)).addPoint(new GHPoint(43.74958, 7.436566)).addPoint(new GHPoint(43.727687, 7.418737)).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
PathWrapper arsp = rsp.getBest();
assertEquals(6875.2, arsp.getDistance(), .1);
assertEquals(179, arsp.getPoints().getSize());
InstructionList il = arsp.getInstructions();
assertEquals(26, il.size());
List<Map<String, Object>> resultJson = il.createJson();
assertEquals("Continue onto Avenue des Guelfes", resultJson.get(0).get("text"));
assertEquals("Continue onto Avenue des Papalins", resultJson.get(1).get("text"));
assertEquals("Turn sharp right onto Quai Jean-Charles Rey", resultJson.get(2).get("text"));
assertEquals("Turn left", resultJson.get(3).get("text"));
assertEquals("Turn right onto Avenue Albert II", resultJson.get(4).get("text"));
assertEquals("Stopover 1", resultJson.get(12).get("text"));
assertEquals("Continue onto Avenue Albert II", resultJson.get(20).get("text"));
assertEquals("Turn left", resultJson.get(21).get("text"));
assertEquals("Turn right onto Quai Jean-Charles Rey", resultJson.get(22).get("text"));
assertEquals("Turn sharp left onto Avenue des Papalins", resultJson.get(23).get("text"));
assertEquals("Continue onto Avenue des Guelfes", resultJson.get(24).get("text"));
assertEquals("Finish!", resultJson.get(25).get("text"));
assertEquals(11, (Double) resultJson.get(0).get("distance"), 1);
assertEquals(289, (Double) resultJson.get(1).get("distance"), 1);
assertEquals(10, (Double) resultJson.get(2).get("distance"), 1);
assertEquals(43, (Double) resultJson.get(3).get("distance"), 1);
assertEquals(122, (Double) resultJson.get(4).get("distance"), 1);
assertEquals(447, (Double) resultJson.get(5).get("distance"), 1);
assertEquals(7, (Long) resultJson.get(0).get("time") / 1000);
assertEquals(207, (Long) resultJson.get(1).get("time") / 1000);
assertEquals(7, (Long) resultJson.get(2).get("time") / 1000);
assertEquals(30, (Long) resultJson.get(3).get("time") / 1000);
assertEquals(87, (Long) resultJson.get(4).get("time") / 1000);
assertEquals(321, (Long) resultJson.get(5).get("time") / 1000);
// special case of identical start and end point
rsp = hopper.route(new GHRequest().addPoint(new GHPoint(43.727687, 7.418737)).addPoint(new GHPoint(43.727687, 7.418737)).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
arsp = rsp.getBest();
assertEquals(0, arsp.getDistance(), .1);
assertEquals(0, arsp.getRouteWeight(), .1);
assertEquals(1, arsp.getPoints().getSize());
assertEquals(1, arsp.getInstructions().size());
assertEquals("Finish!", arsp.getInstructions().createJson().get(0).get("text"));
assertEquals(Instruction.FINISH, arsp.getInstructions().createJson().get(0).get("sign"));
rsp = hopper.route(new GHRequest().addPoint(new GHPoint(43.727687, 7.418737)).addPoint(new GHPoint(43.727687, 7.418737)).addPoint(new GHPoint(43.727687, 7.418737)).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
arsp = rsp.getBest();
assertEquals(0, arsp.getDistance(), .1);
assertEquals(0, arsp.getRouteWeight(), .1);
assertEquals(2, arsp.getPoints().getSize());
assertEquals(2, arsp.getInstructions().size());
assertEquals(Instruction.REACHED_VIA, arsp.getInstructions().createJson().get(0).get("sign"));
assertEquals(Instruction.FINISH, arsp.getInstructions().createJson().get(1).get("sign"));
}
use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.
the class GraphHopperIT method testMonacoNonChMaxWaypointDistance.
@Test
public void testMonacoNonChMaxWaypointDistance() {
GHPoint from = new GHPoint(43.741069, 7.426854);
GHPoint to = new GHPoint(43.727697, 7.419199);
GHRequest req = new GHRequest().addPoint(from).addPoint(to).setVehicle(vehicle).setWeighting("fastest");
// Fail since points are too far
hopper.setNonChMaxWaypointDistance(1000);
GHResponse rsp = hopper.route(req);
assertTrue(rsp.hasErrors());
// Suceed since points are not far anymore
hopper.setNonChMaxWaypointDistance(Integer.MAX_VALUE);
rsp = hopper.route(req);
assertFalse(rsp.hasErrors());
}
Aggregations