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
-
x1
- X coordinate of first endpoint.
-
x2
- X coordinate of second endpoint.
-
y1
- Y coordinate of first endpoint.
-
y2
- Y coordinate of second endpoint.
-
Line()
- Constructs a line with default endpoints.
-
Line(int, int, int, int)
- Constructs a line.
-
Line(Line)
- Constructs a line by copying another line.
-
Line(Point, Point)
- Constructs a line.
-
distanceSq(Point)
- Find the square of the distance from the line to a point.
-
draw(Graphics)
- Draws the line.
-
intersects(Rectangle)
- Check whether the line intersects a given rectangle.
-
isCloser(Point, int)
- Check whether the point is within a given distance from the line.
-
toString()
- Get a string describing the line.
x1
public int x1
- X coordinate of first endpoint.
x2
public int x2
- X coordinate of second endpoint.
y1
public int y1
- Y coordinate of first endpoint.
y2
public int y2
- Y coordinate of second endpoint.
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.
Line
public Line(Point p1,
Point p2)
- Constructs a line.
- Parameters:
- p1 - First endpoint.
- p2 - Second endpoint.
Line
public Line(Line l)
- Constructs a line by copying another line.
- Parameters:
- l - Line to copy.
Line
public Line()
- Constructs a line with default endpoints.
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.
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.
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.
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.
toString
public String toString()
- Get a string describing the line.
- Returns:
- A string describing the line object.
- Overrides:
- toString in class Object