Add method in graph to find node from position.
This commit is contained in:
parent
71accfe13b
commit
1eee9b8dd9
@ -24,6 +24,26 @@ public class Graph {
|
|||||||
*/
|
*/
|
||||||
public ArrayList<Node> getNodes() { return nodes; }
|
public ArrayList<Node> getNodes() { return nodes; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the closet node to the given point.
|
||||||
|
*
|
||||||
|
* @param point
|
||||||
|
*
|
||||||
|
* @return Closest node to the given point.
|
||||||
|
*/
|
||||||
|
public Node findClosestNode(Point point) {
|
||||||
|
Node node = null;
|
||||||
|
double minDis = Double.POSITIVE_INFINITY;
|
||||||
|
for (int n = 0 ; n < nodes.size(); ++n) {
|
||||||
|
double dis = point.distanceTo(nodes.get(n).getPoint());
|
||||||
|
if (dis < minDis) {
|
||||||
|
node = nodes.get(n);
|
||||||
|
minDis = dis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Map ID of this graph.
|
* @return Map ID of this graph.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user