/** * Find the closest point in the graph for a defined point. * @param point for which the closest defined point should be looked up. * @return closest point to <code>point</code> */ public Point2D findClosest(Point2D point) { double distance = Double.MAX_VALUE; Point2D p = null; for (Point2D tempPoint : getHeuristic().keySet()) { if (point.distance(tempPoint) < distance) { distance = point.distance(tempPoint); p = tempPoint; } } return p; }
@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
long timestamp = System.currentTimeMillis(); synchronized (lock) { heuristic = heuristicProvider.getHeuristic(); while(heuristic.size() == 0) { Thread.yield(); heuristic = heuristicProvider.getHeuristic();
private void addEdges(Point2D from, Point2D to, boolean isCity, boolean initial) { if (isCity || isOnSea(to)) { if (!graph.containsNode(to)) { if (initial) { graph.addNodeInternal(to); } else { graph.addNode(to, true); } } heuristicProvider.getHeuristic(); double weight = calculateWeight(from, to); if (initial) { graph.addEdgeInternal(from, to, weight); } else { graph.addEdge(from, to, weight); } weight = calculateWeight(to, from); if (initial) { graph.addEdgeInternal(to, from, weight); } else { graph.addEdge(to, from, weight); } } }