Package org.joml

Class Vector2i

    • Field Summary

      Fields 
      Modifier and Type Field Description
      int x
      The x component of the vector.
      int y
      The y component of the vector.
    • Constructor Summary

      Constructors 
      Constructor Description
      Vector2i​()
      Create a new Vector2i and initialize its components to zero.
      Vector2i​(double x, double y, int mode)
      Create a new Vector2i and initialize its component values and round using the given RoundingMode.
      Vector2i​(float x, float y, int mode)
      Create a new Vector2i and initialize its component values and round using the given RoundingMode.
      Vector2i​(int s)
      Create a new Vector2i and initialize both of its components with the given value.
      Vector2i​(int[] xy)
      Create a new Vector2i and initialize its two components from the first two elements of the given array.
      Vector2i​(int x, int y)
      Create a new Vector2i and initialize its components to the given values.
      Vector2i​(Vector2dc v, int mode)
      Create a new Vector2i and initialize its components to the rounded value of the given vector.
      Vector2i​(Vector2fc v, int mode)
      Create a new Vector2i and initialize its components to the rounded value of the given vector.
      Vector2i​(Vector2ic v)
      Create a new Vector2i and initialize its components to the one of the given vector.
    • Field Detail

      • x

        public int x
        The x component of the vector.
      • y

        public int y
        The y component of the vector.
    • Constructor Detail

      • Vector2i

        public Vector2i​()
        Create a new Vector2i and initialize its components to zero.
      • Vector2i

        public Vector2i​(int s)
        Create a new Vector2i and initialize both of its components with the given value.
        Parameters:
        s - the value of both components
      • Vector2i

        public Vector2i​(int x,
                        int y)
        Create a new Vector2i and initialize its components to the given values.
        Parameters:
        x - the x component
        y - the y component
      • Vector2i

        public Vector2i​(float x,
                        float y,
                        int mode)
        Create a new Vector2i and initialize its component values and round using the given RoundingMode.
        Parameters:
        x - the x component
        y - the y component
        mode - the RoundingMode to use
      • Vector2i

        public Vector2i​(double x,
                        double y,
                        int mode)
        Create a new Vector2i and initialize its component values and round using the given RoundingMode.
        Parameters:
        x - the x component
        y - the y component
        mode - the RoundingMode to use
      • Vector2i

        public Vector2i​(Vector2ic v)
        Create a new Vector2i and initialize its components to the one of the given vector.
        Parameters:
        v - the Vector2ic to copy the values from
      • Vector2i

        public Vector2i​(Vector2fc v,
                        int mode)
        Create a new Vector2i and initialize its components to the rounded value of the given vector.
        Parameters:
        v - the Vector2fc to round and copy the values from
        mode - the RoundingMode to use
      • Vector2i

        public Vector2i​(Vector2dc v,
                        int mode)
        Create a new Vector2i and initialize its components to the rounded value of the given vector.
        Parameters:
        v - the Vector2dc to round and copy the values from
        mode - the RoundingMode to use
      • Vector2i

        public Vector2i​(int[] xy)
        Create a new Vector2i and initialize its two components from the first two elements of the given array.
        Parameters:
        xy - the array containing at least three elements
    • Method Detail

      • x

        public int x​()
        Specified by:
        x in interface Vector2ic
        Returns:
        the value of the x component
      • y

        public int y​()
        Specified by:
        y in interface Vector2ic
        Returns:
        the value of the y component
      • set

        public Vector2i set​(int s)
        Set the x and y components to the supplied value.
        Parameters:
        s - scalar value of both components
        Returns:
        this
      • set

        public Vector2i set​(int x,
                            int y)
        Set the x and y components to the supplied values.
        Parameters:
        x - the x component
        y - the y component
        Returns:
        this
      • set

        public Vector2i set​(Vector2ic v)
        Set this Vector2i to the values of v.
        Parameters:
        v - the vector to copy from
        Returns:
        this
      • set

        public Vector2i set​(Vector2dc v)
        Set this Vector2i to the values of v using RoundingMode.TRUNCATE rounding.

        Note that due to the given vector v storing the components in double-precision, there is the possibility to lose precision.

        Parameters:
        v - the vector to copy from
        Returns:
        this
      • set

        public Vector2i set​(Vector2dc v,
                            int mode)
        Set this Vector2i to the values of v using the given RoundingMode.

        Note that due to the given vector v storing the components in double-precision, there is the possibility to lose precision.

        Parameters:
        v - the vector to copy from
        mode - the RoundingMode to use
        Returns:
        this
      • set

        public Vector2i set​(Vector2fc v,
                            int mode)
        Set this Vector2i to the values of v using the given RoundingMode.

        Note that due to the given vector v storing the components in double-precision, there is the possibility to lose precision.

        Parameters:
        v - the vector to copy from
        mode - the RoundingMode to use
        Returns:
        this
      • set

        public Vector2i set​(int[] xy)
        Set the two components of this vector to the first two elements of the given array.
        Parameters:
        xy - the array containing at least two elements
        Returns:
        this
      • setFromAddress

        public Vector2i setFromAddress​(long address)
        Set the values of this vector by reading 2 integer values from off-heap memory, starting at the given address.

        This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

        This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

        Parameters:
        address - the off-heap memory address to read the vector values from
        Returns:
        this
      • get

        public int get​(int component)
                throws IllegalArgumentException
        Description copied from interface: Vector2ic
        Get the value of the specified component of this vector.
        Specified by:
        get in interface Vector2ic
        Parameters:
        component - the component, within [0..1]
        Returns:
        the value
        Throws:
        IllegalArgumentException - if component is not within [0..1]
      • setComponent

        public Vector2i setComponent​(int component,
                                     int value)
                              throws IllegalArgumentException
        Set the value of the specified component of this vector.
        Parameters:
        component - the component whose value to set, within [0..1]
        value - the value to set
        Returns:
        this
        Throws:
        IllegalArgumentException - if component is not within [0..1]
      • getToAddress

        public Vector2ic getToAddress​(long address)
        Description copied from interface: Vector2ic
        Store this vector at the given off-heap memory address.

        This method will throw an UnsupportedOperationException when JOML is used with `-Djoml.nounsafe`.

        This method is unsafe as it can result in a crash of the JVM process when the specified address range does not belong to this process.

        Specified by:
        getToAddress in interface Vector2ic
        Parameters:
        address - the off-heap address where to store this vector
        Returns:
        this
      • sub

        public Vector2i sub​(Vector2ic v)
        Subtract the supplied vector from this one and store the result in this.
        Parameters:
        v - the vector to subtract
        Returns:
        this
      • sub

        public Vector2i sub​(Vector2ic v,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Subtract the supplied vector from this one and store the result in dest.
        Specified by:
        sub in interface Vector2ic
        Parameters:
        v - the vector to subtract
        dest - will hold the result
        Returns:
        dest
      • sub

        public Vector2i sub​(int x,
                            int y)
        Decrement the components of this vector by the given values.
        Parameters:
        x - the x component to subtract
        y - the y component to subtract
        Returns:
        this
      • sub

        public Vector2i sub​(int x,
                            int y,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Decrement the components of this vector by the given values and store the result in dest.
        Specified by:
        sub in interface Vector2ic
        Parameters:
        x - the x component to subtract
        y - the y component to subtract
        dest - will hold the result
        Returns:
        dest
      • lengthSquared

        public long lengthSquared​()
        Description copied from interface: Vector2ic
        Return the length squared of this vector.
        Specified by:
        lengthSquared in interface Vector2ic
        Returns:
        the length squared
      • lengthSquared

        public static long lengthSquared​(int x,
                                         int y)
        Get the length squared of a 2-dimensional single-precision vector.
        Parameters:
        x - The vector's x component
        y - The vector's y component
        Returns:
        the length squared of the given vector
      • length

        public double length​()
        Description copied from interface: Vector2ic
        Return the length of this vector.
        Specified by:
        length in interface Vector2ic
        Returns:
        the length
      • length

        public static double length​(int x,
                                    int y)
        Get the length of a 2-dimensional single-precision vector.
        Parameters:
        x - The vector's x component
        y - The vector's y component
        Returns:
        the length squared of the given vector
      • distance

        public double distance​(Vector2ic v)
        Description copied from interface: Vector2ic
        Return the distance between this Vector and v.
        Specified by:
        distance in interface Vector2ic
        Parameters:
        v - the other vector
        Returns:
        the distance
      • distance

        public double distance​(int x,
                               int y)
        Description copied from interface: Vector2ic
        Return the distance between this vector and (x, y).
        Specified by:
        distance in interface Vector2ic
        Parameters:
        x - the x component of the other vector
        y - the y component of the other vector
        Returns:
        the euclidean distance
      • distanceSquared

        public long distanceSquared​(Vector2ic v)
        Description copied from interface: Vector2ic
        Return the square of the distance between this vector and v.
        Specified by:
        distanceSquared in interface Vector2ic
        Parameters:
        v - the other vector
        Returns:
        the squared of the distance
      • distanceSquared

        public long distanceSquared​(int x,
                                    int y)
        Description copied from interface: Vector2ic
        Return the square of the distance between this vector and (x, y).
        Specified by:
        distanceSquared in interface Vector2ic
        Parameters:
        x - the x component of the other vector
        y - the y component of the other vector
        Returns:
        the square of the distance
      • gridDistance

        public long gridDistance​(Vector2ic v)
        Description copied from interface: Vector2ic
        Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance) (x, y).
        Specified by:
        gridDistance in interface Vector2ic
        Parameters:
        v - the other vector
        Returns:
        the grid distance
      • gridDistance

        public long gridDistance​(int x,
                                 int y)
        Description copied from interface: Vector2ic
        Return the grid distance in between (aka 1-Norm, Minkowski or Manhattan distance) (x, y).
        Specified by:
        gridDistance in interface Vector2ic
        Parameters:
        x - the x component of the other vector
        y - the y component of the other vector
        Returns:
        the grid distance
      • distance

        public static double distance​(int x1,
                                      int y1,
                                      int x2,
                                      int y2)
        Return the distance between (x1, y1) and (x2, y2).
        Parameters:
        x1 - the x component of the first vector
        y1 - the y component of the first vector
        x2 - the x component of the second vector
        y2 - the y component of the second vector
        Returns:
        the euclidean distance
      • distanceSquared

        public static long distanceSquared​(int x1,
                                           int y1,
                                           int x2,
                                           int y2)
        Return the squared distance between (x1, y1) and (x2, y2).
        Parameters:
        x1 - the x component of the first vector
        y1 - the y component of the first vector
        x2 - the x component of the second vector
        y2 - the y component of the second vector
        Returns:
        the euclidean distance squared
      • add

        public Vector2i add​(Vector2ic v)
        Add v to this vector.
        Parameters:
        v - the vector to add
        Returns:
        this
      • add

        public Vector2i add​(Vector2ic v,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Add the supplied vector to this one and store the result in dest.
        Specified by:
        add in interface Vector2ic
        Parameters:
        v - the vector to add
        dest - will hold the result
        Returns:
        dest
      • add

        public Vector2i add​(int x,
                            int y)
        Increment the components of this vector by the given values.
        Parameters:
        x - the x component to add
        y - the y component to add
        Returns:
        this
      • add

        public Vector2i add​(int x,
                            int y,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Increment the components of this vector by the given values and store the result in dest.
        Specified by:
        add in interface Vector2ic
        Parameters:
        x - the x component to add
        y - the y component to add
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2i mul​(int scalar)
        Multiply all components of this Vector2i by the given scalar value.
        Parameters:
        scalar - the scalar to multiply this vector by
        Returns:
        this
      • mul

        public Vector2i mul​(int scalar,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Multiply all components of this Vector2ic by the given scalar value and store the result in dest.
        Specified by:
        mul in interface Vector2ic
        Parameters:
        scalar - the scalar to multiply this vector by
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2i mul​(Vector2ic v)
        Add the supplied vector by this one.
        Parameters:
        v - the vector to multiply
        Returns:
        this
      • mul

        public Vector2i mul​(Vector2ic v,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Multiply the supplied vector by this one and store the result in dest.
        Specified by:
        mul in interface Vector2ic
        Parameters:
        v - the vector to multiply
        dest - will hold the result
        Returns:
        dest
      • mul

        public Vector2i mul​(int x,
                            int y)
        Multiply the components of this vector by the given values.
        Parameters:
        x - the x component to multiply
        y - the y component to multiply
        Returns:
        this
      • mul

        public Vector2i mul​(int x,
                            int y,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Multiply the components of this vector by the given values and store the result in dest.
        Specified by:
        mul in interface Vector2ic
        Parameters:
        x - the x component to multiply
        y - the y component to multiply
        dest - will hold the result
        Returns:
        dest
      • div

        public Vector2i div​(float scalar)
        Divide all components of this Vector2i by the given scalar value.
        Parameters:
        scalar - the scalar to divide by
        Returns:
        a vector holding the result
      • div

        public Vector2i div​(float scalar,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Divide all components of this Vector2i by the given scalar value and store the result in dest.
        Specified by:
        div in interface Vector2ic
        Parameters:
        scalar - the scalar to divide by
        dest - will hold the result
        Returns:
        dest
      • div

        public Vector2i div​(int scalar)
        Divide all components of this Vector2i by the given scalar value.
        Parameters:
        scalar - the scalar to divide by
        Returns:
        a vector holding the result
      • div

        public Vector2i div​(int scalar,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Divide all components of this Vector2i by the given scalar value and store the result in dest.
        Specified by:
        div in interface Vector2ic
        Parameters:
        scalar - the scalar to divide by
        dest - will hold the result
        Returns:
        dest
      • zero

        public Vector2i zero​()
        Set all components to zero.
        Returns:
        this
      • negate

        public Vector2i negate​()
        Negate this vector.
        Returns:
        this
      • negate

        public Vector2i negate​(Vector2i dest)
        Description copied from interface: Vector2ic
        Negate this vector and store the result in dest.
        Specified by:
        negate in interface Vector2ic
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • min

        public Vector2i min​(Vector2ic v)
        Set the components of this vector to be the component-wise minimum of this and the other vector.
        Parameters:
        v - the other vector
        Returns:
        this
      • min

        public Vector2i min​(Vector2ic v,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Set the components of dest to be the component-wise minimum of this and the other vector.
        Specified by:
        min in interface Vector2ic
        Parameters:
        v - the other vector
        dest - will hold the result
        Returns:
        dest
      • max

        public Vector2i max​(Vector2ic v)
        Set the components of this vector to be the component-wise maximum of this and the other vector.
        Parameters:
        v - the other vector
        Returns:
        this
      • max

        public Vector2i max​(Vector2ic v,
                            Vector2i dest)
        Description copied from interface: Vector2ic
        Set the components of dest to be the component-wise maximum of this and the other vector.
        Specified by:
        max in interface Vector2ic
        Parameters:
        v - the other vector
        dest - will hold the result
        Returns:
        dest
      • maxComponent

        public int maxComponent​()
        Description copied from interface: Vector2ic
        Determine the component with the biggest absolute value.
        Specified by:
        maxComponent in interface Vector2ic
        Returns:
        the component index, within [0..1]
      • minComponent

        public int minComponent​()
        Description copied from interface: Vector2ic
        Determine the component with the smallest (towards zero) absolute value.
        Specified by:
        minComponent in interface Vector2ic
        Returns:
        the component index, within [0..1]
      • absolute

        public Vector2i absolute​()
        Set this vector's components to their respective absolute values.
        Returns:
        this
      • absolute

        public Vector2i absolute​(Vector2i dest)
        Description copied from interface: Vector2ic
        Compute the absolute of each of this vector's components and store the result into dest.
        Specified by:
        absolute in interface Vector2ic
        Parameters:
        dest - will hold the result
        Returns:
        dest
      • hashCode

        public int hashCode​()
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(int x,
                              int y)
        Description copied from interface: Vector2ic
        Compare the vector components of this vector with the given (x, y) and return whether all of them are equal.
        Specified by:
        equals in interface Vector2ic
        Parameters:
        x - the x component to compare to
        y - the y component to compare to
        Returns:
        true if all the vector components are equal
      • toString

        public String toString​()
        Return a string representation of this vector.

        This method creates a new DecimalFormat on every invocation with the format string "0.000E0;-".

        Overrides:
        toString in class Object
        Returns:
        the string representation
      • toString

        public String toString​(NumberFormat formatter)
        Return a string representation of this vector by formatting the vector components with the given NumberFormat.
        Parameters:
        formatter - the NumberFormat used to format the vector components with
        Returns:
        the string representation