public final class VectorM2F extends Object implements Vector2FType
A two-dimensional mutable vector type with float elements.
Values of this type cannot be accessed safely from multiple threads without explicit synchronization.
| Modifier and Type | Class and Description |
|---|---|
static class |
VectorM2F.ContextVM2F
Preallocated storage to allow all vector functions to run without
allocating.
|
| Constructor and Description |
|---|
VectorM2F()
Default constructor, initializing the vector with values
[0.0,
0.0]. |
VectorM2F(float in_x,
float in_y)
Construct a vector initialized with the given values.
|
VectorM2F(VectorReadable2FType in_v)
Construct a vector initialized with the values given in the vector
in_v. |
| Modifier and Type | Method and Description |
|---|---|
static <V extends VectorWritable2FType> |
absolute(VectorReadable2FType v,
V out)
Calculate the absolute values of the elements in vector
v, saving
the result to out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
absoluteInPlace(V v)
Calculate the absolute values of the elements in vector
v,
modifying the vector in-place. |
static <V extends VectorWritable2FType> |
add(VectorReadable2FType v0,
VectorReadable2FType v1,
V out)
Calculate the element-wise sum of the vectors
v0 and v1,
saving the result to out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
addInPlace(V v0,
VectorReadable2FType v1)
Calculate the element-wise sum of the vectors
v0 and v1,
saving the result to v0. |
static <V extends VectorWritable2FType> |
addScaled(VectorReadable2FType v0,
VectorReadable2FType v1,
double r,
V out)
Calculate the element-wise sum of the vectors
v0 and the
element-wise product of v1 and r, saving the result to
out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
addScaledInPlace(V v0,
VectorReadable2FType v1,
double r)
Calculate the element-wise sum of the vectors
v0 and the
element-wise product of v1 and r, saving the result to
v0. |
static boolean |
almostEqual(com.io7m.jequality.AlmostEqualFloat.ContextRelative context,
VectorReadable2FType qa,
VectorReadable2FType qb)
Determine whether or not the vectors
qa and qb are equal to
within the degree of error given in context. |
static double |
angle(VectorReadable2FType v0,
VectorReadable2FType v1)
Calculate the angle between vectors
v0 and v1, in radians. |
static <V extends VectorWritable2FType> |
clamp(VectorReadable2FType v,
float minimum,
float maximum,
V out)
Clamp the elements of the vector
v to the range {@code [minimum .. |
static <V extends VectorWritable2FType> |
clampByVector(VectorReadable2FType v,
VectorReadable2FType minimum,
VectorReadable2FType maximum,
V out)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in minimum and maximum, saving
the result to out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
clampByVectorInPlace(V v,
VectorReadable2FType minimum,
VectorReadable2FType maximum)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in minimum and maximum, saving
the result to v. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
clampInPlace(V v,
float minimum,
float maximum)
Clamp the elements of the vector
v to the range {@code [minimum .. |
static <V extends VectorWritable2FType> |
clampMaximum(VectorReadable2FType v,
float maximum,
V out)
Clamp the elements of the vector
v to the range {@code [-Infinity
.. |
static <V extends VectorWritable2FType> |
clampMaximumByVector(VectorReadable2FType v,
VectorReadable2FType maximum,
V out)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in maximum, saving the result to out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
clampMaximumByVectorInPlace(V v,
VectorReadable2FType maximum)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in maximum, saving the result to v. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
clampMaximumInPlace(V v,
float maximum)
Clamp the elements of the vector
v to the range {@code [-Infinity
.. |
static <V extends VectorWritable2FType> |
clampMinimum(VectorReadable2FType v,
float minimum,
V out)
Clamp the elements of the vector
v to the range {@code [minimum .. |
static <V extends VectorWritable2FType> |
clampMinimumByVector(VectorReadable2FType v,
VectorReadable2FType minimum,
V out)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in minimum, saving the result to out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
clampMinimumByVectorInPlace(V v,
VectorReadable2FType minimum)
Clamp the elements of the vector
v to the inclusive range given by
the corresponding elements in minimum, saving the result to v. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
clampMinimumInPlace(V v,
float minimum)
Clamp the elements of the vector
v to the range {@code [minimum .. |
static <V extends VectorWritable2FType> |
copy(VectorReadable2FType input,
V output)
Copy all elements of the vector
input to the vector output. |
void |
copyFrom2F(VectorReadable2FType in_v)
Set the current vector to the contents of the input vector.
|
static double |
distance(VectorM2F.ContextVM2F c,
VectorReadable2FType v0,
VectorReadable2FType v1)
Calculate the distance between the two vectors
v0 and v1. |
static float |
dotProduct(VectorReadable2FType v0,
VectorReadable2FType v1)
Calculate the scalar product of the vectors
v0 and v1. |
boolean |
equals(Object obj) |
float |
getXF() |
float |
getYF() |
int |
hashCode() |
static <V extends VectorWritable2FType> |
interpolateLinear(VectorM2F.ContextVM2F c,
VectorReadable2FType v0,
VectorReadable2FType v1,
double alpha,
V r)
Linearly interpolate between
v0 and v1 by the amount alpha, saving the result to r. |
static double |
magnitude(VectorReadable2FType v)
Calculate the magnitude of the vector
v. |
static double |
magnitudeSquared(VectorReadable2FType v)
Calculate the squared magnitude of the vector
v. |
static <V extends VectorWritable2FType> |
normalize(VectorReadable2FType v,
V out)
Returns a vector with the same orientation as
v but with magnitude
equal to 1.0 in out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
normalizeInPlace(V v)
Returns a vector with the same orientation as
v but with magnitude
equal to 1.0 in v. |
static <V extends VectorReadable2FType,U extends VectorWritable2FType> |
orthoNormalize(VectorM2F.ContextVM2F c,
VectorReadable2FType v0,
U v0_out,
VectorReadable2FType v1,
U v1_out)
Orthonormalize and return the vectors
v0 and v1 . |
static <V extends VectorWritable2FType & VectorReadable2FType,W extends VectorWritable2FType & VectorReadable2FType> |
orthoNormalizeInPlace(VectorM2F.ContextVM2F c,
V v0,
W v1)
Orthonormalize and the vectors
v0 and v1. |
static <V extends VectorWritable2FType> |
projection(VectorReadable2FType p,
VectorReadable2FType q,
V r)
Calculate the projection of the vector
p onto the vector q,
saving the result in r. |
static <V extends VectorWritable2FType> |
scale(VectorReadable2FType v,
double r,
V out)
Scale the vector
v by the scalar r, saving the result to
out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
scaleInPlace(V v,
double r)
Scale the vector
v by the scalar r, saving the result to
v. |
void |
set2F(float in_x,
float in_y)
Set the current
x and y values of the current vector. |
void |
setXF(float in_x)
Set the current
x value of the current vector. |
void |
setYF(float in_y)
Set the current
y value of the current vector. |
static <V extends VectorWritable2FType> |
subtract(VectorReadable2FType v0,
VectorReadable2FType v1,
V out)
Subtract the vector
v1 from the vector v0, saving the
result to out. |
static <V extends VectorWritable2FType & VectorReadable2FType> |
subtractInPlace(V v0,
VectorReadable2FType v1)
Subtract the vector
v1 from the vector v0, saving the
result to v0. |
String |
toString() |
public VectorM2F()
[0.0,
0.0].public VectorM2F(float in_x,
float in_y)
in_x - The x valuein_y - The y valuepublic VectorM2F(VectorReadable2FType in_v)
in_v.in_v - The source vectorpublic static <V extends VectorWritable2FType> V absolute(VectorReadable2FType v, V out)
v, saving
the result to out.V - The precise type of vectorv - The input vectorout - The output vector(abs v.x, abs v.y)public static <V extends VectorWritable2FType & VectorReadable2FType> V absoluteInPlace(V v)
v,
modifying the vector in-place.V - The precise type of vectorv - The input vector(abs v.x, abs v.y)public static <V extends VectorWritable2FType> V add(VectorReadable2FType v0, VectorReadable2FType v1, V out)
v0 and v1,
saving the result to out.V - The precise type of vectorv0 - The left input vectorv1 - The right input vectorout - The output vector(v0.x + v1.x, v0.y + v1.y)public static <V extends VectorWritable2FType & VectorReadable2FType> V addInPlace(V v0, VectorReadable2FType v1)
v0 and v1,
saving the result to v0.V - The precise type of vectorv0 - The left input vectorv1 - The right input vector(v0.x + v1.x, v0.y + v1.y)public static <V extends VectorWritable2FType> V addScaled(VectorReadable2FType v0, VectorReadable2FType v1, double r, V out)
v0 and the
element-wise product of v1 and r, saving the result to
out.V - The precise type of vectorv0 - The left input vectorv1 - The right input vectorout - The output vectorr - The scaling value(v0.x + (v1.x * r), v0.y + (v1.y * r))public static <V extends VectorWritable2FType & VectorReadable2FType> V addScaledInPlace(V v0, VectorReadable2FType v1, double r)
v0 and the
element-wise product of v1 and r, saving the result to
v0.V - The precise type of vectorv0 - The left input vectorv1 - The right input vectorr - The scaling value(v0.x + (v1.x * r), v0.y + (v1.y * r))public static boolean almostEqual(com.io7m.jequality.AlmostEqualFloat.ContextRelative context,
VectorReadable2FType qa,
VectorReadable2FType qb)
qa and qb are equal to
within the degree of error given in context.context - The equality contextqa - The left input vectorqb - The right input vectortrue if the vectors are almost equalAlmostEqualFloat.almostEqual(AlmostEqualFloat.ContextRelative, float,
float)public static double angle(VectorReadable2FType v0, VectorReadable2FType v1)
v0 and v1, in radians.v0 - The left input vectorv1 - The right input vectorpublic static <V extends VectorWritable2FType> V clamp(VectorReadable2FType v, float minimum, float maximum, V out)
v to the range [minimum ..
maximum] inclusive, saving the result to out.V - The precise type of vectorv - The input vectorminimum - The minimum allowed valuemaximum - The maximum allowed valueout - The output vectormaximum and at
least minimumpublic static <V extends VectorWritable2FType> V clampByVector(VectorReadable2FType v, VectorReadable2FType minimum, VectorReadable2FType maximum, V out)
v to the inclusive range given by
the corresponding elements in minimum and maximum, saving
the result to out.V - The precise type of vectorv - The input vectorminimum - The vector containing the minimum acceptable valuesmaximum - The vector containing the maximum acceptable valuesout - The output vector(min(max(v.x, minimum.x), maximum.x), min(max(v.y,
minimum.y), maximum.y))public static <V extends VectorWritable2FType & VectorReadable2FType> V clampByVectorInPlace(V v, VectorReadable2FType minimum, VectorReadable2FType maximum)
v to the inclusive range given by
the corresponding elements in minimum and maximum, saving
the result to v.V - The precise type of vectorv - 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 <V extends VectorWritable2FType & VectorReadable2FType> V clampInPlace(V v, float minimum, float maximum)
v to the range [minimum ..
maximum] inclusive, saving the result to v.V - The precise type of vectorv - The input vectorminimum - The minimum allowed valuemaximum - The maximum allowed valuemaximum and at
least minimum, in vpublic static <V extends VectorWritable2FType> V clampMaximum(VectorReadable2FType v, float maximum, V out)
v to the range [-Infinity
.. maximum] inclusive, saving the result to out.V - The precise type of vectorv - The input vectorout - The output vectormaximum - The maximum allowed valuemaximumpublic static <V extends VectorWritable2FType> V clampMaximumByVector(VectorReadable2FType v, VectorReadable2FType maximum, V out)
v to the inclusive range given by
the corresponding elements in maximum, saving the result to out.V - The precise type of vectorv - The input vectormaximum - The vector containing the maximum acceptable valuesout - The output vector(min(v.x, maximum.x), min(v.y, maximum.y))public static <V extends VectorWritable2FType & VectorReadable2FType> V clampMaximumByVectorInPlace(V v, VectorReadable2FType maximum)
v to the inclusive range given by
the corresponding elements in maximum, saving the result to v.V - The precise type of vectorv - The input vectormaximum - The vector containing the maximum acceptable values(min(v.x, maximum.x), min(v.y, maximum.y))public static <V extends VectorWritable2FType & VectorReadable2FType> V clampMaximumInPlace(V v, float maximum)
v to the range [-Infinity
.. maximum] inclusive, saving the result to v.V - The precise type of vectorv - The input vectormaximum - The maximum allowed valuemaximum , in
vpublic static <V extends VectorWritable2FType> V clampMinimum(VectorReadable2FType v, float minimum, V out)
v to the range [minimum ..
Infinity] inclusive, saving the result to out.V - The precise type of vectorv - The input vectorout - The output vectorminimum - The minimum allowed valueminimumpublic static <V extends VectorWritable2FType> V clampMinimumByVector(VectorReadable2FType v, VectorReadable2FType minimum, V out)
v to the inclusive range given by
the corresponding elements in minimum, saving the result to out.V - The precise type of vectorv - The input vectorout - The output vectorminimum - The vector containing the minimum acceptable values(max(v.x, minimum.x), max(v.y, minimum.y))public static <V extends VectorWritable2FType & VectorReadable2FType> V clampMinimumByVectorInPlace(V v, VectorReadable2FType minimum)
v to the inclusive range given by
the corresponding elements in minimum, saving the result to v.V - The precise type of vectorv - The input vectorminimum - The vector containing the minimum acceptable values(max(v.x, minimum.x), max(v.y, minimum.y)) , in vpublic static <V extends VectorWritable2FType & VectorReadable2FType> V clampMinimumInPlace(V v, float minimum)
v to the range [minimum ..
Infinity] inclusive, saving the result to v.V - The precise type of vectorv - The input vectorminimum - The minimum allowed valueminimum, in
v.public static <V extends VectorWritable2FType> V copy(VectorReadable2FType input, V output)
input to the vector output.V - The precise type of vectorinput - The input vectoroutput - The output vectorpublic static double distance(VectorM2F.ContextVM2F c, VectorReadable2FType v0, VectorReadable2FType v1)
v0 and v1.c - Preallocated storagev0 - The left input vectorv1 - The right input vectorpublic static float dotProduct(VectorReadable2FType v0, VectorReadable2FType v1)
v0 and v1.v0 - The left input vectorv1 - The right input vectorpublic static <V extends VectorWritable2FType> V interpolateLinear(VectorM2F.ContextVM2F c, VectorReadable2FType v0, VectorReadable2FType v1, double alpha, V r)
v0 and v1 by the amount alpha, saving the result to r.
The alpha parameter controls the degree of interpolation, such
that:
interpolateLinear(v0, v1, 0.0, r) -> r = v0interpolateLinear(v0, v1, 1.0, r) -> r = v1V - The precise type of vectorc - Preallocated storagev0 - The left input vector.v1 - The right input vector.alpha - The interpolation value, between 0.0 and 1.0.r - The result vector.rpublic static double magnitude(VectorReadable2FType v)
v.
Correspondingly, magnitude(normalize(v)) == 1.0.v - The input vectorpublic static double magnitudeSquared(VectorReadable2FType v)
v.v - The input vectorpublic static <V extends VectorWritable2FType> V normalize(VectorReadable2FType v, V out)
v but with magnitude
equal to 1.0 in out. The function returns the zero vector
iff the input is the zero vector.V - The precise type of vectorv - The input vectorout - The output vectorpublic static <V extends VectorWritable2FType & VectorReadable2FType> V normalizeInPlace(V v)
v but with magnitude
equal to 1.0 in v. The function returns the zero vector iff
the input is the zero vector.V - The precise type of vectorv - The input vectorpublic static <V extends VectorReadable2FType,U extends VectorWritable2FType> void orthoNormalize(VectorM2F.ContextVM2F c, VectorReadable2FType v0, U v0_out, VectorReadable2FType v1, U v1_out)
Orthonormalize and return the vectors v0 and v1 .
See GSP
V - The precise type of readable vectorsU - The precise type of writable vectorsc - Preallocated storagev0 - The left vectorv0_out - The orthonormalized form of v0v1 - The right vectorv1_out - The orthonormalized form of v1public static <V extends VectorWritable2FType & VectorReadable2FType,W extends VectorWritable2FType & VectorReadable2FType> void orthoNormalizeInPlace(VectorM2F.ContextVM2F c, V v0, W v1)
Orthonormalize and the vectors v0 and v1.
See GSP
V - The precise type of readable/writable vectorW - The precise type of readable/writable vectorc - Preallocated storagev0 - The left vectorv1 - The right vectorpublic static <V extends VectorWritable2FType> V projection(VectorReadable2FType p, VectorReadable2FType q, V r)
p onto the vector q,
saving the result in r.V - The precise type of vectorp - The left vectorq - The right vectorr - The output vector((dotProduct p q) / magnitudeSquared q) * qpublic static <V extends VectorWritable2FType> V scale(VectorReadable2FType v, double r, V out)
v by the scalar r, saving the result to
out.V - The precise type of vectorv - The input vectorr - The scaling valueout - The output vector(v.x * r, v.y * r)public static <V extends VectorWritable2FType & VectorReadable2FType> V scaleInPlace(V v, double r)
v by the scalar r, saving the result to
v.V - The precise type of vectorv - The input vectorr - The scaling value(v.x * r, v.y * r)public static <V extends VectorWritable2FType> V subtract(VectorReadable2FType v0, VectorReadable2FType v1, V out)
v1 from the vector v0, saving the
result to out.V - The precise type of vectorv0 - The left input vectorv1 - The right input vectorout - The output vector(v0.x - v1.x, v0.y - v1.y)public static <V extends VectorWritable2FType & VectorReadable2FType> V subtractInPlace(V v0, VectorReadable2FType v1)
v1 from the vector v0, saving the
result to v0.V - The precise type of vectorv0 - The left input vectorv1 - The right input vector(v0.x - v1.x, v0.y - v1.y)public void copyFrom2F(VectorReadable2FType in_v)
VectorWritable2FTypecopyFrom2F in interface VectorWritable2FTypein_v - The input vectorpublic float getXF()
getXF in interface VectorReadable2FTypepublic void setXF(float in_x)
VectorWritable2FTypex value of the current vector.setXF in interface VectorWritable2FTypein_x - The new x value.public float getYF()
getYF in interface VectorReadable2FTypepublic void setYF(float in_y)
VectorWritable2FTypey value of the current vector.setYF in interface VectorWritable2FTypein_y - The new y value.public void set2F(float in_x,
float in_y)
VectorWritable2FTypex and y values of the current vector.set2F in interface VectorWritable2FTypein_x - The new x value.in_y - The new y value.Copyright © 2015 <code@io7m.com> http://io7m.com