Record Class Vector2

java.lang.Object
java.lang.Record
com.sk89q.worldedit.math.Vector2

public record Vector2(double x, double z) extends Record
An immutable 2-dimensional vector.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Vector2
     
    static final Vector2
     
    static final Vector2
     
    static final Vector2
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Vector2(double x, double z)
    Creates an instance of a Vector2 record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Returns a vector with the absolute values of the components of this vector.
    add(double x, double z)
    Add another vector to this vector and return the result as a new vector.
    add(Vector2 other)
    Add another vector to this vector and return the result as a new vector.
    add(Vector2... others)
    Add a list of vectors to this vector and return the result as a new vector.
    static Vector2
    at(double x, double z)
     
    int
    Get the X coordinate, aligned to the block grid.
    int
    Get the Z coordinate, aligned to the block grid.
    Rounds all components up.
    boolean
    Checks to see if a vector is contained with another.
    double
    Get the distance between this vector and another vector.
    double
    Get the distance between this vector and another vector, squared.
    divide(double n)
    Perform scalar division and return a new vector.
    divide(double x, double z)
    Divide this vector by another vector on each component.
    divide(Vector2 other)
    Divide this vector by another vector on each component.
    double
    dot(Vector2 other)
    Gets the dot product of this and another vector.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Floors the values of all components.
    Gets the maximum components of two vectors.
    Gets the minimum components of two vectors.
    double
    Deprecated, for removal: This API element is subject to removal in a future version.
    use x() instead
    double
    Deprecated, for removal: This API element is subject to removal in a future version.
    use z() instead
    final int
    Returns a hash code value for this object.
    double
    Get the length of the vector.
    double
    Get the length, squared, of the vector.
    multiply(double n)
    Perform scalar multiplication and return a new vector.
    multiply(double x, double z)
    Multiply this vector by another vector on each component.
    Multiply this vector by another vector on each component.
    multiply(Vector2... 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.
    Rounds all components to the closest integer.
    subtract(double x, double z)
    Subtract another vector from this vector and return the result as a new vector.
    Subtract another vector from this vector and return the result as a new vector.
    subtract(Vector2... others)
    Subtract a list of vectors from this vector and return the result as a new vector.
    Create a new BlockVector2 from this vector.
    toBlockPoint(double x, double z)
     
    Returns a string representation that is supported by the parser.
    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(double x)
    Set the X coordinate.
    withZ(double z)
    Set the Z coordinate.
    double
    x()
    Returns the value of the x record component.
    double
    z()
    Returns the value of the z record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • ZERO

      public static final Vector2 ZERO
    • UNIT_X

      public static final Vector2 UNIT_X
    • UNIT_Z

      public static final Vector2 UNIT_Z
    • ONE

      public static final Vector2 ONE
  • Constructor Details

    • Vector2

      public Vector2(double x, double z)
      Creates an instance of a Vector2 record class.
      Parameters:
      x - the value for the x record component
      z - the value for the z record component
  • Method Details

    • at

      public static Vector2 at(double x, double z)
    • getX

      @Deprecated(forRemoval=true) public double getX()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use x() instead
      Get the X coordinate.
      Returns:
      the x coordinate
    • blockX

      public int blockX()
      Get the X coordinate, aligned to the block grid.
      Returns:
      the block-aligned x coordinate
    • withX

      public Vector2 withX(double x)
      Set the X coordinate.
      Parameters:
      x - the new X
      Returns:
      a new vector
    • blockZ

      public int blockZ()
      Get the Z coordinate, aligned to the block grid.
      Returns:
      the block-aligned z coordinate
    • getZ

      @Deprecated(forRemoval=true) public double getZ()
      Deprecated, for removal: This API element is subject to removal in a future version.
      use z() instead
      Get the Z coordinate.
      Returns:
      the z coordinate
    • withZ

      public Vector2 withZ(double z)
      Set the Z coordinate.
      Parameters:
      z - the new Z
      Returns:
      a new vector
    • add

      public Vector2 add(Vector2 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 Vector2 add(double x, double 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 Vector2 add(Vector2... 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 Vector2 subtract(Vector2 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 Vector2 subtract(double x, double 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 Vector2 subtract(Vector2... 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 Vector2 multiply(Vector2 other)
      Multiply this vector by another vector on each component.
      Parameters:
      other - the other vector
      Returns:
      a new vector
    • multiply

      public Vector2 multiply(double x, double 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 Vector2 multiply(Vector2... others)
      Multiply this vector by zero or more vectors on each component.
      Parameters:
      others - an array of vectors
      Returns:
      a new vector
    • multiply

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

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

      public Vector2 divide(double x, double 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 Vector2 divide(double n)
      Perform scalar division and return a new vector.
      Parameters:
      n - the value to divide by
      Returns:
      a new vector
    • length

      public double length()
      Get the length of the vector.
      Returns:
      length
    • lengthSq

      public double lengthSq()
      Get the length, squared, of the vector.
      Returns:
      length, squared
    • distance

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

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

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

      public double dot(Vector2 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(Vector2 min, Vector2 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 Vector2 floor()
      Floors the values of all components.
      Returns:
      a new vector
    • ceil

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

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

      Components < 0.5 are rounded down, otherwise up.

      Returns:
      a new vector
    • abs

      public Vector2 abs()
      Returns a vector with the absolute values of the components of this vector.
      Returns:
      a new vector
    • transform2D

      public Vector2 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 Vector2 getMinimum(Vector2 v2)
      Gets the minimum components of two vectors.
      Parameters:
      v2 - the second vector
      Returns:
      minimum
    • getMaximum

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

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

      public BlockVector2 toBlockPoint()
      Create a new BlockVector2 from this vector.
      Returns:
      a new BlockVector2
    • 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
    • toString

      public String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • toParserString

      public String 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • x

      public double x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • z

      public double z()
      Returns the value of the z record component.
      Returns:
      the value of the z record component