Class Vector2Int

  • All Implemented Interfaces:
    IVector2

    public class Vector2Int
    extends java.lang.Object
    implements IVector2
    Implementation of a 2-vector using integer values.
    • Field Detail

      • ZERO

        public static final IVector2 ZERO
        Zero vector.
      • UNIT

        public static final IVector2 UNIT
    • Constructor Detail

      • Vector2Int

        public Vector2Int()
        Creates a new Vector2Int with the value (0,0).
      • Vector2Int

        public Vector2Int​(IVector2 vector)
        Creates a new Vector2 with the same value as the input vector.
      • Vector2Int

        public Vector2Int​(int scalar)
        Creates a new Vector2Int using the scalar to assign the value (scalar,scalar).
      • Vector2Int

        public Vector2Int​(int x,
                          int y)
        Creates a new Vector2Int with the given value.
    • Method Detail

      • assign

        public IVector2 assign​(IVector2 vector)
        Assigns this vector the values of another vector.
        Specified by:
        assign in interface IVector2
        Parameters:
        vector - the other vector
        Returns:
        a reference to the called vector (NOT a copy)
      • add

        public IVector2 add​(double scalar)
        Adds a scalar to each component of this vector.
        Specified by:
        add in interface IVector2
        Parameters:
        scalar - scalar value as double
        Returns:
        a reference to the called vector (NOT a copy)
      • add

        public IVector2 add​(IVector1 scalar)
        Adds a scalar to each component of this vector.
        Specified by:
        add in interface IVector2
        Parameters:
        scalar - scalar value
        Returns:
        a reference to the called vector (NOT a copy)
      • add

        public IVector2 add​(IVector2 vector)
        Adds another vector to this vector, adding individual components.
        Specified by:
        add in interface IVector2
        Parameters:
        vector - the vector to add to this vector
        Returns:
        a reference to the called vector (NOT a copy)
      • subtract

        public IVector2 subtract​(double scalar)
        Subtracts a scalar to each component of this vector.
        Specified by:
        subtract in interface IVector2
        Parameters:
        scalar - scalar value as double
        Returns:
        a reference to the called vector (NOT a copy)
      • subtract

        public IVector2 subtract​(IVector1 scalar)
        Subtracts a scalar to each component of this vector.
        Specified by:
        subtract in interface IVector2
        Parameters:
        scalar - scalar value
        Returns:
        a reference to the called vector (NOT a copy)
      • subtract

        public IVector2 subtract​(IVector2 vector)
        Subtracts another vector to this vector, subtracting individual components.
        Specified by:
        subtract in interface IVector2
        Parameters:
        vector - the vector to subtract from this vector
        Returns:
        a reference to the called vector (NOT a copy)
      • mod

        public IVector2 mod​(IVector2 modulus)
        Applies a modulo vector. The modulus will be added first so that values in the interval (-modulus, 0) will wrap over into the positive range.
        Specified by:
        mod in interface IVector2
        Parameters:
        modulus - modulus
        Returns:
        a reference to the called vector (NOT a copy)
      • multiply

        public IVector2 multiply​(double scalar)
        Performs a scalar multiplication (scaling) on the vector.
        Specified by:
        multiply in interface IVector2
        Parameters:
        scalar - the scale factor double
        Returns:
        a reference to the called vector (NOT a copy)
      • multiply

        public IVector2 multiply​(IVector1 scalar)
        Performs a scalar multiplication (scaling) on the vector.
        Specified by:
        multiply in interface IVector2
        Parameters:
        scalar - the scale factor
        Returns:
        a reference to the called vector (NOT a copy)
      • multiply

        public IVector2 multiply​(IVector2 vector)
        Performs a multiplication on the vector.
        Specified by:
        multiply in interface IVector2
        Parameters:
        vector - vector
        Returns:
        a reference to the called vector (NOT a copy)
      • divide

        public IVector2 divide​(IVector2 vector)
        Performs a division on the vector.
        Specified by:
        divide in interface IVector2
        Parameters:
        vector - vector
        Returns:
        a reference to the called vector (NOT a copy)
      • zero

        public IVector2 zero()
        Sets all vector components to zero.
        Specified by:
        zero in interface IVector2
        Returns:
        a reference to the called vector (NOT a copy)
      • negateX

        public IVector2 negateX()
        Negates the x-component.
        Specified by:
        negateX in interface IVector2
        Returns:
        a reference to the called vector (NOT a copy)
      • negateY

        public IVector2 negateY()
        Negates the y-component.
        Specified by:
        negateY in interface IVector2
        Returns:
        a reference to the called vector (NOT a copy)
      • negate

        public IVector2 negate()
        Negates the vector by negating its components.
        Specified by:
        negate in interface IVector2
        Returns:
        a reference to the called vector (NOT a copy)
      • randomX

        public IVector2 randomX​(IVector1 lower,
                                IVector1 upper)
        Sets the x-component to a random value in the interval [lower,upper]
        Specified by:
        randomX in interface IVector2
        Returns:
        a reference to the called vector (NOT a copy)
      • randomY

        public IVector2 randomY​(IVector1 lower,
                                IVector1 upper)
        Sets the y-component to a random value in the interval [lower,upper]
        Specified by:
        randomY in interface IVector2
        Returns:
        a reference to the called vector (NOT a copy)
      • normalize

        public IVector2 normalize()
        Converts the vector to a unit vector (normalization)
        Specified by:
        normalize in interface IVector2
      • redirect

        public IVector2 redirect​(double angle)
        Redirects the vector to a new direction, maintaining the magnitude.
        Specified by:
        redirect in interface IVector2
        Parameters:
        angle - The new direction.
        Returns:
        The vector.
      • getLength

        public IVector1 getLength()
        Returns the length (magnitude) of the vector.
        Specified by:
        getLength in interface IVector2
        Returns:
        vector length
      • getSquaredLength

        public IVector1 getSquaredLength()
        Returns the squared length (magnitude) of the vector.
        Specified by:
        getSquaredLength in interface IVector2
        Returns:
        squared vector length
      • getDirection

        public IVector1 getDirection()
        Returns the direction (theta) of the vector.
        Specified by:
        getDirection in interface IVector2
        Returns:
        vector direction
      • getDirectionAsFloat

        public float getDirectionAsFloat()
        Returns the direction (theta) of the vector as float.
        Specified by:
        getDirectionAsFloat in interface IVector2
        Returns:
        vector direction as float
      • getDirectionAsDouble

        public double getDirectionAsDouble()
        Returns the direction (theta) of the vector as double.
        Specified by:
        getDirectionAsDouble in interface IVector2
        Returns:
        vector direction as double
      • getMean

        public IVector1 getMean()
        Returns the mean average of the vector components.
        Specified by:
        getMean in interface IVector2
        Returns:
        vector direction
      • getDistance

        public IVector1 getDistance​(IVector2 vector)
        Returns the distance to another vector.
        Specified by:
        getDistance in interface IVector2
        Parameters:
        vector - other vector
        Returns:
        distance
      • getX

        public IVector1 getX()
        Returns the x-component of the vector.
        Specified by:
        getX in interface IVector2
        Returns:
        x-component
      • getY

        public IVector1 getY()
        Returns the y-component of the vector.
        Specified by:
        getY in interface IVector2
        Returns:
        y-component
      • setX

        public void setX​(IVector1 x)
      • setY

        public void setY​(IVector1 y)
      • getXAsInteger

        public int getXAsInteger()
        Returns the x-component of the vector as integer.
        Specified by:
        getXAsInteger in interface IVector2
        Returns:
        x-component as integer
      • getYAsInteger

        public int getYAsInteger()
        Returns the component of the vector as integer.
        Specified by:
        getYAsInteger in interface IVector2
        Returns:
        y-component as float
      • getXAsLong

        public long getXAsLong()
        Returns the x-component of the vector as long.
        Specified by:
        getXAsLong in interface IVector2
        Returns:
        x-component as long
      • getYAsLong

        public long getYAsLong()
        Returns the component of the vector as float.
        Specified by:
        getYAsLong in interface IVector2
        Returns:
        y-component as float
      • getXAsFloat

        public float getXAsFloat()
        Returns the x-component of the vector as float.
        Specified by:
        getXAsFloat in interface IVector2
        Returns:
        x-component as float
      • getYAsFloat

        public float getYAsFloat()
        Returns the component of the vector as float.
        Specified by:
        getYAsFloat in interface IVector2
        Returns:
        y-component as float
      • getXAsDouble

        public double getXAsDouble()
        Returns the x-component of the vector as double.
        Specified by:
        getXAsDouble in interface IVector2
        Returns:
        x-component as double
      • getYAsDouble

        public double getYAsDouble()
        Returns the component of the vector as double.
        Specified by:
        getYAsDouble in interface IVector2
        Returns:
        y-component as double
      • getXAsBigDecimal

        public java.math.BigDecimal getXAsBigDecimal()
        Returns the x-component of the vector as BigDecimal.
        Specified by:
        getXAsBigDecimal in interface IVector2
        Returns:
        x-component as BigDecimal
      • getYAsBigDecimal

        public java.math.BigDecimal getYAsBigDecimal()
        Returns the component of the vector as BigDecima;.
        Specified by:
        getYAsBigDecimal in interface IVector2
        Returns:
        y-component as BigDecimal
      • copy

        public IVector2 copy()
        Makes a copy of the vector without using the complex clone interface.
        Specified by:
        copy in interface IVector2
        Returns:
        copy of the vector
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Generates a deep clone of the vector.
        Specified by:
        clone in interface IVector2
        Overrides:
        clone in class java.lang.Object
        Returns:
        clone of this vector
        Throws:
        java.lang.CloneNotSupportedException
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares the vector to an object
        Specified by:
        equals in interface IVector2
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object
        Returns:
        always returns false unless the object is an IVector2, in which case it is equivalent to equals(IVector vector)
      • equals

        public boolean equals​(IVector2 vector)
        Compares the vector to another vector. The vectors are equal if the components are equal.
        Specified by:
        equals in interface IVector2
        Parameters:
        vector - the other vector
        Returns:
        true if the vectors are equal
      • hashCode

        public int hashCode()
        Compute the hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The hash code.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getVector2

        public static IVector2 getVector2​(java.lang.Integer a,
                                          java.lang.Integer b)
        Get a vector for two doubles.
        Parameters:
        a - The first value.
        b - The second value.
        Returns:
        The vector (null if at least one of args is null).
      • getInnerProductAsDouble

        public double getInnerProductAsDouble​(IVector2 vector)
        Description copied from interface: IVector2
        Returns the length (magnitude) of the vector.
        Specified by:
        getInnerProductAsDouble in interface IVector2
        Returns:
        vector length
      • getDirection

        public IVector1 getDirection​(IVector2 vector)
        Description copied from interface: IVector2
        Returns the direction (theta) of the vector.
        Specified by:
        getDirection in interface IVector2
        Returns:
        vector direction
      • getDirectionAsDouble

        public double getDirectionAsDouble​(IVector2 vector)
        Description copied from interface: IVector2
        Returns the direction (theta) of the vector as double.
        Specified by:
        getDirectionAsDouble in interface IVector2
        Returns:
        vector direction as double
      • getDirectionAsFloat

        public float getDirectionAsFloat​(IVector2 vector)
        Description copied from interface: IVector2
        Returns the direction (theta) of the vector as float.
        Specified by:
        getDirectionAsFloat in interface IVector2
        Returns:
        vector direction as float