Class Line

java.lang.Object
   |
   +----Line

public class Line
extends Object
Utility class to represent a line between two points.

Version:
$Revision: 1.5 $, $Date: 2000/10/30 17:04:01 $
Author:
John Cavanaugh

Variable Index

 o x1
X coordinate of first endpoint.
 o x2
X coordinate of second endpoint.
 o y1
Y coordinate of first endpoint.
 o y2
Y coordinate of second endpoint.

Constructor Index

 o Line()
Constructs a line with default endpoints.
 o Line(int, int, int, int)
Constructs a line.
 o Line(Line)
Constructs a line by copying another line.
 o Line(Point, Point)
Constructs a line.

Method Index

 o distanceSq(Point)
Find the square of the distance from the line to a point.
 o draw(Graphics)
Draws the line.
 o intersects(Rectangle)
Check whether the line intersects a given rectangle.
 o isCloser(Point, int)
Check whether the point is within a given distance from the line.
 o toString()
Get a string describing the line.

Variables

 o x1
 public int x1
X coordinate of first endpoint.

 o x2
 public int x2
X coordinate of second endpoint.

 o y1
 public int y1
Y coordinate of first endpoint.

 o y2
 public int y2
Y coordinate of second endpoint.

Constructors

 o Line
 public Line(int x1,
             int y1,
             int x2,
             int y2)
Constructs a line.

Parameters:
x1 - X coordinate of first endpoint.
y1 - Y coordinate of first endpoint.
x2 - X coordinate of second endpoint.
y2 - Y coordinate of second endpoint.
 o Line
 public Line(Point p1,
             Point p2)
Constructs a line.

Parameters:
p1 - First endpoint.
p2 - Second endpoint.
 o Line
 public Line(Line l)
Constructs a line by copying another line.

Parameters:
l - Line to copy.
 o Line
 public Line()
Constructs a line with default endpoints.

Methods

 o draw
 public void draw(Graphics g)
Draws the line. The color must be set in advance.

Parameters:
g - The graphics context for the drawing area.
 o distanceSq
 public double distanceSq(Point p)
Find the square of the distance from the line to a point.

Parameters:
p - A point.
Returns:
The square of the distance from the line to the given point.
 o isCloser
 public boolean isCloser(Point p,
                         int delta)
Check whether the point is within a given distance from the line.

Parameters:
p - A point.
delta - A distance.
Returns:
True if the point is within delta units of the line; false otherwise.
 o intersects
 public boolean intersects(Rectangle r)
Check whether the line intersects a given rectangle.

Parameters:
r - The rectangle.
Returns:
True if the line and rectangle intersect; false otherwise.
 o toString
 public String toString()
Get a string describing the line.

Returns:
A string describing the line object.
Overrides:
toString in class Object