Class Decimal3

java.lang.Object
civitas.celestis.util.tuple.Object3<BigDecimal>
civitas.celestis.math.decimal.Decimal3
All Implemented Interfaces:
DecimalVector<Decimal3,Vector3>, BigVector<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>, BaseTuple<BigDecimal>, Tuple<BigDecimal>, Serializable, Iterable<BigDecimal>

public class Decimal3 extends Object3<BigDecimal> implements DecimalVector<Decimal3,Vector3>
An immutable three-dimensional decimal vector.
See Also:
  • Field Details

    • ZERO

      public static final Decimal3 ZERO
      A vector of no direction or magnitude. Represents origin.
    • POSITIVE_A

      public static final Decimal3 POSITIVE_A
      The positive A unit vector.
    • POSITIVE_B

      public static final Decimal3 POSITIVE_B
      The positive B unit vector.
    • POSITIVE_C

      public static final Decimal3 POSITIVE_C
      The positive C unit vector.
    • NEGATIVE_A

      public static final Decimal3 NEGATIVE_A
      The negative A unit vector.
    • NEGATIVE_B

      public static final Decimal3 NEGATIVE_B
      The negative B unit vector.
    • NEGATIVE_C

      public static final Decimal3 NEGATIVE_C
      The negative C unit vector.
  • Constructor Details

    • Decimal3

      public Decimal3(@Nonnull BigDecimal a, @Nonnull BigDecimal b, @Nonnull BigDecimal c)
      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
    • Decimal3

      public Decimal3(@Nonnull BigDecimal[] components)
      Creates a new vector.
      Parameters:
      components - An array containing the components of this vector in ABC order
      Throws:
      IllegalArgumentException - When the provided array's length is not 3
    • Decimal3

      public Decimal3(@Nonnull Tuple<? extends BigDecimal> 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 3
    • Decimal3

      public Decimal3(@Nonnull Vector3 v)
      Creates a new vector.
      Parameters:
      v - The vector 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<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      Returns:
      The Euclidean norm of this vector
    • norm2

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

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

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

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

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

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

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

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

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

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

      @Nonnull public Decimal3 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<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      Returns:
      The normalized vector of this vector if successful, zero otherwise
    • normalizeOrDefault

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

      @Nonnull public Decimal3 min(@Nonnull Decimal3 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<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      Parameters:
      v - The boundary vector of which to compare to
      Returns:
      The minimum vector of the two vectors
    • max

      @Nonnull public Decimal3 max(@Nonnull Decimal3 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<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      Parameters:
      v - The boundary vector of which to compare to
      Returns:
      The maximum vector of the two vectors
    • clamp

      @Nonnull public Decimal3 clamp(@Nonnull Decimal3 min, @Nonnull Decimal3 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<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      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 Decimal3 v)
      Returns the Euclidean distance between this vector and the provided vector v.
      Specified by:
      distance in interface BigVector<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      Parameters:
      v - The vector of which get the Euclidean distance between
      Returns:
      The Euclidean distance between the two vectors
    • distance2

      @Nonnull public BigDecimal distance2(@Nonnull Decimal3 v)
      Returns the squared Euclidean distance between this vector and the provided vector v.
      Specified by:
      distance2 in interface BigVector<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      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 BigDecimal distanceManhattan(@Nonnull Decimal3 v)
      Returns the Manhattan distance between this vector and the provided vector v.
      Specified by:
      distanceManhattan in interface BigVector<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      Parameters:
      v - The vector of which to get the Manhattan distance between
      Returns:
      The Manhattan distance between the two vectors
    • transform

      @Nonnull public Decimal3 transform(@Nonnull UnaryOperator<BigDecimal> 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<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      Parameters:
      f - The function of which to apply to each component of this vector
      Returns:
      The resulting vector
    • merge

      @Nonnull public Decimal3 merge(@Nonnull Decimal3 v, @Nonnull BinaryOperator<BigDecimal> 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<BigDecimal,BigDecimal,Decimal3,Decimal3,Vector3>
      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
    • quaternion

      @Nonnull public DecimalQuaternion quaternion()
      Converts this vector into a pure quaternion. (a quaternion whose scalar part is 0, and the vector part is populated from this vector's components)
      Returns:
      A pure quaternion constructed from this vector
    • rotate

      @Nonnull public Decimal3 rotate(@Nonnull DecimalQuaternion q)
      Rotates this vector by the provided rotation quaternion q.
      Parameters:
      q - The rotation quaternion of which to apply to this vector
      Returns:
      The rotated vector
    • primValue

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

      @Nonnull public Integer3 bigIntegerValue()
      Converts this vector into a big integer vector.
      Specified by:
      bigIntegerValue in interface DecimalVector<Decimal3,Vector3>
      Returns:
      The big integer representation of this vector
    • equals

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