public final class UnitRectangular extends Object implements IEquatable<UnitRectangular>, IEquatableEpsilon<UnitRectangular>, ImmutableValueType
The normalization of the rectilinear coordinate pair is accomplished in the usual way. It should be noted that this does not guarantee a result whose magnitude will be 1.0 in cases where an individual component underflows upon squaring.
The corresponding 3-dimensional coordinates are UnitCartesian
coordinates.
Constructor and Description |
---|
UnitRectangular()
Initializes a new instance.
|
UnitRectangular(double clock)
Initializes a set of
UnitRectangular coordinates from the provided polar coordinates. |
UnitRectangular(double[] elements)
Initializes a set of
UnitRectangular coordinates from the first 2 consecutive elements in the provided array. |
UnitRectangular(double[] elements,
int startIndex)
Initializes a set of
UnitRectangular coordinates from 2 consecutive elements in the provided array. |
UnitRectangular(double x,
double y)
Initializes a set of
UnitRectangular coordinates from the provided values. |
UnitRectangular(double x,
double y,
double[] magnitude)
Initializes a set of
UnitRectangular coordinates from the provided values. |
UnitRectangular(Rectangular coordinates)
Initializes a set of
UnitRectangular coordinates from the provided set of Rectangular coordinates. |
Modifier and Type | Method and Description |
---|---|
Rectangular |
add(Rectangular other)
Adds the specified set of
Rectangular coordinates to this instance. |
static Rectangular |
add(Rectangular left,
UnitRectangular right)
Adds a specified set of
UnitRectangular coordinates to a specified set of Rectangular coordinates. |
Rectangular |
add(UnitRectangular other)
Adds the specified set of
UnitRectangular coordinates to this instance. |
static Rectangular |
add(UnitRectangular left,
Rectangular right)
Adds a specified set of
UnitRectangular coordinates to a specified set of Rectangular coordinates. |
static Rectangular |
add(UnitRectangular left,
UnitRectangular right)
Adds a specified set of
UnitRectangular coordinates to another specified set of UnitRectangular coordinates. |
double |
angleBetween(UnitRectangular other)
Determines the angle in radians between the specified set of
UnitRectangular coordinates and this instance. |
Rectangular |
divide(double scalar)
Divides this instance by a scalar.
|
static Rectangular |
divide(UnitRectangular left,
double right)
Divides a specified set of
UnitRectangular coordinates by a scalar. |
double |
dot(Rectangular other)
Forms the dot product of the specified set of
Rectangular coordinates with this instance. |
double |
dot(UnitRectangular other)
Forms the dot product of the specified set of
UnitRectangular coordinates with this instance. |
boolean |
equals(Object obj)
Indicates whether another object is exactly equal to this instance.
|
static boolean |
equals(UnitRectangular left,
UnitRectangular right)
Returns
true if the two instances are exactly equal. |
boolean |
equalsEpsilon(UnitRectangular other,
double epsilon)
Indicates whether each coordinate value of another instance of this type
is within the required tolerance of the corresponding coordinate value of this instance.
|
boolean |
equalsType(UnitRectangular other)
Indicates whether another instance of this type is exactly equal to this instance.
|
double |
get(int index)
|
boolean |
getIsUndefined()
Gets a value indicating whether or not any of the coordinates for this instance have the value
Double.NaN . |
int |
getLength()
Gets the number of elements in this set of coordinates.
|
UnitRectangular |
getMostOrthogonalAxis()
Gets the axis which is most orthogonal to this instance.
|
UnitRectangular |
getMostParallelAxis()
Gets the axis which is most parallel to this instance.
|
static UnitRectangular |
getUndefined()
Gets a set of
UnitRectangular coordinates with values of Double.NaN . |
static UnitRectangular |
getUnitX()
Gets a set of
UnitRectangular coordinates representing the x-axis. |
static UnitRectangular |
getUnitY()
Gets a set of
UnitRectangular coordinates representing the y-axis. |
double |
getX()
Gets the linear coordinate along the positive x-axis.
|
double |
getY()
Gets the linear coordinate along the positive y-axis.
|
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
UnitRectangular |
invert()
Inverts this instance.
|
Rectangular |
multiply(double scalar)
Multiplies this instance by a scalar.
|
static Rectangular |
multiply(double left,
UnitRectangular right)
Multiplies a scalar by a specified set of
UnitRectangular coordinates. |
static Rectangular |
multiply(UnitRectangular left,
double right)
Multiplies a specified set of
UnitRectangular coordinates by a scalar. |
static UnitRectangular |
negate(UnitRectangular coordinates)
Negates the specified
UnitRectangular , yielding a new UnitRectangular . |
static boolean |
notEquals(UnitRectangular left,
UnitRectangular right)
Returns
true if the two instances are not exactly equal. |
UnitRectangular |
rotate(double angle)
Produces a set of
UnitRectangular coordinates representing this instance which results from rotating
the original axes used to represent this instance by the provided angle. |
Rectangular |
subtract(Rectangular other)
Subtracts the specified set of
Rectangular coordinates from this instance. |
static Rectangular |
subtract(Rectangular left,
UnitRectangular right)
Subtracts a specified set of
UnitRectangular coordinates from a specified set of Rectangular coordinates. |
Rectangular |
subtract(UnitRectangular other)
Subtracts the specified set of
UnitRectangular coordinates from this instance. |
static Rectangular |
subtract(UnitRectangular left,
Rectangular right)
Subtracts a specified set of
Rectangular coordinates from a specified set of UnitRectangular coordinates. |
static Rectangular |
subtract(UnitRectangular left,
UnitRectangular right)
Subtracts a specified set of
UnitRectangular coordinates from another specified set of UnitRectangular coordinates. |
String |
toString()
Returns the string representation of the value of this instance.
|
public UnitRectangular()
public UnitRectangular(double x, double y)
UnitRectangular
coordinates from the provided values.x
- The linear coordinate along the positive x-axis.y
- The linear coordinate along the positive y-axis.ArithmeticException
- The magnitude of the provided coordinates must not be zero.NotFiniteNumberException
- The magnitude of the provided coordinates must not be infinite.public UnitRectangular(double x, double y, @Nonnull double[] magnitude)
UnitRectangular
coordinates from the provided values.x
- The linear coordinate along the positive x-axis.y
- The linear coordinate along the positive y-axis.magnitude
- On input, an array with one element. On return, the array is populated with
the magnitude of the original set of coordinates.ArithmeticException
- The magnitude of the provided coordinates must not be zero.NotFiniteNumberException
- The magnitude of the provided coordinates must not be infinite.public UnitRectangular(@Nonnull Rectangular coordinates)
UnitRectangular
coordinates from the provided set of Rectangular
coordinates.coordinates
- The set of Rectangular
coordinates.ArithmeticException
- The magnitude of the provided coordinates must not be zero.NotFiniteNumberException
- The magnitude of the provided coordinates must not be infinite.public UnitRectangular(double clock)
UnitRectangular
coordinates from the provided polar coordinates.clock
- The angular coordinate lying in the xy-plane measured from the positive x-axis and toward the positive y-axis.public UnitRectangular(@Nonnull double[] elements)
UnitRectangular
coordinates from the first 2 consecutive elements in the provided array.elements
- The array of coordinate values.ArgumentNullException
- Thrown when elements
is null
.ArgumentOutOfRangeException
- An object of this type must be constructed from an array with at least 2 elements
.ArithmeticException
- The magnitude of the provided coordinates must not be zero.NotFiniteNumberException
- The magnitude of the provided coordinates must not be infinite.public UnitRectangular(@Nonnull double[] elements, int startIndex)
UnitRectangular
coordinates from 2 consecutive elements in the provided array.elements
- The array of coordinate values.startIndex
- The index of the first element in the array to use.ArgumentNullException
- Thrown when elements
is null
.ArgumentOutOfRangeException
- Thrown when an object of this type is constructed from an array with less than 2 elements
.ArithmeticException
- Thrown when the magnitude of the provided coordinates are zero.NotFiniteNumberException
- Thrown when the magnitude of the provided coordinates is infinite.@Nonnull public static UnitRectangular getUndefined()
UnitRectangular
coordinates with values of Double.NaN
.
Use IsUndefined
(get
) to test whether a UnitRectangular
instance
is undefined since it will return true
if any of the coordinate values
are Double.NaN
.
@Nonnull public static UnitRectangular getUnitX()
UnitRectangular
coordinates representing the x-axis.@Nonnull public static UnitRectangular getUnitY()
UnitRectangular
coordinates representing the y-axis.public final double getX()
public final double getY()
@Nonnull public final UnitRectangular invert()
UnitRectangular
coordinates that represents the inverse of this instance.@Nonnull public final Rectangular multiply(double scalar)
scalar
- The multiplier, or value which is to multiply this instance.Rectangular
coordinates that represents the result of the multiplication.@Nonnull public final Rectangular divide(double scalar)
scalar
- The divisor, or value which is to divide this instance.Rectangular
coordinates that represents the result of the division.@Nonnull public final Rectangular add(@Nonnull Rectangular other)
Rectangular
coordinates to this instance.other
- The addend, or value which is to be added to this instance.Rectangular
coordinates that represents the result of the addition.@Nonnull public final Rectangular add(@Nonnull UnitRectangular other)
UnitRectangular
coordinates to this instance.other
- The addend, or value which is to be added to this instance.Rectangular
coordinates that represents the result of the addition.@Nonnull public final Rectangular subtract(@Nonnull Rectangular other)
Rectangular
coordinates from this instance.other
- The subtrahend, or value which is to be subtracted from this instance.Rectangular
coordinates that represents the result of the subtraction.@Nonnull public final Rectangular subtract(@Nonnull UnitRectangular other)
UnitRectangular
coordinates from this instance.other
- The subtrahend, or value which is to be subtracted from this instance.Rectangular
coordinates that represents the result of the subtraction.public final double dot(@Nonnull Rectangular other)
Rectangular
coordinates with this instance.other
- The set of Rectangular
coordinates to dot with this instance.double
that represents the result of the product.public final double dot(@Nonnull UnitRectangular other)
UnitRectangular
coordinates with this instance.other
- The set of UnitRectangular
coordinates to dot with this instance.double
that represents the result of the product.@Nonnull public static Rectangular multiply(@Nonnull UnitRectangular left, double right)
UnitRectangular
coordinates by a scalar.left
- The multiplicand, or value which is to be multiplied by right
.right
- The multiplier, or value which is to multiply left
.Rectangular
coordinates that represents the result of the multiplication.@Nonnull public static Rectangular multiply(double left, @Nonnull UnitRectangular right)
UnitRectangular
coordinates.left
- The multiplicand, or value which is to be multiplied by right
.right
- The multiplier, or value which is to multiply left
.Rectangular
coordinates that represents the result of the multiplication.@Nonnull public static Rectangular divide(@Nonnull UnitRectangular left, double right)
UnitRectangular
coordinates by a scalar.left
- The dividend, or value which is to be divided by right
.right
- The divisor, or value which is to divide left
.Rectangular
coordinates that represents the result of the division.@Nonnull public static Rectangular add(@Nonnull UnitRectangular left, @Nonnull UnitRectangular right)
UnitRectangular
coordinates to another specified set of UnitRectangular
coordinates.left
- The augend, or value to which right
is to be added.right
- The addend, or value which is to be added to left
.Rectangular
coordinates that represents the result of the addition.@Nonnull public static Rectangular add(@Nonnull UnitRectangular left, @Nonnull Rectangular right)
UnitRectangular
coordinates to a specified set of Rectangular
coordinates.left
- The augend, or value to which right
is to be added.right
- The addend, or value which is to be added to left
.Rectangular
coordinates that represents the result of the addition.@Nonnull public static Rectangular add(@Nonnull Rectangular left, @Nonnull UnitRectangular right)
UnitRectangular
coordinates to a specified set of Rectangular
coordinates.left
- The augend, or value to which right
is to be added.right
- The addend, or value which is to be added to left
.Rectangular
coordinates that represents the result of the addition.@Nonnull public static Rectangular subtract(@Nonnull UnitRectangular left, @Nonnull UnitRectangular right)
UnitRectangular
coordinates from another specified set of UnitRectangular
coordinates.left
- The minuend, or value from which right
is to be subtracted.right
- The subtrahend, or value which is to be subtracted from left
.Rectangular
coordinates that represents the result of the subtraction.@Nonnull public static Rectangular subtract(@Nonnull UnitRectangular left, @Nonnull Rectangular right)
Rectangular
coordinates from a specified set of UnitRectangular
coordinates.left
- The minuend, or value from which right
is to be subtracted.right
- The subtrahend, or value which is to be subtracted from left
.Rectangular
coordinates that represents the result of the subtraction.@Nonnull public static Rectangular subtract(@Nonnull Rectangular left, @Nonnull UnitRectangular right)
UnitRectangular
coordinates from a specified set of Rectangular
coordinates.left
- The minuend, or value from which right
is to be subtracted.right
- The subtrahend, or value which is to be subtracted from left
.Rectangular
coordinates that represents the result of the subtraction.@Nonnull public static UnitRectangular negate(@Nonnull UnitRectangular coordinates)
UnitRectangular
, yielding a new UnitRectangular
.coordinates
- The set of coordinates.UnitCartesian
.@Nonnull public final UnitRectangular rotate(double angle)
UnitRectangular
coordinates representing this instance which results from rotating
the original axes used to represent this instance by the provided angle.
This type of rotation is sometimes referred to as an "alias rotation".
angle
- The angle of rotation.UnitRectangular
coordinates which is the result of the rotation.@Nonnull public final UnitRectangular getMostOrthogonalAxis()
@Nonnull public final UnitRectangular getMostParallelAxis()
public final int getLength()
public final double get(int index)
index
of 0 and 1 corresponding to the coordinates
X
(get
), and Y
(get
).index
- The index to retrieve.index
.ArgumentOutOfRangeException
- Thrown when index
is less than 0 or greater than or equal to Length
(get
).public boolean equals(Object obj)
equals
in class Object
obj
- The object to compare to this instance.true
if obj
is an instance of this type and represents the same value as this instance; otherwise false
.Object.hashCode()
,
HashMap
public final boolean equalsType(@Nonnull UnitRectangular other)
equalsType
in interface IEquatable<UnitRectangular>
other
- The instance to compare to this instance.true
if other
represents the same value as this instance; otherwise false
.public final boolean equalsEpsilon(@Nonnull UnitRectangular other, double epsilon)
equalsEpsilon
in interface IEquatableEpsilon<UnitRectangular>
other
- The set of UnitRectangular
coordinates to compare to this instance.epsilon
- The limit at which the absolute differences between the coordinate values will not be considered equal.true
if the absolute differences are less than or equal to epsilon
; otherwise false
.public int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public String toString()
public static boolean equals(@Nonnull UnitRectangular left, @Nonnull UnitRectangular right)
true
if the two instances are exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
represents the same value as right
; otherwise false
.public static boolean notEquals(@Nonnull UnitRectangular left, @Nonnull UnitRectangular right)
true
if the two instances are not exactly equal.left
- The instance to compare to right
.right
- The instance to compare to left
.true
if left
does not represent the same value as right
; otherwise false
.public final boolean getIsUndefined()
Double.NaN
.public final double angleBetween(@Nonnull UnitRectangular other)
UnitRectangular
coordinates and this instance.other
- The set of UnitRectangular
coordinates to evaluate.double
that represents the angle in radians between the two instances.