Package org.joml

Class Vector2f

java.lang.Object
org.joml.Vector2f
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Vector2fc

public class Vector2f extends Object implements Externalizable, Cloneable, Vector2fc
Represents a 2D vector with single-precision.
Author:
RGreenlees, Kai Burjack, F. Neurath
See Also:
Serialized Form
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
    The x component of the vector.
    float
    The y component of the vector.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new Vector2f and initialize its components to zero.
    Vector2f​(float d)
    Create a new Vector2f and initialize both of its components with the given value.
    Vector2f​(float[] xy)
    Create a new Vector2f and initialize its two components from the first two elements of the given array.
    Vector2f​(float x, float y)
    Create a new Vector2f and initialize its components to the given values.
    Vector2f​(int index, ByteBuffer buffer)
    Create a new Vector2f and read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.
    Vector2f​(int index, FloatBuffer buffer)
    Create a new Vector2f and read this vector from the supplied FloatBuffer starting at the specified absolute buffer position/index.
    Vector2f​(ByteBuffer buffer)
    Create a new Vector2f and read this vector from the supplied ByteBuffer at the current buffer position.
    Vector2f​(FloatBuffer buffer)
    Create a new Vector2f and read this vector from the supplied FloatBuffer at the current buffer position.
    Create a new Vector2f and initialize its components to the one of the given vector.
    Create a new Vector2f and initialize its components to the one of the given vector.
  • Method Summary

    Modifier and Type
    Method
    Description
    Set this vector's components to their respective absolute values.
    absolute​(Vector2f dest)
    Compute the absolute of each of this vector's components and store the result into dest.
    add​(float x, float y)
    Increment the components of this vector by the given values.
    add​(float x, float y, Vector2f dest)
    Increment the components of this vector by the given values and store the result in dest.
    add​(Vector2fc v)
    Add v to this vector.
    add​(Vector2fc v, Vector2f dest)
    Add the supplied vector to this one and store the result in dest.
    float
    Return the angle between this vector and the supplied vector.
    Ceil each component of this vector
    ceil​(Vector2f dest)
    Compute for each component of this vector the smallest (closest to negative infinity) float value that is greater than or equal to that component and is equal to a mathematical integer and store the result in dest.
     
    float
    distance​(float x, float y)
    Return the distance between this vector and (x, y).
    static float
    distance​(float x1, float y1, float x2, float y2)
    Return the distance between (x1, y1) and (x2, y2).
    float
    Return the distance between this and v.
    float
    distanceSquared​(float x, float y)
    Return the distance squared between this vector and (x, y).
    static float
    distanceSquared​(float x1, float y1, float x2, float y2)
    Return the squared distance between (x1, y1) and (x2, y2).
    float
    Return the distance squared between this and v.
    div​(float scalar)
    Divide all components of this Vector2f by the given scalar value.
    div​(float x, float y)
    Divide the components of this Vector2f by the given scalar values and store the result in this.
    div​(float x, float y, Vector2f dest)
    Divide the components of this Vector2f by the given scalar values and store the result in dest.
    div​(float scalar, Vector2f dest)
    Divide all components of this Vector2f by the given scalar value and store the result in dest.
    div​(Vector2fc v)
    Divide this Vector2f component-wise by another Vector2fc.
    div​(Vector2fc v, Vector2f dest)
    Divide this Vector2f component-wise by another Vector2fc and store the result in dest.
    float
    dot​(Vector2fc v)
    Return the dot product of this vector and v.
    boolean
    equals​(float x, float y)
    Compare the vector components of this vector with the given (x, y) and return whether all of them are equal.
    boolean
    equals​(Object obj)
     
    boolean
    equals​(Vector2fc v, float delta)
    Compare the vector components of this vector with the given vector using the given delta and return whether all of them are equal within a maximum difference of delta.
    Set each component of this vector to the largest (closest to positive infinity) float value that is less than or equal to that component and is equal to a mathematical integer.
    floor​(Vector2f dest)
    Compute for each component of this vector the largest (closest to positive infinity) float value that is less than or equal to that component and is equal to a mathematical integer and store the result in dest.
    fma​(float a, Vector2fc b)
    Add the component-wise multiplication of a * b to this vector.
    fma​(float a, Vector2fc b, Vector2f dest)
    Add the component-wise multiplication of a * b to this vector and store the result in dest.
    Add the component-wise multiplication of a * b to this vector.
    fma​(Vector2fc a, Vector2fc b, Vector2f dest)
    Add the component-wise multiplication of a * b to this vector and store the result in dest.
    float
    get​(int component)
    Get the value of the specified component of this vector.
    get​(int index, ByteBuffer buffer)
    Store this vector into the supplied ByteBuffer starting at the specified absolute buffer position/index.
    get​(int index, FloatBuffer buffer)
    Store this vector into the supplied FloatBuffer starting at the specified absolute buffer position/index.
    get​(int mode, Vector2i dest)
    Set the components of the given vector dest to those of this vector using the given RoundingMode.
    get​(ByteBuffer buffer)
    Store this vector into the supplied ByteBuffer at the current buffer position.
    get​(FloatBuffer buffer)
    Store this vector into the supplied FloatBuffer at the current buffer position.
    get​(Vector2d dest)
    Set the components of the given vector dest to those of this vector.
    get​(Vector2f dest)
    Set the components of the given vector dest to those of this vector.
    getToAddress​(long address)
    Store this vector at the given off-heap memory address.
    int
     
    boolean
    Determine whether all components are finite floating-point values, that is, they are not NaN and not infinity.
    float
    Return the length of this vector.
    static float
    length​(float x, float y)
    Get the length of a 2-dimensional single-precision vector.
    float
    Return the length squared of this vector.
    static float
    lengthSquared​(float x, float y)
    Get the length squared of a 2-dimensional single-precision vector.
    lerp​(Vector2fc other, float t)
    Linearly interpolate this and other using the given interpolation factor t and store the result in this.
    lerp​(Vector2fc other, float t, Vector2f dest)
    Linearly interpolate this and other using the given interpolation factor t and store the result in dest.
    max​(Vector2fc v)
    Set the components of this vector to be the component-wise maximum of this and the other vector.
    max​(Vector2fc v, Vector2f dest)
    Set the components of dest to be the component-wise maximum of this and the other vector.
    int
    Determine the component with the biggest absolute value.
    min​(Vector2fc v)
    Set the components of this vector to be the component-wise minimum of this and the other vector.
    min​(Vector2fc v, Vector2f dest)
    Set the components of dest to be the component-wise minimum of this and the other vector.
    int
    Determine the component with the smallest (towards zero) absolute value.
    mul​(float scalar)
    Multiply the components of this vector by the given scalar.
    mul​(float x, float y)
    Multiply the components of this Vector2f by the given scalar values and store the result in this.
    mul​(float x, float y, Vector2f dest)
    Multiply the components of this Vector2f by the given scalar values and store the result in dest.
    mul​(float scalar, Vector2f dest)
    Multiply the components of this vector by the given scalar and store the result in dest.
    mul​(Matrix2dc mat)
    Multiply the given matrix with this Vector2f and store the result in this.
    mul​(Matrix2dc mat, Vector2f dest)
    Multiply the given matrix with this Vector2f and store the result in dest.
    mul​(Matrix2fc mat)
    Multiply the given matrix with this Vector2f and store the result in this.
    mul​(Matrix2fc mat, Vector2f dest)
    Multiply the given matrix with this Vector2f and store the result in dest.
    mul​(Vector2fc v)
    Multiply this Vector2f component-wise by another Vector2f.
    mul​(Vector2fc v, Vector2f dest)
    Multiply this Vector2f component-wise by another Vector2f and store the result in dest.
    Multiply the given 3x2 matrix mat with this.
    Multiply the given 3x2 matrix mat with this and store the result in dest.
    Multiply the given 3x2 matrix mat with this.
    Multiply the given 3x2 matrix mat with this and store the result in dest.
    Multiply the transpose of the given matrix with this Vector2f store the result in this.
    Multiply the transpose of the given matrix with this Vector3f and store the result in dest.
    Negate this vector.
    negate​(Vector2f dest)
    Negate this vector and store the result in dest.
    Normalize this vector.
    normalize​(float length)
    Scale this vector to have the given length.
    normalize​(float length, Vector2f dest)
    Scale this vector to have the given length and store the result in dest.
    Normalize this vector and store the result in dest.
    Set this vector to be one of its perpendicular vectors.
    void
     
    Set each component of this vector to the closest float that is equal to a mathematical integer, with ties rounding to positive infinity.
    round​(Vector2f dest)
    Compute for each component of this vector the closest float that is equal to a mathematical integer, with ties rounding to positive infinity and store the result in dest.
    set​(double d)
    Set the x and y components to the supplied value.
    set​(double x, double y)
    Set the x and y components to the supplied values.
    set​(float d)
    Set the x and y components to the supplied value.
    set​(float[] xy)
    Set the two components of this vector to the first two elements of the given array.
    set​(float x, float y)
    Set the x and y components to the supplied values.
    set​(int index, ByteBuffer buffer)
    Read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.
    set​(int index, FloatBuffer buffer)
    Read this vector from the supplied FloatBuffer starting at the specified absolute buffer position/index.
    set​(ByteBuffer buffer)
    Read this vector from the supplied ByteBuffer at the current buffer position.
    set​(FloatBuffer buffer)
    Read this vector from the supplied FloatBuffer at the current buffer position.
    set​(Vector2dc v)
    Set this Vector2f to the values of v.
    set​(Vector2fc v)
    Set this Vector2f to the values of v.
    set​(Vector2ic v)
    Set this Vector2f to the values of v.
    setComponent​(int component, float value)
    Set the value of the specified component of this vector.
    setFromAddress​(long address)
    Set the values of this vector by reading 2 float values from off-heap memory, starting at the given address.
    sub​(float x, float y)
    Subtract (x, y) from this vector.
    sub​(float x, float y, Vector2f dest)
    Subtract (x, y) from this vector and store the result in dest.
    sub​(Vector2fc v)
    Subtract v from this vector.
    sub​(Vector2fc v, Vector2f dest)
    Subtract v from this vector and store the result in dest.
    Return a string representation of this vector.
    toString​(NumberFormat formatter)
    Return a string representation of this vector by formatting the vector components with the given NumberFormat.
    void
     
    float
    x()
     
    float
    y()
     
    Set all components to zero.

    Methods inherited from class java.lang.Object

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

    • x

      public float x
      The x component of the vector.
    • y

      public float y
      The y component of the vector.
  • Constructor Details

    • Vector2f

      public Vector2f()
      Create a new Vector2f and initialize its components to zero.
    • Vector2f

      public Vector2f(float d)
      Create a new Vector2f and initialize both of its components with the given value.
      Parameters:
      d - the value of both components
    • Vector2f

      public Vector2f(float x, float y)
      Create a new Vector2f and initialize its components to the given values.
      Parameters:
      x - the x component
      y - the y component
    • Vector2f

      public Vector2f(Vector2fc v)
      Create a new Vector2f and initialize its components to the one of the given vector.
      Parameters:
      v - the Vector2fc to copy the values from
    • Vector2f

      public Vector2f(Vector2ic v)
      Create a new Vector2f and initialize its components to the one of the given vector.
      Parameters:
      v - the Vector2ic to copy the values from
    • Vector2f

      public Vector2f(float[] xy)
      Create a new Vector2f and initialize its two components from the first two elements of the given array.
      Parameters:
      xy - the array containing at least two elements
    • Vector2f

      public Vector2f(ByteBuffer buffer)
      Create a new Vector2f and read this vector from the supplied ByteBuffer at the current buffer position.

      This method will not increment the position of the given ByteBuffer.

      In order to specify the offset into the ByteBuffer at which the vector is read, use Vector2f(int, ByteBuffer), taking the absolute position as parameter.

      Parameters:
      buffer - values will be read in x, y order
      See Also:
      Vector2f(int, ByteBuffer)
    • Vector2f

      public Vector2f(int index, ByteBuffer buffer)
      Create a new Vector2f and read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given ByteBuffer.

      Parameters:
      index - the absolute position into the ByteBuffer
      buffer - values will be read in x, y order
    • Vector2f

      public Vector2f(FloatBuffer buffer)
      Create a new Vector2f and read this vector from the supplied FloatBuffer at the current buffer position.

      This method will not increment the position of the given FloatBuffer.

      In order to specify the offset into the FloatBuffer at which the vector is read, use Vector2f(int, FloatBuffer), taking the absolute position as parameter.

      Parameters:
      buffer - values will be read in x, y order
      See Also:
      Vector2f(int, FloatBuffer)
    • Vector2f

      public Vector2f(int index, FloatBuffer buffer)
      Create a new Vector2f and read this vector from the supplied FloatBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given FloatBuffer.

      Parameters:
      index - the absolute position into the FloatBuffer
      buffer - values will be read in x, y order
  • Method Details

    • x

      public float x()
      Specified by:
      x in interface Vector2fc
      Returns:
      the value of the x component
    • y

      public float y()
      Specified by:
      y in interface Vector2fc
      Returns:
      the value of the y component
    • set

      public Vector2f set(float d)
      Set the x and y components to the supplied value.
      Parameters:
      d - the value of both components
      Returns:
      this
    • set

      public Vector2f set(float x, float y)
      Set the x and y components to the supplied values.
      Parameters:
      x - the x component
      y - the y component
      Returns:
      this
    • set

      public Vector2f set(double d)
      Set the x and y components to the supplied value.
      Parameters:
      d - the value of both components
      Returns:
      this
    • set

      public Vector2f set(double x, double y)
      Set the x and y components to the supplied values.
      Parameters:
      x - the x component
      y - the y component
      Returns:
      this
    • set

      public Vector2f set(Vector2fc v)
      Set this Vector2f to the values of v.
      Parameters:
      v - the vector to copy from
      Returns:
      this
    • set

      public Vector2f set(Vector2ic v)
      Set this Vector2f to the values of v.
      Parameters:
      v - the vector to copy from
      Returns:
      this
    • set

      public Vector2f set(Vector2dc v)
      Set this Vector2f to the values of v.

      Note that due to the given vector v storing the components in double-precision, there is the possibility to lose precision.

      Parameters:
      v - the vector to copy from
      Returns:
      this
    • set

      public Vector2f set(float[] xy)
      Set the two components of this vector to the first two elements of the given array.
      Parameters:
      xy - the array containing at least two elements
      Returns:
      this
    • set

      public Vector2f set(ByteBuffer buffer)
      Read this vector from the supplied ByteBuffer at the current buffer position.

      This method will not increment the position of the given ByteBuffer.

      In order to specify the offset into the ByteBuffer at which the vector is read, use set(int, ByteBuffer), taking the absolute position as parameter.

      Parameters:
      buffer - values will be read in x, y order
      Returns:
      this
      See Also:
      set(int, ByteBuffer)
    • set

      public Vector2f set(int index, ByteBuffer buffer)
      Read this vector from the supplied ByteBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given ByteBuffer.

      Parameters:
      index - the absolute position into the ByteBuffer
      buffer - values will be read in x, y order
      Returns:
      this
    • set

      public Vector2f set(FloatBuffer buffer)
      Read this vector from the supplied FloatBuffer at the current buffer position.

      This method will not increment the position of the given FloatBuffer.

      In order to specify the offset into the FloatBuffer at which the vector is read, use set(int, FloatBuffer), taking the absolute position as parameter.

      Parameters:
      buffer - values will be read in x, y order
      Returns:
      this
      See Also:
      set(int, FloatBuffer)
    • set

      public Vector2f set(int index, FloatBuffer buffer)
      Read this vector from the supplied FloatBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given FloatBuffer.

      Parameters:
      index - the absolute position into the FloatBuffer
      buffer - values will be read in x, y order
      Returns:
      this
    • setFromAddress

      public Vector2f setFromAddress(long address)
      Set the values of this vector by reading 2 float values from off-heap memory, starting at the given address.

      This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

      This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

      Parameters:
      address - the off-heap memory address to read the vector values from
      Returns:
      this
    • get

      public float get(int component) throws IllegalArgumentException
      Description copied from interface: Vector2fc
      Get the value of the specified component of this vector.
      Specified by:
      get in interface Vector2fc
      Parameters:
      component - the component, within [0..1]
      Returns:
      the value
      Throws:
      IllegalArgumentException - if component is not within [0..1]
    • get

      public Vector2i get(int mode, Vector2i dest)
      Description copied from interface: Vector2fc
      Set the components of the given vector dest to those of this vector using the given RoundingMode.
      Specified by:
      get in interface Vector2fc
      Parameters:
      mode - the RoundingMode to use
      dest - will hold the result
      Returns:
      dest
    • get

      public Vector2f get(Vector2f dest)
      Description copied from interface: Vector2fc
      Set the components of the given vector dest to those of this vector.
      Specified by:
      get in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • get

      public Vector2d get(Vector2d dest)
      Description copied from interface: Vector2fc
      Set the components of the given vector dest to those of this vector.
      Specified by:
      get in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • setComponent

      public Vector2f setComponent(int component, float value) throws IllegalArgumentException
      Set the value of the specified component of this vector.
      Parameters:
      component - the component whose value to set, within [0..1]
      value - the value to set
      Returns:
      this
      Throws:
      IllegalArgumentException - if component is not within [0..1]
    • get

      public ByteBuffer get(ByteBuffer buffer)
      Description copied from interface: Vector2fc
      Store this vector into the supplied ByteBuffer at the current buffer position.

      This method will not increment the position of the given ByteBuffer.

      In order to specify the offset into the ByteBuffer at which the vector is stored, use Vector2fc.get(int, ByteBuffer), taking the absolute position as parameter.

      Specified by:
      get in interface Vector2fc
      Parameters:
      buffer - will receive the values of this vector in x, y order
      Returns:
      the passed in buffer
      See Also:
      Vector2fc.get(int, ByteBuffer)
    • get

      public ByteBuffer get(int index, ByteBuffer buffer)
      Description copied from interface: Vector2fc
      Store this vector into the supplied ByteBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given ByteBuffer.

      Specified by:
      get in interface Vector2fc
      Parameters:
      index - the absolute position into the ByteBuffer
      buffer - will receive the values of this vector in x, y order
      Returns:
      the passed in buffer
    • get

      public FloatBuffer get(FloatBuffer buffer)
      Description copied from interface: Vector2fc
      Store this vector into the supplied FloatBuffer at the current buffer position.

      This method will not increment the position of the given FloatBuffer.

      In order to specify the offset into the FloatBuffer at which the vector is stored, use Vector2fc.get(int, FloatBuffer), taking the absolute position as parameter.

      Specified by:
      get in interface Vector2fc
      Parameters:
      buffer - will receive the values of this vector in x, y order
      Returns:
      the passed in buffer
      See Also:
      Vector2fc.get(int, FloatBuffer)
    • get

      public FloatBuffer get(int index, FloatBuffer buffer)
      Description copied from interface: Vector2fc
      Store this vector into the supplied FloatBuffer starting at the specified absolute buffer position/index.

      This method will not increment the position of the given FloatBuffer.

      Specified by:
      get in interface Vector2fc
      Parameters:
      index - the absolute position into the FloatBuffer
      buffer - will receive the values of this vector in x, y order
      Returns:
      the passed in buffer
    • getToAddress

      public Vector2fc getToAddress(long address)
      Description copied from interface: Vector2fc
      Store this vector at the given off-heap memory address.

      This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

      This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

      Specified by:
      getToAddress in interface Vector2fc
      Parameters:
      address - the off-heap address where to store this vector
      Returns:
      this
    • perpendicular

      public Vector2f perpendicular()
      Set this vector to be one of its perpendicular vectors.
      Returns:
      this
    • sub

      public Vector2f sub(Vector2fc v)
      Subtract v from this vector.
      Parameters:
      v - the vector to subtract
      Returns:
      this
    • sub

      public Vector2f sub(Vector2fc v, Vector2f dest)
      Description copied from interface: Vector2fc
      Subtract v from this vector and store the result in dest.
      Specified by:
      sub in interface Vector2fc
      Parameters:
      v - the vector to subtract
      dest - will hold the result
      Returns:
      dest
    • sub

      public Vector2f sub(float x, float y)
      Subtract (x, y) from this vector.
      Parameters:
      x - the x component to subtract
      y - the y component to subtract
      Returns:
      this
    • sub

      public Vector2f sub(float x, float y, Vector2f dest)
      Description copied from interface: Vector2fc
      Subtract (x, y) from this vector and store the result in dest.
      Specified by:
      sub in interface Vector2fc
      Parameters:
      x - the x component to subtract
      y - the y component to subtract
      dest - will hold the result
      Returns:
      dest
    • dot

      public float dot(Vector2fc v)
      Description copied from interface: Vector2fc
      Return the dot product of this vector and v.
      Specified by:
      dot in interface Vector2fc
      Parameters:
      v - the other vector
      Returns:
      the dot product
    • angle

      public float angle(Vector2fc v)
      Description copied from interface: Vector2fc
      Return the angle between this vector and the supplied vector.
      Specified by:
      angle in interface Vector2fc
      Parameters:
      v - the other vector
      Returns:
      the angle, in radians
    • lengthSquared

      public float lengthSquared()
      Description copied from interface: Vector2fc
      Return the length squared of this vector.
      Specified by:
      lengthSquared in interface Vector2fc
      Returns:
      the length squared
    • lengthSquared

      public static float lengthSquared(float x, float y)
      Get the length squared of a 2-dimensional single-precision vector.
      Parameters:
      x - The vector's x component
      y - The vector's y component
      Returns:
      the length squared of the given vector
    • length

      public float length()
      Description copied from interface: Vector2fc
      Return the length of this vector.
      Specified by:
      length in interface Vector2fc
      Returns:
      the length
    • length

      public static float length(float x, float y)
      Get the length of a 2-dimensional single-precision vector.
      Parameters:
      x - The vector's x component
      y - The vector's y component
      Returns:
      the length of the given vector
    • distance

      public float distance(Vector2fc v)
      Description copied from interface: Vector2fc
      Return the distance between this and v.
      Specified by:
      distance in interface Vector2fc
      Parameters:
      v - the other vector
      Returns:
      the distance
    • distanceSquared

      public float distanceSquared(Vector2fc v)
      Description copied from interface: Vector2fc
      Return the distance squared between this and v.
      Specified by:
      distanceSquared in interface Vector2fc
      Parameters:
      v - the other vector
      Returns:
      the distance squared
    • distance

      public float distance(float x, float y)
      Description copied from interface: Vector2fc
      Return the distance between this vector and (x, y).
      Specified by:
      distance in interface Vector2fc
      Parameters:
      x - the x component of the other vector
      y - the y component of the other vector
      Returns:
      the euclidean distance
    • distanceSquared

      public float distanceSquared(float x, float y)
      Description copied from interface: Vector2fc
      Return the distance squared between this vector and (x, y).
      Specified by:
      distanceSquared in interface Vector2fc
      Parameters:
      x - the x component of the other vector
      y - the y component of the other vector
      Returns:
      the euclidean distance squared
    • distance

      public static float distance(float x1, float y1, float x2, float y2)
      Return the distance between (x1, y1) and (x2, y2).
      Parameters:
      x1 - the x component of the first vector
      y1 - the y component of the first vector
      x2 - the x component of the second vector
      y2 - the y component of the second vector
      Returns:
      the euclidean distance
    • distanceSquared

      public static float distanceSquared(float x1, float y1, float x2, float y2)
      Return the squared distance between (x1, y1) and (x2, y2).
      Parameters:
      x1 - the x component of the first vector
      y1 - the y component of the first vector
      x2 - the x component of the second vector
      y2 - the y component of the second vector
      Returns:
      the euclidean distance squared
    • normalize

      public Vector2f normalize()
      Normalize this vector.
      Returns:
      this
    • normalize

      public Vector2f normalize(Vector2f dest)
      Description copied from interface: Vector2fc
      Normalize this vector and store the result in dest.
      Specified by:
      normalize in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • normalize

      public Vector2f normalize(float length)
      Scale this vector to have the given length.
      Parameters:
      length - the desired length
      Returns:
      this
    • normalize

      public Vector2f normalize(float length, Vector2f dest)
      Description copied from interface: Vector2fc
      Scale this vector to have the given length and store the result in dest.
      Specified by:
      normalize in interface Vector2fc
      Parameters:
      length - the desired length
      dest - will hold the result
      Returns:
      dest
    • add

      public Vector2f add(Vector2fc v)
      Add v to this vector.
      Parameters:
      v - the vector to add
      Returns:
      this
    • add

      public Vector2f add(Vector2fc v, Vector2f dest)
      Description copied from interface: Vector2fc
      Add the supplied vector to this one and store the result in dest.
      Specified by:
      add in interface Vector2fc
      Parameters:
      v - the vector to add
      dest - will hold the result
      Returns:
      dest
    • add

      public Vector2f add(float x, float y)
      Increment the components of this vector by the given values.
      Parameters:
      x - the x component to add
      y - the y component to add
      Returns:
      this
    • add

      public Vector2f add(float x, float y, Vector2f dest)
      Description copied from interface: Vector2fc
      Increment the components of this vector by the given values and store the result in dest.
      Specified by:
      add in interface Vector2fc
      Parameters:
      x - the x component to add
      y - the y component to add
      dest - will hold the result
      Returns:
      dest
    • zero

      public Vector2f zero()
      Set all components to zero.
      Returns:
      this
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • negate

      public Vector2f negate()
      Negate this vector.
      Returns:
      this
    • negate

      public Vector2f negate(Vector2f dest)
      Description copied from interface: Vector2fc
      Negate this vector and store the result in dest.
      Specified by:
      negate in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • mul

      public Vector2f mul(float scalar)
      Multiply the components of this vector by the given scalar.
      Parameters:
      scalar - the value to multiply this vector's components by
      Returns:
      this
    • mul

      public Vector2f mul(float scalar, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply the components of this vector by the given scalar and store the result in dest.
      Specified by:
      mul in interface Vector2fc
      Parameters:
      scalar - the value to multiply this vector's components by
      dest - will hold the result
      Returns:
      dest
    • mul

      public Vector2f mul(float x, float y)
      Multiply the components of this Vector2f by the given scalar values and store the result in this.
      Parameters:
      x - the x component to multiply this vector by
      y - the y component to multiply this vector by
      Returns:
      this
    • mul

      public Vector2f mul(float x, float y, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply the components of this Vector2f by the given scalar values and store the result in dest.
      Specified by:
      mul in interface Vector2fc
      Parameters:
      x - the x component to multiply this vector by
      y - the y component to multiply this vector by
      dest - will hold the result
      Returns:
      dest
    • mul

      public Vector2f mul(Vector2fc v)
      Multiply this Vector2f component-wise by another Vector2f.
      Parameters:
      v - the vector to multiply by
      Returns:
      this
    • mul

      public Vector2f mul(Vector2fc v, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply this Vector2f component-wise by another Vector2f and store the result in dest.
      Specified by:
      mul in interface Vector2fc
      Parameters:
      v - the vector to multiply by
      dest - will hold the result
      Returns:
      dest
    • div

      public Vector2f div(Vector2fc v)
      Divide this Vector2f component-wise by another Vector2fc.
      Parameters:
      v - the vector to divide by
      Returns:
      this
    • div

      public Vector2f div(Vector2fc v, Vector2f dest)
      Description copied from interface: Vector2fc
      Divide this Vector2f component-wise by another Vector2fc and store the result in dest.
      Specified by:
      div in interface Vector2fc
      Parameters:
      v - the vector to divide by
      dest - will hold the result
      Returns:
      dest
    • div

      public Vector2f div(float scalar)
      Divide all components of this Vector2f by the given scalar value.
      Parameters:
      scalar - the scalar to divide by
      Returns:
      this
    • div

      public Vector2f div(float scalar, Vector2f dest)
      Description copied from interface: Vector2fc
      Divide all components of this Vector2f by the given scalar value and store the result in dest.
      Specified by:
      div in interface Vector2fc
      Parameters:
      scalar - the scalar to divide by
      dest - will hold the result
      Returns:
      dest
    • div

      public Vector2f div(float x, float y)
      Divide the components of this Vector2f by the given scalar values and store the result in this.
      Parameters:
      x - the x component to divide this vector by
      y - the y component to divide this vector by
      Returns:
      this
    • div

      public Vector2f div(float x, float y, Vector2f dest)
      Description copied from interface: Vector2fc
      Divide the components of this Vector2f by the given scalar values and store the result in dest.
      Specified by:
      div in interface Vector2fc
      Parameters:
      x - the x component to divide this vector by
      y - the y component to divide this vector by
      dest - will hold the result
      Returns:
      dest
    • mul

      public Vector2f mul(Matrix2fc mat)
      Multiply the given matrix with this Vector2f and store the result in this.
      Parameters:
      mat - the matrix
      Returns:
      this
    • mul

      public Vector2f mul(Matrix2fc mat, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply the given matrix with this Vector2f and store the result in dest.
      Specified by:
      mul in interface Vector2fc
      Parameters:
      mat - the matrix
      dest - will hold the result
      Returns:
      dest
    • mul

      public Vector2f mul(Matrix2dc mat)
      Multiply the given matrix with this Vector2f and store the result in this.
      Parameters:
      mat - the matrix
      Returns:
      this
    • mul

      public Vector2f mul(Matrix2dc mat, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply the given matrix with this Vector2f and store the result in dest.
      Specified by:
      mul in interface Vector2fc
      Parameters:
      mat - the matrix
      dest - will hold the result
      Returns:
      dest
    • mulTranspose

      public Vector2f mulTranspose(Matrix2fc mat)
      Multiply the transpose of the given matrix with this Vector2f store the result in this.
      Parameters:
      mat - the matrix
      Returns:
      this
    • mulTranspose

      public Vector2f mulTranspose(Matrix2fc mat, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply the transpose of the given matrix with this Vector3f and store the result in dest.
      Specified by:
      mulTranspose in interface Vector2fc
      Parameters:
      mat - the matrix
      dest - will hold the result
      Returns:
      dest
    • mulPosition

      public Vector2f mulPosition(Matrix3x2fc mat)
      Multiply the given 3x2 matrix mat with this.

      This method assumes the z component of this to be 1.0.

      Parameters:
      mat - the matrix to multiply this vector by
      Returns:
      this
    • mulPosition

      public Vector2f mulPosition(Matrix3x2fc mat, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply the given 3x2 matrix mat with this and store the result in dest.

      This method assumes the z component of this to be 1.0.

      Specified by:
      mulPosition in interface Vector2fc
      Parameters:
      mat - the matrix to multiply this vector by
      dest - will hold the result
      Returns:
      dest
    • mulDirection

      public Vector2f mulDirection(Matrix3x2fc mat)
      Multiply the given 3x2 matrix mat with this.

      This method assumes the z component of this to be 0.0.

      Parameters:
      mat - the matrix to multiply this vector by
      Returns:
      this
    • mulDirection

      public Vector2f mulDirection(Matrix3x2fc mat, Vector2f dest)
      Description copied from interface: Vector2fc
      Multiply the given 3x2 matrix mat with this and store the result in dest.

      This method assumes the z component of this to be 0.0.

      Specified by:
      mulDirection in interface Vector2fc
      Parameters:
      mat - the matrix to multiply this vector by
      dest - will hold the result
      Returns:
      dest
    • lerp

      public Vector2f lerp(Vector2fc other, float t)
      Linearly interpolate this and other using the given interpolation factor t and store the result in this.

      If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

      Parameters:
      other - the other vector
      t - the interpolation factor between 0.0 and 1.0
      Returns:
      this
    • lerp

      public Vector2f lerp(Vector2fc other, float t, Vector2f dest)
      Description copied from interface: Vector2fc
      Linearly interpolate this and other using the given interpolation factor t and store the result in dest.

      If t is 0.0 then the result is this. If the interpolation factor is 1.0 then the result is other.

      Specified by:
      lerp in interface Vector2fc
      Parameters:
      other - the other vector
      t - the interpolation factor between 0.0 and 1.0
      dest - will hold the result
      Returns:
      dest
    • hashCode

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

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

      public boolean equals(Vector2fc v, float delta)
      Description copied from interface: Vector2fc
      Compare the vector components of this vector with the given vector using the given delta and return whether all of them are equal within a maximum difference of delta.

      Please note that this method is not used by any data structure such as ArrayList HashSet or HashMap and their operations, such as ArrayList.contains(Object) or HashSet.remove(Object), since those data structures only use the Object.equals(Object) and Object.hashCode() methods.

      Specified by:
      equals in interface Vector2fc
      Parameters:
      v - the other vector
      delta - the allowed maximum difference
      Returns:
      true whether all of the vector components are equal; false otherwise
    • equals

      public boolean equals(float x, float y)
      Description copied from interface: Vector2fc
      Compare the vector components of this vector with the given (x, y) and return whether all of them are equal.
      Specified by:
      equals in interface Vector2fc
      Parameters:
      x - the x component to compare to
      y - the y component to compare to
      Returns:
      true if all the vector components are equal
    • toString

      public String toString()
      Return a string representation of this vector.

      This method creates a new DecimalFormat on every invocation with the format string "0.000E0;-".

      Overrides:
      toString in class Object
      Returns:
      the string representation
    • toString

      public String toString(NumberFormat formatter)
      Return a string representation of this vector by formatting the vector components with the given NumberFormat.
      Parameters:
      formatter - the NumberFormat used to format the vector components with
      Returns:
      the string representation
    • fma

      public Vector2f fma(Vector2fc a, Vector2fc b)
      Add the component-wise multiplication of a * b to this vector.
      Parameters:
      a - the first multiplicand
      b - the second multiplicand
      Returns:
      this
    • fma

      public Vector2f fma(float a, Vector2fc b)
      Add the component-wise multiplication of a * b to this vector.
      Parameters:
      a - the first multiplicand
      b - the second multiplicand
      Returns:
      this
    • fma

      public Vector2f fma(Vector2fc a, Vector2fc b, Vector2f dest)
      Description copied from interface: Vector2fc
      Add the component-wise multiplication of a * b to this vector and store the result in dest.
      Specified by:
      fma in interface Vector2fc
      Parameters:
      a - the first multiplicand
      b - the second multiplicand
      dest - will hold the result
      Returns:
      dest
    • fma

      public Vector2f fma(float a, Vector2fc b, Vector2f dest)
      Description copied from interface: Vector2fc
      Add the component-wise multiplication of a * b to this vector and store the result in dest.
      Specified by:
      fma in interface Vector2fc
      Parameters:
      a - the first multiplicand
      b - the second multiplicand
      dest - will hold the result
      Returns:
      dest
    • min

      public Vector2f min(Vector2fc v)
      Set the components of this vector to be the component-wise minimum of this and the other vector.
      Parameters:
      v - the other vector
      Returns:
      this
    • min

      public Vector2f min(Vector2fc v, Vector2f dest)
      Description copied from interface: Vector2fc
      Set the components of dest to be the component-wise minimum of this and the other vector.
      Specified by:
      min in interface Vector2fc
      Parameters:
      v - the other vector
      dest - will hold the result
      Returns:
      dest
    • max

      public Vector2f max(Vector2fc v)
      Set the components of this vector to be the component-wise maximum of this and the other vector.
      Parameters:
      v - the other vector
      Returns:
      this
    • max

      public Vector2f max(Vector2fc v, Vector2f dest)
      Description copied from interface: Vector2fc
      Set the components of dest to be the component-wise maximum of this and the other vector.
      Specified by:
      max in interface Vector2fc
      Parameters:
      v - the other vector
      dest - will hold the result
      Returns:
      dest
    • maxComponent

      public int maxComponent()
      Description copied from interface: Vector2fc
      Determine the component with the biggest absolute value.
      Specified by:
      maxComponent in interface Vector2fc
      Returns:
      the component index, within [0..1]
    • minComponent

      public int minComponent()
      Description copied from interface: Vector2fc
      Determine the component with the smallest (towards zero) absolute value.
      Specified by:
      minComponent in interface Vector2fc
      Returns:
      the component index, within [0..1]
    • floor

      public Vector2f floor()
      Set each component of this vector to the largest (closest to positive infinity) float value that is less than or equal to that component and is equal to a mathematical integer.
      Returns:
      this
    • floor

      public Vector2f floor(Vector2f dest)
      Description copied from interface: Vector2fc
      Compute for each component of this vector the largest (closest to positive infinity) float value that is less than or equal to that component and is equal to a mathematical integer and store the result in dest.
      Specified by:
      floor in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • ceil

      public Vector2f ceil()
      Ceil each component of this vector
      Returns:
      this
    • ceil

      public Vector2f ceil(Vector2f dest)
      Description copied from interface: Vector2fc
      Compute for each component of this vector the smallest (closest to negative infinity) float value that is greater than or equal to that component and is equal to a mathematical integer and store the result in dest.
      Specified by:
      ceil in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • round

      public Vector2f round()
      Set each component of this vector to the closest float that is equal to a mathematical integer, with ties rounding to positive infinity.
      Returns:
      this
    • round

      public Vector2f round(Vector2f dest)
      Description copied from interface: Vector2fc
      Compute for each component of this vector the closest float that is equal to a mathematical integer, with ties rounding to positive infinity and store the result in dest.
      Specified by:
      round in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • isFinite

      public boolean isFinite()
      Description copied from interface: Vector2fc
      Determine whether all components are finite floating-point values, that is, they are not NaN and not infinity.
      Specified by:
      isFinite in interface Vector2fc
      Returns:
      true if all components are finite floating-point values; false otherwise
    • absolute

      public Vector2f absolute()
      Set this vector's components to their respective absolute values.
      Returns:
      this
    • absolute

      public Vector2f absolute(Vector2f dest)
      Description copied from interface: Vector2fc
      Compute the absolute of each of this vector's components and store the result into dest.
      Specified by:
      absolute in interface Vector2fc
      Parameters:
      dest - will hold the result
      Returns:
      dest
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException