Package com.nomagic.awt
Class Line
- java.lang.Object
-
- com.nomagic.awt.Line
-
@OpenApiAll public class Line extends java.lang.ObjectThe 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 asp1and whose second point is specified asp2.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanbelongs(java.awt.Point p)Checks whether specified point belongs to this line.booleanequals(java.lang.Object obj)Checks whether two lines are equal.java.awt.RectanglegetBounds()Gets the bounding rectangle of this line.inthashCode()java.awt.Pointintersection(Line l)Computes the intersection of this line with the specified line.java.awt.Pointintersection(java.awt.Point p)Computes the intersection of this line with the line perpendicular to this line.booleanintersects(Line l)Determines whether this line and the specified line intersect.booleanisVertical()java.lang.StringtoString()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 asp1and 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:
trueif the specified line and this line insersect;falseotherwise.
-
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:
trueif specified point belongs to this line;falseotherwise.
-
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:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare with.- Returns:
trueif the objects are equal;falseotherwise.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
@OpenApi public java.lang.String toString()
Returns a string representation of this line and its values.- Overrides:
toStringin 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
getBoundsmethod 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.
-
-