private Path plotPath(Path tmpPath, Graphics2D g2, int w) { if (!tmpPath.isFound()) { logger.info("nothing found " + w); return tmpPath; } double prevLat = Double.NaN; double prevLon = Double.NaN; boolean plotNodes = false; IntIndexedContainer nodes = tmpPath.calcNodes(); if (plotNodes) { for (int i = 0; i < nodes.size(); i++) { plotNodeName(g2, nodes.get(i)); } } PointList list = tmpPath.calcPoints(); for (int i = 0; i < list.getSize(); i++) { double lat = list.getLatitude(i); double lon = list.getLongitude(i); if (!Double.isNaN(prevLat)) { mg.plotEdge(g2, prevLat, prevLon, lat, lon, w); } else { mg.plot(g2, lat, lon, w); } prevLat = lat; prevLon = lon; } logger.info("dist:" + tmpPath.getDistance() + ", path points(" + list.getSize() + ")"); return tmpPath; }
path.extract(); assertPList(Helper.createPointList(0, 0.1, 8, 1, 9, 1, 1, 0.1, 10, 1, 11, 1, 2, 0.1), path.calcPoints()); InstructionList instr = path.calcInstructions(tr); List<Map<String, Object>> res = instr.createJson(); assertEquals("[6, 6]", tmp.get("interval").toString()); int lastIndex = (Integer) ((List) res.get(res.size() - 1).get("interval")).get(0); assertEquals(path.calcPoints().size() - 1, lastIndex); assertEquals("[3, 6]", tmp.get("interval").toString()); lastIndex = (Integer) ((List) res.get(res.size() - 1).get("interval")).get(0); assertEquals(path.calcPoints().size() - 1, lastIndex); path.extract(); assertPList(Helper.createPointList(2, 0.1, 11, 1, 10, 1, 1, 0.1, 9, 1, 8, 1, 0, 0.1), path.calcPoints()); assertEquals("[3, 6]", tmp.get("interval").toString()); lastIndex = (Integer) ((List) res.get(res.size() - 1).get("interval")).get(0); assertEquals(path.calcPoints().size() - 1, lastIndex);
PointList tmpPoints = path.calcPoints(); if (fullPoints.isEmpty()) fullPoints = new PointList(tmpPoints.size(), tmpPoints.is3D());
@Test public void testWithCoordinates() { Weighting weighting = new ShortestWeighting(carEncoder); GraphHopperStorage graph = createGHStorage(encodingManager, Arrays.asList(weighting), false); graph.edge(0, 1, 2, true).setWayGeometry(Helper.createPointList(1.5, 1)); graph.edge(2, 3, 2, true).setWayGeometry(Helper.createPointList(0, 1.5)); graph.edge(3, 4, 2, true).setWayGeometry(Helper.createPointList(0, 2)); // duplicate but the second edge is longer graph.edge(0, 2, 1.2, true); graph.edge(0, 2, 1.5, true).setWayGeometry(Helper.createPointList(0.5, 0)); graph.edge(1, 3, 1.3, true).setWayGeometry(Helper.createPointList(0.5, 1.5)); graph.edge(1, 4, 1, true); updateDistancesFor(graph, 0, 1, 0.6); updateDistancesFor(graph, 1, 1, 1.5); updateDistancesFor(graph, 2, 0, 0); updateDistancesFor(graph, 3, 0, 1); updateDistancesFor(graph, 4, 0, 2); AlgorithmOptions opts = new AlgorithmOptions(DIJKSTRA_BI, weighting); RoutingAlgorithmFactory prepare = createFactory(graph, opts); Path p = prepare.createAlgo(getGraph(graph, opts.getWeighting()), opts).calcPath(4, 0); assertEquals(IntArrayList.from(new int[]{4, 1, 0}), p.calcNodes()); assertEquals(Helper.createPointList(0, 2, 1, 1.5, 1.5, 1, 1, 0.6), p.calcPoints()); assertEquals(274128, p.calcPoints().calcDistance(new DistanceCalcEarth()), 1); p = prepare.createAlgo(getGraph(graph, opts.getWeighting()), opts).calcPath(2, 1); assertEquals(IntArrayList.from(new int[]{2, 0, 1}), p.calcNodes()); assertEquals(Helper.createPointList(0, 0, 1, 0.6, 1.5, 1, 1, 1.5), p.calcPoints()); assertEquals(279482, p.calcPoints().calcDistance(new DistanceCalcEarth()), 1); }
pathWrapper.setInstructions(wayList); pathWrapper.addPathDetails(details); pathWrapper.setPoints(p.calcPoints()); int numberOfPoints = p.calcPoints().size(); pathWrapper.setInstructions(wayList); pathWrapper.addPathDetails(details); pathWrapper.setPoints(p.calcPoints());
PointList tmpPoints = path.calcPoints(); if (fullPoints.isEmpty()) fullPoints = new PointList(tmpPoints.size(), tmpPoints.is3D());
PointList tmpPoints = path.calcPoints(); if (fullPoints.isEmpty()) fullPoints = new PointList(tmpPoints.size(), tmpPoints.is3D());
PointList tmpPoints = path.calcPoints(); if (fullPoints.isEmpty()) fullPoints = new PointList(tmpPoints.size(), tmpPoints.is3D());