Class Vector2i
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable,Vector2ic
- Author:
- RGreenlees, Kai Burjack, Hans Uhlig
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVector2i()Create a newVector2iand initialize its components to zero.Vector2i(double x, double y, int mode) Create a newVector2iand initialize its component values and round using the givenRoundingMode.Vector2i(float x, float y, int mode) Create a newVector2iand initialize its component values and round using the givenRoundingMode.Vector2i(int s) Create a newVector2iand initialize both of its components with the given value.Vector2i(int[] xy) Create a newVector2iand initialize its two components from the first two elements of the given array.Vector2i(int x, int y) Create a newVector2iand initialize its components to the given values.Vector2i(int index, ByteBuffer buffer) Create a newVector2iand read this vector from the suppliedByteBufferstarting at the specified absolute buffer position/index.Vector2i(ByteBuffer buffer) Create a newVector2iand read this vector from the suppliedByteBufferat the current bufferposition.Create a newVector2iand initialize its components to the rounded value of the given vector.Create a newVector2iand initialize its components to the rounded value of the given vector.Create a newVector2iand initialize its components to the one of the given vector. -
Method Summary
Modifier and TypeMethodDescriptionabsolute()Setthisvector's components to their respective absolute values.Compute the absolute of each of this vector's components and store the result intodest.add(int x, int y) 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.Addvto this vector.Add the supplied vector to this one and store the result indest.clone()doubledistance(int x, int y) Return the distance betweenthisvector and(x, y).static doubledistance(int x1, int y1, int x2, int y2) Return the distance between(x1, y1)and(x2, y2).doubleReturn the distance between this Vector andv.longdistanceSquared(int x, int y) Return the square of the distance betweenthisvector and(x, y).static longdistanceSquared(int x1, int y1, int x2, int y2) Return the squared distance between(x1, y1)and(x2, y2).longReturn the square of the distance between this vector andv.div(float scalar) Divide all components of thisVector2iby the given scalar value.Divide all components of thisVector2iby the given scalar value and store the result indest.div(int scalar) Divide all components of thisVector2iby the given scalar value.Divide all components of thisVector2iby the given scalar value and store the result indest.booleanequals(int x, int y) Compare the vector components ofthisvector with the given(x, y)and return whether all of them are equal.booleanintget(int component) Get the value of the specified component of this vector.get(int index, ByteBuffer buffer) Store this vector into the suppliedByteBufferstarting at the specified absolute buffer position/index.Store this vector into the suppliedIntBufferstarting at the specified absolute buffer position/index.get(ByteBuffer buffer) Store this vector into the suppliedByteBufferat the current bufferposition.getToAddress(long address) Store this vector at the given off-heap memory address.longgridDistance(int x, int y) Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y).longReturn the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y).inthashCode()doublelength()Return the length of this vector.static doublelength(int x, int y) Get the length of a 2-dimensional single-precision vector.longReturn the length squared of this vector.static longlengthSquared(int x, int y) Get the length squared of a 2-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 ofdestto be the component-wise maximum of this and the other vector.intDetermine 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 ofdestto be the component-wise minimum of this and the other vector.intDetermine the component with the smallest (towards zero) absolute value.mul(int scalar) Multiply all components of thisVector2iby the given scalar value.mul(int x, int y) Multiply the components of this vector by the given values.Multiply the components of this vector by the given values and store the result indest.Multiply all components of thisVector2icby the given scalar value and store the result indest.Add the supplied vector by this one.Multiply the supplied vector by this one and store the result indest.negate()Negate this vector.Negate this vector and store the result indest.voidset(int s) Set the x and y components to the supplied value.set(int[] xy) Set the two components of this vector to the first two elements of the given array.set(int x, int y) Set the x and y components to the supplied values.set(int index, ByteBuffer buffer) Read this vector from the suppliedByteBufferstarting at the specified absolute buffer position/index.Read this vector from the suppliedIntBufferstarting at the specified absolute buffer position/index.set(ByteBuffer buffer) Read this vector from the suppliedByteBufferat the current bufferposition.Set thisVector2ito the values of v usingRoundingMode.TRUNCATErounding.Set thisVector2ito the values of v using the givenRoundingMode.Set thisVector2ito the values of v using the givenRoundingMode.Set thisVector2ito the values of v.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 2 integer values from off-heap memory, starting at the given address.sub(int x, int y) Decrement the components of this vector by the given values.Decrement the components of this vector by the given values and store the result indest.Subtract the supplied vector from this one and store the result inthis.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.voidintx()inty()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.
-
-
Constructor Details
-
Vector2i
public Vector2i()Create a newVector2iand initialize its components to zero. -
Vector2i
public Vector2i(int s) Create a newVector2iand initialize both of its components with the given value.- Parameters:
s- the value of both components
-
Vector2i
public Vector2i(int x, int y) Create a newVector2iand initialize its components to the given values.- Parameters:
x- the x componenty- the y component
-
Vector2i
public Vector2i(float x, float y, int mode) Create a newVector2iand initialize its component values and round using the givenRoundingMode.- Parameters:
x- the x componenty- the y componentmode- theRoundingModeto use
-
Vector2i
public Vector2i(double x, double y, int mode) Create a newVector2iand initialize its component values and round using the givenRoundingMode.- Parameters:
x- the x componenty- the y componentmode- theRoundingModeto use
-
Vector2i
Create a newVector2iand initialize its components to the one of the given vector.- Parameters:
v- theVector2icto copy the values from
-
Vector2i
Create a newVector2iand initialize its components to the rounded value of the given vector.- Parameters:
v- theVector2fcto round and copy the values frommode- theRoundingModeto use
-
Vector2i
Create a newVector2iand initialize its components to the rounded value of the given vector.- Parameters:
v- theVector2dcto round and copy the values frommode- theRoundingModeto use
-
Vector2i
public Vector2i(int[] xy) Create a newVector2iand initialize its two components from the first two elements of the given array.- Parameters:
xy- the array containing at least three elements
-
Vector2i
Create a newVector2iand read this vector from the suppliedByteBufferat 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
Vector2i(int, ByteBuffer), taking the absolute position as parameter.- Parameters:
buffer- values will be read inx, yorder- See Also:
-
Vector2i
Create a newVector2iand read this vector from the suppliedByteBufferstarting 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, yorder
-
Vector2i
Create a newVector2iand read this vector from the suppliedIntBufferat 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
Vector2i(int, IntBuffer), taking the absolute position as parameter.- Parameters:
buffer- values will be read inx, yorder- See Also:
-
Vector2i
Create a newVector2iand read this vector from the suppliedIntBufferstarting 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, yorder
-
-
Method Details
-
x
public int x() -
y
public int y() -
set
Set the x and y components to the supplied value.- Parameters:
s- scalar value of both components- Returns:
- this
-
set
Set the x and y components to the supplied values.- Parameters:
x- the x componenty- the y component- Returns:
- this
-
set
Set thisVector2ito the values of v.- Parameters:
v- the vector to copy from- Returns:
- this
-
set
Set thisVector2ito the values of v usingRoundingMode.TRUNCATErounding.Note that due to the given vector
vstoring the components in double-precision, there is the possibility to lose precision.- Parameters:
v- the vector to copy from- Returns:
- this
-
set
Set thisVector2ito the values of v using the givenRoundingMode.Note that due to the given vector
vstoring the components in double-precision, there is the possibility to lose precision.- Parameters:
v- the vector to copy frommode- theRoundingModeto use- Returns:
- this
-
set
Set thisVector2ito the values of v using the givenRoundingMode.Note that due to the given vector
vstoring the components in double-precision, there is the possibility to lose precision.- Parameters:
v- the vector to copy frommode- theRoundingModeto use- Returns:
- this
-
set
Set the two components of this vector to the first two elements of the given array.- Parameters:
xy- the array containing at least two elements- Returns:
- this
-
set
Read this vector from the suppliedByteBufferat 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, yorder- Returns:
- this
- See Also:
-
set
Read this vector from the suppliedByteBufferstarting 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, yorder- Returns:
- this
-
set
Read this vector from the suppliedIntBufferat 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, yorder- Returns:
- this
- See Also:
-
set
Read this vector from the suppliedIntBufferstarting 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, yorder- Returns:
- this
-
setFromAddress
Set the values of this vector by reading 2 integer values from off-heap memory, starting at the given address.This method will throw an
UnsupportedOperationExceptionwhen 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:Vector2icGet the value of the specified component of this vector.- Specified by:
getin interfaceVector2ic- Parameters:
component- the component, within[0..1]- Returns:
- the value
- Throws:
IllegalArgumentException- ifcomponentis not within[0..1]
-
setComponent
Set the value of the specified component of this vector.- Parameters:
component- the component whose value to set, within[0..1]value- the value to set- Returns:
- this
- Throws:
IllegalArgumentException- ifcomponentis not within[0..1]
-
get
Description copied from interface:Vector2icStore this vector into the suppliedByteBufferat 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
Vector2ic.get(int, ByteBuffer), taking the absolute position as parameter. -
get
Description copied from interface:Vector2icStore this vector into the suppliedByteBufferstarting at the specified absolute buffer position/index.This method will not increment the position of the given ByteBuffer.
-
get
Description copied from interface:Vector2icStore this vector into the suppliedIntBufferat 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
Vector2ic.get(int, IntBuffer), taking the absolute position as parameter. -
get
Description copied from interface:Vector2icStore this vector into the suppliedIntBufferstarting at the specified absolute buffer position/index.This method will not increment the position of the given IntBuffer.
-
getToAddress
Description copied from interface:Vector2icStore this vector at the given off-heap memory address.This method will throw an
UnsupportedOperationExceptionwhen 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:
getToAddressin interfaceVector2ic- Parameters:
address- the off-heap address where to store this vector- Returns:
- this
-
sub
Subtract the supplied vector from this one and store the result inthis.- Parameters:
v- the vector to subtract- Returns:
- this
-
sub
Description copied from interface:Vector2icSubtract the supplied vector from this one and store the result indest. -
sub
Decrement the components of this vector by the given values.- Parameters:
x- the x component to subtracty- the y component to subtract- Returns:
- this
-
sub
Description copied from interface:Vector2icDecrement the components of this vector by the given values and store the result indest. -
lengthSquared
public long lengthSquared()Description copied from interface:Vector2icReturn the length squared of this vector.- Specified by:
lengthSquaredin interfaceVector2ic- Returns:
- the length squared
-
lengthSquared
public static long lengthSquared(int x, int y) Get the length squared of a 2-dimensional single-precision vector.- Parameters:
x- The vector's x componenty- The vector's y component- Returns:
- the length squared of the given vector
-
length
public double length()Description copied from interface:Vector2icReturn the length of this vector. -
length
public static double length(int x, int y) Get the length of a 2-dimensional single-precision vector.- Parameters:
x- The vector's x componenty- The vector's y component- Returns:
- the length squared of the given vector
-
distance
Description copied from interface:Vector2icReturn the distance between this Vector andv. -
distance
public double distance(int x, int y) Description copied from interface:Vector2icReturn the distance betweenthisvector and(x, y). -
distanceSquared
Description copied from interface:Vector2icReturn the square of the distance between this vector andv.- Specified by:
distanceSquaredin interfaceVector2ic- Parameters:
v- the other vector- Returns:
- the squared of the distance
-
distanceSquared
public long distanceSquared(int x, int y) Description copied from interface:Vector2icReturn the square of the distance betweenthisvector and(x, y).- Specified by:
distanceSquaredin interfaceVector2ic- Parameters:
x- the x component of the other vectory- the y component of the other vector- Returns:
- the square of the distance
-
gridDistance
Description copied from interface:Vector2icReturn the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y).- Specified by:
gridDistancein interfaceVector2ic- Parameters:
v- the other vector- Returns:
- the grid distance
-
gridDistance
public long gridDistance(int x, int y) Description copied from interface:Vector2icReturn the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance)(x, y).- Specified by:
gridDistancein interfaceVector2ic- Parameters:
x- the x component of the other vectory- the y component of the other vector- Returns:
- the grid distance
-
distance
public static double distance(int x1, int y1, int x2, int y2) Return the distance between(x1, y1)and(x2, y2).- Parameters:
x1- the x component of the first vectory1- the y component of the first vectorx2- the x component of the second vectory2- the y component of the second vector- Returns:
- the euclidean distance
-
distanceSquared
public static long distanceSquared(int x1, int y1, int x2, int y2) Return the squared distance between(x1, y1)and(x2, y2).- Parameters:
x1- the x component of the first vectory1- the y component of the first vectorx2- the x component of the second vectory2- the y component of the second vector- Returns:
- the euclidean distance squared
-
add
Addvto this vector.- Parameters:
v- the vector to add- Returns:
- this
-
add
Description copied from interface:Vector2icAdd 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 add- Returns:
- this
-
add
Description copied from interface:Vector2icIncrement the components of this vector by the given values and store the result indest. -
mul
Multiply all components of thisVector2iby the given scalar value.- Parameters:
scalar- the scalar to multiply this vector by- Returns:
- this
-
mul
Description copied from interface:Vector2icMultiply all components of thisVector2icby the given scalar value and store the result indest. -
mul
Add the supplied vector by this one.- Parameters:
v- the vector to multiply- Returns:
- this
-
mul
Description copied from interface:Vector2icMultiply the supplied vector by this one and store the result indest. -
mul
Multiply the components of this vector by the given values.- Parameters:
x- the x component to multiplyy- the y component to multiply- Returns:
- this
-
mul
Description copied from interface:Vector2icMultiply the components of this vector by the given values and store the result indest. -
div
Divide all components of thisVector2iby the given scalar value.- Parameters:
scalar- the scalar to divide by- Returns:
- a vector holding the result
-
div
Description copied from interface:Vector2icDivide all components of thisVector2iby the given scalar value and store the result indest. -
div
Divide all components of thisVector2iby the given scalar value.- Parameters:
scalar- the scalar to divide by- Returns:
- a vector holding the result
-
div
Description copied from interface:Vector2icDivide all components of thisVector2iby the given scalar value and store the result indest. -
zero
Set all components to zero.- Returns:
- this
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
negate
Negate this vector.- Returns:
- this
-
negate
Description copied from interface:Vector2icNegate this vector and store the result indest. -
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:Vector2icSet the components ofdestto 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:Vector2icSet the components ofdestto be the component-wise maximum of this and the other vector. -
maxComponent
public int maxComponent()Description copied from interface:Vector2icDetermine the component with the biggest absolute value.- Specified by:
maxComponentin interfaceVector2ic- Returns:
- the component index, within
[0..1]
-
minComponent
public int minComponent()Description copied from interface:Vector2icDetermine the component with the smallest (towards zero) absolute value.- Specified by:
minComponentin interfaceVector2ic- Returns:
- the component index, within
[0..1]
-
absolute
Setthisvector's components to their respective absolute values.- Returns:
- this
-
absolute
Description copied from interface:Vector2icCompute 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) Description copied from interface:Vector2icCompare the vector components ofthisvector with the given(x, y)and return whether all of them are equal. -
toString
Return a string representation of this vector.This method creates a new
DecimalFormaton 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- theNumberFormatused to format the vector components with- Returns:
- the string representation
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-