package graphmatcher.helper;
import graphmatcher.graph.Edge;
import graphmatcher.graph.Graph;
import graphmatcher.graph.Vertex;
import java.awt.Point;
public class DistanceHelper {
public static double getDistance(Point point1, Point point2) {
double diffX = point1.x - point2.x;
double diffY = point1.y - point2.y;
return Math.hypot(diffX, diffY);
}
public static double getDistance(Vertex vertex1, Vertex vertex2) {
return getDistance(vertex1.toPoint(), vertex2.toPoint());
}
public static double getLength(Edge edge, Graph graph) {
Vertex vertex1 = graph.vertices()[edge.vertex1];
Vertex vertex2 = graph.vertices()[edge.vertex2];
return getDistance(vertex1, vertex2);
}
public static double getDistanceToCenter(Edge edge, Graph graph) {
double distance = 0;
Vertex vertex1 = graph.vertices()[edge.vertex1];
Vertex vertex2 = graph.vertices()[edge.vertex2];
distance += getDistance(vertex1.toPoint(), graph.getCenter());
distance += getDistance(vertex2.toPoint(), graph.getCenter());
return distance / 2;
}
}