Class Vector4i
- All Implemented Interfaces:
Externalizable
,Serializable
,Cloneable
,Vector4ic
- Author:
- Richard Greenlees, Kai Burjack, Hans Uhlig
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionVector4i()
Create a newVector4i
of(0, 0, 0, 1)
.Vector4i
(int s) Create a newVector4i
and initialize all four components with the given value.Vector4i
(int[] xyzw) Create a newVector4i
and initialize its four components from the first four elements of the given array.Vector4i
(int x, int y, int z, int w) Create a newVector4i
with the given component values.Vector4i
(int index, ByteBuffer buffer) Create a newVector4i
and read this vector from the suppliedByteBuffer
starting at the specified absolute buffer position/index.Vector4i
(ByteBuffer buffer) Create a newVector4i
and read this vector from the suppliedByteBuffer
at the current bufferposition
.Create a newVector4i
with the first three components from the givenv
and the givenw
and round using the givenRoundingMode
.Create a newVector4i
and initialize its components to the rounded value of the given vector.Create a newVector4i
and initialize its components to the rounded value of the given vector.Create a newVector4i
with the same values asv
. -
Method Summary
Modifier and TypeMethodDescriptionabsolute()
Compute the absolute of each of this vector's components.Compute the absolute of each of this vector's components and store the result intodest
.add
(int x, int y, int z, int w) Increment the components of this vector by the given values.Increment the components of this vector by the given values and store the result indest
.Add the supplied vector to this one.Add the supplied vector to this one and store the result indest
.clone()
double
distance
(int x, int y, int z, int w) Return the distance betweenthis
vector and(x, y, z, w)
.static double
distance
(int x1, int y1, int z1, int w1, int x2, int y2, int z2, int w2) Return the distance between(x1, y1, z1, w1)
and(x2, y2, z2, w2)
.double
Return the distance between this Vector andv
.int
distanceSquared
(int x, int y, int z, int w) Return the square of the distance betweenthis
vector and(x, y, z, w)
.static long
distanceSquared
(int x1, int y1, int z1, int w1, int x2, int y2, int z2, int w2) Return the squared distance between(x1, y1, z1, w1)
and(x2, y2, z2, w2)
.int
Return the square of the distance between this vector andv
.div
(float scalar) Divide all components of thisVector3i
by the given scalar value.Divide all components of thisVector4i
by the given scalar value and store the result indest
.div
(int scalar) Divide all components of thisVector4i
by the given scalar value.Divide all components of thisVector4i
by the given scalar value and store the result indest
.Divide this Vector4i component-wise by another Vector4i.Divide this Vector4i component-wise by another Vector4ic and store the result indest
.int
Compute the dot product (inner product) of this vector andv
.boolean
equals
(int x, int y, int z, int w) Compare the vector components ofthis
vector with the given(x, y, z, w)
and return whether all of them are equal.boolean
int
get
(int component) Get the value of the specified component of this vector.get
(int index, ByteBuffer buffer) Store this vector into the suppliedByteBuffer
starting at the specified absolute buffer position/index.Store this vector into the suppliedIntBuffer
starting at the specified absolute buffer position/index.get
(ByteBuffer buffer) Store this vector into the suppliedByteBuffer
at the current bufferposition
.getToAddress
(long address) Store this vector at the given off-heap memory address.long
gridDistance
(int x, int y, int z, int w) Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y)
.long
Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y)
.int
hashCode()
double
length()
Return the length of this vector.static double
length
(int x, int y, int z, int w) Get the length of a 4-dimensional single-precision vector.long
Return the length squared of this vector.static long
lengthSquared
(int x, int y, int z, int w) Get the length squared of a 4-dimensional single-precision vector.Set the components of this vector to be the component-wise maximum of this and the other vector.Set the components ofdest
to be the component-wise maximum of this and the other vector.int
Determine the component with the biggest absolute value.Set the components of this vector to be the component-wise minimum of this and the other vector.Set the components ofdest
to be the component-wise minimum of this and the other vector.int
Determine the component with the smallest (towards zero) absolute value.mul
(int scalar) Multiply all components of thisVector4i
by the given scalar value.Multiply all components of thisVector4i
by the given scalar value and store the result indest
.Multiply this Vector4i component-wise by another Vector4i.Multiply this Vector4i component-wise by another Vector4ic and store the result indest
.negate()
Negate this vector.Negate this vector and store the result indest
.void
set
(int s) Set the x, y, z, and w components to the supplied value.set
(int[] xyzw) Set the four components of this vector to the first four elements of the given array.set
(int x, int y, int z, int w) Set the x, y, z, and w components to the supplied values.set
(int index, ByteBuffer buffer) Read this vector from the suppliedByteBuffer
starting at the specified absolute buffer position/index.Read this vector from the suppliedIntBuffer
starting at the specified absolute buffer position/index.set
(ByteBuffer buffer) Read this vector from the suppliedByteBuffer
at the current bufferposition
.Sets the first two components of this to the components of givenv
and last two components to the givenz
, andw
.Set the first three components of this to the components ofv
and the last component tow
.Set thisVector4i
to the values of v usingRoundingMode.TRUNCATE
rounding.Set thisVector4i
to the values of v using the givenRoundingMode
.Set thisVector4i
to the values of v using the givenRoundingMode
.Set thisVector4i
to the values of the givenv
.setComponent
(int component, int value) Set the value of the specified component of this vector.setFromAddress
(long address) Set the values of this vector by reading 4 integer values from off-heap memory, starting at the given address.sub
(int x, int y, int z, int w) Subtract(x, y, z, w)
from this.Subtract(x, y, z, w)
from this and store the result indest
.Subtract the supplied vector from this one.Subtract the supplied vector from this one and store the result indest
.toString()
Return a string representation of this vector.toString
(NumberFormat formatter) Return a string representation of this vector by formatting the vector components with the givenNumberFormat
.int
w()
void
int
x()
int
y()
int
z()
zero()
Set all components to zero.
-
Field Details
-
x
public int xThe x component of the vector. -
y
public int yThe y component of the vector. -
z
public int zThe z component of the vector. -
w
public int wThe w component of the vector.
-
-
Constructor Details
-
Vector4i
public Vector4i()Create a newVector4i
of(0, 0, 0, 1)
. -
Vector4i
Create a newVector4i
with the same values asv
.- Parameters:
v
- theVector4ic
to copy the values from
-
Vector4i
- Parameters:
v
- theVector3ic
w
- the w component
-
Vector4i
- Parameters:
v
- theVector2ic
z
- the z componentw
- the w component
-
Vector4i
Create a newVector4i
with the first three components from the givenv
and the givenw
and round using the givenRoundingMode
.- Parameters:
v
- theVector3fc
to copy the values fromw
- the w componentmode
- theRoundingMode
to use
-
Vector4i
Create a newVector4i
and initialize its components to the rounded value of the given vector.- Parameters:
v
- theVector4fc
to round and copy the values frommode
- theRoundingMode
to use
-
Vector4i
Create a newVector4i
and initialize its components to the rounded value of the given vector.- Parameters:
v
- theVector4dc
to round and copy the values frommode
- theRoundingMode
to use
-
Vector4i
public Vector4i(int s) Create a newVector4i
and initialize all four components with the given value.- Parameters:
s
- scalar value of all four components
-
Vector4i
public Vector4i(int x, int y, int z, int w) Create a newVector4i
with the given component values.- Parameters:
x
- the x componenty
- the y componentz
- the z componentw
- the w component
-
Vector4i
public Vector4i(int[] xyzw) Create a newVector4i
and initialize its four components from the first four elements of the given array.- Parameters:
xyzw
- the array containing at least four elements
-
Vector4i
Create a newVector4i
and read this vector from the suppliedByteBuffer
at the current bufferposition
.This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which the vector is read, use
Vector4i(int, ByteBuffer)
, taking the absolute position as parameter.- Parameters:
buffer
- values will be read inx, y, z, w
order- See Also:
-
Vector4i
Create a newVector4i
and read this vector from the suppliedByteBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- values will be read inx, y, z, w
order
-
Vector4i
Create a newVector4i
and read this vector from the suppliedIntBuffer
at the current bufferposition
.This method will not increment the position of the given IntBuffer.
In order to specify the offset into the IntBuffer at which the vector is read, use
Vector4i(int, IntBuffer)
, taking the absolute position as parameter.- Parameters:
buffer
- values will be read inx, y, z, w
order- See Also:
-
Vector4i
Create a newVector4i
and read this vector from the suppliedIntBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given IntBuffer.
- Parameters:
index
- the absolute position into the IntBufferbuffer
- values will be read inx, y, z, w
order
-
-
Method Details
-
x
public int x() -
y
public int y() -
z
public int z() -
w
public int w() -
set
Set thisVector4i
to the values of the givenv
.- Parameters:
v
- the vector whose values will be copied into this- Returns:
- this
-
set
Set thisVector4i
to the values of v usingRoundingMode.TRUNCATE
rounding.Note that due to the given vector
v
storing the components in double-precision, there is the possibility to lose precision.- Parameters:
v
- the vector to copy from- Returns:
- this
-
set
Set thisVector4i
to the values of v using the givenRoundingMode
.Note that due to the given vector
v
storing the components in double-precision, there is the possibility to lose precision.- Parameters:
v
- the vector to copy frommode
- theRoundingMode
to use- Returns:
- this
-
set
Set thisVector4i
to the values of v using the givenRoundingMode
.Note that due to the given vector
v
storing the components in double-precision, there is the possibility to lose precision.- Parameters:
v
- the vector to copy frommode
- theRoundingMode
to use- Returns:
- this
-
set
Set the first three components of this to the components ofv
and the last component tow
.- Parameters:
v
- theVector3ic
to copyw
- the w component- Returns:
- this
-
set
Sets the first two components of this to the components of givenv
and last two components to the givenz
, andw
.- Parameters:
v
- theVector2ic
z
- the z componentw
- the w component- Returns:
- this
-
set
Set the x, y, z, and w components to the supplied value.- Parameters:
s
- the value of all four components- Returns:
- this
-
set
Set the x, y, z, and w components to the supplied values.- Parameters:
x
- the x componenty
- the y componentz
- the z componentw
- the w component- Returns:
- this
-
set
Set the four components of this vector to the first four elements of the given array.- Parameters:
xyzw
- the array containing at least four elements- Returns:
- this
-
set
Read this vector from the suppliedByteBuffer
at the current bufferposition
.This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which the vector is read, use
set(int, ByteBuffer)
, taking the absolute position as parameter.- Parameters:
buffer
- values will be read inx, y, z, w
order- Returns:
- this
- See Also:
-
set
Read this vector from the suppliedByteBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
- Parameters:
index
- the absolute position into the ByteBufferbuffer
- values will be read inx, y, z, w
order- Returns:
- this
-
set
Read this vector from the suppliedIntBuffer
at the current bufferposition
.This method will not increment the position of the given IntBuffer.
In order to specify the offset into the IntBuffer at which the vector is read, use
set(int, IntBuffer)
, taking the absolute position as parameter.- Parameters:
buffer
- values will be read inx, y, z, w
order- Returns:
- this
- See Also:
-
set
Read this vector from the suppliedIntBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given IntBuffer.
- Parameters:
index
- the absolute position into the IntBufferbuffer
- values will be read inx, y, z, w
order- Returns:
- this
-
setFromAddress
Set the values of this vector by reading 4 integer values from off-heap memory, starting at the given address.This method will throw an
UnsupportedOperationException
when JOML is used with `-Djoml.nounsafe`.This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.
- Parameters:
address
- the off-heap memory address to read the vector values from- Returns:
- this
-
get
Description copied from interface:Vector4ic
Get the value of the specified component of this vector.- Specified by:
get
in interfaceVector4ic
- Parameters:
component
- the component, within[0..3]
- Returns:
- the value
- Throws:
IllegalArgumentException
- ifcomponent
is not within[0..3]
-
maxComponent
public int maxComponent()Description copied from interface:Vector4ic
Determine the component with the biggest absolute value.- Specified by:
maxComponent
in interfaceVector4ic
- Returns:
- the component index, within
[0..3]
-
minComponent
public int minComponent()Description copied from interface:Vector4ic
Determine the component with the smallest (towards zero) absolute value.- Specified by:
minComponent
in interfaceVector4ic
- Returns:
- the component index, within
[0..3]
-
setComponent
Set the value of the specified component of this vector.- Parameters:
component
- the component whose value to set, within[0..3]
value
- the value to set- Returns:
- this
- Throws:
IllegalArgumentException
- ifcomponent
is not within[0..3]
-
get
Description copied from interface:Vector4ic
Store this vector into the suppliedIntBuffer
at the current bufferposition
.This method will not increment the position of the given IntBuffer.
In order to specify the offset into the IntBuffer at which the vector is stored, use
Vector4ic.get(int, IntBuffer)
, taking the absolute position as parameter. -
get
Description copied from interface:Vector4ic
Store this vector into the suppliedIntBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given IntBuffer.
-
get
Description copied from interface:Vector4ic
Store this vector into the suppliedByteBuffer
at the current bufferposition
.This method will not increment the position of the given ByteBuffer.
In order to specify the offset into the ByteBuffer at which the vector is stored, use
Vector4ic.get(int, ByteBuffer)
, taking the absolute position as parameter. -
get
Description copied from interface:Vector4ic
Store this vector into the suppliedByteBuffer
starting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
-
getToAddress
Description copied from interface:Vector4ic
Store this vector at the given off-heap memory address.This method will throw an
UnsupportedOperationException
when JOML is used with `-Djoml.nounsafe`.This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.
- Specified by:
getToAddress
in interfaceVector4ic
- Parameters:
address
- the off-heap address where to store this vector- Returns:
- this
-
sub
Subtract the supplied vector from this one.- Parameters:
v
- the vector to subtract- Returns:
- this
-
sub
Subtract(x, y, z, w)
from this.- Parameters:
x
- the x component to subtracty
- the y component to subtractz
- the z component to subtractw
- the w component to subtract- Returns:
- this
-
sub
Description copied from interface:Vector4ic
Subtract the supplied vector from this one and store the result indest
. -
sub
Description copied from interface:Vector4ic
Subtract(x, y, z, w)
from this and store the result indest
. -
add
Add the supplied vector to this one.- Parameters:
v
- the vector to add- Returns:
- this
-
add
Description copied from interface:Vector4ic
Add the supplied vector to this one and store the result indest
. -
add
Increment the components of this vector by the given values.- Parameters:
x
- the x component to addy
- the y component to addz
- the z component to addw
- the w component to add- Returns:
- this
-
add
Description copied from interface:Vector4ic
Increment the components of this vector by the given values and store the result indest
. -
mul
Multiply this Vector4i component-wise by another Vector4i.- Parameters:
v
- the other vector- Returns:
- this
-
mul
Description copied from interface:Vector4ic
Multiply this Vector4i component-wise by another Vector4ic and store the result indest
. -
div
Divide this Vector4i component-wise by another Vector4i.- Parameters:
v
- the vector to divide by- Returns:
- this
-
div
Description copied from interface:Vector4ic
Divide this Vector4i component-wise by another Vector4ic and store the result indest
. -
mul
Multiply all components of thisVector4i
by the given scalar value.- Parameters:
scalar
- the scalar to multiply by- Returns:
- this
-
mul
Description copied from interface:Vector4ic
Multiply all components of thisVector4i
by the given scalar value and store the result indest
. -
div
Divide all components of thisVector3i
by the given scalar value.- Parameters:
scalar
- the scalar to divide by- Returns:
- this
-
div
Description copied from interface:Vector4ic
Divide all components of thisVector4i
by the given scalar value and store the result indest
. -
div
Divide all components of thisVector4i
by the given scalar value.- Parameters:
scalar
- the scalar to divide by- Returns:
- this
-
div
Description copied from interface:Vector4ic
Divide all components of thisVector4i
by the given scalar value and store the result indest
. -
lengthSquared
public long lengthSquared()Description copied from interface:Vector4ic
Return the length squared of this vector.- Specified by:
lengthSquared
in interfaceVector4ic
- Returns:
- the length squared
-
lengthSquared
public static long lengthSquared(int x, int y, int z, int w) Get the length squared of a 4-dimensional single-precision vector.- Parameters:
x
- The vector's x componenty
- The vector's y componentz
- The vector's z componentw
- The vector's w component- Returns:
- the length squared of the given vector
-
length
public double length()Description copied from interface:Vector4ic
Return the length of this vector. -
length
public static double length(int x, int y, int z, int w) Get the length of a 4-dimensional single-precision vector.- Parameters:
x
- The vector's x componenty
- The vector's y componentz
- The vector's z componentw
- The vector's w component- Returns:
- the length squared of the given vector
-
distance
Description copied from interface:Vector4ic
Return the distance between this Vector andv
. -
distance
public double distance(int x, int y, int z, int w) Description copied from interface:Vector4ic
Return the distance betweenthis
vector and(x, y, z, w)
. -
gridDistance
Description copied from interface:Vector4ic
Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y)
.- Specified by:
gridDistance
in interfaceVector4ic
- Parameters:
v
- the other vector- Returns:
- the grid distance
-
gridDistance
public long gridDistance(int x, int y, int z, int w) Description copied from interface:Vector4ic
Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y)
.- Specified by:
gridDistance
in interfaceVector4ic
- Parameters:
x
- the x component of the other vectory
- the y component of the other vectorz
- the z component of the other vectorw
- the w component of the other vector- Returns:
- the grid distance
-
distanceSquared
Description copied from interface:Vector4ic
Return the square of the distance between this vector andv
.- Specified by:
distanceSquared
in interfaceVector4ic
- Parameters:
v
- the other vector- Returns:
- the squared of the distance
-
distanceSquared
public int distanceSquared(int x, int y, int z, int w) Description copied from interface:Vector4ic
Return the square of the distance betweenthis
vector and(x, y, z, w)
.- Specified by:
distanceSquared
in interfaceVector4ic
- Parameters:
x
- the x component of the other vectory
- the y component of the other vectorz
- the z component of the other vectorw
- the w component of the other vector- Returns:
- the square of the distance
-
distance
public static double distance(int x1, int y1, int z1, int w1, int x2, int y2, int z2, int w2) Return the distance between(x1, y1, z1, w1)
and(x2, y2, z2, w2)
.- Parameters:
x1
- the x component of the first vectory1
- the y component of the first vectorz1
- the z component of the first vectorw1
- the w component of the first vectorx2
- the x component of the second vectory2
- the y component of the second vectorz2
- the z component of the second vectorw2
- the 2 component of the second vector- Returns:
- the euclidean distance
-
distanceSquared
public static long distanceSquared(int x1, int y1, int z1, int w1, int x2, int y2, int z2, int w2) Return the squared distance between(x1, y1, z1, w1)
and(x2, y2, z2, w2)
.- Parameters:
x1
- the x component of the first vectory1
- the y component of the first vectorz1
- the z component of the first vectorw1
- the w component of the first vectorx2
- the x component of the second vectory2
- the y component of the second vectorz2
- the z component of the second vectorw2
- the w component of the second vector- Returns:
- the euclidean distance squared
-
dot
Description copied from interface:Vector4ic
Compute the dot product (inner product) of this vector andv
. -
zero
Set all components to zero.- Returns:
- this
-
negate
Negate this vector.- Returns:
- this
-
negate
Description copied from interface:Vector4ic
Negate this vector and store the result indest
. -
toString
Return a string representation of this vector.This method creates a new
DecimalFormat
on every invocation with the format string "0.000E0;-
". -
toString
Return a string representation of this vector by formatting the vector components with the givenNumberFormat
.- Parameters:
formatter
- theNumberFormat
used to format the vector components with- Returns:
- the string representation
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
min
Set the components of this vector to be the component-wise minimum of this and the other vector.- Parameters:
v
- the other vector- Returns:
- this
-
min
Description copied from interface:Vector4ic
Set the components ofdest
to be the component-wise minimum of this and the other vector. -
max
Set the components of this vector to be the component-wise maximum of this and the other vector.- Parameters:
v
- the other vector- Returns:
- this
-
max
Description copied from interface:Vector4ic
Set the components ofdest
to be the component-wise maximum of this and the other vector. -
absolute
Compute the absolute of each of this vector's components.- Returns:
- this
-
absolute
Description copied from interface:Vector4ic
Compute the absolute of each of this vector's components and store the result intodest
. -
hashCode
public int hashCode() -
equals
-
equals
public boolean equals(int x, int y, int z, int w) Description copied from interface:Vector4ic
Compare the vector components ofthis
vector with the given(x, y, z, w)
and return whether all of them are equal. -
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-