public final class PointI
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static PointI |
EMPTY
An empty read-only
PointI . |
int |
x
The x-coordinate of the
PointI . |
int |
y
The y-coordinate of the
PointI . |
Constructor and Description |
---|
PointI()
Creates a
PointI with the coordinate origin. |
PointI(int x,
int y)
Creates a
PointI with the specified Integer coordinates. |
Modifier and Type | Method and Description |
---|---|
PointI |
add(PointI point)
Adds the location of the specified
PointI to this instance. |
double |
angle()
Gets the polar angle of the vector represented by the
PointI , in radians. |
double |
angleBetween(PointI vector)
Computes the angle between the vector represented by the
PointI and the specified vector. |
double |
angleBetween(PointI a,
PointI b)
Computes the angle between the vectors from the
PointI to the specified locations. |
long |
crossProductLength(PointI vector)
Computes the length of the cross-product of the vector represented by the
PointI
and the specified vector. |
long |
crossProductLength(PointI a,
PointI b)
Computes the length of the cross-product of the vectors from the
PointI
to the specified locations. |
boolean |
equals(java.lang.Object obj)
Compares the specified
Object to this PointI instance. |
static PointI[] |
fromInts(int... points)
Converts the specified
Integer array to a PointI array. |
static PointI |
fromPolar(double length,
double angle)
Creates a
PointI from the specified polar coordinates. |
int |
hashCode()
Returns a hash code for the
PointI . |
boolean |
isCollinear(PointI a,
PointI b)
Determines if the
PointI is collinear with the specified instances. |
double |
length()
Gets the absolute length of the vector represented by the
PointI . |
long |
lengthSquared()
Gets the squared absolute length of the vector represented by the
PointI . |
long |
multiply(PointI vector)
Multiplies the vectors represented by the specified
PointI and this instance. |
PointI |
restrict(int minX,
int minY,
int maxX,
int maxY)
Restricts the
PointI to the specified location range. |
PointI |
subtract(PointI point)
Subtracts the location of the specified
PointI from this instance. |
static int[] |
toInts(PointI... points)
Converts the specified
PointI array to an Integer array. |
PointD |
toPointD()
|
java.lang.String |
toString()
Returns a
String representation of the PointI . |
public final int x
PointI
.public final int y
PointI
.public static final PointI EMPTY
public PointI add(PointI point)
PointI
to this instance.point
- the PointI
whose location to add to this instancePointI
whose x
and y
equal the addition of the
corresponding dimensions of the specified point
to this instancejava.lang.ArithmeticException
- if the sum in any dimension overflows Integer
java.lang.NullPointerException
- if point
is null
public double angle()
public double angleBetween(PointI vector)
PointI
and the specified vector.
Returns the result of Math.atan2(double, double)
for the cross-product length and the scalar dot product
of the two vectors. The possible range of values is [-Math.PI
, +Math.PI
].
Coordinates are widened to Double
to avoid Integer
overflow.vector
- the PointI
vector to compare with this instancevector
, in that orderjava.lang.NullPointerException
- if vector
is null
public double angleBetween(PointI a, PointI b)
PointI
to the specified locations.
Returns the result of Math.atan2(double, double)
for the cross-product length and the scalar dot product
of the two vectors. The possible range of values is [-Math.PI
, +Math.PI
].public long crossProductLength(PointI vector)
PointI
and the specified vector. The absolute value equals the area of the parallelogram
spanned by the PointI
and the specified vector
. The sign indicates their
spatial relationship, as described in crossProductLength(PointI, PointI)
.
Coordinates are widened to Long
to avoid Integer
overflow.vector
- the PointI
vector to multiply with this instanceLong
value indicating the length of the cross-product of this instance
and the specified vector
, in that orderjava.lang.NullPointerException
- if vector
is null
public long crossProductLength(PointI a, PointI b)
PointI
to the specified locations. The absolute value equals the area of the parallelogram
spanned by the vectors from the PointI
to a
and b
.
The sign indicates their spatial relationship of the two vectors, as follows:
a
and then b
constitutes a right-hand turn, assuming y-coordinates increase upward.a
, and b
are collinear.a
and then b
constitutes a left-hand turn, assuming y-coordinates increase upward.Long
to avoid Integer
overflow.a
- the PointI
location where the first vector endsb
- the PointI
location where the second vector endsLong
value indicating the length of the cross-product of the vectors
from this instance to a
and from this instance to b
, in that orderjava.lang.NullPointerException
- if a
or b
is null
public static PointI[] fromInts(int... points)
Integer
array to a PointI
array.
The returned array has half as many elements as the specified
points
and retains the same coordinate sequence.points
- an array containing the x
and y
components of
PointI
instances, stored in alternating index positionsPointI
array created from points
java.lang.IllegalArgumentException
- if points
has an odd number of elementsjava.lang.NullPointerException
- if points
is null
public static PointI fromPolar(double length, double angle)
PointI
from the specified polar coordinates.
The calculated x
and y
coordinates are converted to the nearest
Integer
values using Fortran.nint(double)
rounding. The resulting
length()
and angle()
may differ accordingly from the specified arguments.length
- the distance from the coordinate origin to the PointI
angle
- the polar angle, in radians, of the PointI
PointI
whose length()
and angle()
approximately equal the specified length
and angle
java.lang.ArithmeticException
- if any resulting Cartesian coordinate overflows Integer
public boolean isCollinear(PointI a, PointI b)
PointI
is collinear with the specified instances.
Returns true
exactly if crossProductLength(PointI, PointI)
is zero for a
and b
.public double length()
PointI
.
Returns the square root of the sum of the squares of x
and y
.PointI
public long lengthSquared()
PointI
.
Returns the sum of the squares of x
and y
, 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 long multiply(PointI vector)
PointI
and this instance.
Returns the sum of the pairwise products of both instances' x
and y
,
widened to Long
to avoid Integer
overflow. That sum equals
lengthSquared()
if the specified vector
equals this instance.vector
- the PointI
to multiply with this instanceLong
value that represents the scalar dot product
of the specified vector
and this instancejava.lang.NullPointerException
- if vector
is null
public PointI restrict(int minX, int minY, int maxX, int maxY)
PointI
to the specified location range.public PointI subtract(PointI point)
PointI
from this instance.point
- the PointI
location to subtract from this instancePointI
whose x
and y
equal the subtraction
of the corresponding dimensions of the specified point
from this instancejava.lang.ArithmeticException
- if the difference in any dimension overflows Integer
java.lang.NullPointerException
- if point
is null
public static int[] toInts(PointI... points)
PointI
array to an Integer
array.
The returned array has twice as many elements as the specified
points
and retains the same coordinate sequence.public PointD toPointD()
public boolean equals(java.lang.Object obj)
Object
to this PointI
instance.public int hashCode()
PointI
.hashCode
in class java.lang.Object
Integer
hash code for the PointI