@VisibleForTesting void addSourcePointInternal(Point2D source, boolean isCity) { synchronized (lock) { if (!heuristic.containsKey(source)) { heuristicProvider.addSourceNodeToHeuristic(source); } if (graph.containsNode(source)) { return; } List<Point2D> nearest = new ArrayList<>(); for (Point2D node : graph) { double distance = node.distance(source); if (distance <= DIAG_CHECK_DISTANCE) { nearest.add(node); } } graph.addNode(source, false); for (Point2D point : nearest) { addEdges(source, point, isCity, false); } } } @Override
@VisibleForTesting void addDestinationPointInternal(Point2D newPoint, boolean isCity) { synchronized (lock) { if (!heuristic.containsKey(newPoint)) { heuristicProvider.addSourceNodeToHeuristic(newPoint); // once reached there we must leave again. heuristicProvider.addTargetNodeToHeuristic(newPoint); heuristicProvider.getHeuristic(); } Preconditions.checkArgument(heuristic.containsKey(newPoint), "Destination not part of the heuristic: "+newPoint); if (graph.containsNode(newPoint)) { return; } List<Point2D> nearest = new ArrayList<>(); for (Point2D node : graph) { double distance = node.distance(newPoint); if (distance <= DIAG_CHECK_DISTANCE) { nearest.add(node); } } graph.addNode(newPoint, true); for (Point2D point : nearest) { addEdges(newPoint, point, isCity, false); } } } @VisibleForTesting