com.alee.utils
Class GeometryUtils

java.lang.Object
  extended by com.alee.utils.GeometryUtils

public final class GeometryUtils
extends java.lang.Object

This class provides a set of utilities to work with points and various shapes.

Author:
Mikle Garin

Constructor Summary
GeometryUtils()
           
 
Method Summary
static java.awt.Rectangle expand(java.awt.Rectangle rect, int expansion)
          Returns rectangle expanded in four directions for the specified value.
static java.awt.Rectangle expand(java.awt.Rectangle rect, int top, int left, int bottom, int right)
          Returns rectangle expanded in four directions for the specified values.
static java.awt.Point findMiddleLineIntersection(java.awt.Rectangle rect, java.awt.Point outer)
          Returns intersection point of the rectangle and the line goin from the middle of that rectangle to the outer point.
static double getAngle(int x1, int y1, int x2, int y2)
          Returns angle between the line specified by points and y=0 line.
static double getAngle(java.awt.Point p1, java.awt.Point p2)
          Returns angle between the line specified by points and y=0 line.
static java.awt.Rectangle getContainingRect(java.util.List<java.awt.Point> points)
          Returns rectangle containing all specified points.
static java.awt.Rectangle getContainingRect(java.awt.Point... points)
          Returns rectangle containing all specified points.
static java.awt.Rectangle getContainingRect(java.awt.Rectangle... rects)
          Returns rectangle containing all specified rectangles.
static java.awt.Rectangle getContainingRect(java.awt.Rectangle r1, java.awt.Rectangle r2)
          Returns rectangle containing two others.
static java.awt.Point middle(int x1, int y1, int x2, int y2)
          Returns middle point between the specified points.
static java.awt.Point middle(java.awt.Point p1, java.awt.Point p2)
          Returns middle point between the specified points.
static java.awt.Point middle(java.awt.Rectangle rectangle)
          Returns middle point for the specified rectangle.
static java.awt.Point modify(java.awt.Point point, int xMod, int yMod)
          Returns modified point.
static double toDegrees(double angle)
          Returns angle converted into degrees.
static double toRadians(double angle)
          Returns angle converted into radians.
static java.awt.Rectangle validateRect(java.awt.Rectangle rect)
          Returns valid rectangle with non-negative width and height.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GeometryUtils

public GeometryUtils()
Method Detail

getContainingRect

public static java.awt.Rectangle getContainingRect(java.util.List<java.awt.Point> points)
Returns rectangle containing all specified points.

Parameters:
points - points to process
Returns:
rectangle containing all specified points

getContainingRect

public static java.awt.Rectangle getContainingRect(java.awt.Point... points)
Returns rectangle containing all specified points.

Parameters:
points - points to process
Returns:
rectangle containing all specified points

getContainingRect

public static java.awt.Rectangle getContainingRect(java.awt.Rectangle... rects)
Returns rectangle containing all specified rectangles.

Parameters:
rects - rectangles to process
Returns:
rectangle containing all specified rectangles

getContainingRect

public static java.awt.Rectangle getContainingRect(java.awt.Rectangle r1,
                                                   java.awt.Rectangle r2)
Returns rectangle containing two others.

Parameters:
r1 - first rectangle
r2 - second rectangle
Returns:
rectangle containing two others or null if both rectangles are null

validateRect

public static java.awt.Rectangle validateRect(java.awt.Rectangle rect)
Returns valid rectangle with non-negative width and height.

Parameters:
rect - rectangle to validate
Returns:
valid rectangle with non-negative width and height

middle

public static java.awt.Point middle(java.awt.Rectangle rectangle)
Returns middle point for the specified rectangle.

Parameters:
rectangle - rectangle to process
Returns:
middle point for the specified rectangle

middle

public static java.awt.Point middle(java.awt.Point p1,
                                    java.awt.Point p2)
Returns middle point between the specified points.

Parameters:
p1 - first point
p2 - second point
Returns:
middle point between the specified points

middle

public static java.awt.Point middle(int x1,
                                    int y1,
                                    int x2,
                                    int y2)
Returns middle point between the specified points.

Parameters:
x1 - first point X coordinate
y1 - first point Y coordinate
x2 - second point X coordinate
y2 - second point Y coordinate
Returns:
middle point between the specified points

expand

public static java.awt.Rectangle expand(java.awt.Rectangle rect,
                                        int expansion)
Returns rectangle expanded in four directions for the specified value.

Parameters:
rect - rectangle to expand
expansion - expansion
Returns:
rectangle expanded in four directions for the specified values

expand

public static java.awt.Rectangle expand(java.awt.Rectangle rect,
                                        int top,
                                        int left,
                                        int bottom,
                                        int right)
Returns rectangle expanded in four directions for the specified values.

Parameters:
rect - rectangle to expand
top - top expansion
left - left expansion
bottom - bottom expansion
right - right expansion
Returns:
rectangle expanded in four directions for the specified values

modify

public static java.awt.Point modify(java.awt.Point point,
                                    int xMod,
                                    int yMod)
Returns modified point.

Parameters:
point - point to modify
xMod - X coordinate modifier
yMod - Y coordinate modifier
Returns:
modified point

getAngle

public static double getAngle(java.awt.Point p1,
                              java.awt.Point p2)
Returns angle between the line specified by points and y=0 line.

Parameters:
p1 - first line point
p2 - second line point
Returns:
angle between the line specified by points and y=0 line

getAngle

public static double getAngle(int x1,
                              int y1,
                              int x2,
                              int y2)
Returns angle between the line specified by points and y=0 line.

Parameters:
x1 - first point X coordinate
y1 - first point Y coordinate
x2 - second point X coordinate
y2 - second point Y coordinate
Returns:
angle between the line specified by points and y=0 line

findMiddleLineIntersection

public static java.awt.Point findMiddleLineIntersection(java.awt.Rectangle rect,
                                                        java.awt.Point outer)
Returns intersection point of the rectangle and the line goin from the middle of that rectangle to the outer point.

Parameters:
rect - rectangle to process
outer - outer point to process
Returns:
intersection point of the rectangle and the line goin from the middle of that rectangle to the outer point

toRadians

public static double toRadians(double angle)
Returns angle converted into radians.

Parameters:
angle - angle to convert
Returns:
angle converted into radians

toDegrees

public static double toDegrees(double angle)
Returns angle converted into degrees.

Parameters:
angle - angle to convert
Returns:
angle converted into degrees