samples.preview_new_graphdraw
Class CoordinateUtil

java.lang.Object
  extended by samples.preview_new_graphdraw.CoordinateUtil

public class CoordinateUtil
extends Object

Author:
Danyel Fisher, Scott White

Nested Class Summary
protected static class CoordinateUtil.Line
          A class which represents a geometric line.
 
Constructor Summary
CoordinateUtil()
           
 
Method Summary
static Coordinates add(Coordinates a, double x, double y)
           
static double angleBetween(Coordinates c, double x, double y)
           
static double distance(Coordinates a, Coordinates b)
          Computes the euclidean distance between two coordinates
static double distance(Coordinates a, double x, double y)
           
static Coordinates getClosestIntersection(Coordinates source, Coordinates dest, Rectangle2D bounds)
          Returns the closest intersection to source of the line defined by source and target, and the bounding box bounds, or null if there is no intersection.
static Collection getIntersections(Coordinates source, Coordinates dest, Rectangle2D bounds)
           
static double getSquareDistance(Coordinates u, double x, double y)
          returns the square of the distance between two points.
static Coordinates midpoint(Coordinates a, Coordinates b)
          Computes the midpoint between the two coordinates
static Coordinates scale(Coordinates a, double x, double y)
           
static double squareDistanceLineToPoint(Coordinates front, Coordinates back, double x, double y)
          Calculates the square of the distance from a segment running (x1, y1) to (x2, y2) to a point (x,y)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoordinateUtil

public CoordinateUtil()
Method Detail

distance

public static double distance(Coordinates a,
                              Coordinates b)
Computes the euclidean distance between two coordinates

Returns:
the euclidean distance

distance

public static double distance(Coordinates a,
                              double x,
                              double y)
Parameters:
coordinates -
x -
y -

midpoint

public static Coordinates midpoint(Coordinates a,
                                   Coordinates b)
Computes the midpoint between the two coordinates

Parameters:
o - another coordinates
Returns:
the midpoint

scale

public static Coordinates scale(Coordinates a,
                                double x,
                                double y)

add

public static Coordinates add(Coordinates a,
                              double x,
                              double y)

squareDistanceLineToPoint

public static double squareDistanceLineToPoint(Coordinates front,
                                               Coordinates back,
                                               double x,
                                               double y)
Calculates the square of the distance from a segment running (x1, y1) to (x2, y2) to a point (x,y)

Parameters:
x1 - The front x of a line
y1 - The front y of a line
x2 - The back x of a line
y2 - The back y of a line
x - The point to check distance
y - The point to check distance
Returns:

getSquareDistance

public static double getSquareDistance(Coordinates u,
                                       double x,
                                       double y)
returns the square of the distance between two points.

Parameters:
x1 -
y1 -
x -
y -
Returns:

angleBetween

public static double angleBetween(Coordinates c,
                                  double x,
                                  double y)
Parameters:
coordinates -
d -
e -
Returns:

getClosestIntersection

public static Coordinates getClosestIntersection(Coordinates source,
                                                 Coordinates dest,
                                                 Rectangle2D bounds)
Returns the closest intersection to source of the line defined by source and target, and the bounding box bounds, or null if there is no intersection.

Returns:

getIntersections

public static Collection getIntersections(Coordinates source,
                                          Coordinates dest,
                                          Rectangle2D bounds)