Package net.risingworld.api.utils
Class Vector2i
java.lang.Object
net.risingworld.api.utils.Vector2i
- All Implemented Interfaces:
- 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.
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionaddLocal(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.floatangleBetween(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.floatdistance(int x, int y) Gets the distance between this vector and the provided coordinates.floatGets the distance between this vector and another vector.floatdistanceSquared(int x, int y) Gets the squared distance between this vector and the provided coordinates.floatdistanceSquared(Vector2i other) Gets the squared distance between this vector and another Vector2i.divideLocal(int scalar) divideLocal(Vector2i other) floatdot(int x, int y) Gets the dot product of this vector with the provided coordinates.floatGets the dot product of this vector with the provided vector.booleanequals(int x, int y) booleanGets whether or not this vector is equal to another object.intgetX()Returns the x value of this vector.intgetY()Returns the y value of this vector.inthashCode()Gets a unique* hash code for this vector, based on its values.booleanisOrthogonal(int x, int y) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).booleanisOrthogonal(Vector2i other) Checks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).booleanChecks if this vector is a unit vector.floatlength()Gets the length of this vector.floatGets 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);).
- 
Field Details- 
ZEROA vector with values 0, 0
- 
ONEA vector with values 1, 1
- 
xpublic int xThe integer X value of this vector
- 
ypublic int yThe integer Y value of this vector
 
- 
- 
Constructor Details- 
Vector2ipublic Vector2i()Creates a new Vector2f with default values 0, 0.
- 
Vector2ipublic Vector2i(int x, int y) Creates a new Vector2i with the provided int values.- Parameters:
- x- the x value of the vector.
- y- the y value of the vector.
 
- 
Vector2iCreates a new Vector2i and copies the x and y values from the provided vector.- Parameters:
- copy- the Vector2i to copy.
 
 
- 
- 
Method Details- 
copyCreates a copy of this Vector.- Returns:
- a new instance with the same values of this Vector.
 
- 
setSets the x and y values of this vector to the values of the provided vector.- Parameters:
- vector- the Vector2i to copy.
- Returns:
- this vector.
 
- 
setSets the x, y and z values of this vector to the provided int values.- Parameters:
- x- the x value.
- y- the y value.
- Returns:
- this vector.
 
- 
setXSets the x value of this vector.- Parameters:
- x- the new x value.
- Returns:
- this vector.
 
- 
setYSets the y value of this vector.- Parameters:
- y- the new y value.
- Returns:
- this vector.
 
- 
getXpublic int getX()Returns the x value of this vector.- Returns:
- the current x value.
 
- 
getYpublic int getY()Returns the y value of this vector.- Returns:
- the current y value.
 
- 
dotGets the dot product of this vector with the provided vector.- Parameters:
- other- the vector to calculate the dot product with.
- Returns:
- the resulting dot product.
 
- 
dotpublic float dot(int x, int y) Gets the dot product of this vector with the provided coordinates.- Parameters:
- x- the x coordinate.
- y- the y coordinate.
- Returns:
- the resulting dot product.
 
- 
lengthpublic float length()Gets the length of this vector.- Returns:
- the length of this vector.
- See Also:
 
- 
lengthSquaredpublic float lengthSquared()Gets the squared length of this vector. Use this function to avoid calculating the squareroot.- Returns:
- the squared length of this vector.
- See Also:
 
- 
distanceGets the distance between this vector and another vector.- Parameters:
- other- the other vector.
- Returns:
- the distance between this vector and another vector.
- See Also:
 
- 
distancepublic float distance(int x, int y) Gets the distance between this vector and the provided coordinates.- Parameters:
- x- the other x coordinate.
- y- the other y coordinate.
- Returns:
- the distance between this vector and the provided coordinates.
- See Also:
 
- 
distanceSquaredGets the squared distance between this vector and another Vector2i. Use this function to avoid calculating the squareroot.- Parameters:
- other- the other Vector2i.
- Returns:
- the squared distance between this vector and the provided Vector2i.
 
- 
distanceSquaredpublic 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.- Parameters:
- x- the other x coordinate.
- y- the other y coordinate.
- Returns:
- the squared distance between this vector and the provided coordinates.
 
- 
addLocalAdds the values of the provided vector to the values of this vector.- Parameters:
- other- the vector to add.
- Returns:
- this vector.
 
- 
addLocalAdds the provided values to the values of this vector.- Parameters:
- addX- the x value to add.
- addY- the y value to add.
- Returns:
- this vector.
 
- 
subtractLocalSubtracts the values of the provided vector from the values of this vector.- Parameters:
- other- the vector to subtract.
- Returns:
- this vector.
 
- 
subtractLocalSubtracts the provided values from the values of this vector.- Parameters:
- subtractX- the x value to subtract.
- subtractY- the y value to subtract.
- Returns:
- this vector.
 
- 
multLocalMultiplies the values of this vector with the provided scalar.- Parameters:
- scalar- the value to multiply this vector by.
- Returns:
- this vector.
 
- 
multLocalMultiplies the values of this vector with the values of the provided vector.- Parameters:
- other- the vector to multiply.
- Returns:
- this vector.
 
- 
multLocalMultiplies the values of this vector with the provided values.- Parameters:
- 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.
- Returns:
- this vector.
 
- 
divideLocal
- 
divideLocal
- 
negateLocalNegates all values of this vector.- Returns:
- this vector.
 
- 
normalizeLocalNormalizes this vector (i.e turn it into a unit vector).- Returns:
- this vector (normalized).
 
- 
angleBetweenGets the angle between this vector and another vector.
 Please note: Both vectors need to be unit vectors (normalized).- Parameters:
- other- the other vector (unit vector).
- Returns:
- the angle in degrees.
 
- 
zeroSets all values to 0 (same setset(0, 0);).- Returns:
- this vector.
 
- 
isUnitVectorpublic boolean isUnitVector()Checks if this vector is a unit vector.- Returns:
- true if this is a unit vector, false if not.
 
- 
isOrthogonalChecks if this vector is orthogonal to another vector (i.e the angle between both vectors is ~ 90° degree).- Parameters:
- other- the other vector.
- Returns:
- true if this vector is orthogonal to the other vector, false if not.
 
- 
isOrthogonalpublic 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).- Parameters:
- x- the x coordinate of the other vector.
- y- the y coordinate of the other vector.
- Returns:
- true if this vector is orthogonal to the other vector, false if not.
 
- 
equalsGets whether or not this vector is equal to another object. This function returns true, if the other object is aVector2iand if it has exactly the same x and y values.
- 
equalspublic boolean equals(int x, int y) 
- 
hashCodepublic 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.
- 
toStringGets a String representation of this vector, for example(42, -24)
 
-