Package com.nomagic.awt
Class Line
- java.lang.Object
-
- com.nomagic.awt.Line
-
@OpenApiAll public class Line extends java.lang.Object
The Line represents a line segment in (x, y) coordinate space.
-
-
Constructor Summary
Constructors Constructor Description 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(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
).Line(Line l)
Constructs a new line, initialized to match the values of the specified line.Line(java.awt.Point p1, java.awt.Point p2)
Constructs a new line whose first point is specified asp1
and whose second point is specified asp2
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
belongs(java.awt.Point p)
Checks whether specified point belongs to this line.boolean
equals(java.lang.Object obj)
Checks whether two lines are equal.java.awt.Rectangle
getBounds()
Gets the bounding rectangle of this line.int
hashCode()
java.awt.Point
intersection(Line l)
Computes the intersection of this line with the specified line.java.awt.Point
intersection(java.awt.Point p)
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
isVertical()
java.lang.String
toString()
Returns a string representation of this line and its values.
-
-
-
Constructor Detail
-
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
public Line(Line l)
Constructs a new line, initialized to match the values of the specified line.- Parameters:
l
- a line from which to copy initial values.
-
Line
public Line(java.awt.Point p1, java.awt.Point p2)
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 Detail
-
intersects
public boolean intersects(Line l)
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
@CheckForNull public java.awt.Point intersection(Line l)
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
@CheckForNull public java.awt.Point intersection(java.awt.Point p)
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
public boolean belongs(java.awt.Point p)
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
public boolean equals(java.lang.Object obj)
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.
- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare with.- Returns:
true
if the objects are equal;false
otherwise.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
@OpenApi public java.lang.String toString()
Returns a string representation of this line and its values.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this line.
-
getBounds
public java.awt.Rectangle 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:
Component.getBounds()
-
isVertical
public boolean isVertical()
- Returns:
- true if line is more vertical than horizontal.
-
-