Package com.sk89q.worldedit.math
Record Class BlockVector2
java.lang.Object
java.lang.Record
com.sk89q.worldedit.math.BlockVector2
An immutable 2-dimensional vector.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Comparator<BlockVector2>
A comparator for BlockVector2ds that orders the vectors by rows, with x as the column and z as the row.static final BlockVector2
static final BlockVector2
static final BlockVector2
static final BlockVector2
-
Constructor Summary
ConstructorDescriptionBlockVector2
(int x, int z) Creates an instance of aBlockVector2
record class. -
Method Summary
Modifier and TypeMethodDescriptionabs()
Returns a vector with the absolute values of the components of this vector.add
(int x, int z) Add another vector to this vector and return the result as a new vector.add
(BlockVector2 other) Add another vector to this vector and return the result as a new vector.add
(BlockVector2... others) Add a list of vectors to this vector and return the result as a new vector.static BlockVector2
at
(double x, double z) static BlockVector2
at
(int x, int z) ceil()
Rounds all components up.boolean
containedWithin
(BlockVector2 min, BlockVector2 max) Checks to see if a vector is contained with another.double
distance
(BlockVector2 other) Get the distance between this vector and another vector.int
distanceSq
(BlockVector2 other) Get the distance between this vector and another vector, squared.divide
(int n) Perform scalar division and return a new vector.divide
(int x, int z) Divide this vector by another vector on each component.divide
(BlockVector2 other) Divide this vector by another vector on each component.int
dot
(BlockVector2 other) Gets the dot product of this and another vector.final boolean
Indicates whether some other object is "equal to" this one.floor()
Floors the values of all components.int
Deprecated, for removal: This API element is subject to removal in a future version.int
Deprecated, for removal: This API element is subject to removal in a future version.usez()
insteadGets the maximum components of two vectors.Gets the minimum components of two vectors.int
getX()
Deprecated, for removal: This API element is subject to removal in a future version.usex()
insteadint
getZ()
Deprecated, for removal: This API element is subject to removal in a future version.usez()
insteadfinal int
hashCode()
Returns a hash code value for this object.double
length()
Get the length of the vector.int
lengthSq()
Get the length, squared, of the vector.multiply
(int n) Perform scalar multiplication and return a new vector.multiply
(int x, int z) Multiply this vector by another vector on each component.multiply
(BlockVector2 other) Multiply this vector by another vector on each component.multiply
(BlockVector2... others) Multiply this vector by zero or more vectors on each component.Get the normalized vector, which is the vector divided by its length, as a new vector.round()
Rounds all components to the closest integer.shr
(int n) Shift all components right byn
.shr
(int x, int z) Shift all components right.subtract
(int x, int z) Subtract another vector from this vector and return the result as a new vector.subtract
(BlockVector2 other) Subtract another vector from this vector and return the result as a new vector.subtract
(BlockVector2... others) Subtract a list of vectors from this vector and return the result as a new vector.Creates a 3D vector by adding a zero Y component to this vector.toBlockVector3
(int y) Creates a 3D vector by adding the specified Y component to this vector.Returns a string representation that is supported by the parser.toString()
Returns a string representation of this record class.Creates a 3D vector by adding a zero Y component to this vector.toVector3
(double y) Creates a 3D vector by adding the specified Y component to this vector.transform2D
(double angle, double aboutX, double aboutZ, double translateX, double translateZ) Perform a 2D transformation on this vector and return a new one.withX
(int x) Set the X coordinate.withZ
(int z) Set the Z coordinate.int
x()
Returns the value of thex
record component.int
z()
Returns the value of thez
record component.
-
Field Details
-
ZERO
-
UNIT_X
-
UNIT_Z
-
ONE
-
COMPARING_GRID_ARRANGEMENT
A comparator for BlockVector2ds that orders the vectors by rows, with x as the column and z as the row.For example, if x is the horizontal axis and z is the vertical axis, it sorts like so:
0123 4567 90ab cdef
-
-
Constructor Details
-
BlockVector2
public BlockVector2(int x, int z) Creates an instance of aBlockVector2
record class.- Parameters:
x
- the value for thex
record componentz
- the value for thez
record component
-
-
Method Details
-
at
-
at
-
getX
Deprecated, for removal: This API element is subject to removal in a future version.usex()
insteadGet the X coordinate.- Returns:
- the x coordinate
-
getBlockX
Deprecated, for removal: This API element is subject to removal in a future version.usex()
insteadGet the X coordinate.- Returns:
- the x coordinate
-
withX
Set the X coordinate.- Parameters:
x
- the new X- Returns:
- a new vector
-
getZ
Deprecated, for removal: This API element is subject to removal in a future version.usez()
insteadGet the Z coordinate.- Returns:
- the z coordinate
-
getBlockZ
Deprecated, for removal: This API element is subject to removal in a future version.usez()
insteadGet the Z coordinate.- Returns:
- the z coordinate
-
withZ
Set the Z coordinate.- Parameters:
z
- the new Z- Returns:
- a new vector
-
add
Add another vector to this vector and return the result as a new vector.- Parameters:
other
- the other vector- Returns:
- a new vector
-
add
Add another vector to this vector and return the result as a new vector.- Parameters:
x
- the value to addz
- the value to add- Returns:
- a new vector
-
add
Add a list of vectors to this vector and return the result as a new vector.- Parameters:
others
- an array of vectors- Returns:
- a new vector
-
subtract
Subtract another vector from this vector and return the result as a new vector.- Parameters:
other
- the other vector- Returns:
- a new vector
-
subtract
Subtract another vector from this vector and return the result as a new vector.- Parameters:
x
- the value to subtractz
- the value to subtract- Returns:
- a new vector
-
subtract
Subtract a list of vectors from this vector and return the result as a new vector.- Parameters:
others
- an array of vectors- Returns:
- a new vector
-
multiply
Multiply this vector by another vector on each component.- Parameters:
other
- the other vector- Returns:
- a new vector
-
multiply
Multiply this vector by another vector on each component.- Parameters:
x
- the value to multiplyz
- the value to multiply- Returns:
- a new vector
-
multiply
Multiply this vector by zero or more vectors on each component.- Parameters:
others
- an array of vectors- Returns:
- a new vector
-
multiply
Perform scalar multiplication and return a new vector.- Parameters:
n
- the value to multiply- Returns:
- a new vector
-
divide
Divide this vector by another vector on each component.- Parameters:
other
- the other vector- Returns:
- a new vector
-
divide
Divide this vector by another vector on each component.- Parameters:
x
- the value to divide byz
- the value to divide by- Returns:
- a new vector
-
divide
Perform scalar division and return a new vector.- Parameters:
n
- the value to divide by- Returns:
- a new vector
-
shr
Shift all components right.- Parameters:
x
- the value to shift x byz
- the value to shift z by- Returns:
- a new vector
-
shr
Shift all components right byn
.- Parameters:
n
- the value to shift by- Returns:
- a new vector
-
length
public double length()Get the length of the vector.- Returns:
- length
-
lengthSq
public int lengthSq()Get the length, squared, of the vector.- Returns:
- length, squared
-
distance
Get the distance between this vector and another vector.- Parameters:
other
- the other vector- Returns:
- distance
-
distanceSq
Get the distance between this vector and another vector, squared.- Parameters:
other
- the other vector- Returns:
- distance
-
normalize
Get the normalized vector, which is the vector divided by its length, as a new vector.- Returns:
- a new vector
-
dot
Gets the dot product of this and another vector.- Parameters:
other
- the other vector- Returns:
- the dot product of this and the other vector
-
containedWithin
Checks to see if a vector is contained with another.- Parameters:
min
- the minimum point (X, Y, and Z are the lowest)max
- the maximum point (X, Y, and Z are the lowest)- Returns:
- true if the vector is contained
-
floor
Floors the values of all components.- Returns:
- a new vector
-
ceil
Rounds all components up.- Returns:
- a new vector
-
round
Rounds all components to the closest integer.Components < 0.5 are rounded down, otherwise up.
- Returns:
- a new vector
-
abs
Returns a vector with the absolute values of the components of this vector.- Returns:
- a new vector
-
transform2D
public BlockVector2 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) Perform a 2D transformation on this vector and return a new one.- Parameters:
angle
- in degreesaboutX
- about which x coordinate to rotateaboutZ
- about which z coordinate to rotatetranslateX
- what to add after rotationtranslateZ
- what to add after rotation- Returns:
- a new vector
- See Also:
-
getMinimum
Gets the minimum components of two vectors.- Parameters:
v2
- the second vector- Returns:
- minimum
-
getMaximum
Gets the maximum components of two vectors.- Parameters:
v2
- the second vector- Returns:
- maximum
-
toVector2
-
toVector3
Creates a 3D vector by adding a zero Y component to this vector.- Returns:
- a new vector
-
toVector3
Creates a 3D vector by adding the specified Y component to this vector.- Parameters:
y
- the Y component- Returns:
- a new vector
-
toBlockVector3
Creates a 3D vector by adding a zero Y component to this vector.- Returns:
- a new vector
-
toBlockVector3
Creates a 3D vector by adding the specified Y component to this vector.- Parameters:
y
- the Y component- Returns:
- a new vector
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
toParserString
Returns a string representation that is supported by the parser.- Returns:
- string
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='. -
x
public int x()Returns the value of thex
record component.- Returns:
- the value of the
x
record component
-
z
public int z()Returns the value of thez
record component.- Returns:
- the value of the
z
record component
-
x()
instead