Class Integer4

java.lang.Object
civitas.celestis.util.tuple.Object4<BigInteger>
civitas.celestis.math.integer.Integer4
All Implemented Interfaces:
IntegerVector<Integer4,Decimal4,Long4>, BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>, BaseTuple<BigInteger>, Tuple<BigInteger>, Serializable, Iterable<BigInteger>

public class Integer4 extends Object4<BigInteger> implements IntegerVector<Integer4,Decimal4,Long4>
An immutable four-dimensional BigInteger vector.
See Also:
  • Constructor Details

    • Integer4

      public Integer4(@Nonnull BigInteger a, @Nonnull BigInteger b, @Nonnull BigInteger c, @Nonnull BigInteger d)
      Creates a new vector.
      Parameters:
      a - The A component of this vector
      b - The B component of this vector
      c - The C component of this vector
      d - The D component of this vector
    • Integer4

      public Integer4(@Nonnull BigInteger[] components)
      Creates a new vector.
      Parameters:
      components - An array containing the component of this vector in ABCD order
      Throws:
      IllegalArgumentException - When the provided array's length is not 4
    • Integer4

      public Integer4(@Nonnull Tuple<? extends BigInteger> t)
      Creates a new vector.
      Parameters:
      t - The tuple of which to copy component values from
      Throws:
      IllegalArgumentException - When the provided tuple t's size is not 4
    • Integer4

      public Integer4(@Nonnull Long4 t)
      Creates a new vector.
      Parameters:
      t - The tuple of which to copy component values from
    • Integer4

      public Integer4(@Nonnull Int4 t)
      Creates a new vector.
      Parameters:
      t - The tuple of which to copy component values from
  • Method Details

    • requireNonNull

      protected final void requireNonNull()
      Requires that all components of this vector are non-null.
    • norm

      @Nonnull public BigDecimal norm()
      Returns the Euclidean norm (the magnitude) of this vector.
      Specified by:
      norm in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Returns:
      The Euclidean norm of this vector
    • norm2

      @Nonnull public BigInteger norm2()
      Returns the squared Euclidean norm (the squared magnitude) of this vector.
      Specified by:
      norm2 in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Returns:
      The squared Euclidean norm of this vector
    • normManhattan

      @Nonnull public BigInteger normManhattan()
      Returns the Manhattan norm of this vector.
      Specified by:
      normManhattan in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Returns:
      The Manhattan norm of this vector
    • add

      @Nonnull public Integer4 add(@Nonnull BigInteger s)
      Adds a scalar to this vector component-wise, then returns the resulting vector.
      Specified by:
      add in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      s - The scalar of which to add to each component of this vector
      Returns:
      The resulting vector
    • subtract

      @Nonnull public Integer4 subtract(@Nonnull BigInteger s)
      Subtracts this vector by a scalar component-wise, then returns the resulting vector.
      Specified by:
      subtract in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      s - The scalar of which to subtract from each component of this vector
      Returns:
      The resulting vector
    • multiply

      @Nonnull public Integer4 multiply(@Nonnull BigInteger s)
      Multiplies this vector by a scalar component-wise, then returns the resulting vector.
      Specified by:
      multiply in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      s - The scalar of which to multiply each component of this vector by
      Returns:
      The resulting vector
    • divide

      @Nonnull public Integer4 divide(@Nonnull BigInteger s) throws ArithmeticException
      Divides this vector by a scalar component-wise, then returns the resulting vector.
      Specified by:
      divide in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      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 public Integer4 add(@Nonnull Integer4 v)
      Adds another vector to this vector, then returns the resulting vector.
      Specified by:
      add in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The vector of which to add to this vector
      Returns:
      The resulting vector
    • subtract

      @Nonnull public Integer4 subtract(@Nonnull Integer4 v)
      Subtracts another vector from this vector, then returns the resulting vector.
      Specified by:
      subtract in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The vector of which to subtract from this vector
      Returns:
      The resulting vector
    • dot

      @Nonnull public BigInteger dot(@Nonnull Integer4 v)
      Returns the dot product between this vector and the provided vector v.
      Specified by:
      dot in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The vector of which to get the dot product between
      Returns:
      The dot product between the two vectors
    • normalize

      @Nonnull public Decimal4 normalize() throws ArithmeticException
      Normalizes this vector to have a Euclidean norm (magnitude) of 1.
      Specified by:
      normalize in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Returns:
      The normalized vector of this vector
      Throws:
      ArithmeticException - When the Euclidean norm of this vector is zero
    • normalizeOrZero

      @Nonnull public Decimal4 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)
      Specified by:
      normalizeOrZero in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Returns:
      The normalized vector of this vector if successful, zero otherwise
    • normalizeOrDefault

      @Nonnull public Decimal4 normalizeOrDefault(@Nonnull Decimal4 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.
      Specified by:
      normalizeOrDefault in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      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 public Integer4 negate()
      Negates all components of this vector, then returns the resulting vector.
      Specified by:
      negate in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Returns:
      The negation of this vector
    • min

      @Nonnull public Integer4 min(@Nonnull Integer4 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.
      Specified by:
      min in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The boundary vector of which to compare to
      Returns:
      The minimum vector of the two vectors
    • max

      @Nonnull public Integer4 max(@Nonnull Integer4 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.
      Specified by:
      max in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The boundary vector of which to compare to
      Returns:
      The maximum vector of the two vectors
    • clamp

      @Nonnull public Integer4 clamp(@Nonnull Integer4 min, @Nonnull Integer4 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.
      Specified by:
      clamp in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      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

      @Nonnull public BigDecimal distance(@Nonnull Integer4 v)
      Returns the Euclidean distance between this vector and the provided vector v.
      Specified by:
      distance in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The vector of which get the Euclidean distance between
      Returns:
      The Euclidean distance between the two vectors
    • distance2

      @Nonnull public BigInteger distance2(@Nonnull Integer4 v)
      Returns the squared Euclidean distance between this vector and the provided vector v.
      Specified by:
      distance2 in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The vector of which to get the squared Euclidean distance between
      Returns:
      The squared Euclidean distance between the two vectors
    • distanceManhattan

      @Nonnull public BigInteger distanceManhattan(@Nonnull Integer4 v)
      Returns the Manhattan distance between this vector and the provided vector v.
      Specified by:
      distanceManhattan in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The vector of which to get the Manhattan distance between
      Returns:
      The Manhattan distance between the two vectors
    • transform

      @Nonnull public Integer4 transform(@Nonnull UnaryOperator<BigInteger> f)
      Applies the provided transformation function f to each component of this vector, then returns a new vector containing the return values of the function f.
      Specified by:
      transform in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      f - The function of which to apply to each component of this vector
      Returns:
      The resulting vector
    • merge

      @Nonnull public Integer4 merge(@Nonnull Integer4 v, @Nonnull BinaryOperator<BigInteger> 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.
      Specified by:
      merge in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      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
    • primValue

      @Nonnull public Long4 primValue()
      Converts this vector into a primitive vector. Precision and/or scale may be lost.
      Specified by:
      primValue in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Returns:
      The primitive representation of this vector
    • equals

      public boolean equals(@Nullable Integer4 v)
      Checks for equality between this vector and the provided vector v.
      Specified by:
      equals in interface BigVector<BigInteger,BigDecimal,Integer4,Decimal4,Long4>
      Parameters:
      v - The vector to compare to
      Returns:
      true if the component values are equal