Class BlockVector2

java.lang.Object
com.sk89q.worldedit.math.BlockVector2
Direct Known Subclasses:
MutableBlockVector2

public class BlockVector2 extends Object
An immutable 2-dimensional vector.
  • Field Details

    • ZERO

      public static final BlockVector2 ZERO
    • UNIT_X

      public static final BlockVector2 UNIT_X
    • UNIT_Z

      public static final BlockVector2 UNIT_Z
    • ONE

      public static final BlockVector2 ONE
    • COMPARING_GRID_ARRANGEMENT

      public static final Comparator<BlockVector2> 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
       
    • x

      protected int x
    • z

      protected int z
  • Constructor Details

    • BlockVector2

      protected BlockVector2()
    • BlockVector2

      protected BlockVector2(int x, int z)
      Construct an instance.
      Parameters:
      x - the X coordinate
      z - the Z coordinate
  • Method Details

    • at

      public static BlockVector2 at(double x, double z)
    • at

      public static BlockVector2 at(int x, int z)
    • setComponents

      public MutableBlockVector2 setComponents(int x, int z)
    • mutX

      public MutableBlockVector2 mutX(double x)
    • mutZ

      public MutableBlockVector2 mutZ(double z)
    • mutX

      public MutableBlockVector2 mutX(int x)
    • mutZ

      public MutableBlockVector2 mutZ(int z)
    • getX

      public int getX()
      Get the X coordinate.
      Returns:
      the x coordinate
    • getBlockX

      public int getBlockX()
      Get the X coordinate.
      Returns:
      the x coordinate
    • withX

      public BlockVector2 withX(int x)
      Set the X coordinate.
      Parameters:
      x - the new X
      Returns:
      a new vector
    • getZ

      public int getZ()
      Get the Z coordinate.
      Returns:
      the z coordinate
    • getBlockZ

      public int getBlockZ()
      Get the Z coordinate.
      Returns:
      the z coordinate
    • withZ

      public BlockVector2 withZ(int z)
      Set the Z coordinate.
      Parameters:
      z - the new Z
      Returns:
      a new vector
    • nextPosition

      public MutableBlockVector2 nextPosition()
    • add

      public BlockVector2 add(BlockVector2 other)
      Add another vector to this vector and return the result as a new vector.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • add

      public BlockVector2 add(int x, int z)
      Add another vector to this vector and return the result as a new vector.
      Parameters:
      x - the value to add
      z - the value to add
      Returns:
      a new vector
    • add

      public BlockVector2 add(BlockVector2... others)
      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

      public BlockVector2 subtract(BlockVector2 other)
      Subtract another vector from this vector and return the result as a new vector.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • subtract

      public BlockVector2 subtract(int x, int z)
      Subtract another vector from this vector and return the result as a new vector.
      Parameters:
      x - the value to subtract
      z - the value to subtract
      Returns:
      a new vector
    • subtract

      public BlockVector2 subtract(BlockVector2... others)
      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

      public BlockVector2 multiply(BlockVector2 other)
      Multiply this vector by another vector on each component.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • multiply

      public BlockVector2 multiply(int x, int z)
      Multiply this vector by another vector on each component.
      Parameters:
      x - the value to multiply
      z - the value to multiply
      Returns:
      a new vector
    • multiply

      public BlockVector2 multiply(BlockVector2... others)
      Multiply this vector by zero or more vectors on each component.
      Parameters:
      others - an array of vectors
      Returns:
      a new vector
    • multiply

      public BlockVector2 multiply(int n)
      Perform scalar multiplication and return a new vector.
      Parameters:
      n - the value to multiply
      Returns:
      a new vector
    • divide

      public BlockVector2 divide(BlockVector2 other)
      Divide this vector by another vector on each component.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • divide

      public BlockVector2 divide(int x, int z)
      Divide this vector by another vector on each component.
      Parameters:
      x - the value to divide by
      z - the value to divide by
      Returns:
      a new vector
    • divide

      public BlockVector2 divide(int n)
      Perform scalar division and return a new vector.
      Parameters:
      n - the value to divide by
      Returns:
      a new vector
    • shr

      public BlockVector2 shr(int x, int z)
      Shift all components right.
      Parameters:
      x - the value to shift x by
      z - the value to shift z by
      Returns:
      a new vector
    • shr

      public BlockVector2 shr(int n)
      Shift all components right by n.
      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

      public double distance(BlockVector2 other)
      Get the distance between this vector and another vector.
      Parameters:
      other - the other vector
      Returns:
      distance
    • distanceSq

      public int distanceSq(BlockVector2 other)
      Get the distance between this vector and another vector, squared.
      Parameters:
      other - the other vector
      Returns:
      distance
    • normalize

      public BlockVector2 normalize()
      Get the normalized vector, which is the vector divided by its length, as a new vector.
      Returns:
      a new vector
    • dot

      public int dot(BlockVector2 other)
      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

      public boolean containedWithin(BlockVector2 min, BlockVector2 max)
      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

      public BlockVector2 floor()
      Floors the values of all components.
      Returns:
      a new vector
    • ceil

      public BlockVector2 ceil()
      Rounds all components up.
      Returns:
      a new vector
    • round

      public BlockVector2 round()
      Rounds all components to the closest integer.

      Components < 0.5 are rounded down, otherwise up.

      Returns:
      a new vector
    • abs

      public BlockVector2 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 degrees
      aboutX - about which x coordinate to rotate
      aboutZ - about which z coordinate to rotate
      translateX - what to add after rotation
      translateZ - what to add after rotation
      Returns:
      a new vector
      See Also:
    • getMinimum

      public BlockVector2 getMinimum(BlockVector2 v2)
      Gets the minimum components of two vectors.
      Parameters:
      v2 - the second vector
      Returns:
      minimum
    • getMaximum

      public BlockVector2 getMaximum(BlockVector2 v2)
      Gets the maximum components of two vectors.
      Parameters:
      v2 - the second vector
      Returns:
      maximum
    • toVector2

      public Vector2 toVector2()
    • toVector3

      public Vector3 toVector3()
      Creates a 3D vector by adding a zero Y component to this vector.
      Returns:
      a new vector
    • toVector3

      public Vector3 toVector3(double y)
      Creates a 3D vector by adding the specified Y component to this vector.
      Parameters:
      y - the Y component
      Returns:
      a new vector
    • toBlockVector3

      public BlockVector3 toBlockVector3()
      Creates a 3D vector by adding a zero Y component to this vector.
      Returns:
      a new vector
    • toBlockVector3

      public BlockVector3 toBlockVector3(int y)
      Creates a 3D vector by adding the specified Y component to this vector.
      Parameters:
      y - the Y component
      Returns:
      a new vector
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toParserString

      public String toParserString()
      Returns a string representation that is supported by the parser.
      Returns:
      string