public class VectorI2I extends Object implements VectorReadable2IType
A two-dimensional immutable vector type with integer elements.
Values of this type are immutable and can therefore be safely accessed from multiple threads.
| Constructor and Description |
|---|
VectorI2I()
Default constructor, initializing the vector with values
[0, 0, 0]. |
VectorI2I(int in_x,
int in_y)
Construct a vector initialized with the given values.
|
VectorI2I(VectorReadable2IType in_v)
Construct a vector initialized with the values given in the vector
v. |
| Modifier and Type | Method and Description |
|---|---|
static VectorI2I |
absolute(VectorReadable2IType v)
Calculate the absolute values of the elements in vector
v. |
static VectorI2I |
add(VectorReadable2IType v0,
VectorReadable2IType v1)
Calculate the element-wise sum of the vectors
v0 and
v1. |
static VectorI2I |
addScaled(VectorReadable2IType v0,
VectorReadable2IType v1,
double r)
Calculate the element-wise sum of the vectors
v0 and the
element-wise product of v1 and r. |
static double |
angle(VectorReadable2IType v0,
VectorReadable2IType v1)
Calculate the angle between the vectors
v0 and
v1 in radians. |
static VectorI2I |
clamp(VectorReadable2IType v,
int minimum,
int maximum)
Clamp the elements of the vector
v to the range
[minimum .. |
static VectorI2I |
clampByVector(VectorReadable2IType v,
VectorReadable2IType minimum,
VectorReadable2IType maximum)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in minimum and
maximum. |
static VectorI2I |
clampMaximum(VectorReadable2IType v,
int maximum)
Clamp the elements of the vector
v to the range
[-Infinity .. |
static VectorI2I |
clampMaximumByVector(VectorReadable2IType v,
VectorReadable2IType maximum)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in maximum. |
static VectorI2I |
clampMinimum(VectorReadable2IType v,
int minimum)
Clamp the elements of the vector
v to the range
[minimum .. |
static VectorI2I |
clampMinimumByVector(VectorReadable2IType v,
VectorReadable2IType minimum)
Clamp the elements of the vector
v to the inclusive range
given by the corresponding elements in minimum. |
static int |
distance(VectorReadable2IType v0,
VectorReadable2IType v1)
Calculate the distance between the two vectors
v0 and
v1. |
static int |
dotProduct(VectorReadable2IType v0,
VectorReadable2IType v1)
Calculate the scalar product of the vectors
v0 and
v1. |
boolean |
equals(Object obj) |
int |
getXI() |
int |
getYI() |
int |
hashCode() |
static VectorI2I |
interpolateLinear(VectorReadable2IType v0,
VectorReadable2IType v1,
double alpha)
Linearly interpolate between
v0 and v1 by the
amount alpha. |
static int |
magnitude(VectorReadable2IType v)
Calculate the magnitude of the vector
v. |
static int |
magnitudeSquared(VectorReadable2IType v)
Calculate the squared magnitude of the vector
v. |
static VectorI2I |
projection(VectorReadable2IType p,
VectorReadable2IType q)
Calculate the projection of the vector
p onto the vector
q. |
static VectorI2I |
scale(VectorReadable2IType v,
double r)
Scale the vector
v by the scalar r. |
static VectorI2I |
subtract(VectorReadable2IType v0,
VectorReadable2IType v1)
Subtract the vector
v1 from the vector v0. |
String |
toString() |
public static final VectorI2I ZERO
public VectorI2I()
[0, 0, 0].public VectorI2I(int in_x,
int in_y)
in_x - The x valuein_y - The y valuepublic VectorI2I(VectorReadable2IType in_v)
v.in_v - The input vectorpublic static final VectorI2I absolute(VectorReadable2IType v) throws ArithmeticException
v.v - The input vector(abs v.x, abs v.y, abs v.z)ArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final VectorI2I add(VectorReadable2IType v0, VectorReadable2IType v1) throws ArithmeticException
v0 and
v1.v0 - The left input vectorv1 - The right input vector(v0.x + v1.x, v0.y + v1.y)ArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final VectorI2I addScaled(VectorReadable2IType v0, VectorReadable2IType v1, double r) throws ArithmeticException
v0 and the
element-wise product of v1 and r.v0 - The left input vectorv1 - The right input vectorr - The scaling value(v0.x + (v1.x * r), v0.y + (v1.y * r))ArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final double angle(VectorReadable2IType v0, VectorReadable2IType v1)
v0 and
v1 in radians.v0 - The left input vectorv1 - The right input vectorpublic static final VectorI2I clamp(VectorReadable2IType v, int minimum, int maximum)
v to the range
[minimum .. maximum] inclusive.v - The input vectorminimum - The minimum allowed valuemaximum - The maximum allowed valuemaximum
and at least minimumpublic static final VectorI2I clampByVector(VectorReadable2IType v, VectorReadable2IType minimum, VectorReadable2IType maximum)
v to the inclusive range
given by the corresponding elements in minimum and
maximum.v - The input vectorminimum - The vector containing the minimum acceptable valuesmaximum - The vector containing the maximum acceptable values(min(max(v.x, minimum.x), maximum.x), min(max(v.y, minimum.y), maximum.y))public static final VectorI2I clampMaximum(VectorReadable2IType v, int maximum)
v to the range
[-Infinity .. maximum] inclusive.v - The input vectormaximum - The maximum allowed valuemaximumpublic static final VectorI2I clampMaximumByVector(VectorReadable2IType v, VectorReadable2IType maximum)
v to the inclusive range
given by the corresponding elements in maximum.v - The input vectormaximum - The vector containing the maximum acceptable values(min(v.x, maximum.x), min(v.y, maximum.y))public static final VectorI2I clampMinimum(VectorReadable2IType v, int minimum)
v to the range
[minimum .. Infinity] inclusive.v - The input vectorminimum - The minimum allowed valueminimumpublic static final VectorI2I clampMinimumByVector(VectorReadable2IType v, VectorReadable2IType minimum)
v to the inclusive range
given by the corresponding elements in minimum.v - The input vectorminimum - The vector containing the minimum acceptable values(max(v.x, minimum.x), max(v.y, minimum.y))public static final int distance(VectorReadable2IType v0, VectorReadable2IType v1) throws ArithmeticException
v0 and
v1.v0 - The left input vectorv1 - The right input vectorArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final int dotProduct(VectorReadable2IType v0, VectorReadable2IType v1) throws ArithmeticException
v0 and
v1.v0 - The left input vectorv1 - The right input vectorArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final VectorI2I interpolateLinear(VectorReadable2IType v0, VectorReadable2IType v1, double alpha) throws ArithmeticException
v0 and v1 by the
amount alpha.
The alpha parameter controls the degree of interpolation,
such that:
interpolateLinear(v0, v1, 0.0, r) -> r = v0interpolateLinear(v0, v1, 1.0, r) -> r = v1v0 - The left input vector.v1 - The right input vector.alpha - The interpolation value, between 0.0 and
1.0.(1 - alpha) * v0 + alpha * v1ArithmeticException - Iff an internal arithmetic operation causes an integer
overflow.public static final int magnitude(VectorReadable2IType v) throws ArithmeticException
v.
Correspondingly, magnitude(normalize(v)) == 1.0.v - The input vectorArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final int magnitudeSquared(VectorReadable2IType v) throws ArithmeticException
v.v - The input vectorArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final VectorI2I projection(VectorReadable2IType p, VectorReadable2IType q) throws ArithmeticException
p onto the vector
q.p - The left vectorq - The right vector((dotProduct p q) / magnitudeSquared q) * qArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final VectorI2I scale(VectorReadable2IType v, double r) throws ArithmeticException
v by the scalar r.v - The input vectorr - The scaling value(v.x * r, v.y * r)ArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic static final VectorI2I subtract(VectorReadable2IType v0, VectorReadable2IType v1) throws ArithmeticException
v1 from the vector v0.v0 - The left input vectorv1 - The right input vector(v0.x - v1.x, v0.y - v1.y)ArithmeticException - Iff an internal arithmetic operation causes an integer overflowpublic final int getXI()
getXI in interface VectorReadable2ITypepublic final int getYI()
getYI in interface VectorReadable2ITypeCopyright © 2015 <code@io7m.com> http://io7m.com