diff --git a/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/ContourBuilder.java b/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/ContourBuilder.java index 30d029b24ae..593c24a68af 100644 --- a/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/ContourBuilder.java +++ b/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/ContourBuilder.java @@ -41,13 +41,10 @@ public ContourBuilder(QuadEdgeSubdivision triangulation) { } public Geometry computeIsoline(double z0) { - Set processed = new HashSet(); - Queue processQ = new ArrayDeque(); - List rings = new ArrayList(); + Set processed = new HashSet<>(); + List rings = new ArrayList<>(); - for (QuadEdge e : ((Collection) triangulation.getPrimaryEdges(true))) { - processQ.add(e); - } + Queue processQ = new ArrayDeque<>(getPrimaryEdges()); while (!processQ.isEmpty()) { QuadEdge e = processQ.remove(); if (processed.contains(e)) @@ -57,7 +54,7 @@ public Geometry computeIsoline(double z0) { if (cut == 0) { continue; // While, next edge } - List polyPoints = new ArrayList(); + List polyPoints = new ArrayList<>(); boolean ccw = cut > 0; while (true) { // Add a point to polyline @@ -96,8 +93,13 @@ public Geometry computeIsoline(double z0) { rings.add(ring); } } - List retval = punchHoles(rings); - return geometryFactory.createMultiPolygon(retval.toArray(new Polygon[retval.size()])); + List isolinePolygons = punchHoles(rings); + return geometryFactory.createMultiPolygon(isolinePolygons.toArray(new Polygon[isolinePolygons.size()])); + } + + @SuppressWarnings("unchecked") // JTS is not generified + private Collection getPrimaryEdges() { + return (Collection) triangulation.getPrimaryEdges(true); } private Coordinate moveEpsilonTowards(Coordinate coordinate, Coordinate distantFrameCoordinate) { @@ -112,8 +114,8 @@ private int cut(double za, double zb, double z0) { @SuppressWarnings("unchecked") private List punchHoles(List rings) { - List shells = new ArrayList(rings.size()); - List holes = new ArrayList(rings.size() / 2); + List shells = new ArrayList<>(rings.size()); + List holes = new ArrayList<>(rings.size() / 2); // 1. Split the polygon list in two: shells and holes (CCW and CW) for (LinearRing ring : rings) { if (CGAlgorithms.signedArea(ring.getCoordinateSequence()) > 0.0) @@ -132,7 +134,6 @@ public int compare(Polygon o1, Polygon o2) { shell.setUserData(new ArrayList()); } // 3. For each hole, determine which shell it fits in. - int nHolesFailed = 0; for (LinearRing hole : holes) { outer: { // Probably most of the time, the first shell will be the one @@ -146,7 +147,7 @@ public int compare(Polygon o1, Polygon o2) { } } // 4. Build the list of punched polygons - List punched = new ArrayList(shells.size()); + List punched = new ArrayList<>(shells.size()); for (Polygon shell : shells) { List shellHoles = ((List) shell.getUserData()); punched.add(geometryFactory.createPolygon((LinearRing) (shell.getExteriorRing()), diff --git a/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/Isochrone.java b/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/Isochrone.java index 880a7b618a6..771191ad39c 100644 --- a/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/Isochrone.java +++ b/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/Isochrone.java @@ -45,7 +45,7 @@ enum ExploreType {TIME, DISTANCE} // TODO use same class as used in GTFS module? class IsoLabel extends SPTEntry { - public IsoLabel(int edgeId, int adjNode, double weight, long time, double distance) { + IsoLabel(int edgeId, int adjNode, double weight, long time, double distance) { super(edgeId, adjNode, weight); this.time = time; this.distance = distance; @@ -71,15 +71,11 @@ public String toString() { public Isochrone(Graph g, Weighting weighting, boolean reverseFlow) { super(g, weighting, TraversalMode.NODE_BASED); - initCollections(1000); + fromHeap = new PriorityQueue<>(1000); + fromMap = new GHIntObjectHashMap<>(1000); this.reverseFlow = reverseFlow; } - protected void initCollections(int size) { - fromHeap = new PriorityQueue<>(size); - fromMap = new GHIntObjectHashMap<>(size); - } - @Override public Path calcPath(int from, int to) { throw new IllegalStateException("call search instead"); @@ -138,8 +134,6 @@ public void apply(int nodeId, IsoLabel label) { double lon2 = na.getLongitude(nodeId); buckets.get(bucketIndex).add(new Double[]{(lon + lon2) / 2, (lat + lat2) / 2}); } - - return; } }); return buckets; @@ -173,13 +167,12 @@ public void apply(int nodeId, IsoLabel label) { } list.get(bucketIndex).add(nodeId); - return; } }); return list; } - public void searchInternal(int from) { + private void searchInternal(int from) { checkAlreadyRun(); currEdge = new IsoLabel(-1, from, 0, 0, 0); fromMap.put(from, currEdge); @@ -236,7 +229,7 @@ public void searchInternal(int from) { } } - final double getExploreValue(IsoLabel label) { + private double getExploreValue(IsoLabel label) { if (exploreType == TIME) return label.time; // if(exploreType == DISTANCE) diff --git a/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/RasterHullBuilder.java b/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/RasterHullBuilder.java index 56ed142437f..c54f0b76704 100644 --- a/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/RasterHullBuilder.java +++ b/isochrone/src/main/java/com/graphhopper/isochrone/algorithm/RasterHullBuilder.java @@ -42,8 +42,7 @@ public class RasterHullBuilder { * @return a list of polygons wrapping the specified points */ @SuppressWarnings("unchecked") - public List> calcList(List> pointsList, int maxIsolines, - double rasterDistance, double bufferDistance, int quadrantSegments) { + public List> calcList(List> pointsList, int maxIsolines) { if (maxIsolines > pointsList.size()) { throw new IllegalStateException("maxIsolines can only be smaller or equals to pointsList"); @@ -102,7 +101,7 @@ public List> calcList(List> pointsList, int maxIso return polygons; } - void fillExteriorRing(List coords, Geometry geo) { + private void fillExteriorRing(List coords, Geometry geo) { if (geo instanceof Polygon) { // normally this will be picked Polygon poly = (Polygon) geo; diff --git a/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/IsochroneTest.java b/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/IsochroneTest.java index 1a80c71cebb..e43d24d7f72 100644 --- a/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/IsochroneTest.java +++ b/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/IsochroneTest.java @@ -45,7 +45,7 @@ public void tearDown() { // 4-5-- | // |/ \--7 // 6----/ - void initDirectedAndDiffSpeed(Graph graph) { + private void initDirectedAndDiffSpeed(Graph graph) { graph.edge(0, 1).setDistance(70).setFlags(carEncoder.setProperties(10, true, false)); graph.edge(0, 4).setDistance(50).setFlags(carEncoder.setProperties(20, true, false)); diff --git a/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/RasterHullBuilderTest.java b/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/RasterHullBuilderTest.java index dee9c53013b..98609c3b45c 100644 --- a/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/RasterHullBuilderTest.java +++ b/isochrone/src/test/java/com/graphhopper/isochrone/algorithm/RasterHullBuilderTest.java @@ -24,7 +24,7 @@ public void testCalc() { list.add(new Double[]{0.001, 0.002}); list.add(new Double[]{0.000, 0.002}); - List> res = instance.calcList(listOfList, listOfList.size(), 3, 0.007, 2); + List> res = instance.calcList(listOfList, listOfList.size()); List geometry = res.get(0); Assert.assertEquals(9, geometry.size()); } diff --git a/web/src/main/java/com/graphhopper/http/resources/IsochroneResource.java b/web/src/main/java/com/graphhopper/http/resources/IsochroneResource.java index ca9d2e38253..781b9d44b28 100644 --- a/web/src/main/java/com/graphhopper/http/resources/IsochroneResource.java +++ b/web/src/main/java/com/graphhopper/http/resources/IsochroneResource.java @@ -124,14 +124,7 @@ public Response doGet( calcRes = list; } else if ("polygon".equalsIgnoreCase(resultStr)) { - // bigger raster distance => bigger raster => less points => stranger buffer results, but faster - double rasterDistance = 0.75; // cmdArgs.getDouble("isochrone.raster_distance", 0.75); - // bigger buffer distance => less holes, lower means less points! - double bufferDistance = 0.003; // cmdArgs.getDouble("isochrone.buffer_distance", 0.003); - // precision of the 'circles' - int quadrantSegments = 3; // cmdArgs.getInt("isochrone.quadrant_segments", 3); - - list = rasterHullBuilder.calcList(list, list.size() - 1, rasterDistance, bufferDistance, quadrantSegments); + list = rasterHullBuilder.calcList(list, list.size() - 1); ArrayList polyList = new ArrayList(); int index = 0;