public final class LineI
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static LineI |
EMPTY
An empty read-only
LineI. |
PointI |
end
The end point of the
LineI. |
PointI |
start
The start point of the
LineI. |
| Constructor and Description |
|---|
LineI()
Creates a
LineI that starts and ends at the coordinate origin. |
LineI(int startX,
int startY,
int endX,
int endY)
Creates a
LineI with the specified Integer coordinates. |
LineI(PointI start,
PointI end)
|
| Modifier and Type | Method and Description |
|---|---|
double |
angle()
Gets the angle of the
LineI, in radians. |
double |
distanceSquared(PointI q)
|
boolean |
equals(java.lang.Object obj)
Compares the specified
Object to this LineI instance. |
double |
findX(double y)
Finds the x-coordinate for the specified y-coordinate on the
LineI or its infinite extension. |
double |
findY(double x)
Finds the y-coordinate for the specified x-coordinate on the
LineI or its infinite extension. |
static LineI[] |
fromInts(int... lines)
Converts the specified
Integer array to a LineI array. |
int |
hashCode()
Returns a hash code for the
LineI. |
LineIntersection |
intersect(LineI line)
Finds the intersection between the
LineI and a specified instance. |
PointD |
intersect(PointI q)
|
double |
inverseSlope()
Gets the inverse slope of the
LineI. |
double |
length()
Gets the absolute length of the
LineI. |
long |
lengthSquared()
Gets the squared absolute length of the
LineI. |
LineLocation |
locate(PointI q)
|
LineLocation |
locateCollinear(PointI q)
|
LineI |
reverse()
Reverses the direction of the
LineI. |
double |
slope()
Gets the slope of the
LineI. |
static int[] |
toInts(LineI... lines)
Converts the specified
LineI array to an Integer array. |
LineD |
toLineD()
|
java.lang.String |
toString()
Returns a
String representation of the LineI. |
PointI |
vector()
Gets the vector defined by the
LineI. |
public static final LineI EMPTY
public LineI()
LineI that starts and ends at the coordinate origin.
Both start and end are set to PointI.EMPTY.public LineI(int startX,
int startY,
int endX,
int endY)
LineI with the specified Integer coordinates.public double angle()
LineI, in radians.
Returns the result of Math.atan2(double, double) for the vertical and horizontal distances between
end and start, within the interval [-Math.PI, +Math.PI].
angle() equals zero if the LineI extends horizontally to the right,
and increases as the line turns clockwise (y-axis pointing down) or counter-clockwise
(y-axis pointing up).
public double distanceSquared(PointI q)
public double findX(double y)
public double findY(double x)
public static LineI[] fromInts(int... lines)
Integer array to a LineI array.
The returned array has a quarter as many elements as the specified
lines and retains the same coordinate sequence.lines - an array containing the coordinates start.x, start.y, end.x, end.y of
LineI instances, stored in successive index positions per LineILineI array created from linesjava.lang.IllegalArgumentException - if the length of lines is not divisible by fourjava.lang.NullPointerException - if lines is nullpublic LineIntersection intersect(LineI line)
LineI and a specified instance.
Returns the result of LineIntersection.find(org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD) for the start and
end points of this instance and the specified line, in that order.line - the LineI to intersect with this instanceLineIntersection that describes if and how this instance
intersects the specified linejava.lang.NullPointerException - if line is nullpublic double inverseSlope()
public double length()
LineI.
Returns the square root of the sum of the squares of the horizontal
and vertical extensions of the LineI.LineIpublic long lengthSquared()
LineI.
Returns the sum of the squares of the horizontal and vertical extensions
of the LineI, widened to Long to avoid Integer overflow.
Use instead of length() if you only need the squared value.Long value that equals the square of length()public LineLocation locate(PointI q)
PointI relative to the LineI.
Never returns null. The return values LineLocation.LEFT and
LineLocation.RIGHT assume that y-coordinates increase upward.
locate is based on the classify algorithm by Michael J. Laszlo,
Computational Geometry and Computer Graphics in C++, Prentice Hall 1996, p.76.
q - the PointI coordinates to examineLineLocation value indicating the location of q relative to the LineIjava.lang.NullPointerException - if q is nullpublic LineLocation locateCollinear(PointI q)
PointI relative to the LineI,
assuming they are collinear.
Returns the result of LineIntersection.locateCollinear(org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD, org.kynosarges.tektosyne.geometry.PointD) for the start
and end points of this instance and the specified q, in that order.
Never returns null, LineLocation.LEFT, or LineLocation.RIGHT
due to the assumption of collinearity.q - the PointI coordinates to examineLineLocation value indicating the location of q relative to the LineIjava.lang.NullPointerException - if q is nullpublic double slope()
LineI.
Equals 1/inverseSlope(). May return a negative value, depending on angle().public static int[] toInts(LineI... lines)
LineI array to an Integer array.
The returned array has four times as many elements as the specified
lines and retains the same coordinate sequence.public LineD toLineD()
LineD whose LineD.start and LineD.end
points equal the corresponding points of the LineIpublic PointI vector()
public boolean equals(java.lang.Object obj)
Object to this LineI instance.public int hashCode()
LineI.hashCode in class java.lang.ObjectInteger hash code for the LineI