Class Vec<T extends Vec<T>>

java.lang.Object
rosequartz.math.Vec<T>
Type Parameters:
T - subclass
Direct Known Subclasses:
Vec2, Vec3, Vec4

public abstract class Vec<T extends Vec<T>> extends Object
Implements various methods for every vector, like scaling or calculating length.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Vec()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Sets every value of this vector to its absolute value.
    add​(float... vec)
    Adds the given vector to this vector component-wise and stores the result in this.
    add​(T vec)
    Adds the given vector to this vector component-wise and stores the result in this.
    add​(T vec, T dest)
    Adds the given vector to this vector component-wise and stores the result in dest.
    addN​(float... vec)
    Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.
    addN​(T vec)
    Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.
    float
    angle​(T vec)
    Calculates the angle between this and the given vector in radians.
    int
    Returns the amount of components the vector has.
    float
    distance​(T vec)
    Calculates the distance between this and the given vector and stores the result in this.
    div​(float... vec)
    Divides this vector by the given vector component-wise and stores the result in this.
    div​(T vec)
    Divides this vector by the given vector component-wise and stores the result in this.
    div​(T vec, T dest)
    Divides this vector by the given vector component-wise and stores the result in dest.
    divN​(float... vec)
    Divides this vector by the given vector component-wise and stores the result in this.
    divN​(T vec)
    Divides this vector by the given vector component-wise and stores the result in this.
    float
    dot​(T vec)
    Calculates the dot product of this and the given vector.
    boolean
    equals​(Object object)
     
    float
    get​(int index)
    Returns the value at the given index.
    protected abstract float[]
    Returns an array containing all components in the order they appear in the vector.
    protected abstract T
    Creates a new vector (values don't matter) of this type.
    float
    Returns the length of the vector.
    max​(T vec)
    Sets the values of this vector to the component-wise maximum of this and the given vector.
    min​(T vec)
    Sets the values of this vector to the component-wise minimum of this and the given vector.
    mul​(float... vec)
    Multiplies the given vector with this vector component-wise and stores the result in this.
    mul​(T vec)
    Multiplies the given vector with this vector component-wise and stores the result in this.
    mul​(T vec, T dest)
    Multiplies the given vector with this vector component-wise and stores the result in dest.
    mulN​(float... vec)
    Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.
    mulN​(T vec)
    Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.
    Negates the vector (scales it by -1).
    Normalizes the vector.
    scale​(float factor)
    Scales the vector by the given factor and stores the result in this.
    protected abstract void
    setComponents​(float[] values)
    Sets the components of the vector.
    sub​(float... vec)
    Subtracts this vector by the given vector component-wise and stores the result in this.
    sub​(T vec)
    Subtracts this vector by the given vector component-wise and stores the result in this.
    sub​(T vec, T dest)
    Subtracts this vector by the given vector component-wise and stores the result in dest.
    subN​(float... vec)
    Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.
    subN​(T vec)
    Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Vec

      public Vec()
  • Method Details

    • getComponents

      protected abstract float[] getComponents()
      Returns an array containing all components in the order they appear in the vector.
      Returns:
      array containing all vector components
    • setComponents

      protected abstract void setComponents(float[] values)
      Sets the components of the vector.
      Parameters:
      values - an array containing the values for all components.
    • getNewVector

      protected abstract T getNewVector()
      Creates a new vector (values don't matter) of this type.
      Returns:
      new vector of this type
    • length

      public float length()
      Returns the length of the vector. For the amount of components, look at 'components'.
      Returns:
      vector length
      See Also:
      components()
    • get

      public float get(int index)
      Returns the value at the given index.
      Parameters:
      index - index of component
      Returns:
      value
    • components

      public int components()
      Returns the amount of components the vector has. A Vector3 has 3 components, a Vector4 has 4 components and so on.
      Returns:
      component count
    • scale

      public T scale(float factor)
      Scales the vector by the given factor and stores the result in this.
      Parameters:
      factor - factor to scale vector with
      Returns:
      this
    • normalize

      public T normalize()
      Normalizes the vector.
      Returns:
      this
    • add

      public T add(T vec)
      Adds the given vector to this vector component-wise and stores the result in this.
      Parameters:
      vec - vector to add to this one
      Returns:
      this
    • add

      public T add(float... vec)
      Adds the given vector to this vector component-wise and stores the result in this.
      Parameters:
      vec - vector to add to this one
      Returns:
      this
    • add

      public T add(T vec, T dest)
      Adds the given vector to this vector component-wise and stores the result in dest.
      Parameters:
      vec - vector to add to this one
      dest - vector to store result in
      Returns:
      this
    • addN

      public T addN(T vec)
      Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.
      Parameters:
      vec - vector to add to this one
      Returns:
      new vector holding result
    • addN

      public T addN(float... vec)
      Adds the given vector to this vector component-wise and stores the result in a new vector, returning it.
      Parameters:
      vec - vector to add to this one
      Returns:
      new vector holding result
    • sub

      public T sub(T vec)
      Subtracts this vector by the given vector component-wise and stores the result in this.
      Parameters:
      vec - vector to subtract this one by
      Returns:
      this
    • sub

      public T sub(float... vec)
      Subtracts this vector by the given vector component-wise and stores the result in this.
      Parameters:
      vec - vector to subtract this one by
      Returns:
      this
    • sub

      public T sub(T vec, T dest)
      Subtracts this vector by the given vector component-wise and stores the result in dest.
      Parameters:
      vec - vector to subtract this one by
      dest - vector to store result in
      Returns:
      this
    • subN

      public T subN(T vec)
      Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.
      Parameters:
      vec - vector to subtract this one by
      Returns:
      this
    • subN

      public T subN(float... vec)
      Subtracts this vector by the given vector component-wise and stores the result in a new vector, returning it.
      Parameters:
      vec - vector to subtract this one by
      Returns:
      this
    • mul

      public T mul(T vec)
      Multiplies the given vector with this vector component-wise and stores the result in this.
      Parameters:
      vec - vector to multiply with this one
      Returns:
      this
    • mul

      public T mul(float... vec)
      Multiplies the given vector with this vector component-wise and stores the result in this.
      Parameters:
      vec - vector to multiply with this one
      Returns:
      this
    • mul

      public T mul(T vec, T dest)
      Multiplies the given vector with this vector component-wise and stores the result in dest.
      Parameters:
      vec - vector to multiply with this one
      dest - vector to store result in
      Returns:
      this
    • mulN

      public T mulN(T vec)
      Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.
      Parameters:
      vec - vector to multiply with this one
      Returns:
      this
    • mulN

      public T mulN(float... vec)
      Multiplies the given vector with this vector component-wise and stores the result in a new vector, returning it.
      Parameters:
      vec - vector to multiply with this one
      Returns:
      this
    • div

      public T div(T vec)
      Divides this vector by the given vector component-wise and stores the result in this.
      Parameters:
      vec - vector to divide this one by
      Returns:
      this
    • div

      public T div(float... vec)
      Divides this vector by the given vector component-wise and stores the result in this.
      Parameters:
      vec - vector to divide this one by
      Returns:
      this
    • div

      public T div(T vec, T dest)
      Divides this vector by the given vector component-wise and stores the result in dest.
      Parameters:
      vec - vector to divide this one by
      dest - vector to store result in
      Returns:
      this
    • divN

      public T divN(T vec)
      Divides this vector by the given vector component-wise and stores the result in this.
      Parameters:
      vec - vector to divide this one by
      Returns:
      this
    • divN

      public T divN(float... vec)
      Divides this vector by the given vector component-wise and stores the result in this.
      Parameters:
      vec - vector to divide this one by
      Returns:
      this
    • distance

      public float distance(T vec)
      Calculates the distance between this and the given vector and stores the result in this.
      Parameters:
      vec - other vector
      Returns:
      distance between this and the other vector
    • dot

      public float dot(T vec)
      Calculates the dot product of this and the given vector.
      Parameters:
      vec - other vector
      Returns:
      dot product
    • angle

      public float angle(T vec)
      Calculates the angle between this and the given vector in radians.
      Parameters:
      vec - other vector
      Returns:
      angle between this and the given vector in radians
    • negate

      public T negate()
      Negates the vector (scales it by -1).
      Returns:
      this
    • min

      public T min(T vec)
      Sets the values of this vector to the component-wise minimum of this and the given vector.
      Parameters:
      vec - other vector
      Returns:
      this
    • max

      public T max(T vec)
      Sets the values of this vector to the component-wise maximum of this and the given vector.
      Parameters:
      vec - other vector
      Returns:
      this
    • abs

      public T abs()
      Sets every value of this vector to its absolute value.
      Returns:
      this
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object