Package graphmatcher.helper

Source Code of graphmatcher.helper.DistanceHelper

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;
  }
}
TOP

Related Classes of graphmatcher.helper.DistanceHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.