JHotDraw 6.0b1

## org.jhotdraw.util Class Geom

java.lang.Object
org.jhotdraw.util.Geom

public class Geom
extends java.lang.Object

Some geometric utilities.

Field Summary
static int EAST

static int NORTH

static int SOUTH

static int WEST

Method Summary
static java.awt.Point angleToPoint(java.awt.Rectangle r, double angle)
Gets the point on a rectangle that corresponds to the given angle.
static java.awt.Point angleToPoint(java.awt.Rectangle r, double angle, java.awt.Point p)
Gets the point on a rectangle that corresponds to the given angle.
static java.awt.Point bottomLeftCorner(java.awt.Rectangle r)
Returns the bottom left corner of the rectangle
static java.awt.Point bottomRightCorner(java.awt.Rectangle r)
Returns the bottom right corner of the rectangle.
static java.awt.Point center(java.awt.Rectangle r)

static java.awt.Point corner(java.awt.Rectangle r)
Returns the corner (bottom right) of the rectangle
static int direction(int x1, int y1, int x2, int y2)
Returns the direction NORTH, SOUTH, WEST, EAST from one point to another one.
static double distanceFromLine(int xa, int ya, int xb, int yb, int xc, int yc)
compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from point
static double distanceFromLine2D(int xa, int ya, int xb, int yb, int xc, int yc)
compute distance of point from line segment.
Uses AWT Line2D utility methods
static java.awt.Point east(java.awt.Rectangle r)

static java.awt.Point intersect(int xa, int ya, int xb, int yb, int xc, int yc, int xd, int yd)
Standard line intersection algorithm Return the point of intersection if it exists, else null
static long length(int x1, int y1, int x2, int y2)
Gets the distance between to points
static long length2(int x1, int y1, int x2, int y2)
Gets the square distance between two points.
static boolean lineContainsPoint(int x1, int y1, int x2, int y2, int px, int py)
Tests if a point is on a line.
static java.awt.Point north(java.awt.Rectangle r)

static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r, double angle)
Gets the point on an oval that corresponds to the given angle.
static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r, double angle, java.awt.Point p)
Gets the point on an oval that corresponds to the given angle.
static double pointToAngle(java.awt.Rectangle r, java.awt.Point p)
Gets the angle of a point relative to a rectangle.
static java.awt.Point polarToPoint(double angle, double fx, double fy)
Converts a polar to a point
static java.awt.Point polarToPoint(double angle, double fx, double fy, java.awt.Point p)
Converts a polar to a point
static int range(int min, int max, int value)
Constains a value to the given range.
static java.awt.Point south(java.awt.Rectangle r)

static java.awt.Point topLeftCorner(java.awt.Rectangle r)
Returns the top left corner of the rectangle
static java.awt.Point topRightCorner(java.awt.Rectangle r)
Returns the top right corner of the rectangle
static java.awt.Point west(java.awt.Rectangle r)

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

### NORTH

public static final int NORTH
Constant Field Values

### SOUTH

public static final int SOUTH
Constant Field Values

### WEST

public static final int WEST
Constant Field Values

### EAST

public static final int EAST
Constant Field Values
Method Detail

### lineContainsPoint

public static boolean lineContainsPoint(int x1,
int y1,
int x2,
int y2,
int px,
int py)
Tests if a point is on a line.

### direction

public static int direction(int x1,
int y1,
int x2,
int y2)
Returns the direction NORTH, SOUTH, WEST, EAST from one point to another one.

### south

public static java.awt.Point south(java.awt.Rectangle r)

### center

public static java.awt.Point center(java.awt.Rectangle r)

### west

public static java.awt.Point west(java.awt.Rectangle r)

### east

public static java.awt.Point east(java.awt.Rectangle r)

### north

public static java.awt.Point north(java.awt.Rectangle r)

### corner

public static java.awt.Point corner(java.awt.Rectangle r)
Returns the corner (bottom right) of the rectangle

Parameters:
r - the rectangle
Returns:
the corner

### topLeftCorner

public static java.awt.Point topLeftCorner(java.awt.Rectangle r)
Returns the top left corner of the rectangle

Parameters:
r - the rectangle
Returns:
the corner

### topRightCorner

public static java.awt.Point topRightCorner(java.awt.Rectangle r)
Returns the top right corner of the rectangle

Parameters:
r - the rectangle
Returns:
the corner

### bottomLeftCorner

public static java.awt.Point bottomLeftCorner(java.awt.Rectangle r)
Returns the bottom left corner of the rectangle

Parameters:
r - the rectangle
Returns:
the corner

### bottomRightCorner

public static java.awt.Point bottomRightCorner(java.awt.Rectangle r)
Returns the bottom right corner of the rectangle. Same as corner, added for naming coherence with the other corner extracting methods

Parameters:
r - the rectangle
Returns:
the corner

### range

public static int range(int min,
int max,
int value)
Constains a value to the given range.

Returns:
the constrained value

### length2

public static long length2(int x1,
int y1,
int x2,
int y2)
Gets the square distance between two points.

### length

public static long length(int x1,
int y1,
int x2,
int y2)
Gets the distance between to points

### pointToAngle

public static double pointToAngle(java.awt.Rectangle r,
java.awt.Point p)
Gets the angle of a point relative to a rectangle.

### angleToPoint

public static java.awt.Point angleToPoint(java.awt.Rectangle r,
double angle)
Gets the point on a rectangle that corresponds to the given angle.

### angleToPoint

public static java.awt.Point angleToPoint(java.awt.Rectangle r,
double angle,
java.awt.Point p)
Gets the point on a rectangle that corresponds to the given angle.

### polarToPoint

public static java.awt.Point polarToPoint(double angle,
double fx,
double fy)
Converts a polar to a point

### polarToPoint

public static java.awt.Point polarToPoint(double angle,
double fx,
double fy,
java.awt.Point p)
Converts a polar to a point

### ovalAngleToPoint

public static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r,
double angle)
Gets the point on an oval that corresponds to the given angle.

### ovalAngleToPoint

public static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r,
double angle,
java.awt.Point p)
Gets the point on an oval that corresponds to the given angle.

### intersect

public static java.awt.Point intersect(int xa,
int ya,
int xb,
int yb,
int xc,
int yc,
int xd,
int yd)
Standard line intersection algorithm Return the point of intersection if it exists, else null

### distanceFromLine

public static double distanceFromLine(int xa,
int ya,
int xb,
int yb,
int xc,
int yc)
compute distance of point from line segment, or Double.MAX_VALUE if perpendicular projection is outside segment; or If pts on line are same, return distance from point

### distanceFromLine2D

public static double distanceFromLine2D(int xa,
int ya,
int xb,
int yb,
int xc,
int yc)
compute distance of point from line segment.
Uses AWT Line2D utility methods

JHotDraw 6.0b1