Package net.risingworld.api.utils
Klasse Vector2i
java.lang.Object
net.risingworld.api.utils.Vector2i
- Alle implementierten Schnittstellen:
Serializable
A Vector which holds two int values: X and Y
It can be used to represent a two dimensional value, like a horizontal integer position.
It can be used to represent a two dimensional value, like a horizontal integer position.
- Siehe auch:
-
Feldübersicht
-
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungaddLocal
(int addX, int addY) Adds the provided values to the values of this vector.Adds the values of the provided vector to the values of this vector.float
angleBetween
(Vector2i other) Gets the angle between this vector and another vector.
Please note: Both vectors need to be unit vectors (normalized).copy()
Creates a copy of this Vector.float
distance
(int x, int y) Gets the distance between this vector and the provided coordinates.float
Gets the distance between this vector and another vector.float
distanceSquared
(int x, int y) Gets the squared distance between this vector and the provided coordinates.float
distanceSquared
(Vector2i other) Gets the squared distance between this vector and another Vector2i.divideLocal
(int scalar) divideLocal
(Vector2i other) float
dot
(int x, int y) Gets the dot product of this vector with the provided coordinates.float
Gets the dot product of this vector with the provided vector.boolean
equals
(int x, int y) boolean
Gets whether or not this vector is equal to another object.int
getX()
Returns the x value of this vector.int
getY()
Returns the y value of this vector.int
hashCode()
Gets a unique* hash code for this vector, based on its values.boolean
isOrthogonal
(int x, int y) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).boolean
isOrthogonal
(Vector2i other) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).boolean
Checks if this vector is a unit vector.float
length()
Gets the length of this vector.float
Gets the squared length of this vector.multLocal
(int scalar) Multiplies the values of this vector with the provided scalar.multLocal
(int multX, int multY) Multiplies the values of this vector with the provided values.Multiplies the values of this vector with the values of the provided vector.Negates all values of this vector.Normalizes this vector (i.e turn it into a unit vector).set
(int x, int y) Sets the x, y and z values of this vector to the provided int values.Sets the x and y values of this vector to the values of the provided vector.setX
(int x) Sets the x value of this vector.setY
(int y) Sets the y value of this vector.subtractLocal
(int subtractX, int subtractY) Subtracts the provided values from the values of this vector.subtractLocal
(Vector2i other) Subtracts the values of the provided vector from the values of this vector.toString()
Gets a String representation of this vector, for example(42, -24)
zero()
Sets all values to 0 (same setset(0, 0);
).
-
Felddetails
-
ZERO
A vector with values 0, 0 -
ONE
A vector with values 1, 1 -
x
public int xThe integer X value of this vector -
y
public int yThe integer Y value of this vector
-
-
Konstruktordetails
-
Vector2i
public Vector2i()Creates a new Vector2f with default values 0, 0. -
Vector2i
public Vector2i(int x, int y) Creates a new Vector2i with the provided int values.- Parameter:
x
- the x value of the vector.y
- the y value of the vector.
-
Vector2i
Creates a new Vector2i and copies the x and y values from the provided vector.- Parameter:
copy
- the Vector2i to copy.
-
-
Methodendetails
-
copy
Creates a copy of this Vector.- Gibt zurück:
- a new instance with the same values of this Vector.
-
set
Sets the x and y values of this vector to the values of the provided vector.- Parameter:
vector
- the Vector2i to copy.- Gibt zurück:
- this vector.
-
set
Sets the x, y and z values of this vector to the provided int values.- Parameter:
x
- the x value.y
- the y value.- Gibt zurück:
- this vector.
-
setX
Sets the x value of this vector.- Parameter:
x
- the new x value.- Gibt zurück:
- this vector.
-
setY
Sets the y value of this vector.- Parameter:
y
- the new y value.- Gibt zurück:
- this vector.
-
getX
public int getX()Returns the x value of this vector.- Gibt zurück:
- the current x value.
-
getY
public int getY()Returns the y value of this vector.- Gibt zurück:
- the current y value.
-
dot
Gets the dot product of this vector with the provided vector.- Parameter:
other
- the vector to calculate the dot product with.- Gibt zurück:
- the resulting dot product.
-
dot
public float dot(int x, int y) Gets the dot product of this vector with the provided coordinates.- Parameter:
x
- the x coordinate.y
- the y coordinate.- Gibt zurück:
- the resulting dot product.
-
length
public float length()Gets the length of this vector.- Gibt zurück:
- the length of this vector.
- Siehe auch:
-
lengthSquared
public float lengthSquared()Gets the squared length of this vector. Use this function to avoid calculating the squareroot.- Gibt zurück:
- the squared length of this vector.
- Siehe auch:
-
distance
Gets the distance between this vector and another vector.- Parameter:
other
- the other vector.- Gibt zurück:
- the distance between this vector and another vector.
- Siehe auch:
-
distance
public float distance(int x, int y) Gets the distance between this vector and the provided coordinates.- Parameter:
x
- the other x coordinate.y
- the other y coordinate.- Gibt zurück:
- the distance between this vector and the provided coordinates.
- Siehe auch:
-
distanceSquared
Gets the squared distance between this vector and another Vector2i. Use this function to avoid calculating the squareroot.- Parameter:
other
- the other Vector2i.- Gibt zurück:
- the squared distance between this vector and the provided Vector2i.
-
distanceSquared
public float distanceSquared(int x, int y) Gets the squared distance between this vector and the provided coordinates. Use this function to avoid calculating the squareroot.- Parameter:
x
- the other x coordinate.y
- the other y coordinate.- Gibt zurück:
- the squared distance between this vector and the provided coordinates.
-
addLocal
Adds the values of the provided vector to the values of this vector.- Parameter:
other
- the vector to add.- Gibt zurück:
- this vector.
-
addLocal
Adds the provided values to the values of this vector.- Parameter:
addX
- the x value to add.addY
- the y value to add.- Gibt zurück:
- this vector.
-
subtractLocal
Subtracts the values of the provided vector from the values of this vector.- Parameter:
other
- the vector to subtract.- Gibt zurück:
- this vector.
-
subtractLocal
Subtracts the provided values from the values of this vector.- Parameter:
subtractX
- the x value to subtract.subtractY
- the y value to subtract.- Gibt zurück:
- this vector.
-
multLocal
Multiplies the values of this vector with the provided scalar.- Parameter:
scalar
- the value to multiply this vector by.- Gibt zurück:
- this vector.
-
multLocal
Multiplies the values of this vector with the values of the provided vector.- Parameter:
other
- the vector to multiply.- Gibt zurück:
- this vector.
-
multLocal
Multiplies the values of this vector with the provided values.- Parameter:
multX
- the x value to multiply the x coordinate of this vector by.multY
- the y value to multiply the y coordinate of this vector by.- Gibt zurück:
- this vector.
-
divideLocal
-
divideLocal
-
negateLocal
Negates all values of this vector.- Gibt zurück:
- this vector.
-
normalizeLocal
Normalizes this vector (i.e turn it into a unit vector).- Gibt zurück:
- this vector (normalized).
-
angleBetween
Gets the angle between this vector and another vector.
Please note: Both vectors need to be unit vectors (normalized).- Parameter:
other
- the other vector (unit vector).- Gibt zurück:
- the angle in degrees.
-
zero
Sets all values to 0 (same setset(0, 0);
).- Gibt zurück:
- this vector.
-
isUnitVector
public boolean isUnitVector()Checks if this vector is a unit vector.- Gibt zurück:
- true if this is a unit vector, false if not.
-
isOrthogonal
Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).- Parameter:
other
- the other vector.- Gibt zurück:
- true if this vector is orthogonal to the other vector, false if not.
-
isOrthogonal
public boolean isOrthogonal(int x, int y) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).- Parameter:
x
- the x coordinate of the other vector.y
- the y coordinate of the other vector.- Gibt zurück:
- true if this vector is orthogonal to the other vector, false if not.
-
equals
Gets whether or not this vector is equal to another object. This function returns true, if the other object is aVector2i
and if it has exactly the same x and y values. -
equals
public boolean equals(int x, int y) -
hashCode
public int hashCode()Gets a unique* hash code for this vector, based on its values. If two vectors have the same x and y values, they will return the same hash code.
* Please keep in mind that the uniqueness is not fully reliable. There is always a small chance that collisions occur (i.e two completely different vectors return the same hash code). But usually the reliability is sufficient. -
toString
Gets a String representation of this vector, for example(42, -24)
-