Class Point2Int

java.lang.Object
com.github.yellowstonegames.grid.Point2Int
All Implemented Interfaces:
com.github.tommyettinger.crux.Point2<Point2Int>, com.github.tommyettinger.crux.PointN<Point2Int>, com.github.tommyettinger.crux.PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>, com.github.tommyettinger.ds.PrimitiveCollection<Integer>, com.github.tommyettinger.ds.PrimitiveCollection.OfInt, PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>

public class Point2Int extends Object implements com.github.tommyettinger.crux.Point2<Point2Int>, PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>, com.github.tommyettinger.ds.PrimitiveCollection.OfInt
A mutable 2D point with int components implementing Point2, PrimitiveCollection.OfInt, and PointNInt.
Contrast with Coord, which is immutable, stores values in a pool, and only allows short components. Coord, being immutable, works better as a key in hashed maps and sets.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.github.tommyettinger.ds.PrimitiveCollection

    com.github.tommyettinger.ds.PrimitiveCollection.OfBoolean, com.github.tommyettinger.ds.PrimitiveCollection.OfByte, com.github.tommyettinger.ds.PrimitiveCollection.OfChar, com.github.tommyettinger.ds.PrimitiveCollection.OfDouble, com.github.tommyettinger.ds.PrimitiveCollection.OfFloat, com.github.tommyettinger.ds.PrimitiveCollection.OfInt, com.github.tommyettinger.ds.PrimitiveCollection.OfLong, com.github.tommyettinger.ds.PrimitiveCollection.OfShort
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Point2Int(int x, int y)
     
    Point2Int(com.github.tommyettinger.crux.Point2<?> p)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(int c)
    Not supported; this collection is fixed-size.
    add(int x, int y)
     
    add(com.github.tommyettinger.crux.Point2<?> point)
     
    add(Point2Int point)
     
    addProduct(com.github.tommyettinger.crux.Point2<?> vec, float scalar)
     
    addProduct(com.github.tommyettinger.crux.Point2<?> vec, com.github.tommyettinger.crux.Point2<?> mulVec)
     
    clampEach(int min, int max)
    For each component, this clamps it between min and max, inclusive.
    clampLength(float min, float max)
     
    void
    Not supported; this collection is fixed-size.
    boolean
    contains(int c)
    Compares c with the components of this collection using ==; if any are considered equal, this returns true.
     
    cpy()
     
    float
    distance(com.github.tommyettinger.crux.Point2<?> point)
     
    int
    distanceSquared(com.github.tommyettinger.crux.Point2<?> point)
     
    div(Point2Int point)
     
    divide(float scalar)
     
    float
    dot(com.github.tommyettinger.crux.Point2<?> other)
     
    static float
    dot(com.github.tommyettinger.crux.Point2<?> a, com.github.tommyettinger.crux.Point2<?> b)
     
    int
    dst2(com.github.tommyettinger.crux.Point2<?> point)
     
    float
    dst2(Point2Int point)
     
    boolean
     
    boolean
    Returns true if this type of point uses float or double for its components, or false otherwise.
    Sets this Point2Int to the value represented by the specified string according to the format of toString().
    int
    get(int index)
    Gets the component at the specified index.
    int
     
    interpolate(com.github.tommyettinger.crux.Point2<?> target, float alpha, com.github.tommyettinger.digital.Interpolations.Interpolator interpolation)
    Calls PointNInt.lerp(PointN, float) with the alpha determined by the given interpolation.
    boolean
     
     
    float
     
    lerp(com.github.tommyettinger.crux.Point2<?> target, float alpha)
    Linear-interpolates from this point toward target, moving a distance proportional to alpha and changing this point in-place if possible.
    limit(float limit)
     
    limit2(float limit2)
     
    limitSquared(float limit2)
     
    minus(float scalar)
     
    mul(float scalar)
    Multiplies each component of this by the given scalar, in-place, and returns this.
    mul(float x, float y)
    Multiplies each component of this by the corresponding scalar, in-place, and returns this.
    mul(int scalar)
     
    mul(com.github.tommyettinger.crux.Point2<?> point)
     
    mul(Point2Int point)
     
    mulAdd(com.github.tommyettinger.crux.Point2<?> vec, float scalar)
     
    mulAdd(com.github.tommyettinger.crux.Point2<?> vec, com.github.tommyettinger.crux.Point2<?> mulVec)
     
    multiply(float scalar)
    Multiplies each component of this by the given scalar, in-place, and returns this.
    multiply(float x, float y)
    Multiplies each component of this by the corresponding scalar, in-place, and returns this.
    multiply(int scalar)
     
    multiply(com.github.tommyettinger.crux.Point2<?> point)
     
    nor()
     
     
    boolean
     
    plus(float scalar)
     
    boolean
    remove(int c)
    Not supported; this collection is fixed-size.
    scale(float scalar)
     
    scale(float x, float y)
     
    scale(com.github.tommyettinger.crux.Point2<?> point)
     
    scl(float scalar)
     
    scl(float x, float y)
     
    scl(int scalar)
     
    scl(com.github.tommyettinger.crux.Point2<?> point)
     
    scl(Point2Int point)
     
    set(float nextX, float nextY)
     
    set(int x, int y)
     
    set(com.github.tommyettinger.crux.Point2<?> point)
     
    set(Point2Int point)
     
    setAt(int index, int value)
    Sets the component at the specified index to the specified value.
    seti(int x, int y)
     
    setLength(float len)
     
    setLength2(float len2)
     
     
    int
     
    sub(int x, int y)
     
    sub(com.github.tommyettinger.crux.Point2<?> point)
     
    sub(Point2Int point)
     
    subtract(int x, int y)
     
    subtract(com.github.tommyettinger.crux.Point2<?> point)
     
    times(float scalar)
     
    Converts this Point2Int to a string in the format (x,y).
    float
    x()
     
    x(float next)
     
    int
    xi()
     
    xi(int next)
     
    float
    y()
     
    y(float next)
     
    int
    yi()
     
    yi(int next)
     

    Methods inherited from class Object

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

    Methods inherited from interface com.github.tommyettinger.crux.Point2

    rank

    Methods inherited from interface com.github.tommyettinger.crux.PointN

    dst, isUnit, isUnit, isZero, isZero, len, mutable

    Methods inherited from interface com.github.tommyettinger.ds.PrimitiveCollection.OfInt

    addAll, addAll, addAll, addAll, addDense, addDense, addLegible, addLegible, addVarargs, appendTo, appendTo, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, denseAppendTo, equalContents, first, forEach, removeAll, removeAll, removeAll, removeAll, removeEach, removeEach, removeEach, removeEach, removeIf, retainAll, retainAll, retainAll, toArray, toArray, toDenseString, toDenseString, toString, toString, toString
  • Field Details

    • x

      public int x
    • y

      public int y
  • Constructor Details

    • Point2Int

      public Point2Int()
    • Point2Int

      public Point2Int(int x, int y)
    • Point2Int

      public Point2Int(Point2Int p)
    • Point2Int

      public Point2Int(com.github.tommyettinger.crux.Point2<?> p)
  • Method Details

    • floatingPoint

      public boolean floatingPoint()
      Returns true if this type of point uses float or double for its components, or false otherwise. This always returns false.
      Specified by:
      floatingPoint in interface com.github.tommyettinger.crux.PointN<Point2Int>
      Specified by:
      floatingPoint in interface com.github.tommyettinger.crux.PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      floatingPoint in interface PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Returns:
      false
    • cpy

      public Point2Int cpy()
      Specified by:
      cpy in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • copy

      public Point2Int copy()
    • len2

      public float len2()
      Specified by:
      len2 in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • set

      public Point2Int set(Point2Int point)
      Specified by:
      set in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • set

      public Point2Int set(com.github.tommyettinger.crux.Point2<?> point)
    • plus

      public Point2Int plus(float scalar)
      Specified by:
      plus in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • minus

      public Point2Int minus(float scalar)
      Specified by:
      minus in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • times

      public Point2Int times(float scalar)
      Specified by:
      times in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • sub

      public Point2Int sub(Point2Int point)
      Specified by:
      sub in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • sub

      public Point2Int sub(com.github.tommyettinger.crux.Point2<?> point)
    • subtract

      public Point2Int subtract(com.github.tommyettinger.crux.Point2<?> point)
    • add

      public Point2Int add(Point2Int point)
      Specified by:
      add in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • add

      public Point2Int add(com.github.tommyettinger.crux.Point2<?> point)
    • scl

      public Point2Int scl(Point2Int point)
      Specified by:
      scl in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • scl

      public Point2Int scl(com.github.tommyettinger.crux.Point2<?> point)
    • scl

      public Point2Int scl(int scalar)
    • scale

      public Point2Int scale(com.github.tommyettinger.crux.Point2<?> point)
    • mul

      public Point2Int mul(Point2Int point)
    • mul

      public Point2Int mul(com.github.tommyettinger.crux.Point2<?> point)
    • mul

      public Point2Int mul(int scalar)
    • multiply

      public Point2Int multiply(int scalar)
    • multiply

      public Point2Int multiply(com.github.tommyettinger.crux.Point2<?> point)
    • dst2

      public float dst2(Point2Int point)
      Specified by:
      dst2 in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • dst2

      public int dst2(com.github.tommyettinger.crux.Point2<?> point)
    • distance

      public float distance(com.github.tommyettinger.crux.Point2<?> point)
    • distanceSquared

      public int distanceSquared(com.github.tommyettinger.crux.Point2<?> point)
    • setZero

      public Point2Int setZero()
      Specified by:
      setZero in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • x

      public float x()
      Specified by:
      x in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • x

      public Point2Int x(float next)
      Specified by:
      x in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • xi

      public int xi()
      Specified by:
      xi in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • xi

      public Point2Int xi(int next)
      Specified by:
      xi in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • seti

      public Point2Int seti(int x, int y)
      Specified by:
      seti in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • y

      public float y()
      Specified by:
      y in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • y

      public Point2Int y(float next)
      Specified by:
      y in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • yi

      public int yi()
      Specified by:
      yi in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • yi

      public Point2Int yi(int next)
      Specified by:
      yi in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • set

      public Point2Int set(float nextX, float nextY)
      Specified by:
      set in interface com.github.tommyettinger.crux.Point2<Point2Int>
    • set

      public Point2Int set(int x, int y)
    • nor

      public Point2Int nor()
      Specified by:
      nor in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • normalize

      public Point2Int normalize()
    • add

      public Point2Int add(int x, int y)
    • sub

      public Point2Int sub(int x, int y)
    • subtract

      public Point2Int subtract(int x, int y)
    • scl

      public Point2Int scl(float scalar)
    • scale

      public Point2Int scale(float scalar)
    • scl

      public Point2Int scl(float x, float y)
    • scale

      public Point2Int scale(float x, float y)
    • mul

      public Point2Int mul(float scalar)
      Multiplies each component of this by the given scalar, in-place, and returns this. This is an alias for scl(float).
      Parameters:
      scalar - a float that will be multiplied with each component
      Returns:
      this, for chaining
    • multiply

      public Point2Int multiply(float scalar)
      Multiplies each component of this by the given scalar, in-place, and returns this. This is an alias for scl(float).
      Parameters:
      scalar - a float that will be multiplied with each component
      Returns:
      this, for chaining
    • mul

      public Point2Int mul(float x, float y)
      Multiplies each component of this by the corresponding scalar, in-place, and returns this. This is an alias for scl(float, float).
      Parameters:
      x - a float that will be multiplied with x
      y - a float that will be multiplied with y
      Returns:
      this, for chaining
    • multiply

      public Point2Int multiply(float x, float y)
      Multiplies each component of this by the corresponding scalar, in-place, and returns this. This is an alias for scl(float, float).
      Parameters:
      x - a float that will be multiplied with x
      y - a float that will be multiplied with y
      Returns:
      this, for chaining
    • div

      public Point2Int div(Point2Int point)
      Specified by:
      div in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • divide

      public Point2Int divide(float scalar)
      Specified by:
      divide in interface com.github.tommyettinger.crux.PointN<Point2Int>
    • addProduct

      public Point2Int addProduct(com.github.tommyettinger.crux.Point2<?> vec, float scalar)
    • mulAdd

      public Point2Int mulAdd(com.github.tommyettinger.crux.Point2<?> vec, float scalar)
    • mulAdd

      public Point2Int mulAdd(com.github.tommyettinger.crux.Point2<?> vec, com.github.tommyettinger.crux.Point2<?> mulVec)
    • addProduct

      public Point2Int addProduct(com.github.tommyettinger.crux.Point2<?> vec, com.github.tommyettinger.crux.Point2<?> mulVec)
    • limit

      public Point2Int limit(float limit)
    • limit2

      public Point2Int limit2(float limit2)
    • limitSquared

      public Point2Int limitSquared(float limit2)
    • clampLength

      public Point2Int clampLength(float min, float max)
    • setLength

      public Point2Int setLength(float len)
    • setLength2

      public Point2Int setLength2(float len2)
    • dot

      public float dot(com.github.tommyettinger.crux.Point2<?> other)
    • dot

      public static float dot(com.github.tommyettinger.crux.Point2<?> a, com.github.tommyettinger.crux.Point2<?> b)
    • lerp

      public Point2Int lerp(com.github.tommyettinger.crux.Point2<?> target, float alpha)
      Description copied from interface: PointNInt
      Linear-interpolates from this point toward target, moving a distance proportional to alpha and changing this point in-place if possible. If this point is not PointN.mutable(), this will return a new or pooled point. The alpha is expected to be in the 0 to 1 range, inclusive.
      Specified by:
      lerp in interface com.github.tommyettinger.crux.PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      lerp in interface PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Parameters:
      target - any point with the same dimension to move toward
      alpha - between 0 and 1, inclusive
      Returns:
      this point after modifications, if possible, or a new PointNInt if this is immutable
    • interpolate

      public Point2Int interpolate(com.github.tommyettinger.crux.Point2<?> target, float alpha, com.github.tommyettinger.digital.Interpolations.Interpolator interpolation)
      Description copied from interface: PointNInt
      Calls PointNInt.lerp(PointN, float) with the alpha determined by the given interpolation. Simply returns lerp(target, interpolation.apply(alpha)) .
      Specified by:
      interpolate in interface PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Parameters:
      target - any point with the same dimension to move toward
      alpha - between 0 and 1, inclusive
      interpolation - an Interpolator from digital, such as Interpolations.smooth
      Returns:
      this point after modifications, if possible, or a new PointNInt if this is immutable
    • clampEach

      public Point2Int clampEach(int min, int max)
      For each component, this clamps it between min and max, inclusive.
      Parameters:
      min - the minimum value allowable for any component, inclusive
      max - the maximum value allowable for any component, inclusive
      Returns:
      this, after modifications
    • get

      public int get(int index)
      Gets the component at the specified index. Kotlin-compatible using square-bracket indexing.
      Specified by:
      get in interface com.github.tommyettinger.crux.PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      get in interface PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Parameters:
      index - which component to get, in order
      Returns:
      the component
    • setAt

      public Point2Int setAt(int index, int value)
      Sets the component at the specified index to the specified value.
      Specified by:
      setAt in interface com.github.tommyettinger.crux.PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Specified by:
      setAt in interface PointNInt<Point2Int, com.github.tommyettinger.crux.Point2<?>>
      Parameters:
      index - which component to set, in order
      value - the value to assign at index
      Returns:
      this, for chaining
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface com.github.tommyettinger.ds.PrimitiveCollection<Integer>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface com.github.tommyettinger.ds.PrimitiveCollection<Integer>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Converts this Point2Int to a string in the format (x,y).
      Overrides:
      toString in class Object
      Returns:
      a string representation of this object.
    • fromString

      public Point2Int fromString(String s)
      Sets this Point2Int to the value represented by the specified string according to the format of toString().
      Parameters:
      s - the string.
      Returns:
      this point for chaining
    • add

      public boolean add(int c)
      Not supported; this collection is fixed-size.
      Specified by:
      add in interface com.github.tommyettinger.ds.PrimitiveCollection.OfInt
      Parameters:
      c - ignored
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - always
    • remove

      public boolean remove(int c)
      Not supported; this collection is fixed-size.
      Specified by:
      remove in interface com.github.tommyettinger.ds.PrimitiveCollection.OfInt
      Parameters:
      c - ignored
      Returns:
      never returns
      Throws:
      UnsupportedOperationException - always
    • clear

      public void clear()
      Not supported; this collection is fixed-size.
      Specified by:
      clear in interface com.github.tommyettinger.ds.PrimitiveCollection<Integer>
      Throws:
      UnsupportedOperationException - always
    • contains

      public boolean contains(int c)
      Compares c with the components of this collection using ==; if any are considered equal, this returns true.
      Specified by:
      contains in interface com.github.tommyettinger.ds.PrimitiveCollection.OfInt
      Parameters:
      c - an int to be compared using ==
      Returns:
      true if any component of this collection is equal to c via == comparison
    • size

      public int size()
      Specified by:
      size in interface com.github.tommyettinger.ds.PrimitiveCollection<Integer>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface com.github.tommyettinger.ds.PrimitiveCollection<Integer>
    • notEmpty

      public boolean notEmpty()
      Specified by:
      notEmpty in interface com.github.tommyettinger.ds.PrimitiveCollection<Integer>
    • iterator

      public PointNIntIterator iterator()
      Specified by:
      iterator in interface com.github.tommyettinger.ds.PrimitiveCollection<Integer>
      Specified by:
      iterator in interface com.github.tommyettinger.ds.PrimitiveCollection.OfInt