Package civitas.celestis.math.integer
Class Integer2
- All Implemented Interfaces:
IntegerVector<Integer2,,Decimal2, Long2> BigVector<BigInteger,,BigDecimal, Integer2, Decimal2, Long2> BaseTuple<BigInteger>,Tuple<BigInteger>,Serializable,Iterable<BigInteger>
An immutable two-dimensional
BigInteger vector.- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new vector.Creates a new vector.Integer2(Tuple<? extends BigInteger> t) Creates a new vector.Integer2(BigInteger[] components) Creates a new vector.Integer2(BigInteger a, BigInteger b) Creates a new vector. -
Method Summary
Modifier and TypeMethodDescriptionAdds another vector to this vector, then returns the resulting vector.add(BigInteger s) Adds a scalar to this vector component-wise, then returns the resulting vector.Between this vector and the provided boundary vectorsminandmax, this returns a new vector whose components are clamped to respect the range of[min, max].Returns the Euclidean distance between this vector and the provided vectorv.Returns the squared Euclidean distance between this vector and the provided vectorv.Returns the Manhattan distance between this vector and the provided vectorv.divide(BigInteger s) Divides this vector by a scalar component-wise, then returns the resulting vector.Returns the dot product between this vector and the provided vectorv.booleanChecks for equality between this vector and the provided vectorv.Between this vector and the provided boundary vectorv, 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.merge(Integer2 v, BinaryOperator<BigInteger> f) Between this vector and the provided vectorv, this applies the merger functionfto each corresponding pair of components, then returns a new vector whose components are populated from the return values of the functionf.Between this vector and the provided boundary vectorv, 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.Multiplies this vector by a scalar component-wise, then returns the resulting vector.negate()Negates all components of this vector, then returns the resulting vector.norm()Returns the Euclidean norm (the magnitude) of this vector.norm2()Returns the squared Euclidean norm (the squared magnitude) of this vector.Normalizes this vector to have a Euclidean norm (magnitude) of1.Normalizes this vector to have a Euclidean norm (magnitude) of1.Normalizes this vector ot have a Euclidean norm (magnitude) of1.Returns the Manhattan norm of this vector.Converts this vector into a primitive vector.protected final voidRequires that all components of this vector are non-null.Subtracts another vector from this vector, then returns the resulting vector.Subtracts this vector by a scalar component-wise, then returns the resulting vector.Applies the provided transformation functionfto each component of this vector, then returns a new vector containing the return values of the function f.Methods inherited from class civitas.celestis.util.tuple.Object2
a, array, b, contains, containsAll, equals, forEach, forEach, get, hashCode, iterator, list, map, mapToDouble, mapToFloat, mapToInt, mapToLong, merge, size, stream, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
spliterator
-
Field Details
-
ZERO
A vector of no direction or magnitude. Represents origin. -
POSITIVE_A
The positive A unit vector. -
POSITIVE_B
The positive B unit vector. -
NEGATIVE_A
The negative A unit vector. -
NEGATIVE_B
The negative B unit vector.
-
-
Constructor Details
-
Integer2
Creates a new vector.- Parameters:
a- The A component of this vectorb- The B component of this vector
-
Integer2
Creates a new vector.- Parameters:
components- An array containing the components of this vector in AB order- Throws:
IllegalArgumentException- When the provided array's length is not2
-
Integer2
Creates a new vector.- Parameters:
t- The tuple of which to copy component values from- Throws:
IllegalArgumentException- When the provided tuplet's size is not2
-
Integer2
Creates a new vector.- Parameters:
t- The tuple of which to copy component values from
-
Integer2
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
Returns the Euclidean norm (the magnitude) of this vector.- Specified by:
normin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Returns:
- The Euclidean norm of this vector
-
norm2
Returns the squared Euclidean norm (the squared magnitude) of this vector.- Specified by:
norm2in interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Returns:
- The squared Euclidean norm of this vector
-
normManhattan
Returns the Manhattan norm of this vector.- Specified by:
normManhattanin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Returns:
- The Manhattan norm of this vector
-
add
Adds a scalar to this vector component-wise, then returns the resulting vector.- Specified by:
addin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
s- The scalar of which to add to each component of this vector- Returns:
- The resulting vector
-
subtract
Subtracts this vector by a scalar component-wise, then returns the resulting vector.- Specified by:
subtractin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
s- The scalar of which to subtract from each component of this vector- Returns:
- The resulting vector
-
multiply
Multiplies this vector by a scalar component-wise, then returns the resulting vector.- Specified by:
multiplyin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
s- The scalar of which to multiply each component of this vector by- Returns:
- The resulting vector
-
divide
Divides this vector by a scalar component-wise, then returns the resulting vector.- Specified by:
dividein interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
s- The scalar of which to divide each component of this vector by- Returns:
- The resulting vector
- Throws:
ArithmeticException- When the denominatorsis zero
-
add
Adds another vector to this vector, then returns the resulting vector.- Specified by:
addin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector of which to add to this vector- Returns:
- The resulting vector
-
subtract
Subtracts another vector from this vector, then returns the resulting vector.- Specified by:
subtractin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector of which to subtract from this vector- Returns:
- The resulting vector
-
dot
Returns the dot product between this vector and the provided vectorv.- Specified by:
dotin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector of which to get the dot product between- Returns:
- The dot product between the two vectors
-
normalize
Normalizes this vector to have a Euclidean norm (magnitude) of1.- Specified by:
normalizein interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Returns:
- The normalized vector of this vector
- Throws:
ArithmeticException- When the Euclidean norm of this vector is zero
-
normalizeOrZero
Normalizes this vector ot have a Euclidean norm (magnitude) of1. 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:
normalizeOrZeroin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Returns:
- The normalized vector of this vector if successful, zero otherwise
-
normalizeOrDefault
Normalizes this vector to have a Euclidean norm (magnitude) of1. If this vector's Euclidean norm is zero, this will return the provided fallback valuev.- Specified by:
normalizeOrDefaultin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - 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
votherwise
-
negate
Negates all components of this vector, then returns the resulting vector.- Specified by:
negatein interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Returns:
- The negation of this vector
-
min
Between this vector and the provided boundary vectorv, 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:
minin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The boundary vector of which to compare to- Returns:
- The minimum vector of the two vectors
-
max
Between this vector and the provided boundary vectorv, 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:
maxin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The boundary vector of which to compare to- Returns:
- The maximum vector of the two vectors
-
clamp
Between this vector and the provided boundary vectorsminandmax, 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:
clampin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
min- The minimum boundary vector to compare tomax- The maximum boundary vector to compare to- Returns:
- The clamped vector which respects the boundaries of
[min, max]
-
distance
Returns the Euclidean distance between this vector and the provided vectorv.- Specified by:
distancein interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector of which get the Euclidean distance between- Returns:
- The Euclidean distance between the two vectors
-
distance2
Returns the squared Euclidean distance between this vector and the provided vectorv.- Specified by:
distance2in interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector of which to get the squared Euclidean distance between- Returns:
- The squared Euclidean distance between the two vectors
-
distanceManhattan
Returns the Manhattan distance between this vector and the provided vectorv.- Specified by:
distanceManhattanin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector of which to get the Manhattan distance between- Returns:
- The Manhattan distance between the two vectors
-
transform
Applies the provided transformation functionfto each component of this vector, then returns a new vector containing the return values of the function f.- Specified by:
transformin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
f- The function of which to apply to each component of this vector- Returns:
- The resulting vector
-
merge
Between this vector and the provided vectorv, this applies the merger functionfto each corresponding pair of components, then returns a new vector whose components are populated from the return values of the functionf.- Specified by:
mergein interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector of which to merge this vector withf- The merger function to handle the merging of the two vectors- Returns:
- The resulting vector
-
primValue
Converts this vector into a primitive vector. Precision and/or scale may be lost.- Specified by:
primValuein interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Returns:
- The primitive representation of this vector
-
equals
Checks for equality between this vector and the provided vectorv.- Specified by:
equalsin interfaceBigVector<BigInteger,BigDecimal, Integer2, Decimal2, Long2> - Parameters:
v- The vector to compare to- Returns:
trueif the component values are equal
-