Interface Vector<V extends Vector<V>>

Type Parameters:
V - The vector itself (the parameter and result of various operations)
All Superinterfaces:
BaseTuple<Double>, DoubleTuple, Serializable
All Known Implementing Classes:
ArrayVector, Vector2, Vector3, Vector4

public interface Vector<V extends Vector<V>> extends DoubleTuple
A mathematical vector.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double s)
    Adds a scalar to this vector component-wise, then returns the resulting vector.
    add(V v)
    Adds another vector to this vector, then returns the resulting vector.
    clamp(V min, V max)
    Between this vector and the provided boundary vectors min and max, this returns a new vector whose components are clamped to respect the range of [min, max].
    double
    Returns the Euclidean distance between this vector and the provided vector v.
    double
    Returns the squared Euclidean distance between this vector and the provided vector v.
    double
    Returns the Manhattan distance between this vector and the provided vector v.
    divide(double s)
    Divides this vector by a scalar component-wise, then returns the resulting vector.
    double
    dot(V v)
    Returns the dot product between this vector and the provided vector v.
    boolean
    equals(V v)
    Checks for equality between this vector and the provided vector v.
    Applies the provided mapper function f to each component of this vector, then returns a new vector containing the return values of the function f.
    max(V v)
    Between this vector and the provided boundary vector v, this takes the maximum of each corresponding pair of components, then returns a new vector whose components are populated from that of the maximum values between each pair of components.
    Between this vector and the provided vector v, this applies the merger function f to each corresponding pair of components, then returns a new vector whose components are populated from the return values of the function f.
    min(V v)
    Between this vector and the provided boundary vector v, this takes the minimum of each corresponding pair of components, then returns a new vector whose components are populated from that of the minimum values between each pair of components.
    multiply(double s)
    Multiplies this vector by a scalar component-wise, then returns the resulting vector.
    Negates all components of this vector, then returns the resulting vector.
    double
    Returns the Euclidean norm (the magnitude) of this vector.
    double
    Returns the squared Euclidean norm (the squared magnitude) of this vector.
    Normalizes this vector to have a Euclidean norm (magnitude) of 1.
    Normalizes this vector to have a Euclidean norm (magnitude) of 1.
    Normalizes this vector ot have a Euclidean norm (magnitude) of 1.
    double
    Returns the Manhattan norm of this vector.
    subtract(double s)
    Subtracts this vector by a scalar component-wise, then returns the resulting vector.
    Subtracts another vector from this vector, then returns the resulting vector.

    Methods inherited from interface civitas.celestis.util.tuple.DoubleTuple

    array, boxed, contains, containsAll, doubleArray, equals, get, isFinite, isInfinite, isNaN, isZero, list, mapToObj, size, stream, toString
  • Method Details

    • norm

      double norm()
      Returns the Euclidean norm (the magnitude) of this vector.
      Returns:
      The Euclidean norm of this vector
    • norm2

      double norm2()
      Returns the squared Euclidean norm (the squared magnitude) of this vector.
      Returns:
      The squared Euclidean norm of this vector
    • normManhattan

      double normManhattan()
      Returns the Manhattan norm of this vector.
      Returns:
      The Manhattan norm of this vector
    • add

      @Nonnull V add(double s)
      Adds a scalar to this vector component-wise, then returns the resulting vector.
      Parameters:
      s - The scalar of which to add to each component of this vector
      Returns:
      The resulting vector
    • subtract

      @Nonnull V subtract(double s)
      Subtracts this vector by a scalar component-wise, then returns the resulting vector.
      Parameters:
      s - The scalar of which to subtract from each component of this vector
      Returns:
      The resulting vector
    • multiply

      @Nonnull V multiply(double s)
      Multiplies this vector by a scalar component-wise, then returns the resulting vector.
      Parameters:
      s - The scalar of which to multiply each component of this vector by
      Returns:
      The resulting vector
    • divide

      @Nonnull V divide(double s) throws ArithmeticException
      Divides this vector by a scalar component-wise, then returns the resulting vector.
      Parameters:
      s - The scalar of which to divide each component of this vector by
      Returns:
      The resulting vector
      Throws:
      ArithmeticException - When the denominator s is zero
    • add

      @Nonnull V add(@Nonnull V v)
      Adds another vector to this vector, then returns the resulting vector.
      Parameters:
      v - The vector of which to add to this vector
      Returns:
      The resulting vector
    • subtract

      @Nonnull V subtract(@Nonnull V v)
      Subtracts another vector from this vector, then returns the resulting vector.
      Parameters:
      v - The vector of which to subtract from this vector
      Returns:
      The resulting vector
    • dot

      double dot(@Nonnull V v)
      Returns the dot product between this vector and the provided vector v.
      Parameters:
      v - The vector of which to get the dot product between
      Returns:
      The dot product between the two vectors
    • normalize

      @Nonnull V normalize() throws ArithmeticException
      Normalizes this vector to have a Euclidean norm (magnitude) of 1.
      Returns:
      The normalized vector of this vector
      Throws:
      ArithmeticException - When the Euclidean norm of this vector is zero
    • normalizeOrZero

      @Nonnull V normalizeOrZero()
      Normalizes this vector ot have a Euclidean norm (magnitude) of 1. If this vector's Euclidean norm is zero, this will return itself. (which is guaranteed to be a vector where all components are zero, as only zero vectors have a Euclidean norm of zero)
      Returns:
      The normalized vector of this vector if successful, zero otherwise
    • normalizeOrDefault

      @Nonnull V normalizeOrDefault(@Nonnull V v)
      Normalizes this vector to have a Euclidean norm (magnitude) of 1. If this vector's Euclidean norm is zero, this will return the provided fallback value v.
      Parameters:
      v - The value of which to return in case of division by zero
      Returns:
      The normalized vector of this vector if successful, the fallback value v otherwise
    • negate

      @Nonnull V negate()
      Negates all components of this vector, then returns the resulting vector.
      Returns:
      The negation of this vector
    • min

      @Nonnull V min(@Nonnull V v)
      Between this vector and the provided boundary vector v, this takes the minimum of each corresponding pair of components, then returns a new vector whose components are populated from that of the minimum values between each pair of components.
      Parameters:
      v - The boundary vector of which to compare to
      Returns:
      The minimum vector of the two vectors
    • max

      @Nonnull V max(@Nonnull V v)
      Between this vector and the provided boundary vector v, this takes the maximum of each corresponding pair of components, then returns a new vector whose components are populated from that of the maximum values between each pair of components.
      Parameters:
      v - The boundary vector of which to compare to
      Returns:
      The maximum vector of the two vectors
    • clamp

      @Nonnull V clamp(@Nonnull V min, @Nonnull V max)
      Between this vector and the provided boundary vectors min and max, this returns a new vector whose components are clamped to respect the range of [min, max]. This is the equivalent of clamping each component to the corresponding pair of minimum and maximum values.
      Parameters:
      min - The minimum boundary vector to compare to
      max - The maximum boundary vector to compare to
      Returns:
      The clamped vector which respects the boundaries of [min, max]
    • distance

      double distance(@Nonnull V v)
      Returns the Euclidean distance between this vector and the provided vector v.
      Parameters:
      v - The vector of which get the Euclidean distance between
      Returns:
      The Euclidean distance between the two vectors
    • distance2

      double distance2(@Nonnull V v)
      Returns the squared Euclidean distance between this vector and the provided vector v.
      Parameters:
      v - The vector of which to get the squared Euclidean distance between
      Returns:
      The squared Euclidean distance between the two vectors
    • distanceManhattan

      double distanceManhattan(@Nonnull V v)
      Returns the Manhattan distance between this vector and the provided vector v.
      Parameters:
      v - The vector of which to get the Manhattan distance between
      Returns:
      The Manhattan distance between the two vectors
    • map

      @Nonnull V map(@Nonnull DoubleUnaryOperator f)
      Applies the provided mapper function f to each component of this vector, then returns a new vector containing the return values of the function f.
      Specified by:
      map in interface DoubleTuple
      Parameters:
      f - The function of which to apply to each component of this vector
      Returns:
      The resulting vector
    • merge

      @Nonnull V merge(@Nonnull V v, @Nonnull BinaryOperator<Double> f)
      Between this vector and the provided vector v, this applies the merger function f to each corresponding pair of components, then returns a new vector whose components are populated from the return values of the function f.
      Parameters:
      v - The vector of which to merge this vector with
      f - The merger function to handle the merging of the two vectors
      Returns:
      The resulting vector
    • equals

      boolean equals(@Nullable V v)
      Checks for equality between this vector and the provided vector v.
      Parameters:
      v - The vector to compare to
      Returns:
      true if the component values are equal