Package com.nomagic.awt
Class Line
java.lang.Object
com.nomagic.awt.Line
The Line represents a line segment in (x, y) coordinate space.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionLine()
Constructs a new line whose first point is at (0,0) in the coordinate space, and whose second point is at (0, 0) in the coordinate space.Line
(int x1, int y1, int x2, int y2) Constructs a new line whose first point is specified as (x
,y
) and whose second point is specified as (x
,y
).Constructs a new line, initialized to match the values of the specified line.Constructs a new line whose first point is specified asp1
and whose second point is specified asp2
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks whether specified point belongs to this line.boolean
Checks whether two lines are equal.Gets the bounding rectangle of this line.int
hashCode()
intersection
(Line l) Computes the intersection of this line with the specified line.Computes the intersection of this line with the line perpendicular to this line.boolean
intersects
(Line l) Determines whether this line and the specified line intersect.boolean
toString()
Returns a string representation of this line and its values.
-
Field Details
-
A
The first point of the line. -
B
The second point of the line.
-
-
Constructor Details
-
Line
public Line()Constructs a new line whose first point is at (0,0) in the coordinate space, and whose second point is at (0, 0) in the coordinate space. -
Line
Constructs a new line, initialized to match the values of the specified line.- Parameters:
l
- a line from which to copy initial values.
-
Line
Constructs a new line whose first point is specified asp1
and whose second point is specified asp2
.- Parameters:
p1
- the first point.p2
- the second point.
-
Line
public Line(int x1, int y1, int x2, int y2) Constructs a new line whose first point is specified as (x
,y
) and whose second point is specified as (x
,y
).- Parameters:
x1
- the first point x coordinate.y1
- the first point y coordinate.x2
- the second point x coordinate.y2
- the second point y coordinate.
-
-
Method Details
-
intersects
Determines whether this line and the specified line intersect.- Parameters:
l
- a line.- Returns:
true
if the specified line and this line insersect;false
otherwise.
-
intersection
Computes the intersection of this line with the specified line. Returns a new point that represents the intersection of the two lines.- Parameters:
l
- a line.- Returns:
- the lines intersection point
-
intersection
Computes the intersection of this line with the line perpendicular to this line. Perpendicular line go throught specified point. Returns a new point that represents the intersection of the two lines.- Parameters:
p
- a point.- Returns:
- the lines intersection point
-
belongs
Checks whether specified point belongs to this line.The result is true if and only if the argument is not null and belongs to this line.
- Parameters:
p
- a point.- Returns:
true
if specified point belongs to this line;false
otherwise.
-
equals
Checks whether two lines are equal.The result is true if and only if the argument is not null and is a Line object that has the same first point and second point as this line.
-
hashCode
public int hashCode() -
toString
Returns a string representation of this line and its values. -
getBounds
Gets the bounding rectangle of this line.This method is included for completeness, to parallel the
getBounds
method ofComponent
.- Returns:
- a new rectangle, equal to the bounding rectangle for this line.
- See Also:
-
isVertical
public boolean isVertical()- Returns:
- true if line is more vertical than horizontal.
-