com.io7m.jtensors

## Class VectorI2I

- java.lang.Object
- - com.io7m.jtensors.VectorI2I

- All Implemented Interfaces:
    VectorReadable2IType

      public class VectorI2I
      extends Object
      implements VectorReadable2IType

  A two-dimensional immutable vector type with integer elements.

  Values of this type are immutable and can therefore be safely accessed from multiple threads.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static VectorI2I` | `ZERO` The zero vector.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `VectorI2I()` Default constructor, initializing the vector with values `[0, 0, 0]`.
    `VectorI2I(int in_x, int in_y)` Construct a vector initialized with the given values.
    `VectorI2I(VectorReadable2IType in_v)` Construct a vector initialized with the values given in the vector `v`.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static VectorI2I` | `absolute(VectorReadable2IType v)` Calculate the absolute values of the elements in vector `v`.
    `static VectorI2I` | `add(VectorReadable2IType v0, VectorReadable2IType v1)` Calculate the element-wise sum of the vectors `v0` and `v1`.
    `static VectorI2I` | `addScaled(VectorReadable2IType v0, VectorReadable2IType v1, double r)` Calculate the element-wise sum of the vectors `v0` and the element-wise product of `v1` and `r`.
    `static double` | `angle(VectorReadable2IType v0, VectorReadable2IType v1)` Calculate the angle between the vectors `v0` and `v1` in radians.
    `static VectorI2I` | `clamp(VectorReadable2IType v, int minimum, int maximum)` Clamp the elements of the vector `v` to the range `[minimum ..`
    `static VectorI2I` | `clampByVector(VectorReadable2IType v, VectorReadable2IType minimum, VectorReadable2IType maximum)` Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `minimum` and `maximum`.
    `static VectorI2I` | `clampMaximum(VectorReadable2IType v, int maximum)` Clamp the elements of the vector `v` to the range `[-Infinity ..`
    `static VectorI2I` | `clampMaximumByVector(VectorReadable2IType v, VectorReadable2IType maximum)` Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `maximum`.
    `static VectorI2I` | `clampMinimum(VectorReadable2IType v, int minimum)` Clamp the elements of the vector `v` to the range `[minimum ..`
    `static VectorI2I` | `clampMinimumByVector(VectorReadable2IType v, VectorReadable2IType minimum)` Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `minimum`.
    `static int` | `distance(VectorReadable2IType v0, VectorReadable2IType v1)` Calculate the distance between the two vectors `v0` and `v1`.
    `static int` | `dotProduct(VectorReadable2IType v0, VectorReadable2IType v1)` Calculate the scalar product of the vectors `v0` and `v1`.
    `boolean` | `equals(Object obj)`
    `int` | `getXI()`
    `int` | `getYI()`
    `int` | `hashCode()`
    `static VectorI2I` | `interpolateLinear(VectorReadable2IType v0, VectorReadable2IType v1, double alpha)` Linearly interpolate between `v0` and `v1` by the amount `alpha`.
    `static int` | `magnitude(VectorReadable2IType v)` Calculate the magnitude of the vector `v`.
    `static int` | `magnitudeSquared(VectorReadable2IType v)` Calculate the squared magnitude of the vector `v`.
    `static VectorI2I` | `projection(VectorReadable2IType p, VectorReadable2IType q)` Calculate the projection of the vector `p` onto the vector `q`.
    `static VectorI2I` | `scale(VectorReadable2IType v, double r)` Scale the vector `v` by the scalar `r`.
    `static VectorI2I` | `subtract(VectorReadable2IType v0, VectorReadable2IType v1)` Subtract the vector `v1` from the vector `v0`.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### ZERO

          public static final VectorI2I ZERO

      The zero vector.

  - ### Constructor Detail

    - #### VectorI2I

          public VectorI2I()

      Default constructor, initializing the vector with values `[0, 0, 0]`.

    - #### VectorI2I

          public VectorI2I(int in_x,
                           int in_y)

      Construct a vector initialized with the given values.
      Parameters:
        `in_x` - The `x` value
        `in_y` - The `y` value

    - #### VectorI2I

          public VectorI2I(VectorReadable2IType in_v)

      Construct a vector initialized with the values given in the vector `v`.
      Parameters:
        `in_v` - The input vector

  - ### Method Detail

    - #### absolute

          public static final VectorI2I absolute(VectorReadable2IType v)
                                          throws ArithmeticException

      Calculate the absolute values of the elements in vector `v`.
      Parameters:
        `v` - The input vector
      Returns:
        `(abs v.x, abs v.y, abs v.z)`
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow
      Since:
        5.0.0

    - #### add

          public static final VectorI2I add(VectorReadable2IType v0,
                                            VectorReadable2IType v1)
                                     throws ArithmeticException

      Calculate the element-wise sum of the vectors `v0` and `v1`.
      Parameters:
        `v0` - The left input vector
        `v1` - The right input vector
      Returns:
        `(v0.x + v1.x, v0.y + v1.y)`
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow

    - #### addScaled

          public static final VectorI2I addScaled(VectorReadable2IType v0,
                                                  VectorReadable2IType v1,
                                                  double r)
                                           throws ArithmeticException

      Calculate the element-wise sum of the vectors `v0` and the element-wise product of `v1` and `r`.
      Parameters:
        `v0` - The left input vector
        `v1` - The right input vector
        `r` - The scaling value
      Returns:
        `(v0.x + (v1.x * r), v0.y + (v1.y * r))`
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow

    - #### angle

          public static final double angle(VectorReadable2IType v0,
                                           VectorReadable2IType v1)

      Calculate the angle between the vectors `v0` and `v1` in radians.
      Parameters:
        `v0` - The left input vector
        `v1` - The right input vector
      Returns:
        The angle between the two vectors, in radians.

    - #### clamp

          public static final VectorI2I clamp(VectorReadable2IType v,
                                              int minimum,
                                              int maximum)

      Clamp the elements of the vector `v` to the range `[minimum .. maximum]` inclusive.
      Parameters:
        `v` - The input vector
        `minimum` - The minimum allowed value
        `maximum` - The maximum allowed value
      Returns:
        A vector with both elements equal to at most `maximum` and at least `minimum`
      Since:
        5.0.0

    - #### clampByVector

          public static final VectorI2I clampByVector(VectorReadable2IType v,
                                                      VectorReadable2IType minimum,
                                                      VectorReadable2IType maximum)

      Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `minimum` and `maximum`.
      Parameters:
        `v` - The input vector
        `minimum` - The vector containing the minimum acceptable values
        `maximum` - The vector containing the maximum acceptable values
      Returns:
        `(min(max(v.x, minimum.x), maximum.x), min(max(v.y, minimum.y), maximum.y))`
      Since:
        5.0.0

    - #### clampMaximum

          public static final VectorI2I clampMaximum(VectorReadable2IType v,
                                                     int maximum)

      Clamp the elements of the vector `v` to the range `[-Infinity .. maximum]` inclusive.
      Parameters:
        `v` - The input vector
        `maximum` - The maximum allowed value
      Returns:
        A vector with both elements equal to at most `maximum`
      Since:
        5.0.0

    - #### clampMaximumByVector

          public static final VectorI2I clampMaximumByVector(VectorReadable2IType v,
                                                             VectorReadable2IType maximum)

      Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `maximum`.
      Parameters:
        `v` - The input vector
        `maximum` - The vector containing the maximum acceptable values
      Returns:
        `(min(v.x, maximum.x), min(v.y, maximum.y))`
      Since:
        5.0.0

    - #### clampMinimum

          public static final VectorI2I clampMinimum(VectorReadable2IType v,
                                                     int minimum)

      Clamp the elements of the vector `v` to the range `[minimum .. Infinity]` inclusive.
      Parameters:
        `v` - The input vector
        `minimum` - The minimum allowed value
      Returns:
        A vector with both elements equal to at least `minimum`
      Since:
        5.0.0

    - #### clampMinimumByVector

          public static final VectorI2I clampMinimumByVector(VectorReadable2IType v,
                                                             VectorReadable2IType minimum)

      Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `minimum`.
      Parameters:
        `v` - The input vector
        `minimum` - The vector containing the minimum acceptable values
      Returns:
        `(max(v.x, minimum.x), max(v.y, minimum.y))`
      Since:
        5.0.0

    - #### distance

          public static final int distance(VectorReadable2IType v0,
                                           VectorReadable2IType v1)
                                    throws ArithmeticException

      Calculate the distance between the two vectors `v0` and `v1`.
      Parameters:
        `v0` - The left input vector
        `v1` - The right input vector
      Returns:
        The distance between the two vectors.
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow
      Since:
        5.0.0

    - #### dotProduct

          public static final int dotProduct(VectorReadable2IType v0,
                                             VectorReadable2IType v1)
                                      throws ArithmeticException

      Calculate the scalar product of the vectors `v0` and `v1`.
      Parameters:
        `v0` - The left input vector
        `v1` - The right input vector
      Returns:
        The scalar product of the two vectors
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow
      Since:
        5.0.0

    - #### interpolateLinear

          public static final VectorI2I interpolateLinear(VectorReadable2IType v0,
                                                          VectorReadable2IType v1,
                                                          double alpha)
                                                   throws ArithmeticException

      Linearly interpolate between `v0` and `v1` by the amount `alpha`. The `alpha` parameter controls the degree of interpolation, such that:
      - `interpolateLinear(v0, v1, 0.0, r) -> r = v0`
      - `interpolateLinear(v0, v1, 1.0, r) -> r = v1`
      Parameters:
        `v0` - The left input vector.
        `v1` - The right input vector.
        `alpha` - The interpolation value, between `0.0` and `1.0`.
      Returns:
        `(1 - alpha) * v0 + alpha * v1`
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow.
      Since:
        5.0.0

    - #### magnitude

          public static final int magnitude(VectorReadable2IType v)
                                     throws ArithmeticException

      Calculate the magnitude of the vector `v`. Correspondingly, `magnitude(normalize(v)) == 1.0`.
      Parameters:
        `v` - The input vector
      Returns:
        The magnitude of the input vector
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow
      Since:
        5.0.0

    - #### magnitudeSquared

          public static final int magnitudeSquared(VectorReadable2IType v)
                                            throws ArithmeticException

      Calculate the squared magnitude of the vector `v`.
      Parameters:
        `v` - The input vector
      Returns:
        The squared magnitude of the input vector
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow
      Since:
        5.0.0

    - #### projection

          public static final VectorI2I projection(VectorReadable2IType p,
                                                   VectorReadable2IType q)
                                            throws ArithmeticException

      Calculate the projection of the vector `p` onto the vector `q`.
      Parameters:
        `p` - The left vector
        `q` - The right vector
      Returns:
        `((dotProduct p q) / magnitudeSquared q) * q`
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow
      Since:
        5.0.0

    - #### scale

          public static final VectorI2I scale(VectorReadable2IType v,
                                              double r)
                                       throws ArithmeticException

      Scale the vector `v` by the scalar `r`.
      Parameters:
        `v` - The input vector
        `r` - The scaling value
      Returns:
        `(v.x * r, v.y * r)`
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow

    - #### subtract

          public static final VectorI2I subtract(VectorReadable2IType v0,
                                                 VectorReadable2IType v1)
                                          throws ArithmeticException

      Subtract the vector `v1` from the vector `v0`.
      Parameters:
        `v0` - The left input vector
        `v1` - The right input vector
      Returns:
        `(v0.x - v1.x, v0.y - v1.y)`
      Throws:
        `ArithmeticException` - Iff an internal arithmetic operation causes an integer overflow

    - #### equals

          public final boolean equals(@Nullable
                                      Object obj)

      Overrides:
        `equals` in class `Object`

    - #### getXI

          public final int getXI()

      Specified by:
        `getXI` in interface `VectorReadable2IType`
      Returns:
        The X value of the given vector.

    - #### getYI

          public final int getYI()

      Specified by:
        `getYI` in interface `VectorReadable2IType`
      Returns:
        The Y value of the given vector.

    - #### hashCode

          public final int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public final String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2015 <code@io7m.com> http://io7m.com