com.io7m.jtensors

## Class VectorI2D

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

- All Implemented Interfaces:
    VectorReadable2DType

      public class VectorI2D
      extends Object
      implements VectorReadable2DType

  A two-dimensional immutable vector type with double precision 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 VectorI2D` | `ZERO` The zero vector.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `VectorI2D()` Default constructor, initializing the vector with values `[0.0, 0.0, 0.0]`.
    `VectorI2D(double in_x, double in_y)` Construct a vector initialized with the given values.
    `VectorI2D(VectorReadable2DType 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 VectorI2D` | `absolute(VectorReadable2DType v)` Calculate the absolute value of the vector `v`.
    `static VectorI2D` | `add(VectorReadable2DType v0, VectorReadable2DType v1)` Calculate the element-wise sum of the vectors `v0` and `v1`.
    `static VectorI2D` | `addScaled(VectorReadable2DType v0, VectorReadable2DType v1, double r)` Calculate the element-wise sum of the vectors `v0` and the element-wise product of `v1` and `r`.
    `static boolean` | `almostEqual(com.io7m.jequality.AlmostEqualDouble.ContextRelative context, VectorReadable2DType qa, VectorReadable2DType qb)` Determine whether or not the vectors `qa` and `qb` are equal to within the degree of error given in `context`.
    `static double` | `angle(VectorReadable2DType v0, VectorReadable2DType v1)` Calculate the angle between the vectors `v0` and `v1` in radians.
    `static VectorI2D` | `clamp(VectorReadable2DType v, double minimum, double maximum)` Clamp the elements of the vector `v` to the range `[minimum ..`
    `static VectorI2D` | `clampByVector(VectorReadable2DType v, VectorReadable2DType minimum, VectorReadable2DType maximum)` Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `minimum` and `maximum`.
    `static VectorI2D` | `clampMaximum(VectorReadable2DType v, double maximum)` Clamp the elements of the vector `v` to the range `[-Infinity ..`
    `static VectorI2D` | `clampMaximumByVector(VectorReadable2DType v, VectorReadable2DType maximum)` Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `maximum`.
    `static VectorI2D` | `clampMinimum(VectorReadable2DType v, double minimum)` Clamp the elements of the vector `v` to the range `[minimum ..`
    `static VectorI2D` | `clampMinimumByVector(VectorReadable2DType v, VectorReadable2DType minimum)` Clamp the elements of the vector `v` to the inclusive range given by the corresponding elements in `minimum`.
    `static double` | `distance(VectorReadable2DType v0, VectorReadable2DType v1)` Calculate the distance between the two vectors `v0` and `v1`.
    `static double` | `dotProduct(VectorReadable2DType v0, VectorReadable2DType v1)` Calculate the scalar product of the vectors `v0` and `v1`.
    `boolean` | `equals(Object obj)`
    `double` | `getXD()`
    `double` | `getYD()`
    `int` | `hashCode()`
    `static VectorI2D` | `interpolateLinear(VectorReadable2DType v0, VectorReadable2DType v1, double alpha)` Linearly interpolate between `v0` and `v1` by the amount `alpha`.
    `static double` | `magnitude(VectorReadable2DType v)` Calculate the magnitude of the vector `v`.
    `static double` | `magnitudeSquared(VectorReadable2DType v)` Calculate the squared magnitude of the vector `v`.
    `static VectorI2D` | `normalize(VectorReadable2DType v)` Normalize the vector `v`, preserving its direction but reducing it to unit length.
    `static com.io7m.jfunctional.Pair<VectorI2D,VectorI2D>` | `orthoNormalize(VectorReadable2DType v0, VectorReadable2DType v1)` Orthonormalize and return the vectors `v0` and `v1` .
    `static VectorI2D` | `projection(VectorReadable2DType p, VectorReadable2DType q)` Calculate the projection of the vector `p` onto the vector `q`.
    `static VectorI2D` | `scale(VectorReadable2DType v, double r)` Scale the vector `v` by the scalar `r`.
    `static VectorI2D` | `subtract(VectorReadable2DType v0, VectorReadable2DType 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 VectorI2D ZERO

      The zero vector.

  - ### Constructor Detail

    - #### VectorI2D

          public VectorI2D()

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

    - #### VectorI2D

          public VectorI2D(double in_x,
                           double in_y)

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

    - #### VectorI2D

          public VectorI2D(VectorReadable2DType 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 VectorI2D absolute(VectorReadable2DType v)

      Calculate the absolute value of the vector `v`.
      Parameters:
        `v` - The input vector
      Returns:
        `(abs v.x, abs v.y)`

    - #### add

          public static final VectorI2D add(VectorReadable2DType v0,
                                            VectorReadable2DType v1)

      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)`

    - #### addScaled

          public static final VectorI2D addScaled(VectorReadable2DType v0,
                                                  VectorReadable2DType v1,
                                                  double r)

      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))`

    - #### almostEqual

          public static final boolean almostEqual(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
                                                  VectorReadable2DType qa,
                                                  VectorReadable2DType qb)

      Determine whether or not the vectors `qa` and `qb` are equal to within the degree of error given in `context`.
      Parameters:
        `context` - The equality context
        `qa` - The left input vector
        `qb` - The right input vector
      Returns:
        `true` iff the vectors are almost equal.
      Since:
        5.0.0
      See Also:
        `AlmostEqualDouble.almostEqual(ContextRelative, double, double)`

    - #### angle

          public static final double angle(VectorReadable2DType v0,
                                           VectorReadable2DType 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 VectorI2D clamp(VectorReadable2DType v,
                                              double minimum,
                                              double 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`.

    - #### clampByVector

          public static final VectorI2D clampByVector(VectorReadable2DType v,
                                                      VectorReadable2DType minimum,
                                                      VectorReadable2DType 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))`

    - #### clampMaximum

          public static final VectorI2D clampMaximum(VectorReadable2DType v,
                                                     double 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`

    - #### clampMaximumByVector

          public static final VectorI2D clampMaximumByVector(VectorReadable2DType v,
                                                             VectorReadable2DType 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))`

    - #### clampMinimum

          public static final VectorI2D clampMinimum(VectorReadable2DType v,
                                                     double 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`

    - #### clampMinimumByVector

          public static final VectorI2D clampMinimumByVector(VectorReadable2DType v,
                                                             VectorReadable2DType 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), max(v.z, minimum.z))`

    - #### distance

          public static final double distance(VectorReadable2DType v0,
                                              VectorReadable2DType v1)

      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

    - #### dotProduct

          public static final double dotProduct(VectorReadable2DType v0,
                                                VectorReadable2DType v1)

      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

    - #### interpolateLinear

          public static final VectorI2D interpolateLinear(VectorReadable2DType v0,
                                                          VectorReadable2DType v1,
                                                          double alpha)

      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) = v0`
      - `interpolateLinear(v0, v1, 1.0) = 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`

    - #### magnitude

          public static final double magnitude(VectorReadable2DType v)

      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

    - #### magnitudeSquared

          public static final double magnitudeSquared(VectorReadable2DType v)

      Calculate the squared magnitude of the vector `v`.
      Parameters:
        `v` - The input vector
      Returns:
        The squared magnitude of the input vector

    - #### normalize

          public static final VectorI2D normalize(VectorReadable2DType v)

      Normalize the vector `v`, preserving its direction but reducing it to unit length.
      Parameters:
        `v` - The input vector
      Returns:
        A vector with the same orientation as `v` but with magnitude equal to `1.0`

    - #### orthoNormalize

          public static final com.io7m.jfunctional.Pair<VectorI2D,VectorI2D> orthoNormalize(VectorReadable2DType v0,
                                                                                            VectorReadable2DType v1)

      Orthonormalize and return the vectors `v0` and `v1` .

      See GSP

      Parameters:
        `v0` - The left vector
        `v1` - The right vector
      Returns:
        A pair `(v0, v1)`, orthonormalized.
      Since:
        5.0.0

    - #### projection

          public static final VectorI2D projection(VectorReadable2DType p,
                                                   VectorReadable2DType q)

      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`

    - #### scale

          public static final VectorI2D scale(VectorReadable2DType v,
                                              double r)

      Scale the vector `v` by the scalar `r`.
      Parameters:
        `v` - The input vector
        `r` - The scaling value
      Returns:
        `(v.x * r, v.y * r)`

    - #### subtract

          public static final VectorI2D subtract(VectorReadable2DType v0,
                                                 VectorReadable2DType v1)

      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)`

    - #### equals

          public final boolean equals(@Nullable
                                      Object obj)

      Overrides:
        `equals` in class `Object`

    - #### getXD

          public final double getXD()

      Specified by:
        `getXD` in interface `VectorReadable2DType`
      Returns:
        The X value of the given vector.

    - #### getYD

          public final double getYD()

      Specified by:
        `getYD` in interface `VectorReadable2DType`
      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